tesseract  4.00.00dev
blkocc.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * File: blkocc.h (Formerly blockocc.h)
4  * Description: Block Occupancy routines
5  * Author: Chris Newton
6  * Created: Fri Nov 8
7  * Modified:
8  * Language: C++
9  * Package: N/A
10  * Status: Experimental (Do Not Distribute)
11  *
12  * (c) Copyright 1991, Hewlett-Packard Company.
13  ** Licensed under the Apache License, Version 2.0 (the "License");
14  ** you may not use this file except in compliance with the License.
15  ** You may obtain a copy of the License at
16  ** http://www.apache.org/licenses/LICENSE-2.0
17  ** Unless required by applicable law or agreed to in writing, software
18  ** distributed under the License is distributed on an "AS IS" BASIS,
19  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  ** See the License for the specific language governing permissions and
21  ** limitations under the License.
22  *
23  ******************************************************************************/
24 
25 #ifndef BLKOCC_H
26 #define BLKOCC_H
27 
28 #include "params.h"
29 #include "elst.h"
30 
31 /***************************************************************************
32 CLASS REGION_OCC
33 
34  The class REGION_OCC defines a section of outline which exists entirely
35  within a single region. The only data held is the min and max x limits of
36  the outline within the region.
37 
38  REGION_OCCs are held on lists, one list for each region. The lists are
39  built in sorted order of min x. Overlapping REGION_OCCs are not permitted on
40  a single list. An overlapping region to be added causes the existing region
41  to be extended. This extension may result in the following REGION_OCC on the
42  list overlapping the amended one. In this case the amended REGION_OCC is
43  further extended to include the range of the following one, so that the
44  following one can be deleted.
45 
46 ****************************************************************************/
47 
48 class REGION_OCC:public ELIST_LINK
49 {
50  public:
51  float min_x; //Lowest x in region
52  float max_x; //Highest x in region
53  inT16 region_type; //Type of crossing
54 
55  REGION_OCC() {} // constructor used
56  // only in COPIER etc
57  REGION_OCC( //constructor
58  float min,
59  float max,
60  inT16 region) {
61  min_x = min;
62  max_x = max;
63  region_type = region;
64  }
65 };
66 
68 #define RANGE_IN_BAND( band_max, band_min, range_max, range_min ) \
69 ( ((range_min) >= (band_min)) && ((range_max) < (band_max)) ) ? TRUE : FALSE
70 /************************************************************************
71 Adapted from the following procedure so that it can be used in the bands
72 class in an include file...
73 
74 BOOL8 range_in_band[
75  range within band?
76 inT16 band_max,
77 inT16 band_min,
78 inT16 range_max,
79 inT16 range_min]
80 {
81  if ( (range_min >= band_min) && (range_max < band_max) )
82  return TRUE;
83  else
84  return FALSE;
85 }
86 ***********************************************************************/
87 #define RANGE_OVERLAPS_BAND( band_max, band_min, range_max, range_min ) \
88 ( ((range_max) >= (band_min)) && ((range_min) < (band_max)) ) ? TRUE : FALSE
89 /************************************************************************
90 Adapted from the following procedure so that it can be used in the bands
91 class in an include file...
92 
93 BOOL8 range_overlaps_band[
94  range crosses band?
95 inT16 band_max,
96 inT16 band_min,
97 inT16 range_max,
98 inT16 range_min]
99 {
100  if ( (range_max >= band_min) && (range_min < band_max) )
101  return TRUE;
102  else
103  return FALSE;
104 }
105 ***********************************************************************/
106 /**********************************************************************
107  Bands
108  -----
109 
110  BAND 4
111 --------------------------------
112  BAND 3
113 --------------------------------
114 
115  BAND 2
116 
117 --------------------------------
118 
119  BAND 1
120 
121 Band 0 is the dot band
122 
123 Each band has an error margin above and below. An outline is not considered to
124 have significantly changed bands until it has moved out of the error margin.
125 *************************************************************************/
126 class BAND
127 {
128  public:
129  inT16 max_max; //upper max
130  inT16 max; //nominal max
131  inT16 min_max; //lower max
132  inT16 max_min; //upper min
133  inT16 min; //nominal min
134  inT16 min_min; //lower min
135 
136  BAND() {
137  } // constructor
138 
139  void set( // initialise a band
140  inT16 new_max_max, // upper max
141  inT16 new_max, // new nominal max
142  inT16 new_min_max, // new lower max
143  inT16 new_max_min, // new upper min
144  inT16 new_min, // new nominal min
145  inT16 new_min_min) { // new lower min
146  max_max = new_max_max;
147  max = new_max;
148  min_max = new_min_max;
149  max_min = new_max_min;
150  min = new_min;
151  min_min = new_min_min;
152  }
153 
154  BOOL8 in_minimal( //in minimal limits?
155  float y) { //y value
156  if ((y >= max_min) && (y < min_max))
157  return TRUE;
158  else
159  return FALSE;
160  }
161 
162  BOOL8 in_nominal( //in nominal limits?
163  float y) { //y value
164  if ((y >= min) && (y < max))
165  return TRUE;
166  else
167  return FALSE;
168  }
169 
170  BOOL8 in_maximal( //in maximal limits?
171  float y) { //y value
172  if ((y >= min_min) && (y < max_max))
173  return TRUE;
174  else
175  return FALSE;
176  }
177 
178  //overlaps min limits?
179  BOOL8 range_overlaps_minimal(float y1, //one range limit
180  float y2) { //other range limit
181  if (y1 > y2)
182  return RANGE_OVERLAPS_BAND (min_max, max_min, y1, y2);
183  else
184  return RANGE_OVERLAPS_BAND (min_max, max_min, y2, y1);
185  }
186 
187  //overlaps nom limits?
188  BOOL8 range_overlaps_nominal(float y1, //one range limit
189  float y2) { //other range limit
190  if (y1 > y2)
191  return RANGE_OVERLAPS_BAND (max, min, y1, y2);
192  else
193  return RANGE_OVERLAPS_BAND (max, min, y2, y1);
194  }
195 
196  //overlaps max limits?
197  BOOL8 range_overlaps_maximal(float y1, //one range limit
198  float y2) { //other range limit
199  if (y1 > y2)
200  return RANGE_OVERLAPS_BAND (max_max, min_min, y1, y2);
201  else
202  return RANGE_OVERLAPS_BAND (max_max, min_min, y2, y1);
203  }
204 
205  BOOL8 range_in_minimal( //within min limits?
206  float y1, //one range limit
207  float y2) { //other range limit
208  if (y1 > y2)
209  return RANGE_IN_BAND (min_max, max_min, y1, y2);
210  else
211  return RANGE_IN_BAND (min_max, max_min, y2, y1);
212  }
213 
214  BOOL8 range_in_nominal( //within nom limits?
215  float y1, //one range limit
216  float y2) { //other range limit
217  if (y1 > y2)
218  return RANGE_IN_BAND (max, min, y1, y2);
219  else
220  return RANGE_IN_BAND (max, min, y2, y1);
221  }
222 
223  BOOL8 range_in_maximal( //within max limits?
224  float y1, //one range limit
225  float y2) { //other range limit
226  if (y1 > y2)
227  return RANGE_IN_BAND (max_max, min_min, y1, y2);
228  else
229  return RANGE_IN_BAND (max_max, min_min, y2, y1);
230  }
231 };
232 
233 /* Standard positions */
234 
235 #define MAX_NUM_BANDS 5
236 #define UNDEFINED_BAND 99
237 #define NO_LOWER_LIMIT -9999
238 #define NO_UPPER_LIMIT 9999
239 
240 #define DOT_BAND 0
241 
242 /* Special occupancy code emitted for the 0 region at the end of a word */
243 
244 #define END_OF_WERD_CODE 255
245 
246 extern BOOL_VAR_H (blockocc_show_result, FALSE, "Show intermediate results");
248 "Descender height after normalisation");
249 extern INT_VAR_H (blockocc_asc_height, 255,
250 "Ascender height after normalisation");
251 extern INT_VAR_H (blockocc_band_count, 4, "Number of bands used");
253 "Fraction of width occupied");
254 
255 BOOL8 test_underline( //look for underlines
256  BOOL8 testing_on, //drawing blob
257  C_BLOB *blob, //blob to test
258  inT16 baseline, //coords of baseline
259  inT16 xheight //height of line
260  );
261 
262 #endif
BOOL8 range_overlaps_minimal(float y1, float y2)
Definition: blkocc.h:179
inT16 max
Definition: blkocc.h:130
inT16 min
Definition: blkocc.h:133
#define TRUE
Definition: capi.h:45
int blockocc_asc_height
inT16 region_type
Definition: blkocc.h:53
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:948
float max_x
Definition: blkocc.h:52
BOOL8 in_nominal(float y)
Definition: blkocc.h:162
int blockocc_band_count
#define RANGE_OVERLAPS_BAND(band_max, band_min, range_max, range_min)
Definition: blkocc.h:87
BOOL8 range_in_minimal(float y1, float y2)
Definition: blkocc.h:205
BOOL8 in_minimal(float y)
Definition: blkocc.h:154
BOOL8 range_in_nominal(float y1, float y2)
Definition: blkocc.h:214
REGION_OCC()
Definition: blkocc.h:55
int16_t inT16
Definition: host.h:36
BOOL8 range_in_maximal(float y1, float y2)
Definition: blkocc.h:223
bool blockocc_show_result
double textord_underline_threshold
Definition: blkocc.cpp:38
unsigned char BOOL8
Definition: host.h:44
#define FALSE
Definition: capi.h:46
#define double_VAR_H(name, val, comment)
Definition: params.h:273
BOOL8 in_maximal(float y)
Definition: blkocc.h:170
inT16 max_min
Definition: blkocc.h:132
int blockocc_desc_height
#define RANGE_IN_BAND(band_max, band_min, range_max, range_min)
Definition: blkocc.h:68
BOOL8 range_overlaps_maximal(float y1, float y2)
Definition: blkocc.h:197
Definition: blkocc.h:126
inT16 min_max
Definition: blkocc.h:131
BAND()
Definition: blkocc.h:136
const int max
#define INT_VAR_H(name, val, comment)
Definition: params.h:264
REGION_OCC(float min, float max, inT16 region)
Definition: blkocc.h:57
#define BOOL_VAR_H(name, val, comment)
Definition: params.h:267
BOOL8 range_overlaps_nominal(float y1, float y2)
Definition: blkocc.h:188
float min_x
Definition: blkocc.h:51
inT16 min_min
Definition: blkocc.h:134
inT16 max_max
Definition: blkocc.h:129
BOOL8 test_underline(BOOL8 testing_on, C_BLOB *blob, inT16 baseline, inT16 xheight)
Definition: blkocc.cpp:53