Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 601 of file paragraphs.cpp.

601  {
602  hypotheses_.push_back_new(LineHypothesis(LT_BODY, model));
603  int old_idx = hypotheses_.get_index(LineHypothesis(LT_BODY, NULL));
604  if (old_idx >= 0)
605  hypotheses_.remove(old_idx);
606 }
#define NULL
Definition: host.h:144
void tesseract::RowScratchRegisters::AddStartLine ( const ParagraphModel model)

Definition at line 594 of file paragraphs.cpp.

594  {
595  hypotheses_.push_back_new(LineHypothesis(LT_START, model));
596  int old_idx = hypotheses_.get_index(LineHypothesis(LT_START, NULL));
597  if (old_idx >= 0)
598  hypotheses_.remove(old_idx);
599 }
#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 487 of file paragraphs.cpp.

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

Definition at line 493 of file paragraphs.cpp.

494  {
495  char s[30];
496  snprintf(s, sizeof(s), "[%3d,%3d;%3d,%3d]",
498  dbg->push_back(s);
499  STRING model_string;
500  model_string += static_cast<char>(GetLineType());
501  model_string += ":";
502 
503  int model_numbers = 0;
504  for (int h = 0; h < hypotheses_.size(); h++) {
505  if (hypotheses_[h].model == NULL)
506  continue;
507  if (model_numbers > 0)
508  model_string += ",";
509  if (StrongModel(hypotheses_[h].model)) {
510  model_string += StrOf(1 + theory.IndexOf(hypotheses_[h].model));
511  } else if (hypotheses_[h].model == kCrownLeft) {
512  model_string += "CrL";
513  } else if (hypotheses_[h].model == kCrownRight) {
514  model_string += "CrR";
515  }
516  model_numbers++;
517  }
518  if (model_numbers == 0)
519  model_string += "0";
520 
521  dbg->push_back(model_string);
522 }
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:52
#define NULL
Definition: host.h:144
int push_back(T object)
bool StrongModel(const ParagraphModel *model)
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:50
LineType GetLineType() const
Definition: paragraphs.cpp:532
Definition: strngs.h:40
void tesseract::RowScratchRegisters::DiscardNonMatchingHypotheses ( const SetOfModels models)

Definition at line 642 of file paragraphs.cpp.

643  {
644  if (models.empty())
645  return;
646  for (int h = hypotheses_.size() - 1; h >= 0; h--) {
647  if (!models.contains(hypotheses_[h].model)) {
648  hypotheses_.remove(h);
649  }
650  }
651 }
LineType tesseract::RowScratchRegisters::GetLineType ( ) const

Definition at line 532 of file paragraphs.cpp.

532  {
533  if (hypotheses_.empty())
534  return LT_UNKNOWN;
535  bool has_start = false;
536  bool has_body = false;
537  for (int i = 0; i < hypotheses_.size(); i++) {
538  switch (hypotheses_[i].ty) {
539  case LT_START: has_start = true; break;
540  case LT_BODY: has_body = true; break;
541  default:
542  tprintf("Encountered bad value in hypothesis list: %c\n",
543  hypotheses_[i].ty);
544  break;
545  }
546  }
547  if (has_start && has_body)
548  return LT_MULTIPLE;
549  return has_start ? LT_START : LT_BODY;
550 }
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
LineType tesseract::RowScratchRegisters::GetLineType ( const ParagraphModel model) const

Definition at line 552 of file paragraphs.cpp.

552  {
553  if (hypotheses_.empty())
554  return LT_UNKNOWN;
555  bool has_start = false;
556  bool has_body = false;
557  for (int i = 0; i < hypotheses_.size(); i++) {
558  if (hypotheses_[i].model != model)
559  continue;
560  switch (hypotheses_[i].ty) {
561  case LT_START: has_start = true; break;
562  case LT_BODY: has_body = true; break;
563  default:
564  tprintf("Encountered bad value in hypothesis list: %c\n",
565  hypotheses_[i].ty);
566  break;
567  }
568  }
569  if (has_start && has_body)
570  return LT_MULTIPLE;
571  return has_start ? LT_START : LT_BODY;
572 }
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
void tesseract::RowScratchRegisters::Init ( const RowInfo row)

Definition at line 524 of file paragraphs.cpp.

524  {
525  ri_ = &row;
526  lmargin_ = 0;
527  lindent_ = row.pix_ldistance;
528  rmargin_ = 0;
529  rindent_ = row.pix_rdistance;
530 }
void tesseract::RowScratchRegisters::NonNullHypotheses ( SetOfModels models) const

Definition at line 622 of file paragraphs.cpp.

622  {
623  for (int h = 0; h < hypotheses_.size(); h++) {
624  if (hypotheses_[h].model != NULL)
625  models->push_back_new(hypotheses_[h].model);
626  }
627 }
#define NULL
Definition: host.h:144
int tesseract::RowScratchRegisters::OffsideIndent ( tesseract::ParagraphJustification  just) const
inline
void tesseract::RowScratchRegisters::SetBodyLine ( )

Definition at line 584 of file paragraphs.cpp.

584  {
585  LineType current_lt = GetLineType();
586  if (current_lt != LT_UNKNOWN && current_lt != LT_BODY) {
587  tprintf("Trying to set a line to be BODY when it's already START.\n");
588  }
589  if (current_lt == LT_UNKNOWN || current_lt == LT_START) {
590  hypotheses_.push_back_new(LineHypothesis(LT_BODY, NULL));
591  }
592 }
#define NULL
Definition: host.h:144
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
LineType GetLineType() const
Definition: paragraphs.cpp:532
void tesseract::RowScratchRegisters::SetStartLine ( )

Definition at line 574 of file paragraphs.cpp.

574  {
575  LineType current_lt = GetLineType();
576  if (current_lt != LT_UNKNOWN && current_lt != LT_START) {
577  tprintf("Trying to set a line to be START when it's already BODY.\n");
578  }
579  if (current_lt == LT_UNKNOWN || current_lt == LT_BODY) {
580  hypotheses_.push_back_new(LineHypothesis(LT_START, NULL));
581  }
582 }
#define NULL
Definition: host.h:144
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
LineType GetLineType() const
Definition: paragraphs.cpp:532
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 608 of file paragraphs.cpp.

608  {
609  for (int h = 0; h < hypotheses_.size(); h++) {
610  if (hypotheses_[h].ty == LT_START && StrongModel(hypotheses_[h].model))
611  models->push_back_new(hypotheses_[h].model);
612  }
613 }
bool StrongModel(const ParagraphModel *model)
void tesseract::RowScratchRegisters::StrongHypotheses ( SetOfModels models) const

Definition at line 615 of file paragraphs.cpp.

615  {
616  for (int h = 0; h < hypotheses_.size(); h++) {
617  if (StrongModel(hypotheses_[h].model))
618  models->push_back_new(hypotheses_[h].model);
619  }
620 }
bool StrongModel(const ParagraphModel *model)
const ParagraphModel * tesseract::RowScratchRegisters::UniqueBodyHypothesis ( ) const

Definition at line 635 of file paragraphs.cpp.

635  {
636  if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_BODY)
637  return NULL;
638  return hypotheses_[0].model;
639 }
#define NULL
Definition: host.h:144
const ParagraphModel * tesseract::RowScratchRegisters::UniqueStartHypothesis ( ) const

Definition at line 629 of file paragraphs.cpp.

629  {
630  if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_START)
631  return NULL;
632  return hypotheses_[0].model;
633 }
#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: