ccmain/werdit.cpp

Go to the documentation of this file.
00001 
00020 #include "mfcpch.h"
00021 #include          "werdit.h"
00022 
00023 #define EXTERN
00024 
00025 //EXTERN BOOL_VAR(wordit_linearc,FALSE,"Pass poly of linearc to Tess");
00026 
00033 void WERDIT::start_page(                        //set iterators
00034                         BLOCK_LIST *block_list  //blocks to check
00035                        ) {
00036   block_it.set_to_list (block_list);
00037   block_it.mark_cycle_pt ();
00038   do {
00039     while (block_it.data ()->row_list ()->empty ()
00040     && !block_it.cycled_list ()) {
00041       block_it.forward ();
00042     }
00043     if (!block_it.data ()->row_list ()->empty ()) {
00044       row_it.set_to_list (block_it.data ()->row_list ());
00045       row_it.mark_cycle_pt ();
00046       while (row_it.data ()->word_list ()->empty ()
00047       && !row_it.cycled_list ()) {
00048         row_it.forward ();
00049       }
00050       if (!row_it.data ()->word_list ()->empty ()) {
00051         word_it.set_to_list (row_it.data ()->word_list ());
00052         word_it.mark_cycle_pt ();
00053       }
00054     }
00055   }
00056   while (!block_it.cycled_list () && row_it.data ()->word_list ()->empty ());
00057 }
00058 
00059 
00071 WERD *WERDIT::forward() {
00072   WERD *word;         //actual word
00073   //WERD    *larc_word;          //linearc copy
00074   WERD *result;                  //output word
00075   ROW *row;                      //row of word
00076 
00077   if (word_it.cycled_list ()) {
00078     return NULL;                 //finished page
00079   }
00080   else {
00081     word = word_it.data ();
00082     row = row_it.data ();
00083     word_it.forward ();
00084     if (word_it.cycled_list ()) {
00085       row_it.forward ();         //finished row
00086       if (row_it.cycled_list ()) {
00087         do {
00088           block_it.forward ();   //finished block
00089           if (!block_it.cycled_list ()) {
00090             row_it.set_to_list (block_it.data ()->row_list ());
00091             row_it.mark_cycle_pt ();
00092           }
00093         }
00094         //find non-empty block
00095         while (!block_it.cycled_list ()
00096           && row_it.cycled_list ());
00097       }
00098       if (!row_it.cycled_list ()) {
00099         word_it.set_to_list (row_it.data ()->word_list ());
00100         word_it.mark_cycle_pt ();
00101       }
00102     }
00103 
00104     //              if (wordit_linearc && !word->flag(W_POLYGON))
00105     //              {
00106     //                      larc_word=word->larc_copy(row->x_height());
00107     //                      result=larc_word->poly_copy(row->x_height());
00108     //                      delete larc_word;
00109     //              }
00110     //              else
00111     result = word->poly_copy (row->x_height ());
00112     return result;
00113   }
00114 }
00115 
00116 
00128 WERD *make_pseudo_word(
00129                        BLOCK_LIST *block_list,
00130                        BOX &selection_box,
00131                        BLOCK *&pseudo_block,
00132                        ROW *&pseudo_row
00133                       ) {
00134   BLOCK_IT block_it(block_list); 
00135   BLOCK *block;
00136   ROW_IT row_it;
00137   ROW *row;
00138   WERD_IT word_it;
00139   WERD *word;
00140   PBLOB_IT blob_it;
00141   PBLOB *blob;
00142   PBLOB_LIST new_blobs;          //list of gathered blobs
00143                                  //iterator
00144   PBLOB_IT new_blob_it = &new_blobs;
00145   WERD *pseudo_word;             //fabricated word
00146   WERD *poly_word;               //poly copy of word
00147   //  WERD         *larc_word;     //linearc copy
00148 
00149   for (block_it.mark_cycle_pt ();
00150   !block_it.cycled_list (); block_it.forward ()) {
00151     block = block_it.data ();
00152     if (block->bounding_box ().overlap (selection_box)) {
00153       pseudo_block = block;
00154       row_it.set_to_list (block->row_list ());
00155       for (row_it.mark_cycle_pt ();
00156       !row_it.cycled_list (); row_it.forward ()) {
00157         row = row_it.data ();
00158         if (row->bounding_box ().overlap (selection_box)) {
00159           word_it.set_to_list (row->word_list ());
00160           for (word_it.mark_cycle_pt ();
00161           !word_it.cycled_list (); word_it.forward ()) {
00162             word = word_it.data ();
00163             if (word->bounding_box ().overlap (selection_box)) {
00164               //  if (wordit_linearc && !word->flag(W_POLYGON))
00165               //  {
00166               //     larc_word=word->larc_copy(row->x_height());
00167               //     poly_word=larc_word->poly_copy(row->x_height());
00168               //     delete larc_word;
00169               //  }
00170               //   else
00171               poly_word = word->poly_copy (row->x_height ());
00172               blob_it.set_to_list (poly_word->blob_list ());
00173               for (blob_it.mark_cycle_pt ();
00174               !blob_it.cycled_list (); blob_it.forward ()) {
00175                 blob = blob_it.data ();
00176                 if (blob->bounding_box ().
00177                 overlap (selection_box)) {
00178                   new_blob_it.add_after_then_move (blob_it.extract ());
00179                   pseudo_row = row; //steal off list
00180                 }
00181               }
00182               delete poly_word;  //get rid of it
00183             }
00184           }
00185         }
00186       }
00187     }
00188   }
00189   if (!new_blobs.empty ()) {
00190     pseudo_word = new WERD (&new_blobs, 1, NULL); //make new word
00191   }
00192   else
00193     pseudo_word = NULL;
00194   return pseudo_word;
00195 }

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