#include <kdtree.h>
class to find closest points in space for a given point cloud
Public Member Functions | |
KDTree () | |
KDTree (KDTree &&src) | |
MAXON_OPERATOR_MOVE_ASSIGNMENT (KDTree) | |
Result< void > | Init (Int maxThreads) |
void | Free () |
Result< void > | Insert (const Vector &point, Int idValue) |
void | Balance () |
Int | FindNearest (Int threadIndex, const Vector &point, KDTreeNearest *nearest) |
Int | FindNearest (Int threadIndex, const Vector &point, Float maxDistance, BaseArray< KDTreeNearest > &list, Int maxElements, Bool sortResults) |
Int | FindRange (Int threadIndex, const Vector &point, Float maxDistance, BaseArray< KDTreeNearest > &list, Bool sortResults) |
Private Member Functions | |
MAXON_DISALLOW_COPY_AND_ASSIGN (KDTree) | |
KDTreeNode * | Balance (Int index, Int count) |
void | InsertElement (BaseArray< KDTreeNearest > &list, Int &count, Float &maxRangeSquare, Int maxElements, KDTreeNode *node, Float distanceSquare) |
Bool | AppendElement (BaseArray< KDTreeNearest > &list, KDTreeNode *node, Float distance) |
Private Attributes | |
KDTreeNode * | _root |
BaseArray< KDTreeNode > | _nodelist |
PointerArray< KDStackArray > | _stack |
KDTree | ( | ) |
|
private |
MAXON_OPERATOR_MOVE_ASSIGNMENT | ( | KDTree | ) |
Initialize the kd-tree.
[in] | maxThreads | Maximum number of threads using the tree at the same time. set to 1 if no MP is used. |
void Free | ( | ) |
free the kd-tree and helper arrays
Insert a node into the kd-tree.
void Balance | ( | ) |
balance the kd-tree. This needs to be done once after all nodes have been inserted calling 'Insert'
Int FindNearest | ( | Int | threadIndex, |
const Vector & | point, | ||
KDTreeNearest * | nearest | ||
) |
Find the nearest node in the kd-tree.
[in] | threadIndex | Index of thread using the tree, set to 0 if no MP is used. |
[in] | point | Point in space that is searched for. |
[out] | nearest | Optional, can be nullptr. If provided the structure will be filled with information about the nearest node. |
Int FindNearest | ( | Int | threadIndex, |
const Vector & | point, | ||
Float | maxDistance, | ||
BaseArray< KDTreeNearest > & | list, | ||
Int | maxElements, | ||
Bool | sortResults | ||
) |
Find the nearest nodes in the kd-tree note: for performance reasons this routine should only be called if the maximum number of searched nodes is sufficiently small (<100), otherwise FindRange is the better choice.
[in] | threadIndex | Index of thread using the tree, set to 0 if no MP is used. |
[in] | point | Point in space that is searched for. |
[in] | maxDistance | Optional, can be MAXVALUE_FLOAT. If provided only nodes within this distance are searched. |
[out] | list | Array that will be filled with search results. the array doesn't have to be initialized before, this will be done inside the routine. for performance reasons try to re-use the array, so that memory doesn't have to be allocated each time. |
[in] | maxElements | Maximum number of elements that shall be searched for. |
[in] | sortResults | If true the resulting array will be sorted by distance, starting with the closest point. |
Int FindRange | ( | Int | threadIndex, |
const Vector & | point, | ||
Float | maxDistance, | ||
BaseArray< KDTreeNearest > & | list, | ||
Bool | sortResults | ||
) |
Find all nodes within a radius in the kd-tree note depending on the structure of the tree there can be a lot of search results (in an extreme case as many as there are nodes in the tree, which costs SIZEOF(KDTreeNearest)*nodes bytes memory.
[in] | threadIndex | Index of thread using the tree, set to 0 if no MP is used. |
[in] | point | Point in space that is searched for. |
[in] | maxDistance | Distance that nodes are searched within. |
[out] | list | Array that will be filled with search results. the array doesn't have to be initialized before, this will be done inside the routine. for performance reasons try to re-use the array, so that memory doesn't have to be allocated each time. |
[in] | sortResults | If true the resulting array will be sorted by distance, starting with the closest point. |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |