00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __BV_KDOPTree_h__
00016 #define __BV_KDOPTree_h__
00017
00018 #include "BV_API.h"
00019 #include "BV_Tree.h"
00020
00021 class UT_IStream;
00022
00023 template <class T>
00024 class UT_RefArray;
00025
00026
00027 template <int K>
00028 class BV_API BV_KDOPNode
00029 {
00030 public:
00031 BV_KDOPNode(int leafId = -1);
00032 BV_KDOPNode(const BV_KDOPNode &rhs);
00033 ~BV_KDOPNode();
00034
00035 bool isLeaf() const
00036 {
00037 UT_ASSERT_P((NULL == myLeft && NULL == myRight && myLeafId >= 0) ||
00038 (NULL != myLeft && NULL != myRight && myLeafId < 0));
00039 return myLeafId >= 0;
00040 }
00041
00042 bool overlaps(const BV_KDOPNode &rhs, fpreal tol) const;
00043
00044 void save(ostream &os, bool onlyStructure) const;
00045 static BV_KDOPNode
00046 *load(UT_IStream &is, bool onlyStructure);
00047
00048 int64 getMemoryUsage() const;
00049
00050
00051
00052
00053 fpreal myExtents[K];
00054
00055 int myLeafId;
00056 BV_KDOPNode *myLeft, *myRight;
00057
00058 private:
00059
00060 BV_KDOPNode &operator=(const BV_KDOPNode &);
00061 };
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 template <int K>
00080 class BV_API BV_KDOPTree : public BV_Tree
00081 {
00082 public:
00083 typedef BV_Tree BaseClass;
00084
00085 BV_KDOPTree();
00086 BV_KDOPTree(const BV_KDOPTree &);
00087 virtual ~BV_KDOPTree();
00088
00089 BV_KDOPTree &operator=(const BV_KDOPTree &);
00090
00091 virtual const char *getType() const;
00092 virtual const BV_Tree
00093 *castTo(const char *type) const;
00094 virtual BV_Tree *castTo(const char *type);
00095
00096
00097 static int getNumSlabs()
00098 { return K/2; }
00099
00100 const UT_Vector3 &getPlaneDir(int k) const
00101 {
00102 UT_ASSERT_P(k < K/2);
00103 return myPlaneDirs[k];
00104 }
00105
00106 protected:
00107 class bvLeaf
00108 {
00109 public:
00110
00111
00112
00113
00114 float mySortKey;
00115 int myLeafId;
00116 UT_Vector3 myBarycenter;
00117 };
00118
00119 virtual BV_Tree *cloneSubclass() const;
00120 virtual int64 getMemoryUsageSubclass() const;
00121 virtual int getNumLeavesSubclass() const;
00122 virtual void saveSubclass(ostream &os, bool onlyStructure) const;
00123 virtual bool loadSubclass(UT_IStream &is, bool onlyStructure);
00124
00125 virtual void buildSubclass(BV_LeafIterator &leafIt);
00126 virtual void updateExtentsSubclass(BV_LeafIterator &leafIt);
00127 virtual Status intersectSubclass(BV_Callback &callback,
00128 const BV_Tree &treeb,
00129 const UT_DMatrix4 &startxforma,
00130 const UT_DMatrix4 &startxformb,
00131 const UT_DMatrix4 &endxforma,
00132 const UT_DMatrix4 &endxformb,
00133 fpreal tol) const;
00134 static bool intersectRecurse(BV_Callback &callback,
00135 const BV_KDOPNode<K> &nodea,
00136 const BV_KDOPNode<K> &nodeb,
00137 fpreal tol);
00138
00139 static BV_KDOPNode<K>*buildRecurse(UT_RefArray<bvLeaf> &leafData,
00140 int startLeaf, int numLeaves);
00141 static void updateExtentsRecurse(BV_LeafIterator &leafIt,
00142 BV_KDOPNode<K> &node);
00143
00144 static const UT_Vector3 myPlaneDirs[K/2];
00145
00146 protected:
00147 const BV_KDOPNode<K>*getRoot() const
00148 { return myRoot; }
00149
00150 private:
00151 BV_KDOPNode<K> *myRoot;
00152 };
00153
00154 typedef BV_KDOPTree<6> BV_AABBTree;
00155 typedef BV_KDOPTree<14> BV_14DOPTree;
00156 typedef BV_KDOPTree<18> BV_18DOPTree;
00157 typedef BV_KDOPTree<26> BV_26DOPTree;
00158
00159 #endif