tesseract  4.00.00dev
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

◆ AddBodyLine()

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

Definition at line 590 of file paragraphs.cpp.

590  {
591  hypotheses_.push_back_new(LineHypothesis(LT_BODY, model));
592  int old_idx = hypotheses_.get_index(LineHypothesis(LT_BODY, NULL));
593  if (old_idx >= 0)
594  hypotheses_.remove(old_idx);
595 }

◆ AddStartLine()

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

Definition at line 583 of file paragraphs.cpp.

583  {
584  hypotheses_.push_back_new(LineHypothesis(LT_START, model));
585  int old_idx = hypotheses_.get_index(LineHypothesis(LT_START, NULL));
586  if (old_idx >= 0)
587  hypotheses_.remove(old_idx);
588 }

◆ AlignsideIndent()

int tesseract::RowScratchRegisters::AlignsideIndent ( tesseract::ParagraphJustification  just) const
inline

◆ AppendDebugHeaderFields()

void tesseract::RowScratchRegisters::AppendDebugHeaderFields ( GenericVector< STRING > *  header)
static

Definition at line 476 of file paragraphs.cpp.

477  {
478  header->push_back("[lmarg,lind;rind,rmarg]");
479  header->push_back("model");
480 }
int push_back(T object)

◆ AppendDebugInfo()

void tesseract::RowScratchRegisters::AppendDebugInfo ( const ParagraphTheory theory,
GenericVector< STRING > *  dbg 
) const

Definition at line 482 of file paragraphs.cpp.

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

◆ DiscardNonMatchingHypotheses()

void tesseract::RowScratchRegisters::DiscardNonMatchingHypotheses ( const SetOfModels models)

Definition at line 631 of file paragraphs.cpp.

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

◆ GetLineType() [1/2]

LineType tesseract::RowScratchRegisters::GetLineType ( ) const

Definition at line 521 of file paragraphs.cpp.

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

◆ GetLineType() [2/2]

LineType tesseract::RowScratchRegisters::GetLineType ( const ParagraphModel model) const

Definition at line 541 of file paragraphs.cpp.

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

◆ Init()

void tesseract::RowScratchRegisters::Init ( const RowInfo row)

Definition at line 513 of file paragraphs.cpp.

513  {
514  ri_ = &row;
515  lmargin_ = 0;
516  lindent_ = row.pix_ldistance;
517  rmargin_ = 0;
518  rindent_ = row.pix_rdistance;
519 }

◆ NonNullHypotheses()

void tesseract::RowScratchRegisters::NonNullHypotheses ( SetOfModels models) const

Definition at line 611 of file paragraphs.cpp.

611  {
612  for (int h = 0; h < hypotheses_.size(); h++) {
613  if (hypotheses_[h].model != NULL)
614  models->push_back_new(hypotheses_[h].model);
615  }
616 }

◆ OffsideIndent()

int tesseract::RowScratchRegisters::OffsideIndent ( tesseract::ParagraphJustification  just) const
inline

◆ SetBodyLine()

void tesseract::RowScratchRegisters::SetBodyLine ( )

Definition at line 573 of file paragraphs.cpp.

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

◆ SetStartLine()

void tesseract::RowScratchRegisters::SetStartLine ( )

Definition at line 563 of file paragraphs.cpp.

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

◆ SetUnknown()

void tesseract::RowScratchRegisters::SetUnknown ( )
inline

Definition at line 123 of file paragraphs_internal.h.

123 { hypotheses_.truncate(0); }

◆ StartHypotheses()

void tesseract::RowScratchRegisters::StartHypotheses ( SetOfModels models) const

Definition at line 597 of file paragraphs.cpp.

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

◆ StrongHypotheses()

void tesseract::RowScratchRegisters::StrongHypotheses ( SetOfModels models) const

Definition at line 604 of file paragraphs.cpp.

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

◆ UniqueBodyHypothesis()

const ParagraphModel * tesseract::RowScratchRegisters::UniqueBodyHypothesis ( ) const

Definition at line 624 of file paragraphs.cpp.

624  {
625  if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_BODY)
626  return NULL;
627  return hypotheses_[0].model;
628 }

◆ UniqueStartHypothesis()

const ParagraphModel * tesseract::RowScratchRegisters::UniqueStartHypothesis ( ) const

Definition at line 618 of file paragraphs.cpp.

618  {
619  if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_START)
620  return NULL;
621  return hypotheses_[0].model;
622 }

Member Data Documentation

◆ lindent_

int tesseract::RowScratchRegisters::lindent_

Definition at line 178 of file paragraphs_internal.h.

◆ lmargin_

int tesseract::RowScratchRegisters::lmargin_

Definition at line 177 of file paragraphs_internal.h.

◆ ri_

const RowInfo* tesseract::RowScratchRegisters::ri_

Definition at line 170 of file paragraphs_internal.h.

◆ rindent_

int tesseract::RowScratchRegisters::rindent_

Definition at line 179 of file paragraphs_internal.h.

◆ rmargin_

int tesseract::RowScratchRegisters::rmargin_

Definition at line 180 of file paragraphs_internal.h.


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