tesseract  5.0.0-alpha-619-ge9db
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  *
7  * (c) Copyright 1991, Hewlett-Packard Company.
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 BLKOCC_H
21 #define BLKOCC_H
22 
23 #include "params.h"
24 #include "elst.h"
25 
26 /***************************************************************************
27 CLASS REGION_OCC
28 
29  The class REGION_OCC defines a section of outline which exists entirely
30  within a single region. The only data held is the min and max x limits of
31  the outline within the region.
32 
33  REGION_OCCs are held on lists, one list for each region. The lists are
34  built in sorted order of min x. Overlapping REGION_OCCs are not permitted on
35  a single list. An overlapping region to be added causes the existing region
36  to be extended. This extension may result in the following REGION_OCC on the
37  list overlapping the amended one. In this case the amended REGION_OCC is
38  further extended to include the range of the following one, so that the
39  following one can be deleted.
40 
41 ****************************************************************************/
42 
43 class REGION_OCC:public ELIST_LINK
44 {
45  public:
46  float min_x; //Lowest x in region
47  float max_x; //Highest x in region
48  int16_t region_type; //Type of crossing
49 
50  REGION_OCC() = default; // constructor used
51  // only in COPIER etc
52  REGION_OCC( //constructor
53  float min,
54  float max,
55  int16_t region) {
56  min_x = min;
57  max_x = max;
58  region_type = region;
59  }
60 };
61 
63 #define RANGE_IN_BAND(band_max, band_min, range_max, range_min) \
64 (((range_min) >= (band_min)) && ((range_max) < (band_max)))
65 /************************************************************************
66 Adapted from the following procedure so that it can be used in the bands
67 class in an include file...
68 
69 bool range_in_band[
70  range within band?
71 int16_t band_max,
72 int16_t band_min,
73 int16_t range_max,
74 int16_t range_min]
75 {
76  if ((range_min >= band_min) && (range_max < band_max))
77  return true;
78  else
79  return false;
80 }
81 ***********************************************************************/
82 #define RANGE_OVERLAPS_BAND(band_max, band_min, range_max, range_min) \
83 (((range_max) >= (band_min)) && ((range_min) < (band_max)))
84 /************************************************************************
85 Adapted from the following procedure so that it can be used in the bands
86 class in an include file...
87 
88 bool range_overlaps_band[
89  range crosses band?
90 int16_t band_max,
91 int16_t band_min,
92 int16_t range_max,
93 int16_t range_min]
94 {
95  if ((range_max >= band_min) && (range_min < band_max))
96  return true;
97  else
98  return false;
99 }
100 ***********************************************************************/
101 /**********************************************************************
102  Bands
103  -----
104 
105  BAND 4
106 --------------------------------
107  BAND 3
108 --------------------------------
109 
110  BAND 2
111 
112 --------------------------------
113 
114  BAND 1
115 
116 Band 0 is the dot band
117 
118 Each band has an error margin above and below. An outline is not considered to
119 have significantly changed bands until it has moved out of the error margin.
120 *************************************************************************/
121 class BAND
122 {
123  public:
124  int16_t max_max; //upper max
125  int16_t max; //nominal max
126  int16_t min_max; //lower max
127  int16_t max_min; //upper min
128  int16_t min; //nominal min
129  int16_t min_min; //lower min
130 
131  BAND() = default; // constructor
132 
133  void set( // initialise a band
134  int16_t new_max_max, // upper max
135  int16_t new_max, // new nominal max
136  int16_t new_min_max, // new lower max
137  int16_t new_max_min, // new upper min
138  int16_t new_min, // new nominal min
139  int16_t new_min_min) { // new lower min
140  max_max = new_max_max;
141  max = new_max;
142  min_max = new_min_max;
143  max_min = new_max_min;
144  min = new_min;
145  min_min = new_min_min;
146  }
147 
148  bool in_minimal( //in minimal limits?
149  float y) { //y value
150  return (y >= max_min) && (y < min_max);
151  }
152 
153  bool in_nominal( //in nominal limits?
154  float y) { //y value
155  return (y >= min) && (y < max);
156  }
157 
158  bool in_maximal( //in maximal limits?
159  float y) { //y value
160  return (y >= min_min) && (y < max_max);
161  }
162 
163  //overlaps min limits?
164  bool range_overlaps_minimal(float y1, //one range limit
165  float y2) { //other range limit
166  if (y1 > y2)
167  return RANGE_OVERLAPS_BAND (min_max, max_min, y1, y2);
168  else
169  return RANGE_OVERLAPS_BAND (min_max, max_min, y2, y1);
170  }
171 
172  //overlaps nom limits?
173  bool range_overlaps_nominal(float y1, //one range limit
174  float y2) { //other range limit
175  if (y1 > y2)
176  return RANGE_OVERLAPS_BAND (max, min, y1, y2);
177  else
178  return RANGE_OVERLAPS_BAND (max, min, y2, y1);
179  }
180 
181  //overlaps max limits?
182  bool range_overlaps_maximal(float y1, //one range limit
183  float y2) { //other range limit
184  if (y1 > y2)
185  return RANGE_OVERLAPS_BAND (max_max, min_min, y1, y2);
186  else
187  return RANGE_OVERLAPS_BAND (max_max, min_min, y2, y1);
188  }
189 
190  bool range_in_minimal( //within min limits?
191  float y1, //one range limit
192  float y2) { //other range limit
193  if (y1 > y2)
194  return RANGE_IN_BAND (min_max, max_min, y1, y2);
195  else
196  return RANGE_IN_BAND (min_max, max_min, y2, y1);
197  }
198 
199  bool range_in_nominal( //within nom limits?
200  float y1, //one range limit
201  float y2) { //other range limit
202  if (y1 > y2)
203  return RANGE_IN_BAND (max, min, y1, y2);
204  else
205  return RANGE_IN_BAND (max, min, y2, y1);
206  }
207 
208  bool range_in_maximal( //within max limits?
209  float y1, //one range limit
210  float y2) { //other range limit
211  if (y1 > y2)
212  return RANGE_IN_BAND (max_max, min_min, y1, y2);
213  else
214  return RANGE_IN_BAND (max_max, min_min, y2, y1);
215  }
216 };
217 
218 /* Standard positions */
219 
220 #define MAX_NUM_BANDS 5
221 #define UNDEFINED_BAND 99
222 #define NO_LOWER_LIMIT -9999
223 #define NO_UPPER_LIMIT 9999
224 
225 #define DOT_BAND 0
226 
227 /* Special occupancy code emitted for the 0 region at the end of a word */
228 
229 #define END_OF_WERD_CODE 255
230 
231 extern BOOL_VAR_H (blockocc_show_result, false, "Show intermediate results");
233 "Descender height after normalisation");
234 extern INT_VAR_H (blockocc_asc_height, 255,
235 "Ascender height after normalisation");
236 extern INT_VAR_H (blockocc_band_count, 4, "Number of bands used");
238 "Fraction of width occupied");
239 
240 bool test_underline( //look for underlines
241  bool testing_on, //drawing blob
242  C_BLOB* blob, //blob to test
243  int16_t baseline, //coords of baseline
244  int16_t xheight //height of line
245 );
246 
247 #endif
elst.h
BAND::min_min
int16_t min_min
Definition: blkocc.h:157
BAND::max_min
int16_t max_min
Definition: blkocc.h:155
REGION_OCC
Definition: blkocc.h:41
BAND::min_max
int16_t min_max
Definition: blkocc.h:154
textord_underline_threshold
double textord_underline_threshold
Definition: blkocc.cpp:33
baseline
Definition: mfoutline.h:62
params.h
BAND::max
int16_t max
Definition: blkocc.h:153
BAND::range_in_maximal
bool range_in_maximal(float y1, float y2)
Definition: blkocc.h:236
BAND::in_maximal
bool in_maximal(float y)
Definition: blkocc.h:186
blockocc_desc_height
int blockocc_desc_height
double_VAR_H
#define double_VAR_H(name, val, comment)
Definition: params.h:298
ELISTIZEH
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:907
C_BLOB
Definition: stepblob.h:36
BAND::range_overlaps_minimal
bool range_overlaps_minimal(float y1, float y2)
Definition: blkocc.h:192
REGION_OCC::max_x
float max_x
Definition: blkocc.h:75
RANGE_OVERLAPS_BAND
#define RANGE_OVERLAPS_BAND(band_max, band_min, range_max, range_min)
Definition: blkocc.h:79
BAND::min
int16_t min
Definition: blkocc.h:156
REGION_OCC::REGION_OCC
REGION_OCC()=default
REGION_OCC::region_type
int16_t region_type
Definition: blkocc.h:76
BAND::BAND
BAND()=default
BAND::range_in_minimal
bool range_in_minimal(float y1, float y2)
Definition: blkocc.h:218
BAND::range_overlaps_nominal
bool range_overlaps_nominal(float y1, float y2)
Definition: blkocc.h:201
REGION_OCC::min_x
float min_x
Definition: blkocc.h:74
blockocc_asc_height
int blockocc_asc_height
BAND::range_overlaps_maximal
bool range_overlaps_maximal(float y1, float y2)
Definition: blkocc.h:210
BAND::in_nominal
bool in_nominal(float y)
Definition: blkocc.h:181
blockocc_band_count
int blockocc_band_count
INT_VAR_H
#define INT_VAR_H(name, val, comment)
Definition: params.h:292
blockocc_show_result
bool blockocc_show_result
BAND::max_max
int16_t max_max
Definition: blkocc.h:152
BOOL_VAR_H
#define BOOL_VAR_H(name, val, comment)
Definition: params.h:294
BAND::in_minimal
bool in_minimal(float y)
Definition: blkocc.h:176
BAND
Definition: blkocc.h:116
BAND::range_in_nominal
bool range_in_nominal(float y1, float y2)
Definition: blkocc.h:227
ELIST_LINK
Definition: elst.h:74
RANGE_IN_BAND
#define RANGE_IN_BAND(band_max, band_min, range_max, range_min)
Definition: blkocc.h:61
test_underline
bool test_underline(bool testing_on, C_BLOB *blob, int16_t baseline, int16_t xheight)
Definition: blkocc.cpp:48
BAND::set
void set(int16_t new_max_max, int16_t new_max, int16_t new_min_max, int16_t new_max_min, int16_t new_min, int16_t new_min_min)
Definition: blkocc.h:161