ccstruct/werd.h

Go to the documentation of this file.
00001 
00020 #ifndef           WERD_H
00021 #define           WERD_H
00022 
00023 #include          "varable.h"
00024 #include          "bits16.h"
00025 #include          "strngs.h"
00026 #include          "blckerr.h"
00027 #include          "stepblob.h"
00028 #include          "polyblob.h"
00029 //#include        "larcblob.h"
00030 
00035 enum WERD_FLAGS
00036 {
00037   W_SEGMENTED,                   // correctly segmented
00038   W_ITALIC,                      // italic text
00039   W_BOLD,                        // bold text
00040   W_BOL,                         // start of line
00041   W_EOL,                         // end of line
00042   W_NORMALIZED,                  // flags
00043   W_POLYGON,                     // approximation
00044   W_LINEARC,                     // linearc approx
00045   W_DONT_CHOP,                   // fixed pitch chopped
00046   W_REP_CHAR,                    // repeated character
00047   W_FUZZY_SP,                    // fuzzy space
00048   W_FUZZY_NON,                   // fuzzy nonspace
00049   W_INVERSE                      // white on black
00050 };
00051 
00056 enum DISPLAY_FLAGS
00057 {
00058   DF_BOX,                        // Bounding box
00059   DF_TEXT,                       // Correct ascii
00060   DF_POLYGONAL,                  // Polyg approx
00061   DF_EDGE_STEP,                  // Edge steps
00062   DF_BN_POLYGONAL                // BL normalisd polyapx
00063 };
00064 
00065 class ROW;                       //forward decl
00066 
00071 class WERD:public ELIST_LINK
00072 {
00073   public:
00074     WERD() { 
00075     }                            //empty constructor
00076     WERD(                        //constructor
00077          C_BLOB_LIST *blob_list, //blobs in word
00078          UINT8 blanks,           //blanks in front
00079          const char *text);      //correct text
00080     WERD(                        //constructor
00081          PBLOB_LIST *blob_list,  //blobs in word
00082          UINT8 blanks,           //blanks in front
00083          const char *text);      //correct text
00084     WERD(                        //constructor
00085          PBLOB_LIST *blob_list,  //blobs in word
00086          WERD *clone);           //use these flags etc.
00087     WERD(                        //constructor
00088          C_BLOB_LIST *blob_list, //blobs in word
00089          WERD *clone);           //use these flags etc.
00090     ~WERD () {                   //destructor
00091       if (flags.bit (W_POLYGON)) {
00092                                  //use right     destructor
00093         ((PBLOB_LIST *) & cblobs)->clear ();
00094                                  //use right     destructor
00095         ((PBLOB_LIST *) & rej_cblobs)->clear ();
00096       }
00097       //   else if (flags.bit(W_LINEARC))
00098       //   ((LARC_BLOB_LIST*)&cblobs)->clear();   //use right destructor
00099     }
00100 
00101     WERD *poly_copy(                 //make copy as poly
00102                     float xheight);  //row xheight
00103     WERD *larc_copy(                 //make copy as larc
00104                     float xheight);  //row xheight
00105 
00106                                  //get DUFF compact blobs
00107     C_BLOB_LIST *rej_cblob_list() { 
00108       if (flags.bit (W_POLYGON))
00109         WRONG_WORD.error ("WERD::rej_cblob_list", ABORT, NULL);
00110       return &rej_cblobs;
00111     }
00112 
00113                                  //get DUFF poly blobs
00114     PBLOB_LIST *rej_blob_list() { 
00115       if (!flags.bit (W_POLYGON))
00116         WRONG_WORD.error ("WERD::rej_blob_list", ABORT, NULL);
00117       return (PBLOB_LIST *) (&rej_cblobs);
00118     }
00119 
00120     C_BLOB_LIST *cblob_list() {  //get compact blobs
00121       if (flags.bit (W_POLYGON) || flags.bit (W_LINEARC))
00122         WRONG_WORD.error ("WERD::cblob_list", ABORT, NULL);
00123       return &cblobs;
00124     }
00125     PBLOB_LIST *blob_list() {  //get poly blobs
00126       if (!flags.bit (W_POLYGON))
00127         WRONG_WORD.error ("WERD::blob_list", ABORT, NULL);
00128                                  //make it right type
00129       return (PBLOB_LIST *) (&cblobs);
00130     }
00131     //      LARC_BLOB_LIST                          *larc_blob_list()                                       //get poly blobs
00132     //      {
00133     //              if (!flags.bit(W_LINEARC))
00134     //                      WRONG_WORD.error("WERD::larc_blob_list",ABORT,NULL);
00135     //              return (LARC_BLOB_LIST*)(&cblobs);                                              //make it right type
00136     //      }
00137     PBLOB_LIST *gblob_list() {  //get generic blobs
00138                                  //make it right type
00139       return (PBLOB_LIST *) (&cblobs);
00140     }
00141 
00142     const char *text() const {  //correct text
00143       return correct.string ();
00144     }
00145     UINT8 space() {  //access function
00146       return blanks;
00147     }
00148     void set_blanks(  //set blanks
00149                     UINT8 new_blanks) {
00150       blanks = new_blanks;
00151     }
00152 
00153     void set_text(                         //replace correct text
00154                   const char *new_text) {  //with this
00155       correct = new_text;
00156     }
00157 
00158     BOX bounding_box();  //compute bounding box
00159 
00160     BOOL8 flag(                          //test flag
00161                WERD_FLAGS mask) const {  //flag to test
00162       return flags.bit (mask);
00163     }
00164     void set_flag(                  //set flag value
00165                   WERD_FLAGS mask,  //flag to test
00166                   BOOL8 value) {    //value to set
00167       flags.set_bit (mask, value);
00168     }
00169 
00170     BOOL8 display_flag(                     //test display flag
00171                        UINT8 flag) const {  //flag to test
00172       return disp_flags.bit (flag);
00173     }
00174 
00175     void set_display_flag(                //set display flag
00176                           UINT8 flag,     //flag to set
00177                           BOOL8 value) {  //value to set
00178       disp_flags.set_bit (flag, value);
00179     }
00180 
00181     WERD *shallow_copy();  //shallow copy word
00182 
00183     void move(                    // reposition word
00184               const ICOORD vec);  // by vector
00185 
00186     void scale(                   // scale word
00187                const float vec);  // by multiplier
00188 
00189     void join_on(                //append word
00190                  WERD *&other);  //Deleting other
00191 
00192     void copy_on(                //copy blobs
00193                  WERD *&other);  //from other
00194 
00195     void baseline_normalise (    // Tess style BL Norm
00196                                  //optional antidote
00197       ROW * row, DENORM * denorm = NULL);
00198 
00199     void baseline_normalise_x (  //Use non standard xht
00200       ROW * row, float x_height, //Weird value to use
00201       DENORM * denorm = NULL);   //optional antidote
00202 
00203     void baseline_denormalise(  //un-normalise
00204                               const DENORM *denorm);
00205 
00206     void print(            //print
00207                FILE *fp);  //file to print on
00208 
00209     void plot (                  //draw one
00210       WINDOW window,             //window to draw in
00211                                  //uniform colour
00212       COLOUR colour, BOOL8 solid = FALSE);
00213 
00214     void plot (                  //draw one
00215                                  //in rainbow colours
00216       WINDOW window, BOOL8 solid = FALSE);
00217 
00218     void plot_rej_blobs (        //draw one
00219                                  //in rainbow colours
00220       WINDOW window, BOOL8 solid = FALSE);
00221 
00222     WERD & operator= (           //assign words
00223       const WERD & source);      //from this
00224 
00225     void prep_serialise() {  //set ptrs to counts
00226       correct.prep_serialise ();
00227       if (flags.bit (W_POLYGON))
00228         ((PBLOB_LIST *) (&cblobs))->prep_serialise ();
00229       //              else if (flags.bit(W_LINEARC))
00230       //                      ((LARC_BLOB_LIST*)(&cblobs))->prep_serialise();
00231       else
00232         cblobs.prep_serialise ();
00233       rej_cblobs.prep_serialise ();
00234     }
00235 
00236     void dump(  //write external bits
00237               FILE *f) {
00238       correct.dump (f);
00239       if (flags.bit (W_POLYGON))
00240         ((PBLOB_LIST *) (&cblobs))->dump (f);
00241       //              else if (flags.bit(W_LINEARC))
00242       //                      ((LARC_BLOB_LIST*)(&cblobs))->dump( f );
00243       else
00244         cblobs.dump (f);
00245       rej_cblobs.dump (f);
00246     }
00247 
00248     void de_dump(  //read external bits
00249                  FILE *f) {
00250       correct.de_dump (f);
00251       if (flags.bit (W_POLYGON))
00252         ((PBLOB_LIST *) (&cblobs))->de_dump (f);
00253       //              else if (flags.bit(W_LINEARC))
00254       //                      ((LARC_BLOB_LIST*)(&cblobs))->de_dump( f );
00255       else
00256         cblobs.de_dump (f);
00257       rej_cblobs.de_dump (f);
00258     }
00259 
00260     make_serialise (WERD) private:
00261     UINT8 blanks;                //no of blanks
00262     UINT8 dummy;                 //padding
00263     BITS16 flags;                //flags about word
00264     BITS16 disp_flags;           //display flags
00265     INT16 dummy2;                //padding
00266     STRING correct;              //correct text
00267     C_BLOB_LIST cblobs;          //compacted blobs
00268     C_BLOB_LIST rej_cblobs;      //DUFF blobs
00269 };
00270 
00271 ELISTIZEH_S (WERD)
00272 #include          "ocrrow.h"     //placed here due to
00273 
00275 extern BOOL_VAR_H (bln_numericmode, 0, "Optimize for numbers");
00276 extern INT_VAR_H (bln_x_height, 128, "Baseline Normalisation X-height");
00277 extern INT_VAR_H (bln_baseline_offset, 64,
00278 "Baseline Norm. offset of baseline");
00280 //void   poly_linearc_outlines(                  //do list of outlines
00281 //LARC_OUTLINE_LIST         *srclist,            //list to convert
00282 //OUTLINE_LIST              *destlist            //desstination list
00283 //);
00284 //OUTLINE                   *poly_larcline(      //draw it
00285 //LARC_OUTLINE              *srcline             //one to approximate
00286 //);
00287 int word_comparator(                     //sort blobs
00288                     const void *word1p,  //ptr to ptr to word1
00289                     const void *word2p   //ptr to ptr to word2
00290                    );
00291 #endif

Generated on Wed Feb 28 19:49:08 2007 for Tesseract by  doxygen 1.5.1