tesseract 4.1.1
Loading...
Searching...
No Matches
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/***************************************************************************
27CLASS 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
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/************************************************************************
66Adapted from the following procedure so that it can be used in the bands
67class in an include file...
68
69bool range_in_band[
70 range within band?
71int16_t band_max,
72int16_t band_min,
73int16_t range_max,
74int16_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/************************************************************************
85Adapted from the following procedure so that it can be used in the bands
86class in an include file...
87
88bool range_overlaps_band[
89 range crosses band?
90int16_t band_max,
91int16_t band_min,
92int16_t range_max,
93int16_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
116Band 0 is the dot band
117
118Each band has an error margin above and below. An outline is not considered to
119have significantly changed bands until it has moved out of the error margin.
120*************************************************************************/
121class 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
231extern BOOL_VAR_H (blockocc_show_result, false, "Show intermediate results");
233"Descender height after normalisation");
234extern INT_VAR_H (blockocc_asc_height, 255,
235"Ascender height after normalisation");
236extern INT_VAR_H (blockocc_band_count, 4, "Number of bands used");
238"Fraction of width occupied");
239
240bool 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
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:918
#define BOOL_VAR_H(name, val, comment)
Definition: params.h:297
#define INT_VAR_H(name, val, comment)
Definition: params.h:295
#define double_VAR_H(name, val, comment)
Definition: params.h:301
@ baseline
Definition: mfoutline.h:63
bool test_underline(bool testing_on, C_BLOB *blob, int16_t baseline, int16_t xheight)
Definition: blkocc.cpp:48
double textord_underline_threshold
Definition: blkocc.cpp:33
bool blockocc_show_result
int blockocc_desc_height
int blockocc_asc_height
#define RANGE_IN_BAND(band_max, band_min, range_max, range_min)
Definition: blkocc.h:63
int blockocc_band_count
#define RANGE_OVERLAPS_BAND(band_max, band_min, range_max, range_min)
Definition: blkocc.h:82
REGION_OCC()=default
float min_x
Definition: blkocc.h:46
int16_t region_type
Definition: blkocc.h:48
REGION_OCC(float min, float max, int16_t region)
Definition: blkocc.h:52
float max_x
Definition: blkocc.h:47
Definition: blkocc.h:122
bool in_maximal(float y)
Definition: blkocc.h:158
int16_t min_max
Definition: blkocc.h:126
int16_t max
Definition: blkocc.h:125
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:133
int16_t min
Definition: blkocc.h:128
bool in_nominal(float y)
Definition: blkocc.h:153
BAND()=default
bool in_minimal(float y)
Definition: blkocc.h:148
bool range_overlaps_nominal(float y1, float y2)
Definition: blkocc.h:173
int16_t max_max
Definition: blkocc.h:124
int16_t min_min
Definition: blkocc.h:129
int16_t max_min
Definition: blkocc.h:127
bool range_overlaps_maximal(float y1, float y2)
Definition: blkocc.h:182
bool range_in_minimal(float y1, float y2)
Definition: blkocc.h:190
bool range_overlaps_minimal(float y1, float y2)
Definition: blkocc.h:164
bool range_in_nominal(float y1, float y2)
Definition: blkocc.h:199
bool range_in_maximal(float y1, float y2)
Definition: blkocc.h:208