23 for (
unsigned int i = 0; i < _initialMesh->size(); i++)
32 for (uint32_t i = 0; i <
primitives.size(); ++i)
40 float invMaxWidth = 1.f / delta[maxAxis];
41 float cubeRoot = 3.f * powf(
float(
primitives.size()), 1.f / 3.f);
42 float voxelsPerUnitDist = cubeRoot * invMaxWidth;
43 for (
int axis = 0; axis < 3; ++axis)
50 for (
int axis = 0; axis < 3; ++axis)
58 for (uint32_t i = 0; i <
primitives.size(); ++i)
63 for (
int axis = 0; axis < 3; ++axis)
70 for (
int z = vmin[2]; z <= vmax[2]; ++z)
71 for (
int y = vmin[1]; y <= vmax[1]; ++y)
72 for (
int x = vmin[0]; x <= vmax[0]; ++x)
108 float NextCrossingT[3], DeltaT[3];
109 int Step[3], Out[3], Pos[3];
110 for (
int axis = 0; axis < 3; ++axis)
117 NextCrossingT[axis] =
126 NextCrossingT[axis] =
147 int bits = ((NextCrossingT[0] < NextCrossingT[1]) << 2) +
148 ((NextCrossingT[0] < NextCrossingT[2]) << 1) + ((NextCrossingT[1] < NextCrossingT[2]));
149 const int cmpToAxis[8] = {2, 1, 2, 1, 2, 2, 0, 0};
150 int stepAxis = cmpToAxis[bits];
151 if (r->
getMaxt() < NextCrossingT[stepAxis])
155 Pos[stepAxis] += Step[stepAxis];
156 if (Pos[stepAxis] == Out[stepAxis])
160 NextCrossingT[stepAxis] += DeltaT[stepAxis];
170 bool hitSomething =
false;
172 for (uint32_t i = 0; i <
primitives.size(); ++i)
176 if (prim->
getIntersection(*ray, currentIntersection) && currentIntersection.
t > 0.0001)
179 result.push_back(currentIntersection);
Base class for accelerators.
leafTreatment::treatment intersectionChoice
Intersection choice.
Definition of a bounding box which is aligned along the axis (BBox AABB).
vec3 pMax
Upper point of the BBox.
bool IntersectP(vec3 rayPos, vec3 rayDir, decimal *hitt0=NULL, decimal *hitt1=NULL) const
Compute the intersection between a Ray and this BBox.
BBox Union(const BBox &b, const vec3 &p)
Union of a point and a BBox. A new BBox is created.
bool Inside(const vec3 &pt) const
Return true if the point pt is inside the BBox.
vec3 pMin
Lower point of the BBox.
int MaximumExtend() const
Return the index of the dominant direction (maximal dimension). Index is 0 for x, 1 for y,...
GridAccelerator(std::vector< Shape * > *_initialMesh=NULL, BBox _globalBox=BBox())
Constructor.
int offset(int x, int y, int z) const
virtual decimal traverse(Ray *r, std::list< Intersection > &result) const
Run this accelerator.
std::vector< Shape * > primitives
Pointer to all the shapes (different from initialMesh) as it is reordered.
int posToVoxel(const vec3 &P, int axis) const
virtual bool build()
Build this accelerator.
float voxelToPos(int p, int axis) const
: Describes a ray by a pair of unsigned int. The first one gives the source number (in the range 0-40...
decimal getMaxt() const
Return maxt.
decimal getMint() const
Return mint.
vec3 getPosition() const
Return starting point ray.
vec3 getDirection() const
Return direction of the ray.
base class for shapes (Cylindre, Mesh, Sphere, Triangle,...)
virtual bool getIntersection(Ray &ray, Intersection &inter)
Get the Intersection between a ray and this shape.
float Clamp(float val, float low, float high)
base_vec3< decimal > vec3
decimal keepFunction(treatment choice, std::list< Intersection > ¤tIntersections, decimal currentTmin)
std::vector< Shape * > primitives
Vector containing the primitives.
void AddPrimitive(Shape *prim)
bool Intersect(Ray *ray, std::list< Intersection > &result, decimal &intermin, leafTreatment::treatment choice)