12 #ifndef __GEO_PointTree__
13 #define __GEO_PointTree__
37 template <
typename IDX_T>
50 bool enable_multithreading =
true);
55 bool enable_multithreading =
true);
62 bool enable_multithreading =
true);
75 bool auto_rebalance=
false);
95 bool auto_rebalance=
false);
102 virtual void clear();
124 bool wrapunitcube =
false);
147 bool wrapunitcube =
false);
185 bool enable_multithreading =
true)
override
208 int idx0,
int idx1,
int dim)
const override;
209 const float *
getP(
int idx)
const override;
274 bool enable_multithreading =
true);
276 const char *attrib,
bool enable_multithreading =
true);
282 bool enable_multithreading =
true);
302 bool enable_multithreading =
true);
304 const char *attrib,
bool enable_multithreading =
true);
306 const char *attrib,
const char *radattrib,
fpreal radscale,
307 bool enable_multithreading =
true);
312 { Super::build(pts, enable_multithreading); }
314 { Super::build(pts, idx, enable_multithreading); }
324 template <
typename IDX_T>
327 , myPointTransform(NULL)
328 , myIsKDTreeDirty(false)
333 template <
typename IDX_T>
336 clearPointTransform();
339 template <
typename IDX_T>
344 enable_multithreading);
347 template <
typename IDX_T>
350 bool enable_multithreading)
356 myPointList.setSizeNoInit(n);
359 if (myPointTransform)
361 for (
exint ptnum = 0; ptnum <
n; ++ptnum)
362 myPointList(ptnum) *= *myPointTransform;
366 myIndexList.setSize(n);
368 for (
exint i = 0; i <
n; i++)
373 buildIfNeeded(enable_multithreading);
376 template <
typename IDX_T>
381 bool enable_multithreading)
385 UT_ASSERT(myPointList.size() == myIndexList.size());
388 if (myPointTransform)
391 for (
exint ptnum = 0; ptnum <
n; ++ptnum)
392 myPointList(ptnum) *= *myPointTransform;
398 buildIfNeeded(enable_multithreading);
401 template <
typename IDX_T>
413 if( myPointTransform )
414 myPointList.append(pt * (*myPointTransform));
416 myPointList.append(pt);
417 myIndexList.append(idx);
428 template <
typename IDX_T>
432 append(pt,
IdxType(myPointList.size()),
false);
435 template <
typename IDX_T>
444 UT_ASSERT(myRadii.size() == myPointList.size());
447 if (myRadii.size() != myPointList.size())
449 UT_ASSERT(!
"Adding radius points to a non-radius based point tree");
453 myRadii.append(radius);
454 append(pt, idx, auto_rebalance);
457 template <
typename IDX_T>
461 appendPtRadius(pt, radius,
IdxType(myPointList.size()),
false);
464 template <
typename IDX_T>
473 idx = findClosest(qpt, 1e37F);
478 return myIndexList(idx);
481 template <
typename IDX_T>
490 (
void) findClosest(idxlist, qpt, maxdist*maxdist, 1);
492 return myIndexList(idxlist(0));
497 template <
typename IDX_T>
510 i = findClosestQueue(qpt, q, maxdist * maxdist);
515 i = findClosestQueue(qpt, q, maxdist * maxdist);
521 return myIndexList(i);
524 template <
typename IDX_T>
538 int numnear = findClosest(group, groupdist, qpt,
543 for (
int i = 0; i < numnear; i++)
545 list(i) = myIndexList(group(i));
551 template <
typename IDX_T>
570 numnear = findClosestQueue(
571 group, groupdist, qpt, q, maxdist * maxdist, groupsize);
576 numnear = findClosestQueue(
577 group, groupdist, qpt, q, maxdist * maxdist, groupsize);
581 for (
exint i = 0; i < numnear; i++)
583 list(i) = myIndexList(group(i));
589 template <
typename IDX_T>
603 for (
exint i = 0; i < numnear; i++)
605 list(i) = myIndexList(idxlist(i));
611 template <
typename IDX_T>
623 queue, maxdist * maxdist, getEntries());
626 for (
exint i = 0; i < numnear; i++)
628 list(i) = myIndexList(idxlist(i));
634 template <
typename IDX_T>
646 exint numnear = findAllClosest(idxlist, pt, radius*radius);
649 for (
exint i = 0; i < numnear; i++)
651 list(i) = myIndexList(idxlist(i));
657 template <
typename IDX_T>
661 myPointList.setSize(0);
662 myIndexList.setSize(0);
671 template <
typename IDX_T>
675 return myPointList.size();
678 template <
typename IDX_T>
682 int64 mem = inclusive ?
sizeof(*this) :
false;
684 if (myPointTransform)
685 mem +=
sizeof(*myPointTransform);
686 mem += myPointList.getMemoryUsage(
false);
687 mem += myIndexList.getMemoryUsage(
false);
688 mem += myRadii.getMemoryUsage(
false);
692 template <
typename IDX_T>
696 delete myPointTransform;
697 myPointTransform = 0;
700 template <
typename IDX_T>
704 clearPointTransform();
709 template <
typename IDX_T>
716 setEntries(myPointList.size());
720 setBalancer(UT_KD_CENTROID);
724 balance(enable_multithreading);
726 myIsKDTreeDirty =
false;
730 template <
typename IDX_T>
734 float delta = myPointList(idx0)(dim) - myPointList(idx1)(dim);
743 template <
typename IDX_T>
747 return myPointList(idx).data();
750 template <
typename IDX_T>
760 template <
typename IDX_T>
void build(const UT_Vector3Array &pts, bool enable_multithreading=true)
void setBalancer(ut_KDBalancer balance)
void dirtyKDTree()
Marks the kd tree as out of date.
UT_Matrix4T< double > UT_DMatrix4
void setBalancer(ut_KDBalancer balance)
Queries for infinite lines (infinite tubes)
~GEO_PointTreeT() override
GEO_PointTreeT< int > GEO_PointTreeInt
For basic opaque integer id trees, use GEO_PointTreeInt.
void setMaxLeafNodes(int max_leaf_nodes)
void build(const UT_Vector3Array &pts, bool enable_multithreading=true)
int findAllCloseIdx(const UT_Vector3 &pt, fpreal maxdist, IdxArrayType &list)
virtual int64 getMemoryUsage(bool inclusive=true) const
Returns the amount of memory used by this tree.
int findAllCloseIdxQueue(const UT_Vector3 &pt, ut_KDPQueue &queue, fpreal maxdist, IdxArrayType &list)
Creates a search queue useful for findAll queries.
int64 getMemoryUsage(bool inclusive) const
GLdouble GLdouble GLdouble q
void updateKDTree(bool enablemultithread=true)
void setSize(exint newsize)
constexpr SYS_FORCE_INLINE const T * data() const noexcept
void setPointTransform(const UT_DMatrix4 &xform)
#define SYS_DEPRECATED_REPLACE(__V__, __R__)
UT_Vector3Array myPointList
The list of all the points.
constexpr size_type size() const noexcept
UT_DMatrix4 * myPointTransform
virtual void clear()
Clears out the tree, leaving it with no entries.
void append(const UT_Vector3 &pt, IdxType idx, bool auto_rebalance=false)
void setMaxLeafNodes(int max_leaf_nodes)
bool pointsHaveRadius() const override
These are used if the user adds points with radii.
GEO_PointTreeT< GA_Index > Super
constexpr iterator begin() const noexcept
constexpr iterator end() const noexcept
Lookup point information to be passed to the query functions.
fpreal getRadius(int idx) const override
Return the radius associated with the point in question.
IdxArrayType myIndexList
This is the mapping from the KD entries into the GDP numbers.
int entries() const
Returns the number of actual points in the tree.
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the queue
void appendPtRadius(const UT_Vector3 &pt, fpreal radius, IdxType idx, bool auto_rebalance=false)
SYS_DECLARE_LEGACY_TR(GU_Detail)
int findAllInTubeIdx(const UT_Vector3 &pt, const UT_Vector3 &dir, fpreal radius, IdxArrayType &list)
Find all of the points inside the given tube.
GEO_PointTreeT< GA_Offset > Super
int comparePosition(int idx0, int idx1, int dim) const override
These are used by KDTree:
int findNearestGroupIdxQueue(const UT_Vector3 &pt, fpreal maxdist, int groupsize, IdxArrayType &group, UT_FloatArray &groupdist, ut_KDPQueue &q, bool wrapunitcube=false)
This uses a pre-built queue to reduce memory allocation.
int findNearestGroupIdx(const UT_Vector3 &pt, fpreal maxdist, int groupsize, IdxArrayType &group, UT_FloatArray &groupdist)
void buildIfNeeded(bool enable_multithreading=true) override
This must be called before querying, to build and balance the tree.
ut_KDBalancer
KD Tree balancing algorithms. See setBalancer.
const float * getP(int idx) const override
Return the position associated with the given point.
UT_Array< IdxType > IdxArrayType
UT_FloatArray myRadii
List of radii for each pont.
void balance(bool enable_multithreading=true)
IdxType findNearestIdxQueue(const UT_Vector3 &pt, ut_KDPQueue &q, fpreal maxdist=1e18f, bool wrapunitcube=false)
This uses a pre-built queue to reduce memory allocation.
void build(const UT_Vector3Array &pts, const GA_IndexArray &idx, bool enable_multithreading=true)
IdxType findNearestIdx(const UT_Vector3 &pt)
void clearPointTransform()
Clears the myPointTransform member data.