WERD Class Reference

#include <werd.h>

Inheritance diagram for WERD:

ELIST_LINK List of all members.

Detailed Description

Class dealing with & operating on each werd.

Definition at line 71 of file werd.h.

Public Member Functions

Public Attributes


Constructor & Destructor Documentation

WERD::WERD (  )  [inline]

Definition at line 74 of file werd.h.

00074            { 
00075     }                            //empty constructor

WERD::WERD ( C_BLOB_LIST *  blob_list,
UINT8  blanks,
const char *  text 
)

WERD::WERD ( PBLOB_LIST *  blob_list,
UINT8  blank_count,
const char *  text 
)

Constructor to build a WERD from a list of BLOBs;.

The BLOBs are not copied so the source list is emptied.

Definition at line 141 of file werd.cpp.

References cblobs, TRUE, and W_POLYGON.

00145  :
00146 flags (0),
00147 correct(text) { 
00148   PBLOB_IT start_it = blob_list; //iterator
00149   PBLOB_IT end_it = blob_list;   //another
00150 
00151   while (!end_it.at_last ())
00152     end_it.forward ();           //move to last
00153   ((PBLOB_LIST *) (&cblobs))->assign_to_sublist (&start_it, &end_it);
00154   //move to our list
00155                                  //it's a polygon
00156   flags.set_bit (W_POLYGON, TRUE);
00157   blanks = blank_count;
00158   //      fprintf(stderr,"Wrong constructor!!!!\n");
00159 }

WERD::WERD ( PBLOB_LIST *  blob_list,
WERD clone 
)

Constructor to build a WERD from a list of BLOBs;.

The BLOBs are not copied so the source list is emptied.

Definition at line 167 of file werd.cpp.

References cblobs, and clone.

00170  :flags (clone->flags), correct (clone->correct) {
00171   PBLOB_IT start_it = blob_list; //iterator
00172   PBLOB_IT end_it = blob_list;   //another
00173 
00174   while (!end_it.at_last ())
00175     end_it.forward ();           //move to last
00176   ((PBLOB_LIST *) (&cblobs))->assign_to_sublist (&start_it, &end_it);
00177   //move to our list
00178   blanks = clone->blanks;
00179   //      fprintf(stderr,"Wrong constructor!!!!\n");
00180 }

WERD::WERD ( C_BLOB_LIST *  blob_list,
WERD clone 
)

Constructor to build a WERD from a list of C_BLOBs;.

The C_BLOBs are not copied so the source list is emptied.

Definition at line 188 of file werd.cpp.

References cblobs, and clone.

00191  :flags (clone->flags), correct (clone->correct) {
00192   C_BLOB_IT start_it = blob_list;//iterator
00193   C_BLOB_IT end_it = blob_list;  //another
00194 
00195   while (!end_it.at_last ())
00196     end_it.forward ();           //move to last
00197   ((C_BLOB_LIST *) (&cblobs))->assign_to_sublist (&start_it, &end_it);
00198   //move to our list
00199   blanks = clone->blanks;
00200   //      fprintf(stderr,"Wrong constructor!!!!\n");
00201 }

WERD::~WERD (  )  [inline]

Definition at line 90 of file werd.h.

References BITS16::bit(), cblobs, flags, rej_cblobs, and W_POLYGON.

00090              {                   //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     }


Member Function Documentation

void WERD::baseline_denormalise ( const DENORM denorm  ) 

Baseline DeNormalise the word in Tesseract style.

I.e origin at centre of word at bottom.

x-height region scaled to region y =
(bln_baseline_offset)..(bln_baseline_offset + bln_x_height)
- usually 64..192)

Definition at line 717 of file werd.cpp.

References ABORT, PBLOB::baseline_denormalise(), cblobs, ERRCODE::error(), FALSE, rej_cblobs, W_NORMALIZED, and WRONG_WORD.

Referenced by adapt_to_good_ems(), adapt_to_good_samples(), apply_box_training(), collect_characters_for_adaption(), collect_ems_for_adaption(), and write_shm_text().

00719                                  {
00720   PBLOB_IT blob_it ((PBLOB_LIST *) & cblobs);
00721   // blob iterator
00722   PBLOB *blob;
00723 
00724   if (!flags.bit (W_NORMALIZED)) {
00725     WRONG_WORD.error ("WERD::baseline_denormalise", ABORT,
00726       "Baseline normalised");
00727   }
00728 
00729   for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
00730     blob = blob_it.data ();
00731                                  //denormalise it
00732     blob->baseline_denormalise (denorm);
00733   }
00734 
00735                                  //Repeat for rej blobs
00736   blob_it.set_to_list ((PBLOB_LIST *) & rej_cblobs);
00737   for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
00738     blob = blob_it.data ();
00739                                  //denormalise it
00740     blob->baseline_denormalise (denorm);
00741   }
00742 
00743                                  //it's not normalised
00744   flags.set_bit (W_NORMALIZED, FALSE);
00745 }

void WERD::baseline_normalise ( ROW row,
DENORM denorm = NULL 
)

Baseline Normalise the word in Tesseract style.

I.e origin at centre of word at bottom.

x-height region scaled to region y =
    (bln_baseline_offset)..(bln_baseline_offset + bln_x_height)
       - usually 64..192)

Definition at line 441 of file werd.cpp.

References baseline_normalise_x(), and ROW::x_height().

Referenced by word_bln_display(), and word_display().

00444                                {
00445   baseline_normalise_x (row, row->x_height (), denorm);
00446   //Use standard x ht
00447 }

void WERD::baseline_normalise_x ( ROW row,
float  x_height,
DENORM denorm = NULL 
)

Baseline Normalise the word in Tesseract style.

I.e origin at centre of word at bottom.

x-height region scaled to region y =
(bln_baseline_offset)..(bln_baseline_offset + bln_x_height)
- usually 64..192)

USE A SPECIFIED X-HEIGHT - NOT NECESSARILY THE ONE IN row

Definition at line 463 of file werd.cpp.

References ABORT, LLSQ::add(), ROW::base_line(), BOX::bottom(), PBLOB::bounding_box(), bounding_box(), LLSQ::c(), cblobs, LLSQ::count(), ERRCODE::error(), f, BOX::height(), BOX::left(), LLSQ::m(), MAX_INT32, PBLOB::move(), NULL, DENORM::origin(), rej_cblobs, BOX::right(), scale(), PBLOB::scale(), DENORM::scale(), DENORM_SEG::scale_factor, BOX::top(), TRUE, W_NORMALIZED, W_POLYGON, WRONG_WORD, DENORM_SEG::xstart, and DENORM_SEG::ycoord.

Referenced by baseline_normalise(), and make_bln_copy().

00467                                  {
00468   BOOL8 using_row;               //as baseline
00469   float blob_x_centre;           //middle of blob
00470   float blob_offset;             //bottom miss
00471   float top_offset;              //top miss
00472   float blob_x_height;           //xh for this blob
00473   INT16 segments;                //no of segments
00474   INT16 segment;                 //current segment
00475   DENORM_SEG *segs;              //array of segments
00476   float mean_x;                  //mean xheight
00477   INT32 x_count;                 //no of xs
00478   BOX word_box = bounding_box ();//word bounding box
00479   BOX blob_box;                  //blob bounding box
00480   PBLOB_IT blob_it ((PBLOB_LIST *) & cblobs);
00481   // blob iterator
00482   PBLOB *blob;
00483   LLSQ line;                     //fitted line
00484   double line_m, line_c;         //fitted line
00485                                  //inverse norm
00486   DENORM antidote (word_box.left () +
00487 
00488     (word_box.right () - word_box.left ()) / 2.0,
00489     bln_x_height / x_height, row);
00490 
00491   if (!flags.bit (W_POLYGON)) {
00492     WRONG_WORD.error ("WERD::baseline_normalise", ABORT,
00493       "Need to poly approx");
00494   }
00495 
00496   if (flags.bit (W_NORMALIZED)) {
00497     WRONG_WORD.error ("WERD::baseline_normalise", ABORT,
00498       "Baseline unnormalised");
00499   }
00500 
00501   if (bln_numericmode) {
00502     segs = new DENORM_SEG[blob_it.length ()];
00503     segments = 0;
00504     float factor;  // For scaling to baseline normalised size.
00505     for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
00506     blob_it.forward ()) {
00507       blob = blob_it.data ();
00508       blob_box = blob->bounding_box ();
00509       blob->move (FCOORD (-antidote.origin (),
00510         -blob_box.bottom ()));
00511       factor = bln_x_height * 4.0f / (3 * blob_box.height ());
00512       // Constrain the scale factor as target numbers should be either
00513       // cap height already or xheight.
00514       if (factor < antidote.scale())
00515         factor = antidote.scale();
00516       else if (factor > antidote.scale() * 1.5f)
00517         factor = antidote.scale() * 1.5f;
00518       blob->scale (factor);
00519       blob->move (FCOORD (0.0, bln_baseline_offset));
00520       segs[segments].xstart = blob->bounding_box().left();
00521       segs[segments].ycoord = blob_box.bottom();
00522       segs[segments++].scale_factor = factor;
00523     }
00524     antidote = DENORM (antidote.origin (), antidote.scale (),
00525       0.0f, 0.0f, segments, segs, true, row);
00526     delete [] segs;
00527 
00528                                  //Repeat for rej blobs
00529     blob_it.set_to_list ((PBLOB_LIST *) & rej_cblobs);
00530     for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
00531     blob_it.forward ()) {
00532       blob = blob_it.data ();
00533       blob_box = blob->bounding_box ();
00534       blob->move (FCOORD (-antidote.origin (),
00535                           -blob_box.bottom ()));
00536       blob->scale (bln_x_height * 4.0f / (3 * blob_box.height ()));
00537       blob->move (FCOORD (0.0, bln_baseline_offset));
00538     }
00539   }
00540   else if (bln_blshift_maxshift < 0) {
00541     for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
00542     blob_it.forward ()) {
00543       blob = blob_it.data ();
00544       blob_box = blob->bounding_box ();
00545       blob_x_centre = blob_box.left () +
00546         (blob_box.right () - blob_box.left ()) / 2.0;
00547       blob->move (FCOORD (-antidote.origin (),
00548         -(row->base_line (blob_x_centre))));
00549       blob->scale (antidote.scale ());
00550       blob->move (FCOORD (0.0, bln_baseline_offset));
00551     }
00552 
00553                                  //Repeat for rej blobs
00554     blob_it.set_to_list ((PBLOB_LIST *) & rej_cblobs);
00555     for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
00556     blob_it.forward ()) {
00557       blob = blob_it.data ();
00558       blob_box = blob->bounding_box ();
00559       blob_x_centre = blob_box.left () +
00560         (blob_box.right () - blob_box.left ()) / 2.0;
00561       blob->move (FCOORD (-antidote.origin (),
00562         -(row->base_line (blob_x_centre))));
00563       blob->scale (antidote.scale ());
00564       blob->move (FCOORD (0.0, bln_baseline_offset));
00565     }
00566 
00567   }
00568   else {
00569     mean_x = x_height;
00570     x_count = 1;
00571     segs = new DENORM_SEG[blob_it.length ()];
00572     segments = 0;
00573     for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
00574     blob_it.forward ()) {
00575       blob = blob_it.data ();
00576       blob_box = blob->bounding_box ();
00577       if (blob_box.height () > bln_blshift_xfraction * x_height) {
00578         blob_x_centre = blob_box.left () +
00579           (blob_box.right () - blob_box.left ()) / 2.0;
00580         blob_offset =
00581           blob_box.bottom () - row->base_line (blob_x_centre);
00582         top_offset = blob_offset + blob_box.height () - x_height - 1;
00583         blob_x_height = top_offset + x_height;
00584         if (top_offset < 0)
00585           top_offset = -top_offset;
00586         if (blob_offset < 0)
00587           blob_offset = -blob_offset;
00588         if (blob_offset < bln_blshift_maxshift * x_height) {
00589           segs[segments].ycoord = blob_box.bottom ();
00590           line.add (blob_x_centre, blob_box.bottom ());
00591           if (top_offset < bln_blshift_maxshift * x_height) {
00592             segs[segments].scale_factor = blob_box.height () - 1.0f;
00593             x_count++;
00594           }
00595           else
00596             segs[segments].scale_factor = 0.0f;
00597           //fix it later
00598         }
00599         else {
00600                                  //not a goer
00601           segs[segments].ycoord = -MAX_INT32;
00602           if (top_offset < bln_blshift_maxshift * x_height) {
00603             segs[segments].scale_factor = blob_x_height;
00604             x_count++;
00605           }
00606           else
00607             segs[segments].scale_factor = 0.0f;
00608           //fix it later
00609         }
00610       }
00611       else {
00612         segs[segments].scale_factor = 0.0f;
00613         segs[segments].ycoord = -MAX_INT32;
00614       }
00615       segs[segments].xstart = blob_box.left ();
00616       segments++;
00617     }
00618     using_row = line.count () <= 1;
00619     if (!using_row) {
00620       line_m = line.m ();
00621       line_c = line.c (line_m);
00622     }
00623     else
00624       line_m = line_c = 0;
00625     segments = 0;
00626     for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
00627     blob_it.forward ()) {
00628       blob = blob_it.data ();
00629       blob_box = blob->bounding_box ();
00630       blob_x_centre = blob_box.left () +
00631         (blob_box.right () - blob_box.left ()) / 2.0;
00632       if (segs[segments].ycoord == -MAX_INT32
00633       && segs[segments].scale_factor != 0 && !using_row) {
00634         blob_offset = line_m * blob_x_centre + line_c;
00635         segs[segments].scale_factor = blob_box.top () - blob_offset;
00636       }
00637       if (segs[segments].scale_factor != 0)
00638         mean_x += segs[segments].scale_factor;
00639       segments++;
00640     }
00641     mean_x /= x_count;
00642     //     printf("mean x=%g, count=%d, line_m=%g, line_c=%g\n",
00643     //             mean_x,x_count,line_m,line_c);
00644     segments = 0;
00645     for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
00646     blob_it.forward ()) {
00647       blob = blob_it.data ();
00648       blob_box = blob->bounding_box ();
00649       blob_x_centre = blob_box.left () +
00650         (blob_box.right () - blob_box.left ()) / 2.0;
00651       if (segs[segments].ycoord != -MAX_INT32)
00652         blob_offset = (float) segs[segments].ycoord;
00653       else if (using_row)
00654         blob_offset = row->base_line (blob_x_centre);
00655       else
00656         blob_offset = line_m * blob_x_centre + line_c;
00657       if (segs[segments].scale_factor == 0)
00658         segs[segments].scale_factor = mean_x;
00659       segs[segments].scale_factor =
00660         bln_x_height / segs[segments].scale_factor;
00661       //   printf("Blob sf=%g, top=%d, bot=%d, base=%g\n",
00662       //                     segs[segments].scale_factor,blob_box.top(),
00663       //                     blob_box.bottom(),blob_offset);
00664       blob->move (FCOORD (-antidote.origin (), -blob_offset));
00665       blob->
00666         scale (FCOORD (antidote.scale (), segs[segments].scale_factor));
00667       blob->move (FCOORD (0.0, bln_baseline_offset));
00668       segments++;
00669     }
00670 
00671                                  //Repeat for rej blobs
00672     blob_it.set_to_list ((PBLOB_LIST *) & rej_cblobs);
00673     segment = 0;
00674     for (blob_it.mark_cycle_pt (); !blob_it.cycled_list ();
00675     blob_it.forward ()) {
00676       blob = blob_it.data ();
00677       blob_box = blob->bounding_box ();
00678       blob_x_centre = blob_box.left () +
00679         (blob_box.right () - blob_box.left ()) / 2.0;
00680       while (segment < segments - 1
00681         && segs[segment + 1].xstart <= blob_x_centre)
00682         segment++;
00683       if (segs[segment].ycoord != -MAX_INT32)
00684         blob_offset = (float) segs[segment].ycoord;
00685       else if (using_row)
00686         blob_offset = row->base_line (blob_x_centre);
00687       else
00688         blob_offset = line_m * blob_x_centre + line_c;
00689       blob->move (FCOORD (-antidote.origin (), -blob_offset));
00690       blob->
00691         scale (FCOORD (antidote.scale (), segs[segment].scale_factor));
00692       blob->move (FCOORD (0.0, bln_baseline_offset));
00693     }
00694     if (line.count () > 0 || x_count > 1)
00695       antidote = DENORM (antidote.origin (), antidote.scale (),
00696         line_m, line_c, segments, segs, using_row, row);
00697     delete[]segs;
00698   }
00699   if (denorm != NULL)
00700     *denorm = antidote;
00701                                  //it's normalised
00702   flags.set_bit (W_NORMALIZED, TRUE);
00703 }

PBLOB_LIST* WERD::blob_list (  )  [inline]

Definition at line 125 of file werd.h.

References ABORT, BITS16::bit(), cblobs, ERRCODE::error(), flags, NULL, W_POLYGON, and WRONG_WORD.

Referenced by adapt_to_good_ems(), adapt_to_good_samples(), apply_box_testing(), apply_box_training(), block_space_stat(), char_clip_word(), check_block_occ(), classify_word_pass1(), collect_characters_for_adaption(), collect_ems_for_adaption(), est_ambigs(), find_mean_blob_spacing(), fix_hyphens(), fix_quotes(), fp_eval_word_spacing(), improve_estimate(), insert_rej_cblobs(), make_epaper_choice(), make_pseudo_word(), make_tess_word(), match_word_pass2(), merge_tess_fails(), noise_outlines(), print_boxes(), process_all_blobs(), process_selected_blobs(), re_estimate_x_ht(), recog_word(), recog_word_recursive(), row_space_stat(), show_point(), split_and_recog_word(), suspect_em(), suspect_fullstop(), uniformly_spaced(), unrej_good_chs(), word_blob_quality(), word_char_quality(), word_display(), word_outline_errs(), worst_noise_blob(), write_results(), and write_shm_text().

00125                             {  //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     }

BOX WERD::bounding_box (  ) 

Return the bounding box of the WERD;.

This is quite a mess to compute! ORIGINALLY, REJECT CBLOBS WERE EXCLUDED, however, this led to bugs when the words on the row were re-sorted. The original words were built with reject blobs included. The FUZZY SPACE flags were set accordingly. If ALL the blobs in a word are rejected the BB for the word is NULL, causing the sort to screw up, leading to the erroneous possibility of the first word in a row being marked as FUZZY space.

Definition at line 283 of file werd.cpp.

References cblobs, rej_cblobs, and W_POLYGON.

Referenced by adapt_to_good_ems(), adapt_to_good_samples(), add_word(), baseline_normalise_x(), char_clip_word(), check_debug_pt(), collect_characters_for_adaption(), collect_ems_for_adaption(), determine_newline_type(), display_clip_image(), find_repeated_chars(), find_row_of_box(), fixspace_dbg(), make_prop_words(), make_pseudo_word(), print(), process_selected_blobs(), process_selected_words(), process_selected_words_it(), re_scale_and_move_bln_word(), re_segment_word(), ROW::recalc_bounding_box(), resegment_box(), show_point(), tidy_up(), transform_to_next_perm(), word_blank_and_set_display(), word_comparator(), word_deletable(), word_delete(), word_display(), write_cooked_text(), and write_shm_text().

00283                        {  //bounding box
00284   BOX box;                       //box being built
00285                                  //rejected blobs in wd
00286   C_BLOB_IT rej_cblob_it = &rej_cblobs;
00287 
00288   for (rej_cblob_it.mark_cycle_pt ();
00289   !rej_cblob_it.cycled_list (); rej_cblob_it.forward ()) {
00290     box += rej_cblob_it.data ()->bounding_box ();
00291   }
00292 
00293   if (flags.bit (W_POLYGON)) {
00294                                  //polygons
00295     PBLOB_IT it = (PBLOB_LIST *) (&cblobs);
00296 
00297     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00298       box += it.data ()->bounding_box ();
00299     }
00300   }
00301   else {
00302     C_BLOB_IT it = &cblobs;      //blobs of WERD
00303 
00304     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00305       box += it.data ()->bounding_box ();
00306     }
00307   }
00308   return box;
00309 }

C_BLOB_LIST* WERD::cblob_list (  )  [inline]

Definition at line 120 of file werd.h.

References ABORT, BITS16::bit(), cblobs, ERRCODE::error(), flags, NULL, W_LINEARC, W_POLYGON, and WRONG_WORD.

Referenced by block_space_stat(), break_noisiest_blob_word(), clean_noise_from_row(), clean_noise_from_words(), find_mean_blob_spacing(), process_all_blobs(), process_selected_blobs(), row_space_stat(), show_point(), tweak_row_baseline(), and word_display().

00120                               {  //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     }

void WERD::copy_on ( WERD *&  other  ) 

Copy blobs from other word onto this one.

Definition at line 391 of file werd.cpp.

References cblobs, rej_cblobs, and W_POLYGON.

Referenced by WERD_RES::copy_on().

00393                     {
00394   if (flags.bit (W_POLYGON)) {
00395     PBLOB_IT blob_it ((PBLOB_LIST *) & cblobs);
00396     // blob iterator
00397     PBLOB_LIST blobs;
00398 
00399     blobs.deep_copy ((PBLOB_LIST *) (&other->cblobs));
00400     blob_it.move_to_last ();
00401     blob_it.add_list_after (&blobs);
00402   }
00403   //      else if (flags.bit(W_LINEARC))
00404   //      {
00405   //         LARC_BLOB_IT    larc_blob_it( (LARC_BLOB_LIST*)&cblobs );
00406   //         LARC_BLOB_LIST  larc_blobs;
00407 
00408   //         larc_blobs.deep_copy((LARC_BLOB_LIST*)(&other->cblobs));
00409   //         larc_blob_it.move_to_last();
00410   //         larc_blob_it.add_list_after( &larc_blobs );
00411   //      }
00412   else {
00413     C_BLOB_IT c_blob_it(&cblobs); 
00414     C_BLOB_LIST c_blobs;
00415 
00416     c_blobs.deep_copy (&other->cblobs);
00417     c_blob_it.move_to_last ();
00418     c_blob_it.add_list_after (&c_blobs);
00419   }
00420   if (!other->rej_cblobs.empty ()) {
00421     C_BLOB_IT rej_c_blob_it(&rej_cblobs); 
00422     C_BLOB_LIST new_rej_c_blobs;
00423 
00424     new_rej_c_blobs.deep_copy (&other->rej_cblobs);
00425     rej_c_blob_it.move_to_last ();
00426     rej_c_blob_it.add_list_after (&new_rej_c_blobs);
00427   }
00428 }

void WERD::de_dump ( FILE *  f  )  [inline]

Definition at line 248 of file werd.h.

References BITS16::bit(), cblobs, correct, STRING::de_dump(), flags, rej_cblobs, and W_POLYGON.

00249                           {
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     }

void ELIST_LINK::de_serialise_asc ( FILE *  f  )  [inherited]

Reimplemented in ICOORDELT.

Definition at line 39 of file elst.cpp.

References ABORT, ERRCODE::error(), and SERIALISE_LINKS.

00040                                            {
00041   SERIALISE_LINKS.error ("ELIST_LINK::de_serialise_asc", ABORT,
00042     "Don't call this, override!");
00043 }

BOOL8 WERD::display_flag ( UINT8  flag  )  const [inline]

Definition at line 170 of file werd.h.

References BITS16::bit(), and disp_flags.

Referenced by word_change_text(), and word_display().

00171                                          {  //flag to test
00172       return disp_flags.bit (flag);
00173     }

void WERD::dump ( FILE *  f  )  [inline]

Definition at line 236 of file werd.h.

References BITS16::bit(), cblobs, correct, STRING::dump(), flags, rej_cblobs, and W_POLYGON.

00237                        {
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     }

BOOL8 WERD::flag ( WERD_FLAGS  mask  )  const [inline]

Definition at line 160 of file werd.h.

References BITS16::bit(), and flags.

Referenced by adapt_to_good_ems(), adapt_to_good_samples(), block_space_stat(), char_clip_word(), classify_word_pass1(), classify_word_pass2(), clean_noise_from_row(), clean_noise_from_words(), collect_characters_for_adaption(), collect_ems_for_adaption(), WERD_RES::copy_on(), determine_newline_type(), find_mean_blob_spacing(), find_row_of_box(), fix_sp_fp_word(), make_epaper_choice(), match_word_pass2(), process_all_blobs(), process_selected_blobs(), re_segment_word(), recog_word_recursive(), resegment_box(), ROW_RES::ROW_RES(), row_space_stat(), show_point(), tess_segment_pass1(), tess_segment_pass2(), tilde_delete(), transform_to_next_perm(), word_display(), word_toggle_seg(), write_cooked_text(), write_map(), write_results(), write_shm_text(), and write_unlv_text().

00161                                       {  //flag to test
00162       return flags.bit (mask);
00163     }

PBLOB_LIST* WERD::gblob_list (  )  [inline]

Definition at line 137 of file werd.h.

References cblobs.

Referenced by apply_box_testing(), apply_box_training(), find_row_of_box(), fix_fuzzy_spaces(), fixspace_dbg(), re_segment_word(), resegment_box(), tidy_up(), unrej_good_chs(), word_blob_quality(), and word_char_quality().

00137                              {  //get generic blobs
00138                                  //make it right type
00139       return (PBLOB_LIST *) (&cblobs);
00140     }

void WERD::join_on ( WERD *&  other  ) 

Join other word onto this one. Delete the old word.

Definition at line 368 of file werd.cpp.

References cblobs, and rej_cblobs.

Referenced by split_and_recog_word(), and transform_to_next_perm().

00370                     {
00371   PBLOB_IT blob_it ((PBLOB_LIST *) & cblobs);
00372   // blob iterator
00373   PBLOB_IT src_it ((PBLOB_LIST *) & other->cblobs);
00374   C_BLOB_IT rej_cblob_it(&rej_cblobs); 
00375   C_BLOB_IT src_rej_it (&other->rej_cblobs);
00376 
00377   while (!src_it.empty ()) {
00378     blob_it.add_to_end (src_it.extract ());
00379     src_it.forward ();
00380   }
00381   while (!src_rej_it.empty ()) {
00382     rej_cblob_it.add_to_end (src_rej_it.extract ());
00383     src_rej_it.forward ();
00384   }
00385 }

WERD* WERD::larc_copy ( float  xheight  ) 

void WERD::move ( const ICOORD  vec  ) 

Reposition WERD by vector.

NOTE!! REJECT CBLOBS ARE NOT MOVED

Definition at line 317 of file werd.cpp.

References cblobs, and W_POLYGON.

Referenced by re_scale_and_move_bln_word().

00319                  {
00320   PBLOB_IT blob_it ((PBLOB_LIST *) & cblobs);
00321   // blob iterator
00322   //      LARC_BLOB_IT   lblob_it((LARC_BLOB_LIST*)&cblobs);
00323   C_BLOB_IT cblob_it(&cblobs);  // cblob iterator
00324 
00325   if (flags.bit (W_POLYGON))
00326     for (blob_it.mark_cycle_pt ();
00327     !blob_it.cycled_list (); blob_it.forward ())
00328   blob_it.data ()->move (vec);
00329   //      else if (flags.bit(W_LINEARC))
00330   //              for( lblob_it.mark_cycle_pt();
00331   //                      !lblob_it.cycled_list();
00332   //                      lblob_it.forward() )
00333   //                      lblob_it.data()->move( vec );
00334   else
00335     for (cblob_it.mark_cycle_pt ();
00336     !cblob_it.cycled_list (); cblob_it.forward ())
00337   cblob_it.data ()->move (vec);
00338 }

WERD & WERD::operator= ( const WERD source  ) 

Assign a word, DEEP copying the blob list.

Definition at line 915 of file werd.cpp.

References cblobs, correct, dummy, flags, ELIST_LINK::operator=(), rej_cblobs, and W_POLYGON.

00917   {
00918   this->ELIST_LINK::operator= (source);
00919   blanks = source.blanks;
00920   flags = source.flags;
00921   dummy = source.dummy;
00922   correct = source.correct;
00923   if (flags.bit (W_POLYGON)) {
00924     if (!cblobs.empty ())
00925       ((PBLOB_LIST *) (&cblobs))->clear ();
00926     ((PBLOB_LIST *) (&cblobs))->deep_copy ((PBLOB_LIST *) (&source.cblobs));
00927 
00928     if (!rej_cblobs.empty ())
00929       ((PBLOB_LIST *) (&rej_cblobs))->clear ();
00930     ((PBLOB_LIST *) (&rej_cblobs))->deep_copy ((PBLOB_LIST *) (&source.
00931       rej_cblobs));
00932 
00933   }
00934   //  else if (flags.bit(W_LINEARC))
00935   //  {
00936   //      if ( !cblobs.empty() )
00937   //          ((LARC_BLOB_LIST*)(&cblobs))->clear();
00938   //      ((LARC_BLOB_LIST*)(&cblobs))->deep_copy(
00939   //          (LARC_BLOB_LIST*)(&source.cblobs));
00940 
00941   //      if ( !rej_cblobs.empty() )
00942   //          rej_cblobs.clear();
00943   //      rej_cblobs.deep_copy( &source.rej_cblobs );
00944   //  }
00945   else {
00946     if (!cblobs.empty ())
00947       cblobs.clear ();
00948     cblobs.deep_copy (&source.cblobs);
00949 
00950     if (!rej_cblobs.empty ())
00951       rej_cblobs.clear ();
00952     rej_cblobs.deep_copy (&source.rej_cblobs);
00953   }
00954   return *this;
00955 }

void WERD::plot ( WINDOW  window,
BOOL8  solid = FALSE 
)

Draw the WERD in rainbow colours.

Definition at line 821 of file werd.cpp.

References cblobs, CHILD_COLOUR, FIRST_COLOUR, LAST_COLOUR, plot_rej_blobs(), and W_POLYGON.

00824                  {
00825   COLOUR colour = FIRST_COLOUR;  //current colour
00826   if (flags.bit (W_POLYGON)) {
00827                                  //polygons
00828     PBLOB_IT it = (PBLOB_LIST *) (&cblobs);
00829 
00830     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00831       it.data ()->plot (window, colour, CHILD_COLOUR);
00832       colour = (COLOUR) (colour + 1);
00833       if (colour == LAST_COLOUR)
00834         colour = FIRST_COLOUR;   //cycle round
00835     }
00836   }
00837   //  else if (flags.bit(W_LINEARC))
00838   //  {
00839   //      LARC_BLOB_IT   it=(LARC_BLOB_LIST*)(&cblobs);
00840 
00841   //      for ( it.mark_cycle_pt(); !it.cycled_list(); it.forward() )
00842   //      {
00843   //         it.data()->plot(window,solid,colour,solid ? BLACK : CHILD_COLOUR);
00844   //         colour=(COLOUR)(colour+1);
00845   //         if (colour==LAST_COLOUR)
00846   //                 colour=FIRST_COLOUR;
00847   //      }
00848   else {
00849     C_BLOB_IT it = &cblobs;      //blobs of WERD
00850 
00851     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00852       it.data ()->plot (window, colour, CHILD_COLOUR);
00853       colour = (COLOUR) (colour + 1);
00854       if (colour == LAST_COLOUR)
00855         colour = FIRST_COLOUR;   //cycle round
00856     }
00857   }
00858   plot_rej_blobs(window, solid); 
00859 }

void WERD::plot ( WINDOW  window,
COLOUR  colour,
BOOL8  solid = FALSE 
)

Draw the WERD in the given colour.

Definition at line 783 of file werd.cpp.

References cblobs, plot_rej_blobs(), and W_POLYGON.

Referenced by classify_word_pass2(), display_clip_image(), ROW::plot(), word_bln_display(), and word_display().

00787                  {
00788   if (flags.bit (W_POLYGON)) {
00789                                  //polygons
00790     PBLOB_IT it = (PBLOB_LIST *) (&cblobs);
00791 
00792     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00793       it.data ()->plot (window, colour, colour);
00794     }
00795   }
00796   //      else if (flags.bit(W_LINEARC))
00797   //      {
00798   //          LARC_BLOB_IT  it=(LARC_BLOB_LIST*)(&cblobs);
00799 
00800   //          for ( it.mark_cycle_pt(); !it.cycled_list(); it.forward() )
00801   //          {
00802   //             it.data()->plot(window,solid,colour,solid ? BLACK : colour);
00803   //          }
00804   //      }
00805   else {
00806     C_BLOB_IT it = &cblobs;      //blobs of WERD
00807 
00808     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00809       it.data ()->plot (window, colour, colour);
00810     }
00811   }
00812   plot_rej_blobs(window, solid); 
00813 }

void WERD::plot_rej_blobs ( WINDOW  window,
BOOL8  solid = FALSE 
)

Draw the WERD rejected blobs - ALWAYS GREY.

Definition at line 868 of file werd.cpp.

References GREY, rej_cblobs, and W_POLYGON.

Referenced by plot().

00871                            {
00872   if (flags.bit (W_POLYGON)) {
00873     PBLOB_IT it = (PBLOB_LIST *) (&rej_cblobs);
00874     //polygons
00875 
00876     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00877       it.data ()->plot (window, GREY, GREY);
00878     }
00879   }
00880   //  else if (flags.bit(W_LINEARC))
00881   //  {
00882   //      LARC_BLOB_IT    it=(LARC_BLOB_LIST*)(&rej_cblobs);
00883   //      for ( it.mark_cycle_pt(); !it.cycled_list(); it.forward() )
00884   //      {
00885   //          it.data()->plot(window,solid,GREY,solid ? BLACK : GREY);
00886   //      }
00887   else {
00888     C_BLOB_IT it = &rej_cblobs;  //blobs of WERD
00889 
00890     for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00891       it.data ()->plot (window, GREY, GREY);
00892     }
00893   }
00894 }

WERD * WERD::poly_copy ( float  xheight  ) 

Make a copy of a WERD in polygon format;.

The source WERD is untouched.

Definition at line 209 of file werd.cpp.

References cblobs, correct, dummy, flags, rej_cblobs, BITS16::set_bit(), TRUE, and W_POLYGON.

Referenced by WERDIT::forward(), make_bln_copy(), make_pseudo_word(), recog_word(), recog_word_recursive(), split_and_recog_word(), word_bln_display(), and word_display().

00211                        {
00212   PBLOB *blob;                   //new blob
00213   WERD *result = new WERD;       //output word
00214   C_BLOB_IT src_it = &cblobs;    //iterator
00215   //      LARC_BLOB_IT                            larc_it=(LARC_BLOB_LIST*)(&cblobs);
00216   PBLOB_IT dest_it = (PBLOB_LIST *) (&result->cblobs);
00217   //another
00218 
00219   if (flags.bit (W_POLYGON)) {
00220     *result = *this;             //just copy it
00221   }
00222   else {
00223     result->flags = flags;
00224     result->correct = correct;   //copy info
00225     result->dummy = dummy;
00226     if (!src_it.empty ()) {
00227       //      if (flags.bit(W_LINEARC))
00228       //      {
00229       //         do
00230       //         {
00231       //             blob=new PBLOB;
00232       //             poly_linearc_outlines(larc_it.data()->out_list(),
00233       //                blob->out_list());      //convert outlines
00234       //             dest_it.add_after_then_move(blob); //add to dest list
00235       //             larc_it.forward();
00236       //         }
00237       //         while (!larc_it.at_first());
00238       //       }
00239       //         else
00240       //       {
00241       do {
00242         blob = new PBLOB (src_it.data (), xheight);
00243         //convert blob
00244                                  //add to dest list
00245         dest_it.add_after_then_move (blob);
00246         src_it.forward ();
00247       }
00248       while (!src_it.at_first ());
00249       //                      }
00250     }
00251     if (!rej_cblobs.empty ()) {
00252       /* Polygonal approx of reject blobs */
00253       src_it.set_to_list (&rej_cblobs);
00254       dest_it = (PBLOB_LIST *) (&result->rej_cblobs);
00255       do {
00256                                  //convert blob
00257         blob = new PBLOB (src_it.data (), xheight);
00258                                  //add to dest list
00259         dest_it.add_after_then_move (blob);
00260         src_it.forward ();
00261       }
00262       while (!src_it.at_first ());
00263     }
00264                                  //polygon now
00265     result->flags.set_bit (W_POLYGON, TRUE);
00266     result->blanks = blanks;
00267   }
00268   return result;
00269 }

void WERD::prep_serialise (  )  [inline]

Definition at line 225 of file werd.h.

References BITS16::bit(), cblobs, correct, flags, STRING::prep_serialise(), rej_cblobs, and W_POLYGON.

00225                           {  //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     }

void WERD::print ( FILE *  fp  ) 

Display members.

Definition at line 751 of file werd.cpp.

References bounding_box(), correct, BOX::print(), rej_cblobs, STRING::string(), tprintf(), W_BOL, W_DONT_CHOP, W_EOL, W_FUZZY_NON, W_FUZZY_SP, W_ITALIC, W_LINEARC, W_NORMALIZED, W_POLYGON, W_REP_CHAR, and W_SEGMENTED.

Referenced by check_debug_pt(), and word_dumper().

00753                   {
00754   tprintf ("Blanks= %d\n", blanks);
00755   bounding_box ().print ();
00756   tprintf ("Flags = %d = 0%o\n", flags.val, flags.val);
00757   tprintf ("   W_SEGMENTED = %s\n",
00758     flags.bit (W_SEGMENTED) ? "TRUE" : "FALSE ");
00759   tprintf ("   W_ITALIC = %s\n", flags.bit (W_ITALIC) ? "TRUE" : "FALSE ");
00760   tprintf ("   W_BOL = %s\n", flags.bit (W_BOL) ? "TRUE" : "FALSE ");
00761   tprintf ("   W_EOL = %s\n", flags.bit (W_EOL) ? "TRUE" : "FALSE ");
00762   tprintf ("   W_NORMALIZED = %s\n",
00763     flags.bit (W_NORMALIZED) ? "TRUE" : "FALSE ");
00764   tprintf ("   W_POLYGON = %s\n", flags.bit (W_POLYGON) ? "TRUE" : "FALSE ");
00765   tprintf ("   W_LINEARC = %s\n", flags.bit (W_LINEARC) ? "TRUE" : "FALSE ");
00766   tprintf ("   W_DONT_CHOP = %s\n",
00767     flags.bit (W_DONT_CHOP) ? "TRUE" : "FALSE ");
00768   tprintf ("   W_REP_CHAR = %s\n",
00769     flags.bit (W_REP_CHAR) ? "TRUE" : "FALSE ");
00770   tprintf ("   W_FUZZY_SP = %s\n",
00771     flags.bit (W_FUZZY_SP) ? "TRUE" : "FALSE ");
00772   tprintf ("   W_FUZZY_NON = %s\n",
00773     flags.bit (W_FUZZY_NON) ? "TRUE" : "FALSE ");
00774   tprintf ("Correct= %s\n", correct.string ());
00775   tprintf ("Rejected cblob count = %d\n", rej_cblobs.length ());
00776 }

PBLOB_LIST* WERD::rej_blob_list (  )  [inline]

Definition at line 114 of file werd.h.

References ABORT, BITS16::bit(), ERRCODE::error(), flags, NULL, rej_cblobs, W_POLYGON, and WRONG_WORD.

Referenced by fixspace_dbg(), insert_rej_cblobs(), and recog_word().

00114                                 { 
00115       if (!flags.bit (W_POLYGON))
00116         WRONG_WORD.error ("WERD::rej_blob_list", ABORT, NULL);
00117       return (PBLOB_LIST *) (&rej_cblobs);
00118     }

C_BLOB_LIST* WERD::rej_cblob_list (  )  [inline]

Definition at line 107 of file werd.h.

References ABORT, BITS16::bit(), ERRCODE::error(), flags, NULL, rej_cblobs, W_POLYGON, and WRONG_WORD.

Referenced by break_noisiest_blob_word(), clean_noise_from_words(), and fix_sp_fp_word().

00107                                   { 
00108       if (flags.bit (W_POLYGON))
00109         WRONG_WORD.error ("WERD::rej_cblob_list", ABORT, NULL);
00110       return &rej_cblobs;
00111     }

void WERD::scale ( const float  vec  ) 

Scale WERD by multiplier.

Definition at line 344 of file werd.cpp.

References ABORT, CANT_SCALE_EDGESTEPS, cblobs, ERRCODE::error(), NULL, and W_POLYGON.

Referenced by baseline_normalise_x(), and re_scale_and_move_bln_word().

00346                   {
00347   PBLOB_IT blob_it ((PBLOB_LIST *) & cblobs);
00348   // blob iterator
00349   //      LARC_BLOB_IT    lblob_it((LARC_BLOB_LIST*)&cblobs);
00350 
00351   if (flags.bit (W_POLYGON))
00352     for (blob_it.mark_cycle_pt ();
00353     !blob_it.cycled_list (); blob_it.forward ())
00354   blob_it.data ()->scale (f);
00355   //      else if (flags.bit(W_LINEARC))
00356   //              for (lblob_it.mark_cycle_pt();
00357   //                              !lblob_it.cycled_list();
00358   //                              lblob_it.forward() )
00359   //                      lblob_it.data()->scale( f );
00360   else
00361     CANT_SCALE_EDGESTEPS.error ("WERD::scale", ABORT, NULL);
00362 }

void ELIST_LINK::serialise_asc ( FILE *  f  )  [inherited]

Generates an error, as it should never be called.

Definition at line 32 of file elst.cpp.

References ABORT, ERRCODE::error(), and SERIALISE_LINKS.

00033                                         {
00034   SERIALISE_LINKS.error ("ELIST_LINK::serialise_asc", ABORT,
00035     "Don't call this, override!");
00036 }

void WERD::set_blanks ( UINT8  new_blanks  )  [inline]

Definition at line 148 of file werd.h.

Referenced by break_noisiest_blob_word(), and make_prop_words().

00149                                       {
00150       blanks = new_blanks;
00151     }

void WERD::set_display_flag ( UINT8  flag,
BOOL8  value 
) [inline]

Definition at line 175 of file werd.h.

References disp_flags, and BITS16::set_bit().

Referenced by word_set_display().

00177                                        {  //value to set
00178       disp_flags.set_bit (flag, value);
00179     }

void WERD::set_flag ( WERD_FLAGS  mask,
BOOL8  value 
) [inline]

Definition at line 164 of file werd.h.

References flags, and BITS16::set_bit().

Referenced by break_noisiest_blob_word(), WERD_RES::copy_on(), find_repeated_chars(), make_prop_words(), make_real_word(), ROW::recalc_bounding_box(), transform_to_next_perm(), and word_toggle_seg().

00166                                {    //value to set
00167       flags.set_bit (mask, value);
00168     }

void WERD::set_text ( const char *  new_text  )  [inline]

Definition at line 153 of file werd.h.

References correct.

Referenced by classify_word_pass1(), resegment_box(), and word_change_text().

00154                                         {  //with this
00155       correct = new_text;
00156     }

WERD * WERD::shallow_copy (  ) 

Make a shallow copy of a word.

Definition at line 901 of file werd.cpp.

References correct, dummy, and flags.

Referenced by re_segment_word(), and resegment_box().

00901                          {  //shallow copy
00902   WERD *new_word = new WERD;
00903 
00904   new_word->blanks = blanks;
00905   new_word->flags = flags;
00906   new_word->dummy = dummy;
00907   new_word->correct = correct;
00908   return new_word;
00909 }

UINT8 WERD::space (  )  [inline]

Definition at line 145 of file werd.h.

Referenced by determine_newline_type(), doc_and_block_rejection(), make_epaper_choice(), write_cooked_text(), write_map(), write_results(), write_shm_text(), and write_unlv_text().

00145                   {  //access function
00146       return blanks;
00147     }

const char* WERD::text (  )  const [inline]

Definition at line 142 of file werd.h.

References correct, and STRING::string().

Referenced by apply_box_testing(), apply_box_training(), classify_word_pass1(), make_tess_word(), match_word_pass2(), resegment_box(), tidy_up(), word_change_text(), and word_display().

00142                              {  //correct text
00143       return correct.string ();
00144     }


Member Data Documentation

C_BLOB_LIST WERD::cblobs

Definition at line 267 of file werd.h.

Referenced by baseline_denormalise(), baseline_normalise_x(), blob_list(), bounding_box(), cblob_list(), copy_on(), de_dump(), dump(), gblob_list(), join_on(), move(), operator=(), plot(), poly_copy(), prep_serialise(), scale(), WERD(), and ~WERD().

STRING WERD::correct

Definition at line 266 of file werd.h.

Referenced by de_dump(), dump(), operator=(), poly_copy(), prep_serialise(), print(), set_text(), shallow_copy(), and text().

BITS16 WERD::disp_flags

Definition at line 264 of file werd.h.

Referenced by display_flag(), and set_display_flag().

make_serialise (WERD) private UINT8 WERD::dummy

Definition at line 260 of file werd.h.

Referenced by operator=(), poly_copy(), and shallow_copy().

INT16 WERD::dummy2

Definition at line 265 of file werd.h.

BITS16 WERD::flags

Definition at line 263 of file werd.h.

Referenced by blob_list(), cblob_list(), de_dump(), dump(), flag(), operator=(), poly_copy(), prep_serialise(), rej_blob_list(), rej_cblob_list(), set_flag(), shallow_copy(), and ~WERD().

C_BLOB_LIST WERD::rej_cblobs

Definition at line 268 of file werd.h.

Referenced by baseline_denormalise(), baseline_normalise_x(), bounding_box(), copy_on(), de_dump(), dump(), join_on(), operator=(), plot_rej_blobs(), poly_copy(), prep_serialise(), print(), rej_blob_list(), rej_cblob_list(), and ~WERD().


The documentation for this class was generated from the following files:
Generated on Wed Feb 28 19:49:34 2007 for Tesseract by  doxygen 1.5.1