All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
search_column.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: search_column.h
3  * Description: Declaration of the Beam Search Column Class
4  * Author: Ahmad Abdulkader
5  * Created: 2008
6  *
7  * (C) Copyright 2008, Google Inc.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 // The SearchColumn class abstracts a column in the lattice that is created
21 // by the BeamSearch during the recognition process
22 // The class holds the lattice nodes. New nodes are added by calls to AddNode
23 // made from the BeamSearch
24 // The class maintains a hash table of the nodes to be able to lookup nodes
25 // quickly using their lang_mod_edge. This is needed to merge similar paths
26 // in the lattice
27 
28 #ifndef SEARCH_COLUMN_H
29 #define SEARCH_COLUMN_H
30 
31 #include "search_node.h"
32 #include "lang_mod_edge.h"
33 #include "cube_reco_context.h"
34 
35 namespace tesseract {
36 
37 class SearchColumn {
38  public:
39  SearchColumn(int col_idx, int max_node_cnt);
40  ~SearchColumn();
41  // Accessor functions
42  inline int ColIdx() const { return col_idx_; }
43  inline int NodeCount() const { return node_cnt_; }
44  inline SearchNode **Nodes() const { return node_array_; }
45 
46  // Prune the nodes if necessary. Pruning is done such that a max
47  // number of nodes is kept, i.e., the beam width
48  void Prune();
49  SearchNode *AddNode(LangModEdge *edge, int score,
50  SearchNode *parent, CubeRecoContext *cntxt);
51  // Returns the node with the least cost
53  // Sort the lattice nodes. Needed for visualization
54  void Sort();
55  // Free up the Hash Table. Added to be called by the Beam Search after
56  // a column is pruned to reduce memory foot print
57  void FreeHashTable() {
58  if (node_hash_table_ != NULL) {
59  delete node_hash_table_;
60  node_hash_table_ = NULL;
61  }
62  }
63 
64  private:
65  static const int kNodeAllocChunk = 1024;
66  static const int kScoreBins = 1024;
67  bool init_;
68  int min_cost_;
69  int max_cost_;
70  int max_node_cnt_;
71  int node_cnt_;
72  int col_idx_;
73  int score_bins_[kScoreBins];
74  SearchNode **node_array_;
75  SearchNodeHashTable *node_hash_table_;
76 
77  // Free node array and hash table
78  void Cleanup();
79  // Create hash table
80  bool Init();
81 };
82 }
83 
84 #endif // SEARCH_COLUMN_H
SearchColumn(int col_idx, int max_node_cnt)
SearchNode * AddNode(LangModEdge *edge, int score, SearchNode *parent, CubeRecoContext *cntxt)
SearchNode ** Nodes() const
Definition: search_column.h:44
#define NULL
Definition: host.h:144