All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 ammended one. In this case the ammended 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 
56  }; //constructor used
57  //only in COPIER etc
58  REGION_OCC( //constructor
59  float min,
60  float max,
61  inT16 region) {
62  min_x = min;
63  max_x = max;
64  region_type = region;
65  }
66 };
67 
69 #define RANGE_IN_BAND( band_max, band_min, range_max, range_min ) \
70 ( ((range_min) >= (band_min)) && ((range_max) < (band_max)) ) ? TRUE : FALSE
71 /************************************************************************
72 Adapted from the following procedure so that it can be used in the bands
73 class in an include file...
74 
75 BOOL8 range_in_band[
76  range within band?
77 inT16 band_max,
78 inT16 band_min,
79 inT16 range_max,
80 inT16 range_min]
81 {
82  if ( (range_min >= band_min) && (range_max < band_max) )
83  return TRUE;
84  else
85  return FALSE;
86 }
87 ***********************************************************************/
88 #define RANGE_OVERLAPS_BAND( band_max, band_min, range_max, range_min ) \
89 ( ((range_max) >= (band_min)) && ((range_min) < (band_max)) ) ? TRUE : FALSE
90 /************************************************************************
91 Adapted from the following procedure so that it can be used in the bands
92 class in an include file...
93 
94 BOOL8 range_overlaps_band[
95  range crosses band?
96 inT16 band_max,
97 inT16 band_min,
98 inT16 range_max,
99 inT16 range_min]
100 {
101  if ( (range_max >= band_min) && (range_min < band_max) )
102  return TRUE;
103  else
104  return FALSE;
105 }
106 ***********************************************************************/
107 /**********************************************************************
108  Bands
109  -----
110 
111  BAND 4
112 --------------------------------
113  BAND 3
114 --------------------------------
115 
116  BAND 2
117 
118 --------------------------------
119 
120  BAND 1
121 
122 Band 0 is the dot band
123 
124 Each band has an error margin above and below. An outline is not considered to
125 have significantly changed bands until it has moved out of the error margin.
126 *************************************************************************/
127 class BAND
128 {
129  public:
130  inT16 max_max; //upper max
131  inT16 max; //nominal max
132  inT16 min_max; //lower max
133  inT16 max_min; //upper min
134  inT16 min; //nominal min
135  inT16 min_min; //lower min
136 
137  BAND() {
138  } // constructor
139 
140  void set( // initialise a band
141  inT16 new_max_max, // upper max
142  inT16 new_max, // new nominal max
143  inT16 new_min_max, // new lower max
144  inT16 new_max_min, // new upper min
145  inT16 new_min, // new nominal min
146  inT16 new_min_min) { // new lower min
147  max_max = new_max_max;
148  max = new_max;
149  min_max = new_min_max;
150  max_min = new_max_min;
151  min = new_min;
152  min_min = new_min_min;
153  }
154 
155  BOOL8 in_minimal( //in minimal limits?
156  float y) { //y value
157  if ((y >= max_min) && (y < min_max))
158  return TRUE;
159  else
160  return FALSE;
161  }
162 
163  BOOL8 in_nominal( //in nominal limits?
164  float y) { //y value
165  if ((y >= min) && (y < max))
166  return TRUE;
167  else
168  return FALSE;
169  }
170 
171  BOOL8 in_maximal( //in maximal limits?
172  float y) { //y value
173  if ((y >= min_min) && (y < max_max))
174  return TRUE;
175  else
176  return FALSE;
177  }
178 
179  //overlaps min limits?
180  BOOL8 range_overlaps_minimal(float y1, //one range limit
181  float y2) { //other range limit
182  if (y1 > y2)
183  return RANGE_OVERLAPS_BAND (min_max, max_min, y1, y2);
184  else
185  return RANGE_OVERLAPS_BAND (min_max, max_min, y2, y1);
186  }
187 
188  //overlaps nom limits?
189  BOOL8 range_overlaps_nominal(float y1, //one range limit
190  float y2) { //other range limit
191  if (y1 > y2)
192  return RANGE_OVERLAPS_BAND (max, min, y1, y2);
193  else
194  return RANGE_OVERLAPS_BAND (max, min, y2, y1);
195  }
196 
197  //overlaps max limits?
198  BOOL8 range_overlaps_maximal(float y1, //one range limit
199  float y2) { //other range limit
200  if (y1 > y2)
201  return RANGE_OVERLAPS_BAND (max_max, min_min, y1, y2);
202  else
203  return RANGE_OVERLAPS_BAND (max_max, min_min, y2, y1);
204  }
205 
206  BOOL8 range_in_minimal( //within min limits?
207  float y1, //one range limit
208  float y2) { //other range limit
209  if (y1 > y2)
210  return RANGE_IN_BAND (min_max, max_min, y1, y2);
211  else
212  return RANGE_IN_BAND (min_max, max_min, y2, y1);
213  }
214 
215  BOOL8 range_in_nominal( //within nom limits?
216  float y1, //one range limit
217  float y2) { //other range limit
218  if (y1 > y2)
219  return RANGE_IN_BAND (max, min, y1, y2);
220  else
221  return RANGE_IN_BAND (max, min, y2, y1);
222  }
223 
224  BOOL8 range_in_maximal( //within max limits?
225  float y1, //one range limit
226  float y2) { //other range limit
227  if (y1 > y2)
228  return RANGE_IN_BAND (max_max, min_min, y1, y2);
229  else
230  return RANGE_IN_BAND (max_max, min_min, y2, y1);
231  }
232 };
233 
234 /* Standard positions */
235 
236 #define MAX_NUM_BANDS 5
237 #define UNDEFINED_BAND 99
238 #define NO_LOWER_LIMIT -9999
239 #define NO_UPPER_LIMIT 9999
240 
241 #define DOT_BAND 0
242 
243 /* Special occupancy code emitted for the 0 region at the end of a word */
244 
245 #define END_OF_WERD_CODE 255
246 
247 extern BOOL_VAR_H (blockocc_show_result, FALSE, "Show intermediate results");
249 "Descender height after normalisation");
250 extern INT_VAR_H (blockocc_asc_height, 255,
251 "Ascender height after normalisation");
252 extern INT_VAR_H (blockocc_band_count, 4, "Number of bands used");
254 "Fraction of width occupied");
255 
256 BOOL8 test_underline( //look for underlines
257  BOOL8 testing_on, //drawing blob
258  C_BLOB *blob, //blob to test
259  inT16 baseline, //coords of baseline
260  inT16 xheight //height of line
261  );
262 
263 #endif
REGION_OCC(float min, float max, inT16 region)
Definition: blkocc.h:58
inT16 max_min
Definition: blkocc.h:133
BOOL8 in_maximal(float y)
Definition: blkocc.h:171
int blockocc_asc_height
int blockocc_desc_height
float max_x
Definition: blkocc.h:52
#define INT_VAR_H(name, val, comment)
Definition: params.h:265
inT16 max_max
Definition: blkocc.h:130
inT16 region_type
Definition: blkocc.h:53
inT16 min
Definition: blkocc.h:134
unsigned char BOOL8
Definition: host.h:113
inT16 min_max
Definition: blkocc.h:132
BOOL8 in_nominal(float y)
Definition: blkocc.h:163
REGION_OCC()
Definition: blkocc.h:55
double textord_underline_threshold
Definition: blkocc.cpp:38
void set(inT16 new_max_max, inT16 new_max, inT16 new_min_max, inT16 new_max_min, inT16 new_min, inT16 new_min_min)
Definition: blkocc.h:140
bool blockocc_show_result
#define RANGE_IN_BAND(band_max, band_min, range_max, range_min)
Definition: blkocc.h:69
BOOL8 range_in_minimal(float y1, float y2)
Definition: blkocc.h:206
inT16 min_min
Definition: blkocc.h:135
BOOL8 test_underline(BOOL8 testing_on, C_BLOB *blob, inT16 baseline, inT16 xheight)
Definition: blkocc.cpp:53
BOOL8 range_in_nominal(float y1, float y2)
Definition: blkocc.h:215
BOOL8 range_overlaps_minimal(float y1, float y2)
Definition: blkocc.h:180
inT16 max
Definition: blkocc.h:131
BOOL8 range_in_maximal(float y1, float y2)
Definition: blkocc.h:224
BOOL8 in_minimal(float y)
Definition: blkocc.h:155
float min_x
Definition: blkocc.h:51
BOOL8 range_overlaps_maximal(float y1, float y2)
Definition: blkocc.h:198
#define double_VAR_H(name, val, comment)
Definition: params.h:274
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:981
Definition: blkocc.h:127
BAND()
Definition: blkocc.h:137
#define FALSE
Definition: capi.h:29
int blockocc_band_count
#define TRUE
Definition: capi.h:28
#define RANGE_OVERLAPS_BAND(band_max, band_min, range_max, range_min)
Definition: blkocc.h:88
#define BOOL_VAR_H(name, val, comment)
Definition: params.h:268
BOOL8 range_overlaps_nominal(float y1, float y2)
Definition: blkocc.h:189
short inT16
Definition: host.h:100