Ponca
aa50bfdf187919869239c5b44b748842569114c1
Point Cloud Analysis library
|
This module provides spatial datastructures to speed up spatial queries (e.g., neighbors search).
All datastructures are available in arbitrary dimensions.
Ponca queries are defined according to their input type (QueryInputIsIndex, or QueryInputIsPosition) and their output type (closest point with QueryOutputIsNearest, k-neighborhood with QueryOutputIsKNearest, and range neighborhood with QueryOutputIsRange):
QueryType | Closest Point | k-neighborhood | Range neighborhood |
---|---|---|---|
Index | NearestIndexQuery | KNearestIndexQuery | RangeIndexQuery |
Coordinate | NearestPointQuery | KNearestPointQuery | RangePointQuery |
These classes provide a consistent API for all datastructures, where the results are exposed as Range
and thus accessed through iterators, ie.:
Thanks to the iterator formalism, queries can be seamlessly combined with Basket::computeWithIds:
In Ponca, the kd-tree is a binary search tree that
The class Ponca::KdTreeDense provides methods to construct a tree and query points neighborhoods. The class Ponca::KdTreeSparse provides the same functionalities as its dense counterpart, but allows construction from a subset of points. They both share the same API with their abstract base class KdTree.
As for the other modules, the point type is defined by a template parameter DataPoint
. At construction time, the coordinates are copied in the tree from a container provided by the caller. For instance, to generate a tree from a random point cloud:
For convenience, it is possible to convert the custom input points to DataPoint
using a converter.
When using a Ponca::KdTreeSparse, it is possible to provide a set of indices to sample a subset of the input point during the construction. Here, to randomly select half of the points:
As for other datastructures, queries are objects generated by the KdTree, and are designed as Range
: accessing the neighbors requires to iterate over the query. Here an example from the test suite, where the indices returned from the queries are compared with an explicit search
Several query types are provided (see KdTreeBase for related method list):
Several KdTree queries are illustrated in the example Ponca::KdTree neighbor searches. KdTree usage is also demonstrated both in tests and examples:
tests/src/basket.cpp
tests/src/queries_knearest.cpp
tests/src/queries_nearest.cpp
tests/src/queries_range.cpp
examples/cpp/nanoflann/ponca_nanoflann.cpp
There are two main ways of iterating over a KdTree: over points or over samples. Points are the underlying data storage, which the KdTree does not modify, while samples are a set of indices into the point storage that the KdTree reorders internally when it is constructed to keep track of spatial partitions.
We call indices into the underlying point storage point indices and indices into the sample storage sample indices. Note that the sample storage stores point indices: sample number 0 may, for example, refer to point number 25. The point storage can be accessed with KdTreeBase::points, while the array of samples can be accessed with KdTreeBase::samples.
While most of the KdTree API is built on using point indices, it can still be useful to iterate over samples instead (e.g. when using a Ponca::KdTreeSparse). If you ever need to convert sample indices to point indices, see KdTreeBase::pointFromSample (see also KdTreeBase::pointDataFromSample).
The trees can be customized using Traits
, to change containers and nodes types. KdTreeDefaultTraits provides general-purpose Traits
that fit most usages, and is directly used by Ponca::KdTree, Ponca::KdTreeDense and Ponca::KdTreeSparse:
To use your own type of Traits
, see KdTreeDefaultTraits and KdTreeCustomizableNode APIs. See also:
examples/cpp/ponca_customize_kdtree.cpp
KdTree provides the common interface of KdTreeDense and KdTreeSparse. This class can be used to store or pass references/pointers that can be of either child type, see for instance:
KdTreeBase provides the same abstraction for arbitrary types of traits. When the type of Traits
is not restricted, it is recommended to use KdTreeBase to declare functions parameters or variables. In this example:
the variable m_kdtree
can be either dense or sparse, and have any type of Traits
.
The class Ponca::KnnGraph provides methods to construct a neighbor graph and query points neighborhoods.
The graph is constructed from an existing KdTree, and the point collection is accessed through it (with no copy). Here an example from the test-suite where a graph is constructed, where only closest neighbors are connected:
As for other datastructures, queries are objects generated by KdTrees, and are designed as Range
: accessing the neighbors requires to iterate over the query.
Two types of queries are provided (see KnnGraphBase for related method list):
k=1
.