Woolz Image Processing
Version 1.8.3
|
Files | |
file | AlcKDTree.c |
A general purpose, arbitrary dimension, integer/floating point binary space partition tree (kD-tree). | |
Data Structures | |
struct | _AlcKDTNode |
A node in a binary space partition tree (kD-tree). Typedef: AlcKDTNode. More... | |
struct | _AlcKDTTree |
A binary space partition tree (kD-tree). Typedef: AlcKDTTree. More... | |
Functions | |
AlcKDTTree * | AlcKDTTreeNew (AlcPointType type, int dim, double tol, size_t nNodes, AlcErrno *dstErr) |
Creates a KD-tree data structure. More... | |
int | AlcKDTTreeFacts (AlcKDTTree *tree, FILE *fP) |
Prints facts about the kD-tree structure to a file. More... | |
AlcErrno | AlcKDTTreeFree (AlcKDTTree *tree) |
Free's the given KD-tree data structure and any nodes in the tree. More... | |
AlcKDTNode * | AlcKDTNodeNew (AlcKDTTree *tree, AlcKDTNode *parent, AlcPointP key, int cmp, AlcErrno *dstErr) |
Allocates a new node and sets it's fields. More... | |
void | AlcKDTNodeFree (AlcKDTTree *tree, AlcKDTNode *node) |
Free's the given KD-tree node and all it's child nodes by pushing them onto the stack of available nodes. More... | |
AlcKDTNode * | AlcKDTInsert (AlcKDTTree *tree, void *keyVal, AlcKDTNode **dstFndNod, AlcErrno *dstErr) |
Checks for a node in the tree with the given key, if such a node doesn't exist then insert a new one. More... | |
AlcKDTNode * | AlcKDTGetMatch (AlcKDTTree *tree, void *keyVal, AlcErrno *dstErr) |
Searches for a node with a matching key to the given key. More... | |
AlcKDTNode * | AlcKDTGetLeaf (AlcKDTTree *tree, AlcKDTNode *node, AlcPointP key) |
Searches for the leaf node containing the given key. progressing downwards in the tree. More... | |
AlcKDTNode * | AlcKDTGetNN (AlcKDTTree *tree, void *keyVal, double minDist, double *dstNNDist, AlcErrno *dstErr) |
Searches for the nearest neighbour node to the given key within the tree. More... | |
AlcKDTTree* AlcKDTTreeNew | ( | AlcPointType | type, |
int | dim, | ||
double | tol, | ||
size_t | nNodes, | ||
AlcErrno * | dstErr | ||
) |
Creates a KD-tree data structure.
type | Type of tree node key. |
dim | Dimension of tree (must be >= 1). |
tol | Tollerance for key comparision, only used if the tree has floating point keys. If the tolerance is negative it is set to a default value. |
nNodes | Expected number of nodes in the tree, 0 if unknown. This can be used to optimise node allocation. |
dstErr | Destination pointer for error code, may be NULL. |
References ALC_ER_ALLOC, ALC_ER_NONE, ALC_ER_PARAM, ALC_POINTTYPE_DBL, ALC_POINTTYPE_INT, AlcCalloc(), _AlcKDTTree::dim, _AlcKDTTree::keySz, _AlcKDTTree::nodeBlockSz, _AlcKDTTree::tol, and _AlcKDTTree::type.
Referenced by WlzPointsFromDomObj(), WlzScalarFeatures2D(), WlzSnapFit(), and WlzVerticesBuildTree().
int AlcKDTTreeFacts | ( | AlcKDTTree * | tree, |
FILE * | fP | ||
) |
Prints facts about the kD-tree structure to a file.
tree | The KD-tree tree |
fP | Output file stream. |
References _AlcKDTTree::dim, _AlcKDTTree::freeStack, _AlcKDTTree::keySz, _AlcKDTTree::nNodes, _AlcKDTTree::nodeBlockSz, _AlcKDTTree::nodeStack, _AlcKDTTree::root, _AlcKDTTree::tol, and _AlcKDTTree::type.
AlcErrno AlcKDTTreeFree | ( | AlcKDTTree * | tree | ) |
Free's the given KD-tree data structure and any nodes in the tree.
tree | The KD-tree data structure. |
References ALC_ER_NONE, AlcBlockStackFree(), AlcFree(), and _AlcKDTTree::freeStack.
Referenced by WlzDistMetricDirVertex2D(), WlzDistMetricDirVertex3D(), WlzPointsFromDomObj(), WlzScalarFeatures2D(), and WlzSnapFit().
AlcKDTNode* AlcKDTNodeNew | ( | AlcKDTTree * | tree, |
AlcKDTNode * | parent, | ||
AlcPointP | key, | ||
int | cmp, | ||
AlcErrno * | dstErr | ||
) |
Allocates a new node and sets it's fields.
tree | The KD-tree data structure. |
parent | Parent node, NULL if this is the first node of the tree. |
key | Key values to test agains those of the given node. (int or double) and dimension. |
cmp | The sign of cmp indicates which of the parent's children the new node will become:
|
dstErr | Destination pointer for error code, may be NULL. |
References ALC_ER_NONE.
Referenced by AlcKDTInsert().
void AlcKDTNodeFree | ( | AlcKDTTree * | tree, |
AlcKDTNode * | node | ||
) |
Free's the given KD-tree node and all it's child nodes by pushing them onto the stack of available nodes.
tree | The KD-tree data structure. |
node | The KD-tree node data structure. |
References _AlcKDTNode::childN, _AlcKDTNode::childP, and _AlcKDTTree::nodeStack.
AlcKDTNode* AlcKDTInsert | ( | AlcKDTTree * | tree, |
void * | keyVal, | ||
AlcKDTNode ** | dstFndNod, | ||
AlcErrno * | dstErr | ||
) |
Checks for a node in the tree with the given key, if such a node doesn't exist then insert a new one.
tree | Given tree. |
keyVal | Key values which must be consistent with the tree's node key type and dimension. |
dstFndNod | Destination pointer for matched node, may be NULL. |
dstErr | Destination pointer for error code, may be NULL. |
References ALC_ER_NONE, ALC_ER_NULLPTR, AlcKDTNodeNew(), _AlcPointP::kV, and _AlcKDTTree::root.
Referenced by WlzPointsFromDomObj(), WlzScalarFeatures2D(), WlzSnapFit(), and WlzVerticesBuildTree().
AlcKDTNode* AlcKDTGetMatch | ( | AlcKDTTree * | tree, |
void * | keyVal, | ||
AlcErrno * | dstErr | ||
) |
Searches for a node with a matching key to the given key.
tree | Given tree, |
keyVal | Key values which must be consistent with the tree's node key type and dimension. |
dstErr | Destination pointer for error code, may be NULL. |
References ALC_ER_NONE, ALC_ER_NULLPTR, _AlcPointP::kV, and _AlcKDTTree::root.
AlcKDTNode* AlcKDTGetLeaf | ( | AlcKDTTree * | tree, |
AlcKDTNode * | node, | ||
AlcPointP | key | ||
) |
Searches for the leaf node containing the given key. progressing downwards in the tree.
key or NULL if tree has no nodes.
tree | Given tree, |
node | Node to search from. |
key | Key values which must be consistent with the tree's node key type and dimension. |
Referenced by AlcKDTGetNN().
AlcKDTNode* AlcKDTGetNN | ( | AlcKDTTree * | tree, |
void * | keyVal, | ||
double | minDist, | ||
double * | dstNNDist, | ||
AlcErrno * | dstErr | ||
) |
Searches for the nearest neighbour node to the given key within the tree.
tree has no nodes.
tree | Given tree, |
keyVal | Key values which must be consistent with the tree's node key type and dimension. |
minDist | Maximum distance between given key and the nearest neighbour, any node at a greater distance is not a nearest neighbour. Confusingly used for the minimum key-node distance found. |
dstNNDist | Destination pointer for distance to nearest neighbour, may be NULL. |
dstErr | Destination pointer for error code, may be NULL. |
References ALC_ER_NONE, ALC_ER_NULLPTR, AlcKDTGetLeaf(), _AlcPointP::kV, and _AlcKDTTree::root.
Referenced by WlzDistMetricDirVertex2D(), WlzDistMetricDirVertex3D(), WlzPointsFromDomObj(), WlzScalarFeatures2D(), and WlzSnapFit().