tesseract
5.0.0-alpha-619-ge9db
|
#include "kdtree.h"
#include "emalloc.h"
#include <algorithm>
#include <cfloat>
#include <cstdio>
#include <cmath>
Go to the source code of this file.
Classes | |
class | MinK< Key, Value > |
struct | MinK< Key, Value >::Element |
class | KDTreeSearch |
Macros | |
#define | Magnitude(X) ((X) < 0 ? -(X) : (X)) |
#define | NodeFound(N, K, D) (((N)->Key == (K)) && ((N)->Data == (D))) |
#define | MINSEARCH -FLT_MAX |
#define | MAXSEARCH FLT_MAX |
Functions | |
KDTREE * | MakeKDTree (int16_t KeySize, const PARAM_DESC KeyDesc[]) |
void | KDStore (KDTREE *Tree, float *Key, void *Data) |
void | KDDelete (KDTREE *Tree, float Key[], void *Data) |
void | KDNearestNeighborSearch (KDTREE *Tree, float Query[], int QuerySize, float MaxDistance, int *NumberOfResults, void **NBuffer, float DBuffer[]) |
void | KDWalk (KDTREE *Tree, void_proc action, void *context) |
void | FreeKDTree (KDTREE *Tree) |
KDNODE * | MakeKDNode (KDTREE *tree, float Key[], void *Data, int Index) |
void | FreeKDNode (KDNODE *Node) |
float | DistanceSquared (int k, PARAM_DESC *dim, float p1[], float p2[]) |
float | ComputeDistance (int k, PARAM_DESC *dim, float p1[], float p2[]) |
void | Walk (KDTREE *tree, void_proc action, void *context, KDNODE *sub_tree, int32_t level) |
void | InsertNodes (KDTREE *tree, KDNODE *nodes) |
void | FreeSubTree (KDNODE *sub_tree) |
#define Magnitude | ( | X | ) | ((X) < 0 ? -(X) : (X)) |
Definition at line 28 of file kdtree.cpp.
#define MAXSEARCH FLT_MAX |
Definition at line 35 of file kdtree.cpp.
#define MINSEARCH -FLT_MAX |
Definition at line 34 of file kdtree.cpp.
#define NodeFound | ( | N, | |
K, | |||
D | |||
) | (((N)->Key == (K)) && ((N)->Data == (D))) |
Definition at line 29 of file kdtree.cpp.
float ComputeDistance | ( | int | k, |
PARAM_DESC * | dim, | ||
float | p1[], | ||
float | p2[] | ||
) |
Definition at line 447 of file kdtree.cpp.
float DistanceSquared | ( | int | k, |
PARAM_DESC * | dim, | ||
float | p1[], | ||
float | p2[] | ||
) |
Returns the Euclidean distance squared between p1 and p2 for all essential dimensions.
k | keys are in k-space |
dim | dimension descriptions (essential, circular, etc) |
p1,p2 | two different points in K-D space |
Definition at line 426 of file kdtree.cpp.
void FreeKDNode | ( | KDNODE * | Node | ) |
Definition at line 369 of file kdtree.cpp.
void FreeKDTree | ( | KDTREE * | Tree | ) |
This routine frees all memory which is allocated to the specified KD-tree. This includes the data structure for the kd-tree itself plus the data structures for each node in the tree. It does not include the Key and Data items which are pointed to by the nodes. This memory is left untouched.
Tree | tree data structure to be released |
Definition at line 330 of file kdtree.cpp.
void FreeSubTree | ( | KDNODE * | sub_tree | ) |
Given a subtree nodes, insert all of its elements into tree.
Definition at line 521 of file kdtree.cpp.
void KDDelete | ( | KDTREE * | Tree, |
float | Key[], | ||
void * | Data | ||
) |
This routine deletes a node from Tree. The node to be deleted is specified by the Key for the node and the Data contents of the node. These two pointers must be identical to the pointers that were used for the node when it was originally stored in the tree. A node will be deleted from the tree only if its key and data pointers are identical to Key and Data respectively. The tree is re-formed by removing the affected subtree and inserting all elements but the root.
Tree | K-D tree to delete node from |
Key | key of node to be deleted |
Data | data contents of node to be deleted |
Definition at line 252 of file kdtree.cpp.
void KDNearestNeighborSearch | ( | KDTREE * | Tree, |
float | Query[], | ||
int | QuerySize, | ||
float | MaxDistance, | ||
int * | NumberOfResults, | ||
void ** | NBuffer, | ||
float | DBuffer[] | ||
) |
This routine searches the K-D tree specified by Tree and finds the QuerySize nearest neighbors of Query. All neighbors must be within MaxDistance of Query. The data contents of the nearest neighbors are placed in NBuffer and their distances from Query are placed in DBuffer.
Tree | ptr to K-D tree to be searched |
Query | ptr to query key (point in D-space) |
QuerySize | number of nearest neighbors to be found |
MaxDistance | all neighbors must be within this distance |
NBuffer | ptr to QuerySize buffer to hold nearest neighbors |
DBuffer | ptr to QuerySize buffer to hold distances from nearest neighbor to query point |
NumberOfResults | [out] Number of nearest neighbors actually found |
Definition at line 304 of file kdtree.cpp.
void KDStore | ( | KDTREE * | Tree, |
float * | Key, | ||
void * | Data | ||
) |
This routine stores Data in the K-D tree specified by Tree using Key as an access key.
Tree | K-D tree in which data is to be stored |
Key | ptr to key by which data can be retrieved |
Data | ptr to data to be stored in the tree |
Definition at line 211 of file kdtree.cpp.
This routine allocates memory for a new K-D tree node and places the specified Key and Data into it. The left and right subtree pointers for the node are initialized to empty subtrees.
tree | The tree to create the node for |
Key | Access key for new node in KD tree |
Data | ptr to data to be stored in new node |
Index | index of Key to branch on |
Definition at line 351 of file kdtree.cpp.
KDTREE* MakeKDTree | ( | int16_t | KeySize, |
const PARAM_DESC | KeyDesc[] | ||
) |
KeySize | # of dimensions in the K-D tree |
KeyDesc | array of params to describe key dimensions |
Definition at line 179 of file kdtree.cpp.
Walk a tree, calling action once on each node.
Operation: This routine walks through the specified sub_tree and invokes action action at each node as follows: action(context, data, level) data the data contents of the node being visited, level is the level of the node in the tree with the root being level 0.
tree | root of the tree being walked. |
action | action to be performed at every node |
context | action's context |
sub_tree | ptr to root of subtree to be walked |
level | current level in the tree for this node |
Definition at line 511 of file kdtree.cpp.