00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __UT_LineTree_h__
00024 #define __UT_LineTree_h__
00025
00026 #include "UT_API.h"
00027 class UT_Vector3;
00028 class UT_BoundingBox;
00029 class utLineTreeNode;
00030 class utLeafNode;
00031 class utLineList;
00032
00033 class UT_API UT_LineTree
00034 {
00035 public:
00036 UT_LineTree();
00037 virtual ~UT_LineTree();
00038
00039
00040 int addLine( const UT_Vector3 &pt1, const UT_Vector3 &pt2 );
00041
00042
00043
00044
00045
00046
00047 int buildTree( UT_BoundingBox &bbox );
00048
00049
00050 void clear();
00051
00052
00053
00054
00055
00056
00057 int findNearestLineSegment( const UT_Vector3 &pt, float *dist2 = NULL );
00058
00059
00060
00061
00062
00063
00064 unsigned findKNearestLineSegments( const UT_Vector3 &pt,
00065 int line_id[],
00066 float line_dist2[],
00067 unsigned max_lines );
00068
00069
00070
00071 void requestThreshold( unsigned threshold )
00072 { myRequestedThreshold = threshold; }
00073
00074
00075
00076 int getLineById( int id, UT_Vector3 &pt1, UT_Vector3 &pt2 );
00077
00078
00079 void dumpTree() const;
00080
00081 private:
00082
00083 void addLineToTree( utLineTreeNode *&root, unsigned idx, int depth = 0,
00084 int split = 1 );
00085
00086 static utLineTreeNode *newLeafNode(
00087 unsigned max_lines,
00088 const UT_Vector3 &corner1,
00089 const UT_Vector3 &corner2 );
00090
00091 int findPoint( utLineTreeNode *tree, const UT_Vector3 &pt,
00092 utLeafNode *&node, utLineTreeNode *&parent ) const;
00093
00094 int getClosestLine( utLineTreeNode *tree, const UT_Vector3 &pt,
00095 utLineTreeNode *avoid,
00096 int &line_idx, float &mindist2 ) const;
00097 int getClosestLineWithinBBox( utLineTreeNode *tree,
00098 const UT_Vector3 &pt,
00099 const UT_BoundingBox &bbox,
00100 utLineTreeNode *avoid, int &line_idx,
00101 float &mindist2 ) const;
00102
00103 void getKClosestLineWithinBBox(
00104 utLineTreeNode *tree, const UT_Vector3 &pt,
00105 const UT_BoundingBox &bbox, utLineTreeNode *avoid,
00106 int line_idx[], float mindist2[],
00107 unsigned &num_lines, unsigned max_lines ) const;
00108 void getKClosestLine(
00109 utLineTreeNode *tree, const UT_Vector3 &pt,
00110 utLineTreeNode *avoid,
00111 int line_idx[], float mindist2[],
00112 unsigned &num_lines, unsigned max_lines ) const;
00113
00114 private:
00115 utLineTreeNode *myRoot;
00116 utLineList *myLineList;
00117 char *myLineUsed;
00118 unsigned myRequestedThreshold;
00119 unsigned myThreshold;
00120 };
00121
00122 #endif // __UT_LineTree_h__