HDK
|
#include <UT_KDTree.h>
Classes | |
class | AggregateVolume |
class | KDSplit |
class | Visitor |
Interface for tree traversals. More... | |
class | VolumeData |
Interface for aggregate data used by volume filtering. More... | |
Public Types | |
enum | ut_KDBalancer { UT_KD_MEDIAN, UT_KD_SAH, UT_KD_CENTROID } |
KD Tree balancing algorithms. See setBalancer. More... | |
Public Member Functions | |
UT_KDTree (int dim=3, size_t size=0) | |
virtual | ~UT_KDTree () |
virtual void | buildIfNeeded (bool enable_multithreading=true) |
This must be called before querying, to build and balance the tree. More... | |
int64 | getMemoryUsage (bool inclusive) const |
void | setEntries (size_t size) |
size_t | getEntries () const |
void | growEntries (size_t amount) |
size_t | getRebalanceCount () const |
void | setRebalanceCount (size_t count) |
void | setBalancer (ut_KDBalancer balance) |
void | setMaxLeafNodes (int max_leaf_nodes) |
void | flagDirty () |
virtual int | comparePosition (int idx0, int idx1, int dim) const =0 |
virtual const float * | getP (int idx) const =0 |
Return the position associated with the given point. More... | |
virtual bool | pointsHaveRadius () const |
virtual fpreal | getRadius (int) const |
Return the radius associated with the point in question. More... | |
virtual bool | isValid (int) const |
Returns whether the given index should be considered in searches. More... | |
virtual bool | isValid (int idx, const UT_KDQueryPt &) const |
virtual int | getInvalidLimit (int maxn) const |
template<typename QueryPoint > | |
int | findClosest (const QueryPoint &pt, fpreal max_distance_squared) |
template<typename QueryPoint > | |
int | findClosestQueue (const QueryPoint &pt, ut_KDPQueue &queue, fpreal max_distance_squared) |
template<typename QueryPoint > | |
int | findClosest (UT_IntArray &list, const QueryPoint &pt, fpreal max_distance_squared, int max_nodes, bool sorted=true) |
template<typename QueryPoint > | |
int | findClosestQueue (UT_IntArray &list, const QueryPoint &pt, ut_KDPQueue &q, fpreal max_distance_squared, int max_nodes, bool sorted=true) |
template<typename QueryPoint > | |
int | findClosest (UT_IntArray &list, UT_FloatArray &dist, const QueryPoint &pt, fpreal max_distance_squared, int max_nodes, bool sorted=true) |
template<typename QueryPoint > | |
int | findClosestQueue (UT_IntArray &list, UT_FloatArray &dist, const QueryPoint &pt, ut_KDPQueue &q, fpreal max_distance_squared, int max_nodes, bool sorted=true) |
template<typename QueryPoint > | |
int | findNClosest (UT_IntArray &list, const QueryPoint &pt, int max_nodes) |
template<typename QueryPoint > | |
int | findAllClosest (UT_IntArray &list, const QueryPoint &pt, fpreal max_distance_squared) |
void | traverse (Visitor &visitor) |
void | filterVolume (VolumeData &data, const UT_Vector3 &pos, const UT_Filter &filter, const AggregateVolume &aggdata, int max_nodes) |
const fpreal * | getBoxMin () |
const fpreal * | getBoxMax () |
Static Public Member Functions | |
static ut_KDPQueuePtr | createQueue () |
Protected Member Functions | |
int | getHead () const |
bool | isValid (int node, const UT_KDTubeQuery &) const |
bool | isValid (int node, const UT_KDLineQuery &) const |
bool | isValid (int node, const UT_KDTriQuery &) const |
bool | isValid (int node, const UT_KDTetQuery &) const |
bool | isValid (int node, const UT_KDQueryPtUnitWrap &) const |
template<typename QueryPoint > | |
int | findClosest (ut_KDPQueue &list, const QueryPoint &pt) |
template<typename QueryPoint > | |
void | recurseFind (ut_KDPQueue &list, const QueryPoint &pt, int split, int lo, int hi) const |
template<typename QueryPoint > | |
void | recurseFindTube (ut_KDPQueue &list, const QueryPoint &pt, int split, int lo, int hi) const |
template<typename QueryPoint > | |
void | recurseFindTri (ut_KDPQueue &list, const QueryPoint &pt, int split, int lo, int hi) const |
template<typename QueryPoint > | |
void | findInLeaf (ut_KDPQueue &list, const QueryPoint &pt, int lo, int hi, int invalid_limit, int &invalid) const |
bool | isBalanced () const |
void | traverseRecursive (Visitor &visitor, int split, int nodeid, UT_BoundingBox &box, int lo, int hi) |
void | computeBox (int start_index=0) |
bool | isBoxClose (const fpreal *P, fpreal qd, fpreal r) const |
void | balance (bool enable_multithreading=true) |
void | balanceSet (int &split, fpreal &radius, int *list, int entries, fpreal *boxmin, fpreal *boxmax, UT_Lock *splitlock) |
Protected Attributes | |
fpreal | myBMin [UT_KD_MAXDIM] |
fpreal | myBMax [UT_KD_MAXDIM] |
int * | myList |
UT_Array< KDSplit > | mySplits |
UT_Lock | myLock |
For protecting tree balancing and bounding box computation. More... | |
size_t | myEntries |
This marks the number of entries that have been added to our tree. More... | |
size_t | myFullEntries |
size_t | myRebalanceCount |
int | myDim |
int | myMaxLeafNodes |
bool | myBalanced |
bool | myBoxComputed |
bool | myHasRadius |
A faster way to evaluate pointsHaveRadius() at runtime. More... | |
ut_KDBalancer | myBalancer |
Friends | |
class | ut_KDPQueueDeleter |
Definition at line 465 of file UT_KDTree.h.
KD Tree balancing algorithms. See setBalancer.
Enumerator | |
---|---|
UT_KD_MEDIAN | |
UT_KD_SAH | |
UT_KD_CENTROID |
Definition at line 469 of file UT_KDTree.h.
|
inline |
Definition at line 476 of file UT_KDTree.h.
|
virtual |
|
protected |
Creates a KD tree from an unsorted set of points. Given a list of points, we: 1) Find the dimension in which there is most change. 2) Use the balancing algorithm to choose a splitting plane and partition myList into left and right portions. 3) Store the splitting information in mySplits 4) Recurse on the two halves. This is repeated until myMaxLeafNodes is reached where we just leave it as a linear list.
|
protected |
Balances a subset, returning the maximum radius of that subset. If splitlock is NULL, the balancing will all be done serially instead of in parallel.
|
inlinevirtual |
This must be called before querying, to build and balance the tree.
Reimplemented in GEO_PointTreeT< IDX_T >, GEO_PointTreeT< GA_Index >, GEO_PointTreeT< int >, GEO_PointTreeT< GA_Offset >, and GEO_2DTree.
Definition at line 489 of file UT_KDTree.h.
The compare function should compare the distance between two points (given by idx0 and idx1) in the dimension specified. The dimension will be between 0 and 3. For example, comparePosition(...) { fpreal delta = myP[idx0](dim) - myP[idx1](dim); return delta < 0 ? -1 : (delta > 0 ? 1 : 0); }
Implemented in GEO_PointTreeT< IDX_T >, GEO_PointTreeT< GA_Index >, GEO_PointTreeT< int >, GEO_PointTreeT< GA_Offset >, and GU_SortKDTree.
|
static |
This allows you to create a search queue so you can maintain it over time, avoiding the cost of reallocing for each search. NOTE THAT max_distance_squared IS SQUARED DISTANCE.
void UT_KDTree::filterVolume | ( | VolumeData & | data, |
const UT_Vector3 & | pos, | ||
const UT_Filter & | filter, | ||
const AggregateVolume & | aggdata, | ||
int | max_nodes | ||
) |
Filtered evaluation for 3D volumes. This method interprets the KD-Tree as a volume, and filters aggregate point data using the volumetric coverage for aggregate nodes in the tree. The max_nodes parameter controls the approximate number of points that should be averaged to produce the filtered result. The actual filter radius used will depend on max_nodes and on the size of KD-Tree nodes close to the query point. Since this is an approximate query, the actual number of points that contribute to the result may be larger than max_nodes.
This method relies on implemented subclasses for AggregateVolume and for VolumeData. You must compute aggregate volume data before calling this method.
UT_KDTree tree; AggregateVolumeSubclass aggdata; VolumeDataSubclass data;
// Store aggregate values (do this once) kdtree.traverse(aggdata);
// Filter aggregate data (do this many times) kdtree.filterVolume(data, pos, filter, aggdata, max_nodes);
|
inline |
Definition at line 646 of file UT_KDTree.h.
int UT_KDTree::findClosest | ( | const QueryPoint & | pt, |
fpreal | max_distance_squared | ||
) |
Find the closest node to the position specified. This method returns -1 if no photon is found. NOTE THAT max_distance_squared IS SQUARED DISTANCE.
int UT_KDTree::findClosest | ( | UT_IntArray & | list, |
const QueryPoint & | pt, | ||
fpreal | max_distance_squared, | ||
int | max_nodes, | ||
bool | sorted = true |
||
) |
Find the closest N (max_nodes) nodes to the position given. Only points within the sphere defined by max_distance_squared will be considered. NOTE THAT max_distance_squared IS SQUARED DISTANCE.
int UT_KDTree::findClosest | ( | UT_IntArray & | list, |
UT_FloatArray & | dist, | ||
const QueryPoint & | pt, | ||
fpreal | max_distance_squared, | ||
int | max_nodes, | ||
bool | sorted = true |
||
) |
Find the closest N (max_nodes) nodes to the position given. Only points within the sphere defined by max_distance_squared will be considered. NOTE THAT max_distance_squared IS SQUARED DISTANCE.
|
protected |
int UT_KDTree::findClosestQueue | ( | const QueryPoint & | pt, |
ut_KDPQueue & | queue, | ||
fpreal | max_distance_squared | ||
) |
int UT_KDTree::findClosestQueue | ( | UT_IntArray & | list, |
const QueryPoint & | pt, | ||
ut_KDPQueue & | q, | ||
fpreal | max_distance_squared, | ||
int | max_nodes, | ||
bool | sorted = true |
||
) |
int UT_KDTree::findClosestQueue | ( | UT_IntArray & | list, |
UT_FloatArray & | dist, | ||
const QueryPoint & | pt, | ||
ut_KDPQueue & | q, | ||
fpreal | max_distance_squared, | ||
int | max_nodes, | ||
bool | sorted = true |
||
) |
|
protected |
|
inline |
Definition at line 639 of file UT_KDTree.h.
|
inline |
Marks the tree as dirty. Note, however, that this has O(size) time cost.
Definition at line 556 of file UT_KDTree.h.
const fpreal* UT_KDTree::getBoxMax | ( | ) |
const fpreal* UT_KDTree::getBoxMin | ( | ) |
|
inline |
Definition at line 513 of file UT_KDTree.h.
|
inlineprotected |
Definition at line 790 of file UT_KDTree.h.
Return the maximum number of invalid indices that should be considered before bailing. Return -1 for no limit. maxn - the search limit
Definition at line 590 of file UT_KDTree.h.
|
inline |
Definition at line 494 of file UT_KDTree.h.
Return the position associated with the given point.
Implemented in GEO_PointTreeT< IDX_T >, GEO_PointTreeT< GA_Index >, GEO_PointTreeT< int >, GEO_PointTreeT< GA_Offset >, and GU_SortKDTree.
Return the radius associated with the point in question.
Reimplemented in GEO_PointTreeT< IDX_T >, GEO_PointTreeT< GA_Index >, GEO_PointTreeT< int >, and GEO_PointTreeT< GA_Offset >.
Definition at line 579 of file UT_KDTree.h.
|
inline |
Definition at line 529 of file UT_KDTree.h.
void UT_KDTree::growEntries | ( | size_t | amount | ) |
Sometimes, a tree might have new points added since it's construction. Rather than re-balancing the tree (which can be relatively expensive), we have allow N points to be added to the tree without re-balancing. To add entries to the tree, simply call "growEntries" with the number of points being added. If the size of the unsorted pool exceeds the re-balance count, then the tree will be re-balanced.
The rebalance count is automatically scaled as the tree is constructed, so it shouldn't be required to set the count (unless you know what you're doing).
To force a re-build of the tree, simply call setEntries(), or flag the tree as dirty.
|
inlineprotected |
Definition at line 836 of file UT_KDTree.h.
|
inlinevirtual |
Returns whether the given index should be considered in searches.
Definition at line 582 of file UT_KDTree.h.
|
inlinevirtual |
Definition at line 584 of file UT_KDTree.h.
|
inlineprotected |
Definition at line 793 of file UT_KDTree.h.
|
inlineprotected |
Definition at line 795 of file UT_KDTree.h.
|
inlineprotected |
Definition at line 797 of file UT_KDTree.h.
|
inlineprotected |
Definition at line 799 of file UT_KDTree.h.
|
inlineprotected |
Definition at line 801 of file UT_KDTree.h.
|
inlinevirtual |
If each point in the KD Tree has a radius associated with it, then this method should return true. Adding a per-point radius can affect performance adversely.
Reimplemented in GEO_PointTreeT< IDX_T >, GEO_PointTreeT< GA_Index >, GEO_PointTreeT< int >, and GEO_PointTreeT< GA_Offset >.
Definition at line 577 of file UT_KDTree.h.
|
protected |
|
protected |
|
protected |
|
inline |
Sets the KD-tree balancing algorithm.
Definition at line 542 of file UT_KDTree.h.
void UT_KDTree::setEntries | ( | size_t | size | ) |
setEntries instructs the KD Tree about the number of points that it should read back from its callbacks. Note that each call to setEntries has O(size) cost! Thus, for (i = 0; i < n; i++) tree.setEntries(i); is O(n^2). There isn't a good reason for this (as one could instead just mark the tree as dirty until the next query, much like already happens with rebalancing) but it is the way things are so be
Sets the maximum number of nodes to be stored in a leaf. Smaller values will produce deeper and more memory-hungry trees.
Definition at line 548 of file UT_KDTree.h.
void UT_KDTree::setRebalanceCount | ( | size_t | count | ) |
Traverse the KD Tree in depth first order. This routine only works on 3D trees. NOTE: This will call balance() if the tree isn't balanced.
|
protected |
|
friend |
Definition at line 743 of file UT_KDTree.h.
|
protected |
Definition at line 893 of file UT_KDTree.h.
|
protected |
Definition at line 898 of file UT_KDTree.h.
|
protected |
Definition at line 867 of file UT_KDTree.h.
|
protected |
Stores the bounding box of all of the points in the KD tree, including their individual radii, in each of the possible dimensions. Note that during balanceSet these values are temporarily altered before recursion, so don't be too shocked.
Definition at line 866 of file UT_KDTree.h.
|
protected |
Definition at line 894 of file UT_KDTree.h.
|
protected |
Definition at line 891 of file UT_KDTree.h.
|
protected |
This marks the number of entries that have been added to our tree.
Definition at line 884 of file UT_KDTree.h.
|
protected |
This marks the total number of entries in this data structure. The difference between this and myEntries is the unsorted chaff at the end.
Definition at line 889 of file UT_KDTree.h.
|
protected |
A faster way to evaluate pointsHaveRadius() at runtime.
Definition at line 897 of file UT_KDTree.h.
|
protected |
Nodes in a KD tree have two indices. One is the index that they were added in. This is the index used in getP, for example. The other is there location in the binary heap. myList takes a binary heap location and returns the index useable for getP().
Definition at line 874 of file UT_KDTree.h.
|
protected |
For protecting tree balancing and bounding box computation.
Definition at line 881 of file UT_KDTree.h.
|
protected |
Definition at line 892 of file UT_KDTree.h.
|
protected |
Definition at line 890 of file UT_KDTree.h.
Split information stored as a tree structure. This stores the midpoints, splitting offset, axis, and max radius.
Definition at line 878 of file UT_KDTree.h.