|
| | NCollection_KDTree () |
| | Empty constructor. Creates an empty tree.
|
| |
| template<bool R = HasRadii, typename = std::enable_if_t<!R>> |
| void | Build (const ThePointType *thePoints, size_t theCount) |
| | Build the tree from a C array of points (no radii). Only available when HasRadii is false.
|
| |
| template<bool R = HasRadii, typename = std::enable_if_t<!R>> |
| void | Build (const NCollection_Array1< ThePointType > &thePoints) |
| | Build the tree from an NCollection_Array1 (no radii). Only available when HasRadii is false.
|
| |
| template<bool R = HasRadii, typename = std::enable_if_t<R>> |
| void | Build (const ThePointType *thePoints, const double *theRadii, size_t theCount) |
| | Build the tree from a C array of points with per-point radii. Only available when HasRadii is true.
|
| |
| template<bool R = HasRadii, typename = std::enable_if_t<R>> |
| void | Build (const NCollection_Array1< ThePointType > &thePoints, const NCollection_Array1< double > &theRadii) |
| | Build the tree from NCollection_Array1 of points with radii. Only available when HasRadii is true.
|
| |
| bool | IsEmpty () const |
| | Returns true if the tree contains no points.
|
| |
| size_t | Size () const |
| | Returns the number of points in the tree.
|
| |
| void | Clear () |
| | Clears the tree.
|
| |
| const ThePointType & | Point (size_t theIndex) const |
| | Returns the point at the given 1-based original index.
|
| |
| template<bool R = HasRadii, typename = std::enable_if_t<R>> |
| double | Radius (size_t theIndex) const |
| | Returns the radius of the point at the given 1-based original index. Only available when HasRadii is true.
|
| |
| size_t | NearestPoint (const ThePointType &theQuery) const |
| | Finds the nearest point to theQuery.
|
| |
| size_t | NearestPoint (const ThePointType &theQuery, double &theSqDistance) const |
| | Finds the nearest point to theQuery and returns the squared distance.
|
| |
| NCollection_DynamicArray< size_t > | NearestPoints (const ThePointType &theQuery, double theTolerance, double &theSqDistance) const |
| | Finds all nearest points to theQuery that share the same minimum distance. Useful when multiple points are equidistant from the query. First finds the nearest distance via tree traversal, then collects all points at that distance using a range search with theTolerance for floating-point comparison.
|
| |
| size_t | KNearestPoints (const ThePointType &theQuery, size_t theK, NCollection_Array1< size_t > &theIndices, NCollection_Array1< double > &theSqDistances) const |
| | Finds the K nearest points to theQuery. Results are sorted by distance (closest first).
|
| |
| NCollection_DynamicArray< size_t > | RangeSearch (const ThePointType &theQuery, double theRadius) const |
| | Finds all points within theRadius of theQuery (sphere search).
|
| |
| template<typename Functor > |
| void | ForEachInRange (const ThePointType &theQuery, double theRadius, Functor theFunctor) const |
| | Calls theFunctor for each point within theRadius of theQuery. Zero-allocation alternative to RangeSearch - avoids DynamicArray overhead. Indices passed to theFunctor are 1-based (same convention as RangeSearch).
|
| |
| NCollection_DynamicArray< size_t > | BoxSearch (const ThePointType &theMin, const ThePointType &theMax) const |
| | Finds all points within the axis-aligned bounding box [theMin, theMax].
|
| |
| template<bool R = HasRadii, typename = std::enable_if_t<R>> |
| NCollection_DynamicArray< size_t > | ContainingSearch (const ThePointType &theQuery) const |
| | Finds all points whose sphere contains theQuery. Point i "contains" theQuery if dist(theQuery, point_i) <= radius_i. Only available when HasRadii is true.
|
| |
| template<bool R = HasRadii, typename = std::enable_if_t<R>> |
| size_t | NearestWeighted (const ThePointType &theQuery) const |
| | Finds the point whose sphere surface is closest to theQuery. Minimizes gap distance = dist(theQuery, point_i) - radius_i. Negative gap means theQuery is inside the sphere. Only available when HasRadii is true.
|
| |
| template<bool R = HasRadii, typename = std::enable_if_t<R>> |
| size_t | NearestWeighted (const ThePointType &theQuery, double &theGapDistance) const |
| | Finds the point whose sphere surface is closest to theQuery. Minimizes gap distance = dist(theQuery, point_i) - radius_i. Negative gap means theQuery is inside the sphere. Only available when HasRadii is true.
|
| |
| | NCollection_KDTree (const NCollection_KDTree &theOther)=default |
| | Copy constructor.
|
| |
| | NCollection_KDTree (NCollection_KDTree &&theOther) noexcept |
| | Move constructor.
|
| |
| NCollection_KDTree & | operator= (const NCollection_KDTree &theOther) |
| | Copy assignment.
|
| |
| NCollection_KDTree & | operator= (NCollection_KDTree &&theOther) noexcept |
| | Move assignment.
|
| |
template<
class ThePointType,
int TheDimension,
bool HasRadii = false>
class NCollection_KDTree< ThePointType, TheDimension, HasRadii >
Static KD-Tree for efficient point set queries.
NCollection_KDTree is a balanced KD-Tree built once from a set of points, supporting efficient nearest-neighbor, k-nearest, range (sphere), and box (AABB) queries.
Key features:
- O(N log N) construction via median-split (std::nth_element)
- O(log N) nearest-neighbor search with bounding box pruning
- O(N^(1-1/d) + k) range and box search
- Cache-friendly permutation-based layout (no node allocations)
- Optional per-point radii for sphere-aware queries (compile-time, zero overhead when unused)
- Works with any point type providing Coord(int) with 1-based indexing
Best suited for:
- Static point clouds (build once, query many times)
- Nearest-neighbor and k-nearest queries
- Spatial range filtering
- Sphere containment and weighted nearest queries (when HasRadii = true)
Required interface for ThePointType (besides copy constructor and operator =):
{
public:
double Coord(int theIndex) const;
};
STL input iterator that wraps an OCCT More()/Next() iterator.
Definition NCollection_ForwardRange.hxx:142
Works out-of-the-box with gp_Pnt, gp_Pnt2d, gp_XYZ, gp_XY.
- Template Parameters
-
| ThePointType | Point type providing Coord(int) with 1-based indexing |
| TheDimension | Spatial dimension (compile-time constant, typically 2 or 3) |
| HasRadii | When true, enables per-point radii for ContainingSearch and NearestWeighted queries (default: false) |