All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
tesseract::RowScratchRegisters Class Reference

#include <paragraphs_internal.h>

Public Member Functions

void Init (const RowInfo &row)
 
LineType GetLineType () const
 
LineType GetLineType (const ParagraphModel *model) const
 
void SetStartLine ()
 
void SetBodyLine ()
 
void AddStartLine (const ParagraphModel *model)
 
void AddBodyLine (const ParagraphModel *model)
 
void SetUnknown ()
 
void StartHypotheses (SetOfModels *models) const
 
void StrongHypotheses (SetOfModels *models) const
 
void NonNullHypotheses (SetOfModels *models) const
 
void DiscardNonMatchingHypotheses (const SetOfModels &models)
 
const ParagraphModelUniqueStartHypothesis () const
 
const ParagraphModelUniqueBodyHypothesis () const
 
int OffsideIndent (tesseract::ParagraphJustification just) const
 
int AlignsideIndent (tesseract::ParagraphJustification just) const
 
void AppendDebugInfo (const ParagraphTheory &theory, GenericVector< STRING > *dbg) const
 

Static Public Member Functions

static void AppendDebugHeaderFields (GenericVector< STRING > *header)
 

Public Attributes

const RowInfori_
 
int lmargin_
 
int lindent_
 
int rindent_
 
int rmargin_
 

Detailed Description

Definition at line 100 of file paragraphs_internal.h.

Member Function Documentation

void tesseract::RowScratchRegisters::AddBodyLine ( const ParagraphModel model)

Definition at line 589 of file paragraphs.cpp.

589  {
590  hypotheses_.push_back_new(LineHypothesis(LT_BODY, model));
591  int old_idx = hypotheses_.get_index(LineHypothesis(LT_BODY, NULL));
592  if (old_idx >= 0)
593  hypotheses_.remove(old_idx);
594 }
#define NULL
Definition: host.h:144
void tesseract::RowScratchRegisters::AddStartLine ( const ParagraphModel model)

Definition at line 582 of file paragraphs.cpp.

582  {
583  hypotheses_.push_back_new(LineHypothesis(LT_START, model));
584  int old_idx = hypotheses_.get_index(LineHypothesis(LT_START, NULL));
585  if (old_idx >= 0)
586  hypotheses_.remove(old_idx);
587 }
#define NULL
Definition: host.h:144
int tesseract::RowScratchRegisters::AlignsideIndent ( tesseract::ParagraphJustification  just) const
inline
void tesseract::RowScratchRegisters::AppendDebugHeaderFields ( GenericVector< STRING > *  header)
static

Definition at line 475 of file paragraphs.cpp.

476  {
477  header->push_back("[lmarg,lind;rind,rmarg]");
478  header->push_back("model");
479 }
int push_back(T object)
void tesseract::RowScratchRegisters::AppendDebugInfo ( const ParagraphTheory theory,
GenericVector< STRING > *  dbg 
) const

Definition at line 481 of file paragraphs.cpp.

482  {
483  char s[30];
484  snprintf(s, sizeof(s), "[%3d,%3d;%3d,%3d]",
486  dbg->push_back(s);
487  STRING model_string;
488  model_string += static_cast<char>(GetLineType());
489  model_string += ":";
490 
491  int model_numbers = 0;
492  for (int h = 0; h < hypotheses_.size(); h++) {
493  if (hypotheses_[h].model == NULL)
494  continue;
495  if (model_numbers > 0)
496  model_string += ",";
497  if (StrongModel(hypotheses_[h].model)) {
498  model_string += StrOf(1 + theory.IndexOf(hypotheses_[h].model));
499  } else if (hypotheses_[h].model == kCrownLeft) {
500  model_string += "CrL";
501  } else if (hypotheses_[h].model == kCrownRight) {
502  model_string += "CrR";
503  }
504  model_numbers++;
505  }
506  if (model_numbers == 0)
507  model_string += "0";
508 
509  dbg->push_back(model_string);
510 }
int push_back(T object)
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:47
bool StrongModel(const ParagraphModel *model)
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:45
Definition: strngs.h:44
LineType GetLineType() const
Definition: paragraphs.cpp:520
#define NULL
Definition: host.h:144
void tesseract::RowScratchRegisters::DiscardNonMatchingHypotheses ( const SetOfModels models)

Definition at line 630 of file paragraphs.cpp.

631  {
632  if (models.empty())
633  return;
634  for (int h = hypotheses_.size() - 1; h >= 0; h--) {
635  if (!models.contains(hypotheses_[h].model)) {
636  hypotheses_.remove(h);
637  }
638  }
639 }
LineType tesseract::RowScratchRegisters::GetLineType ( ) const

Definition at line 520 of file paragraphs.cpp.

520  {
521  if (hypotheses_.empty())
522  return LT_UNKNOWN;
523  bool has_start = false;
524  bool has_body = false;
525  for (int i = 0; i < hypotheses_.size(); i++) {
526  switch (hypotheses_[i].ty) {
527  case LT_START: has_start = true; break;
528  case LT_BODY: has_body = true; break;
529  default:
530  tprintf("Encountered bad value in hypothesis list: %c\n",
531  hypotheses_[i].ty);
532  break;
533  }
534  }
535  if (has_start && has_body)
536  return LT_MULTIPLE;
537  return has_start ? LT_START : LT_BODY;
538 }
#define tprintf(...)
Definition: tprintf.h:31
LineType tesseract::RowScratchRegisters::GetLineType ( const ParagraphModel model) const

Definition at line 540 of file paragraphs.cpp.

540  {
541  if (hypotheses_.empty())
542  return LT_UNKNOWN;
543  bool has_start = false;
544  bool has_body = false;
545  for (int i = 0; i < hypotheses_.size(); i++) {
546  if (hypotheses_[i].model != model)
547  continue;
548  switch (hypotheses_[i].ty) {
549  case LT_START: has_start = true; break;
550  case LT_BODY: has_body = true; break;
551  default:
552  tprintf("Encountered bad value in hypothesis list: %c\n",
553  hypotheses_[i].ty);
554  break;
555  }
556  }
557  if (has_start && has_body)
558  return LT_MULTIPLE;
559  return has_start ? LT_START : LT_BODY;
560 }
#define tprintf(...)
Definition: tprintf.h:31
void tesseract::RowScratchRegisters::Init ( const RowInfo row)

Definition at line 512 of file paragraphs.cpp.

512  {
513  ri_ = &row;
514  lmargin_ = 0;
515  lindent_ = row.pix_ldistance;
516  rmargin_ = 0;
517  rindent_ = row.pix_rdistance;
518 }
void tesseract::RowScratchRegisters::NonNullHypotheses ( SetOfModels models) const

Definition at line 610 of file paragraphs.cpp.

610  {
611  for (int h = 0; h < hypotheses_.size(); h++) {
612  if (hypotheses_[h].model != NULL)
613  models->push_back_new(hypotheses_[h].model);
614  }
615 }
#define NULL
Definition: host.h:144
int tesseract::RowScratchRegisters::OffsideIndent ( tesseract::ParagraphJustification  just) const
inline
void tesseract::RowScratchRegisters::SetBodyLine ( )

Definition at line 572 of file paragraphs.cpp.

572  {
573  LineType current_lt = GetLineType();
574  if (current_lt != LT_UNKNOWN && current_lt != LT_BODY) {
575  tprintf("Trying to set a line to be BODY when it's already START.\n");
576  }
577  if (current_lt == LT_UNKNOWN || current_lt == LT_START) {
578  hypotheses_.push_back_new(LineHypothesis(LT_BODY, NULL));
579  }
580 }
#define tprintf(...)
Definition: tprintf.h:31
LineType GetLineType() const
Definition: paragraphs.cpp:520
#define NULL
Definition: host.h:144
void tesseract::RowScratchRegisters::SetStartLine ( )

Definition at line 562 of file paragraphs.cpp.

562  {
563  LineType current_lt = GetLineType();
564  if (current_lt != LT_UNKNOWN && current_lt != LT_START) {
565  tprintf("Trying to set a line to be START when it's already BODY.\n");
566  }
567  if (current_lt == LT_UNKNOWN || current_lt == LT_BODY) {
568  hypotheses_.push_back_new(LineHypothesis(LT_START, NULL));
569  }
570 }
#define tprintf(...)
Definition: tprintf.h:31
LineType GetLineType() const
Definition: paragraphs.cpp:520
#define NULL
Definition: host.h:144
void tesseract::RowScratchRegisters::SetUnknown ( )
inline

Definition at line 123 of file paragraphs_internal.h.

123 { hypotheses_.truncate(0); }
void tesseract::RowScratchRegisters::StartHypotheses ( SetOfModels models) const

Definition at line 596 of file paragraphs.cpp.

596  {
597  for (int h = 0; h < hypotheses_.size(); h++) {
598  if (hypotheses_[h].ty == LT_START && StrongModel(hypotheses_[h].model))
599  models->push_back_new(hypotheses_[h].model);
600  }
601 }
bool StrongModel(const ParagraphModel *model)
void tesseract::RowScratchRegisters::StrongHypotheses ( SetOfModels models) const

Definition at line 603 of file paragraphs.cpp.

603  {
604  for (int h = 0; h < hypotheses_.size(); h++) {
605  if (StrongModel(hypotheses_[h].model))
606  models->push_back_new(hypotheses_[h].model);
607  }
608 }
bool StrongModel(const ParagraphModel *model)
const ParagraphModel * tesseract::RowScratchRegisters::UniqueBodyHypothesis ( ) const

Definition at line 623 of file paragraphs.cpp.

623  {
624  if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_BODY)
625  return NULL;
626  return hypotheses_[0].model;
627 }
#define NULL
Definition: host.h:144
const ParagraphModel * tesseract::RowScratchRegisters::UniqueStartHypothesis ( ) const

Definition at line 617 of file paragraphs.cpp.

617  {
618  if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_START)
619  return NULL;
620  return hypotheses_[0].model;
621 }
#define NULL
Definition: host.h:144

Member Data Documentation

int tesseract::RowScratchRegisters::lindent_

Definition at line 178 of file paragraphs_internal.h.

int tesseract::RowScratchRegisters::lmargin_

Definition at line 177 of file paragraphs_internal.h.

const RowInfo* tesseract::RowScratchRegisters::ri_

Definition at line 170 of file paragraphs_internal.h.

int tesseract::RowScratchRegisters::rindent_

Definition at line 179 of file paragraphs_internal.h.

int tesseract::RowScratchRegisters::rmargin_

Definition at line 180 of file paragraphs_internal.h.


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