|
const NodeList & | _getNodes (void) |
|
const PointList & | _getPoints (void) |
|
const PointList & | _getIndices (void) |
|
| KdTree (const PointList &points, unsigned int nofPointsPerCell=KD_POINT_PER_CELL, unsigned int maxDepth=KD_MAX_DEPTH) |
| Create the Kd-Tree using memory copy. More...
|
|
| KdTree (unsigned int size=0, unsigned int nofPointsPerCell=KD_POINT_PER_CELL, unsigned int maxDepth=KD_MAX_DEPTH) |
| Create a void KdTree. More...
|
|
template<class VectorDerived > |
void | add (const VectorDerived &p) |
| Add a new vertex in the KdTree. More...
|
|
void | add (Scalar *position) |
|
void | finalize () |
| Finalize the creation of the KdTree. More...
|
|
const AxisAlignedBoxType & | aabb () const |
|
| ~KdTree () |
|
template<int stackSize, typename Container = std::vector<VectorType>> |
void | doQueryDist (RangeQuery< stackSize > &query, Container &result) const |
| Performs distance query and return vector coordinates. More...
|
|
template<int stackSize, typename IndexContainer = std::vector<Index>> |
void | doQueryDistIndices (RangeQuery< stackSize > &query, IndexContainer &result) const |
| Performs distance query and return indices. More...
|
|
template<int stackSize, typename Functor > |
void | doQueryDistProcessIndices (RangeQuery< stackSize > &query, Functor f) const |
| Performs distance query and return indices. More...
|
|
template<int stackSize> |
Index | doQueryRestrictedClosestIndex (RangeQuery< stackSize > &query, int currentId=-1) const |
| Finds the closest element index within the range [0:sqrt(sqdist)]. More...
|
|
template<typename _Scalar, typename _Index = int>
class GlobalRegistration::KdTree< _Scalar, _Index >
Generation
You can create the KdTree in two way :
- Simple pass construction : easy to use, but use a full vertices memory copy :
basic::TArray < KdTree<float>::VectorType > data(60);
int i = 0;
for ( ; i != 30; i++ ) {
data << vec3 (rand() % 10 + 1,
rand() % 10 + 1,
rand() % 10 + 1);
}
data << vec3(0.5,0.5,0.5);
i++;
for ( ; i != 60; i++ ) {
data << vec3 (rand() % 10 + 1,
rand() % 10 + 1,
rand() % 10 + 1);
}
KdTree<float> t ( data );
- Per-vertex pass construction : more code, but avoid copy :
KdTree<float> t ( 60 );
int i = 0;
for ( ; i != 30; i++ ) {
vec3 v( rand() % 10 + 1,
rand() % 10 + 1,
rand() % 10 + 1);
t.set( i ,v );
}
t.set(i, vec3(0.5,0.5,0.5));
i++;
for ( ; i != 60; i++ ) {
vec3 v( rand() % 10 + 1,
rand() % 10 + 1,
rand() % 10 + 1);
t.set( i ,v );
}
t.finalize();
This version is very usefull if data are computed on the fly.
Closest-Point query
It is important to note that in the case of multiple neighbors request, the result isn't sorted (see HeapMaxPriorityQueue for more explanations). So if you want to get the closest point, you must perform a single request.
You must specify the size of the request using setMaxNofNeighbors.
t.setMaxNofNeighbors(1);
vec3 result = t.getNeighbor( 0 ).p;
unsigned int resultId = t.getNeighborId( 0 );
cout << resultId << endl;
cout << result(0) << " " << result(1) << " " << result(2) << endl;
cout << t.getNeighborSquaredDistance( 0 ) << endl;
template<typename Scalar , typename Index >
template<int stackSize>
Finds the closest element index within the range [0:sqrt(sqdist)].
This algorithm uses the simple distance to the split plane to prune nodes.
- Parameters
-
currentId | Index of the querypoint if it belongs to the tree |
A more elaborated approach consists to track the closest corner of the cell relatively to the current query point. This strategy allows to save about 5% of the leaves. However, in practice the slight overhead due to this tracking reduces the overall performance.
This algorithm also use a simple stack while a priority queue using the squared distances to the cells as a priority values allows to save about 10% of the leaves. But, again, priority queue insertions and deletions are quite involved, and therefore a simple stack is by far much faster.
The optionnal parameter currentId is used when the query point is stored in the tree, and must thus be avoided during the query