00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __TS_Octree_H__
00022 #define __TS_Octree_H__
00023
00024 #include "TS_API.h"
00025 #include <UT/UT_RefArray.h>
00026 #include <UT/UT_BoundingBox.h>
00027 #include "TS_Expression.h"
00028 #include "TS_Primitive.h"
00029
00030 #define TS_OCTREE_INITIALIZED 1 // Normal octree intersect
00031 #define TS_OCTREE_DOFAST 2 // For small octrees (1 deep)
00032
00033
00034
00035
00036
00037
00038 class TS_API TS_OctreeVoxel {
00039 public:
00040 TS_OctreeVoxel();
00041 ~TS_OctreeVoxel();
00042
00043 TS_OctreeVoxel *myKids[2];
00044 TS_ExpressionList myList;
00045 unsigned myAxis;
00046 float myAvg;
00047 UT_BoundingBox myBBox;
00048
00049 float xmin() const { return myBBox(0, 0); }
00050 float xmax() const { return myBBox(0, 1); }
00051 float ymin() const { return myBBox(1, 0); }
00052 float ymax() const { return myBBox(1, 1); }
00053 float zmin() const { return myBBox(2, 0); }
00054 float zmax() const { return myBBox(2, 1); }
00055 TS_OctreeVoxel *left() { return myKids[0]; }
00056 TS_OctreeVoxel *right() { return myKids[1]; }
00057
00058 void addThing(TS_MetaPrimitive *object);
00059
00060 void subdivide(const TS_ExpressionList &nodes,
00061 unsigned maxEntries, unsigned level);
00062 private:
00063 void bestSplit(unsigned maxEntries,
00064 const TS_ExpressionList &nodes);
00065 void getKids(TS_ExpressionList &kids,
00066 const TS_ExpressionList &nodes,
00067 int left = 1);
00068 };
00069
00070
00071
00072
00073
00074 class TS_API TS_OctreeStack {
00075 public:
00076 TS_OctreeVoxel *myVoxel;
00077 float myMin, myMax;
00078
00079 TS_OctreeStack &operator=(const TS_OctreeStack &d)
00080 {
00081 myVoxel = d.myVoxel;
00082 myMin = d.myMin;
00083 myMax = d.myMax;
00084 return *this;
00085 }
00086 unsigned operator==(const TS_OctreeStack &) const
00087 {
00088 return 0;
00089 }
00090 };
00091
00092
00093
00094
00095 class TS_API TS_Octree {
00096 public:
00097 TS_Octree();
00098 TS_Octree(const TS_MetaExpression *e);
00099 virtual ~TS_Octree();
00100
00101 void setSweepList(const TS_Ray &ray, TS_SweepList &sweep,
00102 fpreal tmin=0, fpreal tmax=1e20);
00103 TS_OctreeVoxel *findVoxel(const UT_Vector3 &P) const;
00104
00105 protected:
00106 virtual int buildMe();
00107
00108 TS_OctreeVoxel *myHead;
00109 unsigned myMaxLevel;
00110
00111 private:
00112 UT_RefArray<TS_OctreeStack> myStack;
00113 const TS_MetaExpression *myOwner;
00114 unsigned myStackPtr;
00115 };
00116
00117 #endif