Tesseract  3.02
tesseract-ocr/textord/blkocc.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * File:        blkocc.h  (Formerly blockocc.h)
00004  * Description:  Block Occupancy routines
00005  * Author:       Chris Newton
00006  * Created:      Fri Nov 8
00007  * Modified:
00008  * Language:     C++
00009  * Package:      N/A
00010  * Status:       Experimental (Do Not Distribute)
00011  *
00012  * (c) Copyright 1991, Hewlett-Packard Company.
00013  ** Licensed under the Apache License, Version 2.0 (the "License");
00014  ** you may not use this file except in compliance with the License.
00015  ** You may obtain a copy of the License at
00016  ** http://www.apache.org/licenses/LICENSE-2.0
00017  ** Unless required by applicable law or agreed to in writing, software
00018  ** distributed under the License is distributed on an "AS IS" BASIS,
00019  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020  ** See the License for the specific language governing permissions and
00021  ** limitations under the License.
00022  *
00023  ******************************************************************************/
00024 
00025 #ifndef           BLKOCC_H
00026 #define           BLKOCC_H
00027 
00028 #include                   "params.h"
00029 #include          "elst.h"
00030 #include          "notdll.h"
00031 #include          "notdll.h"
00032 
00033 /***************************************************************************
00034 CLASS REGION_OCC
00035 
00036   The class REGION_OCC defines a section of outline which exists entirely
00037   within a single region. The only data held is the min and max x limits of
00038   the outline within the region.
00039 
00040   REGION_OCCs are held on lists, one list for each region.  The lists are
00041   built in sorted order of min x. Overlapping REGION_OCCs are not permitted on
00042   a single list. An overlapping region to be added causes the existing region
00043   to be extended. This extension may result in the following REGION_OCC on the
00044   list overlapping the ammended one. In this case the ammended REGION_OCC is
00045   further extended to include the range of the following one, so that the
00046   following one can be deleted.
00047 
00048 ****************************************************************************/
00049 
00050 class REGION_OCC:public ELIST_LINK
00051 {
00052   public:
00053     float min_x;                 //Lowest x in region
00054     float max_x;                 //Highest x in region
00055     inT16 region_type;           //Type of crossing
00056 
00057     REGION_OCC() {
00058     };                           //constructor used
00059     //only in COPIER etc
00060     REGION_OCC(  //constructor
00061                float min,
00062                float max,
00063                inT16 region) {
00064       min_x = min;
00065       max_x = max;
00066       region_type = region;
00067     }
00068 };
00069 
00070 ELISTIZEH (REGION_OCC)
00071 #define RANGE_IN_BAND( band_max, band_min, range_max, range_min ) \
00072 ( ((range_min) >= (band_min)) && ((range_max) < (band_max)) ) ? TRUE : FALSE
00073 /************************************************************************
00074 Adapted from the following procedure so that it can be used in the bands
00075 class in an include file...
00076 
00077 BOOL8                                           range_in_band[
00078               range within band?
00079 inT16                                           band_max,
00080 inT16                                           band_min,
00081 inT16                                           range_max,
00082 inT16                                           range_min]
00083 {
00084   if ( (range_min >= band_min) && (range_max < band_max) )
00085     return TRUE;
00086   else
00087     return FALSE;
00088 }
00089 ***********************************************************************/
00090 #define RANGE_OVERLAPS_BAND( band_max, band_min, range_max, range_min ) \
00091 ( ((range_max) >= (band_min)) && ((range_min) < (band_max)) ) ? TRUE : FALSE
00092 /************************************************************************
00093 Adapted from the following procedure so that it can be used in the bands
00094 class in an include file...
00095 
00096 BOOL8                                           range_overlaps_band[
00097               range crosses band?
00098 inT16                                           band_max,
00099 inT16                                           band_min,
00100 inT16                                           range_max,
00101 inT16                                           range_min]
00102 {
00103   if ( (range_max >= band_min) && (range_min < band_max) )
00104     return TRUE;
00105   else
00106     return FALSE;
00107 }
00108 ***********************************************************************/
00109 /**********************************************************************
00110   Bands
00111   -----
00112 
00113   BAND 4
00114 --------------------------------
00115   BAND 3
00116 --------------------------------
00117 
00118   BAND 2
00119 
00120 --------------------------------
00121 
00122   BAND 1
00123 
00124 Band 0 is the dot band
00125 
00126 Each band has an error margin above and below. An outline is not considered to
00127 have significantly changed bands until it has moved out of the error margin.
00128 *************************************************************************/
00129 class BAND
00130 {
00131   public:
00132     inT16 max_max;               //upper max
00133     inT16 max;                   //nominal max
00134     inT16 min_max;               //lower max
00135     inT16 max_min;               //upper min
00136     inT16 min;                   //nominal min
00137     inT16 min_min;               //lower min
00138 
00139     BAND() {
00140     }                            // constructor
00141 
00142     void set(                      // initialise a band
00143              inT16 new_max_max,    // upper max
00144              inT16 new_max,        // new nominal max
00145              inT16 new_min_max,    // new lower max
00146              inT16 new_max_min,    // new upper min
00147              inT16 new_min,        // new nominal min
00148              inT16 new_min_min) {  // new lower min
00149       max_max = new_max_max;
00150       max = new_max;
00151       min_max = new_min_max;
00152       max_min = new_max_min;
00153       min = new_min;
00154       min_min = new_min_min;
00155     }
00156 
00157     BOOL8 in_minimal(            //in minimal limits?
00158                      float y) {  //y value
00159       if ((y >= max_min) && (y < min_max))
00160         return TRUE;
00161       else
00162         return FALSE;
00163     }
00164 
00165     BOOL8 in_nominal(            //in nominal limits?
00166                      float y) {  //y value
00167       if ((y >= min) && (y < max))
00168         return TRUE;
00169       else
00170         return FALSE;
00171     }
00172 
00173     BOOL8 in_maximal(            //in maximal limits?
00174                      float y) {  //y value
00175       if ((y >= min_min) && (y < max_max))
00176         return TRUE;
00177       else
00178         return FALSE;
00179     }
00180 
00181                                  //overlaps min limits?
00182     BOOL8 range_overlaps_minimal(float y1,    //one range limit
00183                                  float y2) {  //other range limit
00184       if (y1 > y2)
00185         return RANGE_OVERLAPS_BAND (min_max, max_min, y1, y2);
00186       else
00187         return RANGE_OVERLAPS_BAND (min_max, max_min, y2, y1);
00188     }
00189 
00190                                  //overlaps nom limits?
00191     BOOL8 range_overlaps_nominal(float y1,    //one range limit
00192                                  float y2) {  //other range limit
00193       if (y1 > y2)
00194         return RANGE_OVERLAPS_BAND (max, min, y1, y2);
00195       else
00196         return RANGE_OVERLAPS_BAND (max, min, y2, y1);
00197     }
00198 
00199                                  //overlaps max limits?
00200     BOOL8 range_overlaps_maximal(float y1,    //one range limit
00201                                  float y2) {  //other range limit
00202       if (y1 > y2)
00203         return RANGE_OVERLAPS_BAND (max_max, min_min, y1, y2);
00204       else
00205         return RANGE_OVERLAPS_BAND (max_max, min_min, y2, y1);
00206     }
00207 
00208     BOOL8 range_in_minimal(             //within min limits?
00209                            float y1,    //one range limit
00210                            float y2) {  //other range limit
00211       if (y1 > y2)
00212         return RANGE_IN_BAND (min_max, max_min, y1, y2);
00213       else
00214         return RANGE_IN_BAND (min_max, max_min, y2, y1);
00215     }
00216 
00217     BOOL8 range_in_nominal(             //within nom limits?
00218                            float y1,    //one range limit
00219                            float y2) {  //other range limit
00220       if (y1 > y2)
00221         return RANGE_IN_BAND (max, min, y1, y2);
00222       else
00223         return RANGE_IN_BAND (max, min, y2, y1);
00224     }
00225 
00226     BOOL8 range_in_maximal(             //within max limits?
00227                            float y1,    //one range limit
00228                            float y2) {  //other range limit
00229       if (y1 > y2)
00230         return RANGE_IN_BAND (max_max, min_min, y1, y2);
00231       else
00232         return RANGE_IN_BAND (max_max, min_min, y2, y1);
00233     }
00234 };
00235 
00236 /* Standard positions */
00237 
00238 #define MAX_NUM_BANDS 5
00239 #define UNDEFINED_BAND 99
00240 #define NO_LOWER_LIMIT -9999
00241 #define NO_UPPER_LIMIT 9999
00242 
00243 #define DOT_BAND 0
00244 
00245 /* Special occupancy code emitted for the 0 region at the end of a word */
00246 
00247 #define END_OF_WERD_CODE 255
00248 
00249 extern BOOL_VAR_H (blockocc_show_result, FALSE, "Show intermediate results");
00250 extern INT_VAR_H (blockocc_desc_height, 0,
00251 "Descender height after normalisation");
00252 extern INT_VAR_H (blockocc_asc_height, 255,
00253 "Ascender height after normalisation");
00254 extern INT_VAR_H (blockocc_band_count, 4, "Number of bands used");
00255 extern double_VAR_H (textord_underline_threshold, 0.9,
00256 "Fraction of width occupied");
00257 
00258 BOOL8 test_underline(                   //look for underlines
00259                      BOOL8 testing_on,  //drawing blob
00260                      C_BLOB *blob,      //blob to test
00261                      inT16 baseline,    //coords of baseline
00262                      inT16 xheight      //height of line
00263                     );
00264 
00265 #endif