• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////
2 // File:        tablefind.h
3 // Description: Helper classes to find tables from ColPartitions.
4 // Author:      Faisal Shafait (faisal.shafait@dfki.de)
5 // Created:     Tue Jan 06 11:13:01 PST 2009
6 //
7 // (C) Copyright 2009, 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 #ifndef TESSERACT_TEXTORD_TABLEFIND_H__
21 #define TESSERACT_TEXTORD_TABLEFIND_H__
22 
23 #include "rect.h"
24 #include "elst.h"
25 
26 namespace tesseract {
27 
28 // Possible types for a column segment.
29 enum ColSegType {
30   COL_UNKNOWN,
31   COL_TEXT,
32   COL_TABLE,
33   COL_MIXED,
34   COL_COUNT
35 };
36 
37 // ColSegment holds rectangular blocks that represent segmentation of a page
38 // into regions containing single column text/table.
39 class ColSegment;
40 ELISTIZEH(ColSegment)
CLISTIZEH(ColSegment)41 CLISTIZEH(ColSegment)
42 
43 class ColSegment : public ELIST_LINK {
44  public:
45   ColSegment() : num_table_cells_(0), num_text_cells_(0),
46                  type_(COL_UNKNOWN) {
47   }
48   ~ColSegment() { }
49 
50   // Simple accessors and mutators
51   const TBOX& bounding_box() const {
52     return bounding_box_;
53   }
54 
55   void set_top(int y) {
56     bounding_box_.set_top(y);
57   }
58 
59   void set_bottom(int y) {
60     bounding_box_.set_bottom(y);
61   }
62 
63   void set_left(int x) {
64     bounding_box_.set_left(x);
65   }
66 
67   void set_right(int x) {
68     bounding_box_.set_right(x);
69   }
70 
71   void set_bounding_box(const TBOX& other) {
72     bounding_box_ = other;
73   }
74 
75   int get_num_table_cells() {
76     return num_table_cells_;
77   }
78 
79   // set the number of table colpartitions covered by the bounding_box_
80   void set_num_table_cells(int n) {
81     num_table_cells_ = n;
82   }
83 
84   int get_num_text_cells() {
85     return num_text_cells_;
86   }
87 
88   // set the number of text colpartitions covered by the bounding_box_
89   void set_num_text_cells(int n) {
90     num_text_cells_ = n;
91   }
92 
93   ColSegType type() {
94     return type_;
95   }
96 
97   // set the type of the block based on the ratio of table to text
98   // colpartitions covered by it.
99   void set_type();
100 
101   // Provides a color for BBGrid to draw the rectangle.
102   ScrollView::Color  BoxColor() const;
103 
104   // Insert a rectangle into bounding_box_
105   void InsertBox(const TBOX& other);
106 
107  private:
108   // Initializes the bulk of the members to default values.
109   void Init() {
110   }
111 
112   TBOX bounding_box_;                    // bounding box
113   int num_table_cells_;
114   int num_text_cells_;
115   ColSegType type_;
116 };
117 
118 // Typedef BBGrid of ColSegments
119 typedef BBGrid<ColSegment,
120                ColSegment_CLIST,
121                ColSegment_C_IT> ColSegmentGrid;
122 
123 
124 }  // namespace tesseract.
125 
126 #endif  // TESSERACT_TEXTORD_TABLEFIND_H__
127