16 #ifndef KDTREEACCELERATOR_H
17 #define KDTREEACCELERATOR_H
32 return ((
int)(
flag & 3)) == 3;
36 return ((
int)(
flag & 3)) < 3;
62 void createLeaf(
unsigned int _nbPrims,
unsigned int _firstIndex,
63 unsigned int* _prims);
64 void createNode(
int axis,
float _split,
unsigned int nextChild);
162 virtual bool build();
202 void generateMidKdTree(
int currentProfondeur,
BBox& localBox,
unsigned int nbPrims,
unsigned int* prims);
205 unsigned int nbPrims,
unsigned int* prims);
Base class for accelerators.
Definition of a bounding box which is aligned along the axis (BBox AABB).
K-d tree Accelerator (based on space splitting)
int realMaxProfondeur
Real max depth.
std::vector< BBox > & getBBox()
Get the vector of bounding boxes.
std::vector< BBox > tableBox
Bounding boxes list of the tree.
void setMaxPrimPerLeaf(int _maxPrimPerLeaf)
Set maximal primitives per leaf.
int getMaxPrimPerLeaf()
Get maximal primitives per leaf.
float emptyBonus
Parameter for best splitting.
virtual decimal traverse(Ray *r, std::list< Intersection > &result) const
Run this accelerator.
void generateSAHKdTree(int currentProfondeur, BBox &localBox, TaBRecBoundEdge *edges[3], unsigned int nbPrims, unsigned int *prims)
Generate the tree with SAH (Surface Area Heuristic) method.
int maxPrimPerLeaf
Maximal primitives per leaf.
virtual ~KdtreeAccelerator()
Destructor.
float isectCost
Parameter for best splitting.
KdtreeAccelerator(std::vector< Shape * > *_initialMesh=NULL, BBox _globalBox=BBox())
Constructor.
int getMaxProfondeur()
Get maximal depth.
void setMaxProfondeur(int _maxProfondeur)
Set maximal depth.
std::vector< Shape * > * initialMesh
Pointer to the mesh.
float traversalCost
Parameter for best splitting.
int maxProfondeur
Maximal depth.
bool alreadyFail
Unused attribute.
virtual bool build()
Build this accelerator.
void generateMidKdTree(int currentProfondeur, BBox &localBox, unsigned int nbPrims, unsigned int *prims)
Generate the tree by middle subdivision.
void print()
Print the tree (not implemented yet)
unsigned int nbFail
Unused attribute.
std::vector< InfoPrim > tablePrimitive
List of primitives and their bounding box.
bool trace
Unused attribute.
std::vector< KDNode > tableNode
: Describes a ray by a pair of unsigned int. The first one gives the source number (in the range 0-40...
Stack structure for the k-d tree. Optimized storage for the nodes.
float tmax
Left time from the node.
KDNode node
Next node to browser if fail happens.
float tmin
Entry time inside the node.
unsigned int pos
Position in the stack.
bool operator<(const TaBRecBoundEdge &e) const
TaBRecBoundEdge(float tt, int pn, bool starting)
Constructor.
TaBRecBoundEdge()
Default constructor.
enum TaBRecBoundEdge::@6 type
Node structure (optimized to be stored on 2 bytes)
unsigned int AboveChild()
Return second child.
int flag
0 : node, x axis, 1 : node, y axis, 2 : node, z axis, 3 : leaf. 2 bits used
unsigned int * prims
Leaf : array containing primitives indexes.
int getAxe()
Return the axis number of the separator plane (node)
unsigned int nbPrims
Leaf : number of primitives. Use 30 bits integer.
unsigned int secondChild
Node : the first child is just after current node, second one is further.
void createLeaf(unsigned int _nbPrims, unsigned int _firstIndex, unsigned int *_prims)
Leaf initialization.
bool isNode()
Return true if the node is a node.
unsigned int firstIndex
Leaf : index of the first primitive in the list.
float getAxeValue()
Return the axis value of the separator plane (node)
bool isLeaf()
Return true if the node is a leaf.
void createNode(int axis, float _split, unsigned int nextChild)
Node initialization.
unsigned int getFirstIndex()
Return the index of the first node primitive (all)
float split
Node : separator axis value.
unsigned int * getPrims()
Get the primitives.
unsigned int getNbPrimitives()
Return primitives number.