tesseract
3.05.02
|
#include "kdtree.h"
#include "const.h"
#include "emalloc.h"
#include "freelist.h"
#include <stdio.h>
#include <math.h>
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 -MAX_FLOAT32 |
#define | MAXSEARCH MAX_FLOAT32 |
Functions | |
KDTREE * | MakeKDTree (inT16 KeySize, const PARAM_DESC KeyDesc[]) |
void | KDStore (KDTREE *Tree, FLOAT32 *Key, void *Data) |
void | KDDelete (KDTREE *Tree, FLOAT32 Key[], void *Data) |
void | KDNearestNeighborSearch (KDTREE *Tree, FLOAT32 Query[], int QuerySize, FLOAT32 MaxDistance, int *NumberOfResults, void **NBuffer, FLOAT32 DBuffer[]) |
void | KDWalk (KDTREE *Tree, void_proc action, void *context) |
void | FreeKDTree (KDTREE *Tree) |
KDNODE * | MakeKDNode (KDTREE *tree, FLOAT32 Key[], void *Data, int Index) |
void | FreeKDNode (KDNODE *Node) |
FLOAT32 | DistanceSquared (int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) |
FLOAT32 | ComputeDistance (int k, PARAM_DESC *dim, FLOAT32 p1[], FLOAT32 p2[]) |
void | Walk (KDTREE *tree, void_proc action, void *context, KDNODE *sub_tree, inT32 level) |
void | InsertNodes (KDTREE *tree, KDNODE *nodes) |
void | FreeSubTree (KDNODE *sub_tree) |
#define Magnitude | ( | X | ) | ((X) < 0 ? -(X) : (X)) |
Definition at line 31 of file kdtree.cpp.
#define MAXSEARCH MAX_FLOAT32 |
Definition at line 38 of file kdtree.cpp.
#define MINSEARCH -MAX_FLOAT32 |
Definition at line 37 of file kdtree.cpp.
#define NodeFound | ( | N, | |
K, | |||
D | |||
) | (( (N)->Key == (K) ) && ( (N)->Data == (D) )) |
Definition at line 32 of file kdtree.cpp.
FLOAT32 ComputeDistance | ( | int | k, |
PARAM_DESC * | dim, | ||
FLOAT32 | p1[], | ||
FLOAT32 | p2[] | ||
) |
Definition at line 472 of file kdtree.cpp.
FLOAT32 DistanceSquared | ( | int | k, |
PARAM_DESC * | dim, | ||
FLOAT32 | p1[], | ||
FLOAT32 | 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 451 of file kdtree.cpp.
void FreeKDNode | ( | KDNODE * | Node | ) |
Definition at line 391 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 350 of file kdtree.cpp.
void FreeSubTree | ( | KDNODE * | sub_tree | ) |
Given a subtree nodes, insert all of its elements into tree.
Definition at line 545 of file kdtree.cpp.
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 265 of file kdtree.cpp.
void KDNearestNeighborSearch | ( | KDTREE * | Tree, |
FLOAT32 | Query[], | ||
int | QuerySize, | ||
FLOAT32 | MaxDistance, | ||
int * | NumberOfResults, | ||
void ** | NBuffer, | ||
FLOAT32 | 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 321 of file kdtree.cpp.
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 219 of file kdtree.cpp.
Walk a given Tree with action.
Definition at line 331 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 373 of file kdtree.cpp.
KDTREE* MakeKDTree | ( | inT16 | KeySize, |
const PARAM_DESC | KeyDesc[] | ||
) |
KeySize | # of dimensions in the K-D tree |
KeyDesc | array of params to describe key dimensions |
Definition at line 183 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 535 of file kdtree.cpp.