00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __UT_PointTree_h__
00028 #define __UT_PointTree_h__
00029
00030 #include "UT_API.h"
00031 #include "UT_BoundingBox.h"
00032 #include "UT_PtrArray.h"
00033 #include "UT_FloatArray.h"
00034
00035 typedef int (*UT_PointTreeValidNearestFunc)(void *data, void *userdata);
00036
00037 class ut_PointTreeQueue;
00038
00039 class utPointNode;
00040 class UT_Vector3;
00041 class UT_Vector3Array;
00042
00043 class UT_API UT_PointTree
00044 {
00045 public:
00046
00047 UT_PointTree();
00048 virtual ~UT_PointTree(void);
00049
00050
00051
00052
00053 int build(const UT_PtrArray<void *> &data,
00054 const UT_Vector3Array &points,
00055 int maxsize = 5);
00056
00057
00058
00059 void *findNearest(const UT_Vector3 &pt, float maxdist,
00060 UT_PointTreeValidNearestFunc = NULL,
00061 void *user_data = NULL);
00062
00063
00064
00065
00066 void findNearestGroup(const UT_Vector3 &pt, float maxdist,
00067 int groupsize,
00068 UT_PtrArray<void *> &group,
00069 UT_FloatArray &groupdist2,
00070 UT_PointTreeValidNearestFunc = NULL,
00071 void *user_data = NULL);
00072
00073
00074 int findAllClose(const UT_Vector3 &pt, float maxdist,
00075 UT_PtrArray<void *> &data);
00076
00077
00078 int findAllInTube(const UT_Vector3 &orig,
00079 const UT_Vector3 &dir, fpreal rad,
00080 UT_PtrArray<void *> &data);
00081
00082 void getBBox(UT_BoundingBox &box) const { box = myBBox; }
00083
00084
00085 int verifyTree() const;
00086
00087 void destroyTree();
00088
00089 protected:
00090
00091 void destroyNode(utPointNode *node);
00092
00093
00094 int verifyNode(UT_BoundingBox &box, utPointNode *node)
00095 const;
00096
00097
00098
00099 void testAxis(const UT_BoundingBox &box, int axis,
00100 const UT_Vector3Array &points,
00101 int &splitleft, int &splitright);
00102
00103
00104
00105 void splitOnAxis(const UT_BoundingBox &box, int axis,
00106 const UT_PtrArray<void *> &data,
00107 const UT_Vector3Array &points,
00108 UT_PtrArray<void *> &dataleft,
00109 UT_Vector3Array &pointsleft,
00110 UT_PtrArray<void *> &dataright,
00111 UT_Vector3Array &pointsright);
00112
00113 utPointNode *buildChildNode(const UT_BoundingBox &box,
00114 const UT_PtrArray<void *> &data,
00115 const UT_Vector3Array &points,
00116 int inbboxnode = 0);
00117
00118 void *findNearestNode(UT_BoundingBox &box,
00119 utPointNode *node, const UT_Vector3 &pt,
00120 float &maxdist,
00121 UT_PointTreeValidNearestFunc = NULL,
00122 void *user_data = NULL);
00123 void findNearestNodeGroup(UT_BoundingBox &box,
00124 utPointNode *node, const UT_Vector3 &pt,
00125 ut_PointTreeQueue &q,
00126 UT_PointTreeValidNearestFunc = NULL,
00127 void *user_data = NULL);
00128
00129 int findCloseNodes(UT_BoundingBox &box,
00130 utPointNode *node, const UT_Vector3 &pt,
00131 float &maxdist,
00132 UT_PtrArray<void *> &data);
00133
00134 int findInTube(UT_BoundingBox &box,
00135 utPointNode *node, const UT_Vector3 &orig,
00136 const UT_Vector3 &dir,
00137 fpreal radius, fpreal radius2,
00138 UT_PtrArray<void *> &data);
00139
00140 utPointNode *myRoot;
00141 UT_BoundingBox myBBox;
00142 int myMaxSize;
00143 };
00144
00145 #endif