00001
00019 #ifndef BLKOCC_H
00020 #define BLKOCC_H
00021
00022 #include "varable.h"
00023 #include "polyblob.h"
00024 #include "elst.h"
00025 #include "notdll.h"
00026 #include "notdll.h"
00027
00042 class REGION_OCC:public ELIST_LINK
00043 {
00044 public:
00045 float min_x;
00046 float max_x;
00047 INT16 region_type;
00048
00049 REGION_OCC() {
00050 };
00051
00052 REGION_OCC(
00053 float min,
00054 float max,
00055 INT16 region) {
00056 min_x = min;
00057 max_x = max;
00058 region_type = region;
00059 }
00060 };
00061
00062 ELISTIZEH (REGION_OCC)
00063 #define RANGE_IN_BAND( band_max, band_min, range_max, range_min ) \
00064 ( ((range_min) >= (band_min)) && ((range_max) < (band_max)) ) ? TRUE : FALSE
00065
00086 #define RANGE_OVERLAPS_BAND( band_max, band_min, range_max, range_min ) \
00087 ( ((range_max) >= (band_min)) && ((range_min) < (band_max)) ) ? TRUE : FALSE
00088
00135 class BAND
00136 {
00137 public:
00138 INT16 max_max;
00139 INT16 max;
00140 INT16 min_max;
00141 INT16 max_min;
00142 INT16 min;
00143 INT16 min_min;
00144
00145 BAND() {
00146 }
00147
00148 void set(
00149 INT16 new_max_max,
00150 INT16 new_max,
00151 INT16 new_min_max,
00152 INT16 new_max_min,
00153 INT16 new_min,
00154 INT16 new_min_min) {
00155 max_max = new_max_max;
00156 max = new_max;
00157 min_max = new_min_max;
00158 max_min = new_max_min;
00159 min = new_min;
00160 min_min = new_min_min;
00161 }
00162
00163 BOOL8 in_minimal(
00164 float y) {
00165 if ((y >= max_min) && (y < min_max))
00166 return TRUE;
00167 else
00168 return FALSE;
00169 }
00170
00171 BOOL8 in_nominal(
00172 float y) {
00173 if ((y >= min) && (y < max))
00174 return TRUE;
00175 else
00176 return FALSE;
00177 }
00178
00179 BOOL8 in_maximal(
00180 float y) {
00181 if ((y >= min_min) && (y < max_max))
00182 return TRUE;
00183 else
00184 return FALSE;
00185 }
00186
00187
00188 BOOL8 range_overlaps_minimal(float y1,
00189 float y2) {
00190 if (y1 > y2)
00191 return RANGE_OVERLAPS_BAND (min_max, max_min, y1, y2);
00192 else
00193 return RANGE_OVERLAPS_BAND (min_max, max_min, y2, y1);
00194 }
00195
00196
00197 BOOL8 range_overlaps_nominal(float y1,
00198 float y2) {
00199 if (y1 > y2)
00200 return RANGE_OVERLAPS_BAND (max, min, y1, y2);
00201 else
00202 return RANGE_OVERLAPS_BAND (max, min, y2, y1);
00203 }
00204
00205
00206 BOOL8 range_overlaps_maximal(float y1,
00207 float y2) {
00208 if (y1 > y2)
00209 return RANGE_OVERLAPS_BAND (max_max, min_min, y1, y2);
00210 else
00211 return RANGE_OVERLAPS_BAND (max_max, min_min, y2, y1);
00212 }
00213
00214 BOOL8 range_in_minimal(
00215 float y1,
00216 float y2) {
00217 if (y1 > y2)
00218 return RANGE_IN_BAND (min_max, max_min, y1, y2);
00219 else
00220 return RANGE_IN_BAND (min_max, max_min, y2, y1);
00221 }
00222
00223 BOOL8 range_in_nominal(
00224 float y1,
00225 float y2) {
00226 if (y1 > y2)
00227 return RANGE_IN_BAND (max, min, y1, y2);
00228 else
00229 return RANGE_IN_BAND (max, min, y2, y1);
00230 }
00231
00232 BOOL8 range_in_maximal(
00233 float y1,
00234 float y2) {
00235 if (y1 > y2)
00236 return RANGE_IN_BAND (max_max, min_min, y1, y2);
00237 else
00238 return RANGE_IN_BAND (max_max, min_min, y2, y1);
00239 }
00240 };
00241
00243 #define MAX_NUM_BANDS 5
00244
00245 #define UNDEFINED_BAND 99
00246 #define NO_LOWER_LIMIT -9999
00247 #define NO_UPPER_LIMIT 9999
00248
00250 #define DOT_BAND 0
00251
00253 #define END_OF_WERD_CODE 255
00254
00257 extern BOOL_VAR_H (blockocc_show_result, FALSE, "Show intermediate results");
00258 extern INT_VAR_H (blockocc_desc_height, 0,
00259 "Descender height after normalisation");
00260 extern INT_VAR_H (blockocc_asc_height, 255,
00261 "Ascender height after normalisation");
00262 extern INT_VAR_H (blockocc_band_count, 4, "Number of bands used");
00263 extern double_VAR_H (textord_underline_threshold, 0.9,
00264 "Fraction of width occupied");
00267 BOOL8 test_underline(
00268 BOOL8 testing_on,
00269 PBLOB *blob,
00270 float baseline,
00271 float xheight
00272 );
00273 BOOL8 test_underline(
00274 BOOL8 testing_on,
00275 C_BLOB *blob,
00276 INT16 baseline,
00277 INT16 xheight
00278 );
00279
00280 void horizontal_cblob_projection(C_BLOB *blob,
00281 STATS *stats
00282 );
00283 void horizontal_coutline_projection(
00284 C_OUTLINE *outline,
00285 STATS *stats
00286 );
00287 void set_bands(
00288 float baseline,
00289 float xheight
00290 );
00291 void block_occ (PBLOB * blob,
00292 float occs[]
00293 );
00294
00295 void find_transitions(PBLOB *blob, REGION_OCC_LIST *region_occ_list);
00296 void record_region(
00297 INT16 band,
00298 float new_min,
00299 float new_max,
00300 INT16 region_type,
00301 REGION_OCC_LIST *region_occ_list);
00302 INT16 find_containing_maximal_band(
00303 float y1,
00304 float y2,
00305 BOOL8 *doubly_contained);
00306 void find_significant_line(POLYPT_IT it, INT16 *band);
00307 INT16 find_overlapping_minimal_band(
00308 float y1,
00309 float y2);
00310 INT16 find_region_type(INT16 entry_band,
00311 INT16 current_band,
00312 INT16 exit_band,
00313 float entry_x,
00314 float exit_x);
00315 void find_trans_point(POLYPT_IT *pt_it,
00316 INT16 current_band,
00317 INT16 next_band,
00318 FCOORD *transition_pt);
00319 void next_region(POLYPT_IT *start_pt_it,
00320 INT16 start_band,
00321 INT16 *to_band,
00322 float *min_x,
00323 float *max_x,
00324 INT16 *increment,
00325 FCOORD *exit_pt);
00326 INT16 find_band(
00327 float y);
00328 void compress_region_list(
00329 REGION_OCC_LIST *region_occ_list);
00330 void find_fbox(OUTLINE_IT *out_it,
00331 float *min_x,
00332 float *min_y,
00333 float *max_x,
00334 float *max_y);
00335 void maintain_limits(float *min_x, float *max_x, float x);
00336 #endif