| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#ifndef _OCTREE_H_ |
| 30 |
#define _OCTREE_H_ |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#include <vector> |
| 36 |
#include "minivector.h" |
| 37 |
#include "boundingBox.h" |
| 38 |
#include "triangle.h" |
| 39 |
#include "simpleSphere.h" |
| 40 |
|
| 41 |
template<class TriangleClass> |
| 42 |
class Octree |
| 43 |
{ |
| 44 |
public: |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
Octree(int maxDepth=10, int depth=0); |
| 49 |
~Octree() { deallocate(); } |
| 50 |
|
| 51 |
bool build(std::vector<TriangleClass> & triangleList, BoundingBox & parentCube, int maxNumTriangles); |
| 52 |
|
| 53 |
|
| 54 |
bool build(std::vector<TriangleClass> & triangleList, int maxNumTriangles); |
| 55 |
void setBuildPrintInfo(int info); |
| 56 |
void getBuildInfo(int * numMaxDepthExceededCases, int * numMaxTriInDepthExceededCases); |
| 57 |
|
| 58 |
|
| 59 |
void buildCollisionList(std::vector<TriangleClass*> & triangleList, const SimpleSphere & simpleSphere); |
| 60 |
void buildCollisionList(std::vector<TriangleClass*> & triangleList, const Vec3d & segmentStartPoint, const Vec3d & segmentEndPoint, std::vector<Vec3d> * intersectionList = NULL); |
| 61 |
|
| 62 |
void render(); |
| 63 |
void render(int level); |
| 64 |
void render(int level, int boxIndex); |
| 65 |
void setRenderInfo(int info) { printRenderInfo = info; } |
| 66 |
|
| 67 |
int getDepth(); |
| 68 |
BoundingBox getBoundingBox() { return boundingBox; } |
| 69 |
|
| 70 |
protected: |
| 71 |
|
| 72 |
void deallocate(); |
| 73 |
void createChildCubes(BoundingBox * childCubeBoxes); |
| 74 |
|
| 75 |
BoundingBox boundingBox; |
| 76 |
Octree * childrenNodes[8]; |
| 77 |
|
| 78 |
int maxDepth; |
| 79 |
int depth; |
| 80 |
|
| 81 |
void renderHelper(int level, int boxIndex); |
| 82 |
static int renderCounter; |
| 83 |
static int printRenderInfo; |
| 84 |
|
| 85 |
std::vector<TriangleClass> triangles; |
| 86 |
|
| 87 |
static int buildPrintInfo; |
| 88 |
static int numMaxDepthExceededCases; |
| 89 |
static int numMaxTriInDepthExceededCases; |
| 90 |
}; |
| 91 |
|
| 92 |
template<class TriangleClass> |
| 93 |
inline void Octree<TriangleClass>::getBuildInfo(int * numMaxDepthExceededCases, int * numMaxTriInDepthExceededCases) |
| 94 |
{ |
| 95 |
*numMaxDepthExceededCases = this->numMaxDepthExceededCases; |
| 96 |
*numMaxTriInDepthExceededCases = this->numMaxTriInDepthExceededCases; |
| 97 |
} |
| 98 |
|
| 99 |
template<class TriangleClass> |
| 100 |
inline void Octree<TriangleClass>::setBuildPrintInfo(int info) |
| 101 |
{ |
| 102 |
buildPrintInfo = info; |
| 103 |
if (info == 1) |
| 104 |
{ |
| 105 |
numMaxDepthExceededCases = 0; |
| 106 |
numMaxTriInDepthExceededCases = 0; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
#endif |
| 111 |
|