tesseract  5.0.0-alpha-619-ge9db
kdtree.h
Go to the documentation of this file.
1 /******************************************************************************
2  ** Filename: kdtree.h
3  ** Purpose: Definition of K-D tree access routines.
4  ** Author: Dan Johnson
5  **
6  ** (c) Copyright Hewlett-Packard Company, 1988.
7  ** Licensed under the Apache License, Version 2.0 (the "License");
8  ** you may not use this file except in compliance with the License.
9  ** You may obtain a copy of the License at
10  ** http://www.apache.org/licenses/LICENSE-2.0
11  ** Unless required by applicable law or agreed to in writing, software
12  ** distributed under the License is distributed on an "AS IS" BASIS,
13  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  ** See the License for the specific language governing permissions and
15  ** limitations under the License.
16  *****************************************************************************/
17 
18 #ifndef KDTREE_H
19 #define KDTREE_H
20 
21 /*-----------------------------------------------------------------------------
22  Include Files and Type Defines
23 -----------------------------------------------------------------------------*/
24 #include "ocrfeatures.h"
25 
26 using void_proc = void (*)(...);
27 
38 struct KDNODE {
39  float* Key;
40  void* Data;
41  float BranchPoint;
42  float LeftBranch;
43  float RightBranch;
44  struct KDNODE* Left;
45  struct KDNODE* Right;
46 };
47 
48 struct KDTREE {
49  int16_t KeySize; /* number of dimensions in the tree */
50  KDNODE Root; /* Root.Left points to actual root node */
51  PARAM_DESC KeyDesc[1]; /* description of each dimension */
52 };
53 
54 /*----------------------------------------------------------------------------
55  Macros
56 -----------------------------------------------------------------------------*/
57 #define RootOf(T) ((T)->Root.Left->Data)
58 
59 /*-----------------------------------------------------------------------------
60  Public Function Prototypes
61 -----------------------------------------------------------------------------*/
62 KDTREE* MakeKDTree(int16_t KeySize, const PARAM_DESC KeyDesc[]);
63 
64 void KDStore(KDTREE* Tree, float* Key, void* Data);
65 
66 void KDDelete(KDTREE* Tree, float Key[], void* Data);
67 
68 void KDNearestNeighborSearch(KDTREE* Tree, float Query[], int QuerySize,
69  float MaxDistance, int* NumberOfResults,
70  void** NBuffer, float DBuffer[]);
71 
72 void KDWalk(KDTREE* Tree, void_proc Action, void* context);
73 
74 void FreeKDTree(KDTREE* Tree);
75 
76 /*-----------------------------------------------------------------------------
77  Private Function Prototypes
78 -----------------------------------------------------------------------------*/
79 KDNODE* MakeKDNode(KDTREE* tree, float Key[], void* Data, int Index);
80 
81 void FreeKDNode(KDNODE* Node);
82 
83 float DistanceSquared(int k, PARAM_DESC* dim, float p1[], float p2[]);
84 
85 float ComputeDistance(int k, PARAM_DESC* dim, float p1[], float p2[]);
86 
87 int QueryInSearch(KDTREE* tree);
88 
89 void Walk(KDTREE* tree, void_proc action, void* context, KDNODE* SubTree,
90  int32_t Level);
91 
92 void InsertNodes(KDTREE* tree, KDNODE* nodes);
93 
94 void FreeSubTree(KDNODE* SubTree);
95 
96 #endif
Walk
void Walk(KDTREE *tree, void_proc action, void *context, KDNODE *SubTree, int32_t Level)
Definition: kdtree.cpp:511
KDNODE::Key
float * Key
Definition: kdtree.h:38
KDNearestNeighborSearch
void KDNearestNeighborSearch(KDTREE *Tree, float Query[], int QuerySize, float MaxDistance, int *NumberOfResults, void **NBuffer, float DBuffer[])
Definition: kdtree.cpp:304
QueryInSearch
int QueryInSearch(KDTREE *tree)
InsertNodes
void InsertNodes(KDTREE *tree, KDNODE *nodes)
Definition: kdtree.cpp:521
KDTREE::KeyDesc
PARAM_DESC KeyDesc[1]
Definition: kdtree.h:50
FreeKDNode
void FreeKDNode(KDNODE *Node)
Definition: kdtree.cpp:369
ComputeDistance
float ComputeDistance(int k, PARAM_DESC *dim, float p1[], float p2[])
Definition: kdtree.cpp:447
void_proc
void(*)(...) void_proc
Definition: kdtree.h:25
KDTREE
Definition: kdtree.h:47
DistanceSquared
float DistanceSquared(int k, PARAM_DESC *dim, float p1[], float p2[])
Definition: kdtree.cpp:426
ocrfeatures.h
KDNODE::Data
void * Data
Definition: kdtree.h:39
KDTREE::Root
KDNODE Root
Definition: kdtree.h:49
KDNODE::Left
struct KDNODE * Left
Definition: kdtree.h:43
MakeKDNode
KDNODE * MakeKDNode(KDTREE *tree, float Key[], void *Data, int Index)
Definition: kdtree.cpp:351
FreeKDTree
void FreeKDTree(KDTREE *Tree)
Definition: kdtree.cpp:330
KDTREE::KeySize
int16_t KeySize
Definition: kdtree.h:48
MakeKDTree
KDTREE * MakeKDTree(int16_t KeySize, const PARAM_DESC KeyDesc[])
Definition: kdtree.cpp:179
KDWalk
void KDWalk(KDTREE *Tree, void_proc Action, void *context)
Definition: kdtree.cpp:314
PARAM_DESC
Definition: ocrfeatures.h:41
KDNODE::Right
struct KDNODE * Right
Definition: kdtree.h:44
KDStore
void KDStore(KDTREE *Tree, float *Key, void *Data)
Definition: kdtree.cpp:211
KDNODE::RightBranch
float RightBranch
Definition: kdtree.h:42
KDNODE::LeftBranch
float LeftBranch
Definition: kdtree.h:41
KDNODE::BranchPoint
float BranchPoint
Definition: kdtree.h:40
KDNODE
Definition: kdtree.h:37
KDDelete
void KDDelete(KDTREE *Tree, float Key[], void *Data)
Definition: kdtree.cpp:252
tesstrain_utils.action
action
Definition: tesstrain_utils.py:159
FreeSubTree
void FreeSubTree(KDNODE *SubTree)
Definition: kdtree.cpp:531