display/pagewalk.h File Reference

#include "ocrblock.h"
#include "ocrrow.h"
#include "werd.h"
#include "polyblob.h"
#include "stepblob.h"
#include "rect.h"
#include "varable.h"
#include "notdll.h"

Go to the source code of this file.

Defines

Functions


Define Documentation

#define BLOCK_SPACING   20

Spacing when plotting, pixels?

Definition at line 32 of file pagewalk.h.

Referenced by block_list_compress(), and do_tidy_cmd().


Function Documentation

BOX block_list_bounding_box ( BLOCK_LIST *  block_list  ) 

Find bounding box.

Scan block list to find the bounding box of all blocks.

Definition at line 36 of file pagewalk.cpp.

Referenced by do_tidy_cmd(), pgeditor_main(), and smd_cmd().

00038                              {
00039   BLOCK_IT block_it(block_list); 
00040   BOX enclosing_box;
00041 
00042   for (block_it.mark_cycle_pt (); !block_it.cycled_list ();
00043     block_it.forward ())
00044   enclosing_box += block_it.data ()->bounding_box ();
00045   return enclosing_box;
00046 }

const BOX block_list_compress ( BLOCK_LIST *  block_list  ) 

Shuffle up blocks.

Pack a block list to occupy a smaller space by compressing each block and moving the compressed blocks one above the other.

The compressed block list has the same top left point as the uncompressed first. Blocks are reordered so that the source names are in alphabetic order. (This gathers together, but does not combine, blocks from the same file.)

The enclosing box of the compressed block list is returned.

Definition at line 62 of file pagewalk.cpp.

References block_name_order(), BLOCK_SPACING, BOX::botleft(), and BOX::move_bottom_edge().

Referenced by do_tidy_cmd().

00063                                                       {
00064   BLOCK_IT block_it(block_list); 
00065   BLOCK *block;
00066   ICOORD initial_top_left;
00067   ICOORD block_spacing (0, BLOCK_SPACING);
00068   BOX enclosing_box;             //for full display
00069 
00070   initial_top_left = block_it.data ()->bounding_box ().topleft ();
00071                                  //group srcfile blks
00072   block_it.sort (block_name_order);
00073 
00074   /* Compress the target block list into an area starting from the top left of
00075     the first block on the list */
00076 
00077   enclosing_box = BOX (initial_top_left, initial_top_left);
00078   enclosing_box.move_bottom_edge (BLOCK_SPACING);
00079 
00080   for (block_it.mark_cycle_pt ();
00081   !block_it.cycled_list (); block_it.forward ()) {
00082     block = block_it.data ();
00083     block->compress (enclosing_box.botleft () - block_spacing -
00084       block->bounding_box ().topleft ());
00085     enclosing_box += block->bounding_box ();
00086   }
00087   return enclosing_box;
00088 }

void block_list_move ( BLOCK_LIST *  block_list,
ICOORD  vec 
)

Move all the blocks in the list by a vector.

Definition at line 94 of file pagewalk.cpp.

Referenced by do_tidy_cmd(), and do_write_file().

00097                       {
00098   BLOCK_IT block_it(block_list); 
00099 
00100   for (block_it.mark_cycle_pt (); !block_it.cycled_list ();
00101     block_it.forward ())
00102   block_it.data ()->move (vec);
00103 }

int block_name_order ( const void *  block1p,
const void *  block2p 
)

Sort blocks.

Block comparator used to sort a block list so that blocks from the same filename are located together, and blocks from the same file are ordered by vertical position.

Definition at line 113 of file pagewalk.cpp.

Referenced by block_list_compress().

00116                       {
00117   int result;
00118   BLOCK *block1 = *(BLOCK **) block1p;
00119   BLOCK *block2 = *(BLOCK **) block2p;
00120 
00121   result = strcmp (block1->name (), block2->name ());
00122   if (result == 0)
00123     result = block2->bounding_box ().top () - block1->bounding_box ().top ();
00124   return result;
00125 }

void process_all_blobs ( BLOCK_LIST *  block_list,
BOOL8   blob_processor(BLOCK *, ROW *, WERD *, PBLOB *),
BOOL8   c_blob_processor(BLOCK *, ROW *, WERD *, C_BLOB *) 
)

Process blobs.

Walk the current block list applying the specified blob processor function to all blobs

Definition at line 135 of file pagewalk.cpp.

References WERD::blob_list(), WERD::cblob_list(), WERD::flag(), NULL, W_POLYGON, and ROW::word_list().

00141   {
00142   BLOCK_IT block_it(block_list); 
00143   BLOCK *block;
00144   ROW_IT row_it;
00145   ROW *row;
00146   WERD_IT word_it;
00147   WERD *word;
00148   PBLOB_IT blob_it;
00149   PBLOB *blob;
00150   C_BLOB_IT c_blob_it;
00151   C_BLOB *c_blob;
00152 
00153   for (block_it.mark_cycle_pt ();
00154   !block_it.cycled_list (); block_it.forward ()) {
00155     block = block_it.data ();
00156     row_it.set_to_list (block->row_list ());
00157     for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
00158       row = row_it.data ();
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->flag (W_POLYGON)) {
00164           if (blob_processor != NULL) {
00165             blob_it.set_to_list (word->blob_list ());
00166             for (blob_it.mark_cycle_pt ();
00167             !blob_it.cycled_list (); blob_it.forward ()) {
00168               blob = blob_it.data ();
00169               if (!blob_processor (block, row, word, blob) ||
00170                 selection_quit)
00171                 return;
00172             }
00173           }
00174         }
00175         else {
00176           if (c_blob_processor != NULL) {
00177             c_blob_it.set_to_list (word->cblob_list ());
00178             for (c_blob_it.mark_cycle_pt ();
00179             !c_blob_it.cycled_list (); c_blob_it.forward ()) {
00180               c_blob = c_blob_it.data ();
00181               if (!c_blob_processor (block, row, word, c_blob) ||
00182                 selection_quit)
00183                 return;
00184             }
00185           }
00186         }
00187       }
00188     }
00189   }
00190 }

void process_all_blocks ( BLOCK_LIST *  block_list,
BOOL8   block_processor(BLOCK *) 
)

Process blocks.

Walk the current block list applying the specified block processor function to each block.

Definition at line 456 of file pagewalk.cpp.

00459           {
00460   BLOCK_IT block_it(block_list); 
00461   BLOCK *block;
00462 
00463   for (block_it.mark_cycle_pt ();
00464   !block_it.cycled_list (); block_it.forward ()) {
00465     block = block_it.data ();
00466     if (!block_processor (block) || selection_quit)
00467       return;
00468   }
00469 }

void process_all_rows ( BLOCK_LIST *  block_list,
BOOL8   row_processor(BLOCK *, ROW *) 
)

Process words.

Walk the current block list applying the specified row processor function to all rows

Definition at line 505 of file pagewalk.cpp.

00508                  {
00509   BLOCK_IT block_it(block_list); 
00510   BLOCK *block;
00511   ROW_IT row_it;
00512   ROW *row;
00513 
00514   for (block_it.mark_cycle_pt ();
00515   !block_it.cycled_list (); block_it.forward ()) {
00516     block = block_it.data ();
00517     row_it.set_to_list (block->row_list ());
00518     for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
00519       row = row_it.data ();
00520       if (!row_processor (block, row) || selection_quit)
00521         return;
00522     }
00523   }
00524 }

void process_all_rows_it ( BLOCK_LIST *  block_list,
BOOL8   row_processor(BLOCK *, ROW *, BLOCK_IT &, ROW_IT &) 
)

Process words.

Walk the current block list applying the specified row processor function to all rows; PASS ITERATORS

Definition at line 570 of file pagewalk.cpp.

00574                               {
00575   BLOCK_IT block_it(block_list); 
00576   BLOCK *block;
00577   ROW_IT row_it;
00578   ROW *row;
00579 
00580   for (block_it.mark_cycle_pt ();
00581   !block_it.cycled_list (); block_it.forward ()) {
00582     block = block_it.data ();
00583     row_it.set_to_list (block->row_list ());
00584     for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
00585       row = row_it.data ();
00586       if (!row_processor (block, row, block_it, row_it) || selection_quit)
00587         return;
00588     }
00589   }
00590 }

void process_all_words ( BLOCK_LIST *  block_list,
BOOL8   word_processor(BLOCK *, ROW *, WERD *) 
)

Process words.

Walk the current block list applying the specified word processor function to all words

Definition at line 284 of file pagewalk.cpp.

References ROW::word_list().

00287                          {
00288   BLOCK_IT block_it(block_list); 
00289   BLOCK *block;
00290   ROW_IT row_it;
00291   ROW *row;
00292   WERD_IT word_it;
00293   WERD *word;
00294 
00295   for (block_it.mark_cycle_pt ();
00296   !block_it.cycled_list (); block_it.forward ()) {
00297     block = block_it.data ();
00298     row_it.set_to_list (block->row_list ());
00299     for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
00300       row = row_it.data ();
00301       word_it.set_to_list (row->word_list ());
00302       for (word_it.mark_cycle_pt ();
00303       !word_it.cycled_list (); word_it.forward ()) {
00304         word = word_it.data ();
00305         if (!word_processor (block, row, word) || selection_quit)
00306           return;
00307       }
00308     }
00309   }
00310 }

void process_all_words_it ( BLOCK_LIST *  block_list,
BOOL8   word_processor(BLOCK *, ROW *, WERD *, BLOCK_IT &, ROW_IT &, WERD_IT &) 
)

Process words.

Walk the current block list applying the specified word processor function to all words; PASS ITERATORS

Definition at line 367 of file pagewalk.cpp.

References ROW::word_list().

00374                       {
00375   BLOCK_IT block_it(block_list); 
00376   BLOCK *block;
00377   ROW_IT row_it;
00378   ROW *row;
00379   WERD_IT word_it;
00380   WERD *word;
00381 
00382   for (block_it.mark_cycle_pt ();
00383   !block_it.cycled_list (); block_it.forward ()) {
00384     block = block_it.data ();
00385     row_it.set_to_list (block->row_list ());
00386     for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) {
00387       row = row_it.data ();
00388       word_it.set_to_list (row->word_list ());
00389       for (word_it.mark_cycle_pt ();
00390       !word_it.cycled_list (); word_it.forward ()) {
00391         word = word_it.data ();
00392         if (!word_processor
00393           (block, row, word, block_it, row_it, word_it)
00394           || selection_quit)
00395           return;
00396       }
00397     }
00398   }
00399 }

void process_selected_blobs ( BLOCK_LIST *  block_list,
BOX selection_box,
BOOL8   blob_processor(BLOCK *, ROW *, WERD *, PBLOB *),
BOOL8   c_blob_processor(BLOCK *, ROW *, WERD *, C_BLOB *) 
)

Process blobs.

Walk the current block list applying the specified blob processor function to each selected blob

Definition at line 200 of file pagewalk.cpp.

References WERD::blob_list(), PBLOB::bounding_box(), WERD::bounding_box(), ROW::bounding_box(), WERD::cblob_list(), WERD::flag(), NULL, BOX::overlap(), W_POLYGON, and ROW::word_list().

00207   {
00208   BLOCK_IT block_it(block_list); 
00209   BLOCK *block;
00210   ROW_IT row_it;
00211   ROW *row;
00212   WERD_IT word_it;
00213   WERD *word;
00214   PBLOB_IT blob_it;
00215   PBLOB *blob;
00216   C_BLOB_IT c_blob_it;
00217   C_BLOB *c_blob;
00218 
00219   for (block_it.mark_cycle_pt ();
00220   !block_it.cycled_list (); block_it.forward ()) {
00221     block = block_it.data ();
00222     if (block->bounding_box ().overlap (selection_box)) {
00223       row_it.set_to_list (block->row_list ());
00224       for (row_it.mark_cycle_pt ();
00225       !row_it.cycled_list (); row_it.forward ()) {
00226         row = row_it.data ();
00227         if (row->bounding_box ().overlap (selection_box)) {
00228           word_it.set_to_list (row->word_list ());
00229           for (word_it.mark_cycle_pt ();
00230           !word_it.cycled_list (); word_it.forward ()) {
00231             word = word_it.data ();
00232             if (word->bounding_box ().overlap (selection_box)) {
00233               if (word->flag (W_POLYGON)) {
00234                 if (blob_processor != NULL) {
00235                   blob_it.set_to_list (word->blob_list ());
00236                   for (blob_it.mark_cycle_pt ();
00237                     !blob_it.cycled_list ();
00238                   blob_it.forward ()) {
00239                     blob = blob_it.data ();
00240                     if (blob->bounding_box ().
00241                     overlap (selection_box)) {
00242                       if (!blob_processor
00243                         (block, row, word, blob)
00244                         || selection_quit)
00245                         return;
00246                     }
00247                   }
00248                 }
00249               }
00250               else {
00251                 if (c_blob_processor != NULL) {
00252                   c_blob_it.set_to_list (word->cblob_list ());
00253                   for (c_blob_it.mark_cycle_pt ();
00254                     !c_blob_it.cycled_list ();
00255                   c_blob_it.forward ()) {
00256                     c_blob = c_blob_it.data ();
00257                     if (c_blob->
00258                       bounding_box ().
00259                     overlap (selection_box)) {
00260                       if (!c_blob_processor
00261                         (block, row, word, c_blob)
00262                         || selection_quit)
00263                         return;
00264                     }
00265                   }
00266                 }
00267               }
00268             }
00269           }
00270         }
00271       }
00272     }
00273   }
00274 }

void process_selected_blocks ( BLOCK_LIST *  block_list,
BOX selection_box,
BOOL8   block_processor(BLOCK *) 
)

Process blocks.

Walk the current block list applying the specified block processor function to each block selected.

Definition at line 479 of file pagewalk.cpp.

00483   {
00484   BLOCK_IT block_it(block_list); 
00485   BLOCK *block;
00486 
00487   for (block_it.mark_cycle_pt ();
00488   !block_it.cycled_list (); block_it.forward ()) {
00489     block = block_it.data ();
00490     if (block->bounding_box ().overlap (selection_box)) {
00491       if (!block_processor (block) || selection_quit)
00492         return;
00493     }
00494   }
00495 }

void process_selected_rows ( BLOCK_LIST *  block_list,
BOX selection_box,
BOOL8   row_processor(BLOCK *, ROW *) 
)

Process rows.

Walk the current block list applying the specified row processor function to each row selected.

Definition at line 534 of file pagewalk.cpp.

References ROW::bounding_box(), and BOX::overlap().

00539         {
00540   BLOCK_IT block_it(block_list); 
00541   BLOCK *block;
00542   ROW_IT row_it;
00543   ROW *row;
00544 
00545   for (block_it.mark_cycle_pt ();
00546   !block_it.cycled_list (); block_it.forward ()) {
00547     block = block_it.data ();
00548     if (block->bounding_box ().overlap (selection_box)) {
00549       row_it.set_to_list (block->row_list ());
00550       for (row_it.mark_cycle_pt ();
00551       !row_it.cycled_list (); row_it.forward ()) {
00552         row = row_it.data ();
00553         if (row->bounding_box ().overlap (selection_box)) {
00554           if (!row_processor (block, row) || selection_quit)
00555             return;
00556         }
00557       }
00558     }
00559   }
00560 }

void process_selected_rows_it ( BLOCK_LIST *  block_list,
BOX selection_box,
BOOL8   row_processor(BLOCK *, ROW *, BLOCK_IT &, ROW_IT &) 
)

Process rows.

Walk the current block list applying the specified row processor function to each row selected; PASS ITERATORS

Definition at line 600 of file pagewalk.cpp.

References ROW::bounding_box(), and BOX::overlap().

00605   {
00606   BLOCK_IT block_it(block_list); 
00607   BLOCK *block;
00608   ROW_IT row_it;
00609   ROW *row;
00610 
00611   for (block_it.mark_cycle_pt ();
00612   !block_it.cycled_list (); block_it.forward ()) {
00613     block = block_it.data ();
00614     if (block->bounding_box ().overlap (selection_box)) {
00615       row_it.set_to_list (block->row_list ());
00616       for (row_it.mark_cycle_pt ();
00617       !row_it.cycled_list (); row_it.forward ()) {
00618         row = row_it.data ();
00619         if (row->bounding_box ().overlap (selection_box)) {
00620           if (!row_processor (block, row, block_it, row_it) ||
00621             selection_quit)
00622             return;
00623         }
00624       }
00625     }
00626   }
00627 }

void process_selected_words ( BLOCK_LIST *  block_list,
BOX selection_box,
BOOL8   word_processor(BLOCK *, ROW *, WERD *) 
)

Process words.

Walk the current block list applying the specified word processor function to each word selected.

Definition at line 320 of file pagewalk.cpp.

References WERD::bounding_box(), ROW::bounding_box(), BOX::overlap(), and ROW::word_list().

Referenced by extend_moded_commands(), and process_image_event().

00326          {
00327   BLOCK_IT block_it(block_list); 
00328   BLOCK *block;
00329   ROW_IT row_it;
00330   ROW *row;
00331   WERD_IT word_it;
00332   WERD *word;
00333 
00334   for (block_it.mark_cycle_pt ();
00335   !block_it.cycled_list (); block_it.forward ()) {
00336     block = block_it.data ();
00337     if (block->bounding_box ().overlap (selection_box)) {
00338       row_it.set_to_list (block->row_list ());
00339       for (row_it.mark_cycle_pt ();
00340       !row_it.cycled_list (); row_it.forward ()) {
00341         row = row_it.data ();
00342         if (row->bounding_box ().overlap (selection_box)) {
00343           word_it.set_to_list (row->word_list ());
00344           for (word_it.mark_cycle_pt ();
00345           !word_it.cycled_list (); word_it.forward ()) {
00346             word = word_it.data ();
00347             if (word->bounding_box ().overlap (selection_box)) {
00348               if (!word_processor (block, row, word) ||
00349                 selection_quit)
00350                 return;
00351             }
00352           }
00353         }
00354       }
00355     }
00356   }
00357 }

void process_selected_words_it ( BLOCK_LIST *  block_list,
BOX selection_box,
BOOL8   word_processor(BLOCK *, ROW *, WERD *, BLOCK_IT &, ROW_IT &, WERD_IT &) 
)

Process words.

Walk the current block list applying the specified word processor function to each word selected; PASS ITERATORS

Definition at line 409 of file pagewalk.cpp.

References WERD::bounding_box(), ROW::bounding_box(), BOX::overlap(), and ROW::word_list().

Referenced by process_image_event().

00414   {
00415   BLOCK_IT block_it(block_list); 
00416   BLOCK *block;
00417   ROW_IT row_it;
00418   ROW *row;
00419   WERD_IT word_it;
00420   WERD *word;
00421 
00422   for (block_it.mark_cycle_pt ();
00423   !block_it.cycled_list (); block_it.forward ()) {
00424     block = block_it.data ();
00425     if (block->bounding_box ().overlap (selection_box)) {
00426       row_it.set_to_list (block->row_list ());
00427       for (row_it.mark_cycle_pt ();
00428       !row_it.cycled_list (); row_it.forward ()) {
00429         row = row_it.data ();
00430         if (row->bounding_box ().overlap (selection_box)) {
00431           word_it.set_to_list (row->word_list ());
00432           for (word_it.mark_cycle_pt ();
00433           !word_it.cycled_list (); word_it.forward ()) {
00434             word = word_it.data ();
00435             if (word->bounding_box ().overlap (selection_box)) {
00436               if (!word_processor (block, row, word,
00437                 block_it, row_it, word_it) ||
00438                 selection_quit)
00439                 return;
00440             }
00441           }
00442         }
00443       }
00444     }
00445   }
00446 }


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