Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PAGE_RES_IT Class Reference

#include <pageres.h>

Public Member Functions

 PAGE_RES_IT ()
 
 PAGE_RES_IT (PAGE_RES *the_page_res)
 
bool operator== (const PAGE_RES_IT &other) const
 
bool operator!= (const PAGE_RES_IT &other) const
 
int cmp (const PAGE_RES_IT &other) const
 
WERD_RESrestart_page ()
 
WERD_RESrestart_page_with_empties ()
 
WERD_RESstart_page (bool empty_ok)
 
WERD_RESrestart_row ()
 
WERD_RESInsertSimpleCloneWord (const WERD_RES &clone_res, WERD *new_word)
 
void DeleteCurrentWord ()
 
WERD_RESforward ()
 
WERD_RESforward_with_empties ()
 
WERD_RESforward_paragraph ()
 
WERD_RESforward_block ()
 
WERD_RESprev_word () const
 
ROW_RESprev_row () const
 
BLOCK_RESprev_block () const
 
WERD_RESword () const
 
ROW_RESrow () const
 
BLOCK_RESblock () const
 
WERD_RESnext_word () const
 
ROW_RESnext_row () const
 
BLOCK_RESnext_block () const
 
void rej_stat_word ()
 

Public Attributes

PAGE_RESpage_res
 

Detailed Description

Definition at line 689 of file pageres.h.

Constructor & Destructor Documentation

PAGE_RES_IT::PAGE_RES_IT ( )
inline

Definition at line 693 of file pageres.h.

693  {
694  } // empty contructor
PAGE_RES_IT::PAGE_RES_IT ( PAGE_RES the_page_res)
inline

Definition at line 696 of file pageres.h.

696  { // page result
697  page_res = the_page_res;
698  restart_page(); // ready to scan
699  }
WERD_RES * restart_page()
Definition: pageres.h:713
PAGE_RES * page_res
Definition: pageres.h:691

Member Function Documentation

BLOCK_RES* PAGE_RES_IT::block ( ) const
inline

Definition at line 763 of file pageres.h.

763  { // block of cur. word
764  return block_res;
765  }
int PAGE_RES_IT::cmp ( const PAGE_RES_IT other) const

Definition at line 851 of file pageres.cpp.

851  {
852  ASSERT_HOST(page_res == other.page_res);
853  if (other.block_res == NULL) {
854  // other points to the end of the page.
855  if (block_res == NULL)
856  return 0;
857  return -1;
858  }
859  if (block_res == NULL) {
860  return 1; // we point to the end of the page.
861  }
862  if (block_res == other.block_res) {
863  if (other.row_res == NULL || row_res == NULL) {
864  // this should only happen if we hit an image block.
865  return 0;
866  }
867  if (row_res == other.row_res) {
868  // we point to the same block and row.
869  ASSERT_HOST(other.word_res != NULL && word_res != NULL);
870  if (word_res == other.word_res) {
871  // we point to the same word!
872  return 0;
873  }
874 
875  WERD_RES_IT word_res_it(&row_res->word_res_list);
876  for (word_res_it.mark_cycle_pt(); !word_res_it.cycled_list();
877  word_res_it.forward()) {
878  if (word_res_it.data() == word_res) {
879  return -1;
880  } else if (word_res_it.data() == other.word_res) {
881  return 1;
882  }
883  }
884  ASSERT_HOST("Error: Incomparable PAGE_RES_ITs" == NULL);
885  }
886 
887  // we both point to the same block, but different rows.
888  ROW_RES_IT row_res_it(&block_res->row_res_list);
889  for (row_res_it.mark_cycle_pt(); !row_res_it.cycled_list();
890  row_res_it.forward()) {
891  if (row_res_it.data() == row_res) {
892  return -1;
893  } else if (row_res_it.data() == other.row_res) {
894  return 1;
895  }
896  }
897  ASSERT_HOST("Error: Incomparable PAGE_RES_ITs" == NULL);
898  }
899 
900  // We point to different blocks.
901  BLOCK_RES_IT block_res_it(&page_res->block_res_list);
902  for (block_res_it.mark_cycle_pt();
903  !block_res_it.cycled_list(); block_res_it.forward()) {
904  if (block_res_it.data() == block_res) {
905  return -1;
906  } else if (block_res_it.data() == other.block_res) {
907  return 1;
908  }
909  }
910  // Shouldn't happen...
911  ASSERT_HOST("Error: Incomparable PAGE_RES_ITs" == NULL);
912  return 0;
913 }
BLOCK_RES_LIST block_res_list
Definition: pageres.h:222
#define NULL
Definition: host.h:144
WERD_RES_LIST word_res_list
Definition: pageres.h:290
ROW_RES_LIST row_res_list
Definition: pageres.h:269
#define ASSERT_HOST(x)
Definition: errcode.h:84
PAGE_RES * page_res
Definition: pageres.h:691
void PAGE_RES_IT::DeleteCurrentWord ( )

Definition at line 950 of file pageres.cpp.

950  {
951  // Check that this word is as we expect. part_of_combos are NEVER iterated
952  // by the normal iterator, so we should never be trying to delete them.
953  ASSERT_HOST(!word_res->part_of_combo);
954  if (!word_res->combination) {
955  // Combinations own their own word, so we won't find the word on the
956  // row's word_list, but it is legitimate to try to delete them.
957  // Delete word from the ROW when not a combination.
958  WERD_IT w_it(row()->row->word_list());
959  for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
960  if (w_it.data() == word_res->word) {
961  break;
962  }
963  }
964  ASSERT_HOST(!w_it.cycled_list());
965  delete w_it.extract();
966  }
967  // Remove the WERD_RES for the new_word.
968  // Remove the WORD_RES from the ROW_RES.
969  WERD_RES_IT wr_it(&row()->word_res_list);
970  for (wr_it.mark_cycle_pt(); !wr_it.cycled_list(); wr_it.forward()) {
971  if (wr_it.data() == word_res) {
972  word_res = NULL;
973  break;
974  }
975  }
976  ASSERT_HOST(!wr_it.cycled_list());
977  delete wr_it.extract();
978  ResetWordIterator();
979 }
ROW_RES * row() const
Definition: pageres.h:760
BOOL8 part_of_combo
Definition: pageres.h:451
#define NULL
Definition: host.h:144
BOOL8 combination
Definition: pageres.h:450
WERD * word
Definition: pageres.h:334
#define ASSERT_HOST(x)
Definition: errcode.h:84
WERD_RES* PAGE_RES_IT::forward ( )
inline

Definition at line 737 of file pageres.h.

737  { // Get next word.
738  return internal_forward(false, false);
739  }
WERD_RES * PAGE_RES_IT::forward_block ( )

Definition at line 1130 of file pageres.cpp.

1130  {
1131  while (block_res == next_block_res) {
1132  internal_forward(false, true);
1133  }
1134  return internal_forward(false, true);
1135 }
WERD_RES * PAGE_RES_IT::forward_paragraph ( )

Definition at line 1115 of file pageres.cpp.

1115  {
1116  while (block_res == next_block_res &&
1117  (next_row_res != NULL && next_row_res->row != NULL &&
1118  row_res->row->para() == next_row_res->row->para())) {
1119  internal_forward(false, true);
1120  }
1121  return internal_forward(false, true);
1122 }
#define NULL
Definition: host.h:144
PARA * para() const
Definition: ocrrow.h:112
ROW * row
Definition: pageres.h:286
WERD_RES* PAGE_RES_IT::forward_with_empties ( )
inline

Definition at line 741 of file pageres.h.

741  {
742  return internal_forward(false, true);
743  }
WERD_RES * PAGE_RES_IT::InsertSimpleCloneWord ( const WERD_RES clone_res,
WERD new_word 
)

Definition at line 918 of file pageres.cpp.

919  {
920  // Insert new_word into the ROW.
921  WERD_IT w_it(row()->row->word_list());
922  for (w_it.mark_cycle_pt(); !w_it.cycled_list(); w_it.forward()) {
923  WERD* word = w_it.data();
924  if (word == word_res->word)
925  break;
926  }
927  ASSERT_HOST(!w_it.cycled_list());
928  w_it.add_before_then_move(new_word);
929  // Make a WERD_RES for the new_word.
930  WERD_RES* new_res = new WERD_RES(new_word);
931  new_res->CopySimpleFields(clone_res);
932  // Insert into the appropriate place in the ROW_RES.
933  WERD_RES_IT wr_it(&row()->word_res_list);
934  for (wr_it.mark_cycle_pt(); !wr_it.cycled_list(); wr_it.forward()) {
935  WERD_RES* word = wr_it.data();
936  if (word == word_res)
937  break;
938  }
939  ASSERT_HOST(!wr_it.cycled_list());
940  wr_it.add_before_then_move(new_res);
941  if (wr_it.at_first()) {
942  // This is the new first word, so reset the member iterator so it
943  // detects the cycled_list state correctly.
944  ResetWordIterator();
945  }
946  return new_res;
947 }
ROW_RES * row() const
Definition: pageres.h:760
WERD_RES * word() const
Definition: pageres.h:757
WERD * word
Definition: pageres.h:334
Definition: werd.h:60
void CopySimpleFields(const WERD_RES &source)
Definition: pageres.cpp:234
#define ASSERT_HOST(x)
Definition: errcode.h:84
BLOCK_RES* PAGE_RES_IT::next_block ( ) const
inline

Definition at line 772 of file pageres.h.

772  { // block of next word
773  return next_block_res;
774  }
ROW_RES* PAGE_RES_IT::next_row ( ) const
inline

Definition at line 769 of file pageres.h.

769  { // row of next word
770  return next_row_res;
771  }
WERD_RES* PAGE_RES_IT::next_word ( ) const
inline

Definition at line 766 of file pageres.h.

766  { // next word
767  return next_word_res;
768  }
bool PAGE_RES_IT::operator!= ( const PAGE_RES_IT other) const
inline

Definition at line 705 of file pageres.h.

705 {return !(*this == other); }
bool PAGE_RES_IT::operator== ( const PAGE_RES_IT other) const

Definition at line 845 of file pageres.cpp.

845  {
846  return word_res == other.word_res &&
847  row_res == other.row_res &&
848  block_res == other.block_res;
849 }
BLOCK_RES* PAGE_RES_IT::prev_block ( ) const
inline

Definition at line 754 of file pageres.h.

754  { // block of prev word
755  return prev_block_res;
756  }
ROW_RES* PAGE_RES_IT::prev_row ( ) const
inline

Definition at line 751 of file pageres.h.

751  { // row of prev word
752  return prev_row_res;
753  }
WERD_RES* PAGE_RES_IT::prev_word ( ) const
inline

Definition at line 748 of file pageres.h.

748  { // previous word
749  return prev_word_res;
750  }
void PAGE_RES_IT::rej_stat_word ( )

Definition at line 1137 of file pageres.cpp.

1137  {
1138  inT16 chars_in_word;
1139  inT16 rejects_in_word = 0;
1140 
1141  chars_in_word = word_res->reject_map.length ();
1142  page_res->char_count += chars_in_word;
1143  block_res->char_count += chars_in_word;
1144  row_res->char_count += chars_in_word;
1145 
1146  rejects_in_word = word_res->reject_map.reject_count ();
1147 
1148  page_res->rej_count += rejects_in_word;
1149  block_res->rej_count += rejects_in_word;
1150  row_res->rej_count += rejects_in_word;
1151  if (chars_in_word == rejects_in_word)
1152  row_res->whole_word_rej_count += rejects_in_word;
1153 }
inT32 rej_count
Definition: pageres.h:221
REJMAP reject_map
Definition: pageres.h:408
inT32 char_count
Definition: pageres.h:259
inT32 rej_count
Definition: pageres.h:260
inT32 whole_word_rej_count
Definition: pageres.h:289
short inT16
Definition: host.h:100
inT32 char_count
Definition: pageres.h:287
inT32 length() const
Definition: rejctmap.h:238
inT32 char_count
Definition: pageres.h:220
inT32 rej_count
Definition: pageres.h:288
PAGE_RES * page_res
Definition: pageres.h:691
inT16 reject_count()
Definition: rejctmap.h:244
WERD_RES* PAGE_RES_IT::restart_page ( )
inline

Definition at line 713 of file pageres.h.

713  {
714  return start_page(false); // Skip empty blocks.
715  }
WERD_RES * start_page(bool empty_ok)
Definition: pageres.cpp:987
WERD_RES* PAGE_RES_IT::restart_page_with_empties ( )
inline

Definition at line 716 of file pageres.h.

716  {
717  return start_page(true); // Allow empty blocks.
718  }
WERD_RES * start_page(bool empty_ok)
Definition: pageres.cpp:987
WERD_RES * PAGE_RES_IT::restart_row ( )

Definition at line 1100 of file pageres.cpp.

1100  {
1101  ROW_RES *row = this->row();
1102  if (!row) return NULL;
1103  for (restart_page(); this->row() != row; forward()) {
1104  // pass
1105  }
1106  return word();
1107 }
ROW_RES * row() const
Definition: pageres.h:760
WERD_RES * restart_page()
Definition: pageres.h:713
#define NULL
Definition: host.h:144
WERD_RES * word() const
Definition: pageres.h:757
WERD_RES * forward()
Definition: pageres.h:737
ROW_RES* PAGE_RES_IT::row ( ) const
inline

Definition at line 760 of file pageres.h.

760  { // row of current word
761  return row_res;
762  }
WERD_RES * PAGE_RES_IT::start_page ( bool  empty_ok)

Definition at line 987 of file pageres.cpp.

987  {
988  block_res_it.set_to_list(&page_res->block_res_list);
989  block_res_it.mark_cycle_pt();
990  prev_block_res = NULL;
991  prev_row_res = NULL;
992  prev_word_res = NULL;
993  block_res = NULL;
994  row_res = NULL;
995  word_res = NULL;
996  next_block_res = NULL;
997  next_row_res = NULL;
998  next_word_res = NULL;
999  internal_forward(true, empty_ok);
1000  return internal_forward(false, empty_ok);
1001 }
BLOCK_RES_LIST block_res_list
Definition: pageres.h:222
#define NULL
Definition: host.h:144
PAGE_RES * page_res
Definition: pageres.h:691
WERD_RES* PAGE_RES_IT::word ( ) const
inline

Definition at line 757 of file pageres.h.

757  { // current word
758  return word_res;
759  }

Member Data Documentation

PAGE_RES* PAGE_RES_IT::page_res

Definition at line 691 of file pageres.h.


The documentation for this class was generated from the following files: