00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _LUXRAYS_BVHACCEL_H
00023 #define _LUXRAYS_BVHACCEL_H
00024
00025 #include <vector>
00026
00027 #include "luxrays/luxrays.h"
00028 #include "luxrays/core/acceleretor.h"
00029
00030 namespace luxrays {
00031
00032 struct BVHAccelTreeNode {
00033 BBox bbox;
00034 unsigned int primitive;
00035 BVHAccelTreeNode *leftChild;
00036 BVHAccelTreeNode *rightSibling;
00037 };
00038
00039 struct BVHAccelArrayNode {
00040 BBox bbox;
00041 unsigned int primitive;
00042 unsigned int skipIndex;
00043 };
00044
00045
00046 class BVHAccel : public Accelerator {
00047 public:
00048
00049 BVHAccel(const Context *context,
00050 const unsigned int treetype, const int csamples, const int icost,
00051 const int tcost, const float ebonus);
00052 ~BVHAccel();
00053
00054 AcceleratorType GetType() const { return ACCEL_BVH; }
00055 void Init(const std::deque<Mesh *> &meshes, const unsigned int totalVertexCount,
00056 const unsigned int totalTriangleCount);
00057
00058 const TriangleMeshID GetMeshID(const unsigned int index) const { return preprocessedMeshIDs[index]; }
00059 const TriangleMeshID *GetMeshIDTable() const { return preprocessedMeshIDs; }
00060 const TriangleID GetMeshTriangleID(const unsigned int index) const { return preprocessedMeshTriangleIDs[index]; }
00061 const TriangleID *GetMeshTriangleIDTable() const { return preprocessedMeshTriangleIDs; }
00062
00063 bool Intersect(const Ray *ray, RayHit *hit) const;
00064
00065 const TriangleMesh *GetPreprocessedMesh() const { return preprocessedMesh; }
00066
00067 friend class OpenCLIntersectionDevice;
00068
00069 private:
00070
00071 BVHAccelTreeNode *BuildHierarchy(std::vector<BVHAccelTreeNode *> &list, unsigned int begin, unsigned int end, unsigned int axis);
00072 void FindBestSplit(std::vector<BVHAccelTreeNode *> &list, unsigned int begin, unsigned int end, float *splitValue, unsigned int *bestAxis);
00073 unsigned int BuildArray(BVHAccelTreeNode *node, unsigned int offset);
00074 void FreeHierarchy(BVHAccelTreeNode *node);
00075
00076 unsigned int treeType;
00077 int costSamples, isectCost, traversalCost;
00078 float emptyBonus;
00079 unsigned int nNodes;
00080 BVHAccelArrayNode *bvhTree;
00081
00082 const Context *ctx;
00083 TriangleMesh *preprocessedMesh;
00084 TriangleMeshID *preprocessedMeshIDs;
00085 TriangleID *preprocessedMeshTriangleIDs;
00086
00087 bool initialized;
00088 };
00089
00090 }
00091
00092 #endif