tesseract  4.1.1
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 103 of file paragraphs_internal.h.

Member Function Documentation

◆ AddBodyLine()

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

Definition at line 603 of file paragraphs.cpp.

603  {
604  hypotheses_.push_back_new(LineHypothesis(LT_BODY, model));
605  int old_idx = hypotheses_.get_index(LineHypothesis(LT_BODY, nullptr));
606  if (old_idx >= 0)
607  hypotheses_.remove(old_idx);
608 }

◆ AddStartLine()

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

Definition at line 596 of file paragraphs.cpp.

596  {
597  hypotheses_.push_back_new(LineHypothesis(LT_START, model));
598  int old_idx = hypotheses_.get_index(LineHypothesis(LT_START, nullptr));
599  if (old_idx >= 0)
600  hypotheses_.remove(old_idx);
601 }

◆ AlignsideIndent()

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

Definition at line 158 of file paragraphs_internal.h.

158  {
159  switch (just) {
162  default: return lindent_ > rindent_ ? lindent_ : rindent_;
163  }
164  }
@ JUSTIFICATION_LEFT
Definition: publictypes.h:253
@ JUSTIFICATION_RIGHT
Definition: publictypes.h:255

◆ AppendDebugHeaderFields()

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

Definition at line 489 of file paragraphs.cpp.

490  {
491  header->push_back("[lmarg,lind;rind,rmarg]");
492  header->push_back("model");
493 }
int push_back(T object)

◆ AppendDebugInfo()

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

Definition at line 495 of file paragraphs.cpp.

496  {
497  char s[30];
498  snprintf(s, sizeof(s), "[%3d,%3d;%3d,%3d]",
500  dbg->push_back(s);
501  STRING model_string;
502  model_string += static_cast<char>(GetLineType());
503  model_string += ":";
504 
505  int model_numbers = 0;
506  for (int h = 0; h < hypotheses_.size(); h++) {
507  if (hypotheses_[h].model == nullptr)
508  continue;
509  if (model_numbers > 0)
510  model_string += ",";
511  if (StrongModel(hypotheses_[h].model)) {
512  model_string += StrOf(1 + theory.IndexOf(hypotheses_[h].model));
513  } else if (hypotheses_[h].model == kCrownLeft) {
514  model_string += "CrL";
515  } else if (hypotheses_[h].model == kCrownRight) {
516  model_string += "CrR";
517  }
518  model_numbers++;
519  }
520  if (model_numbers == 0)
521  model_string += "0";
522 
523  dbg->push_back(model_string);
524 }
bool StrongModel(const ParagraphModel *model)
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:54
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:56
Definition: strngs.h:45

◆ DiscardNonMatchingHypotheses()

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

Definition at line 644 of file paragraphs.cpp.

645  {
646  if (models.empty())
647  return;
648  for (int h = hypotheses_.size() - 1; h >= 0; h--) {
649  if (!models.contains(hypotheses_[h].model)) {
650  hypotheses_.remove(h);
651  }
652  }
653 }

◆ GetLineType() [1/2]

LineType tesseract::RowScratchRegisters::GetLineType ( ) const

Definition at line 534 of file paragraphs.cpp.

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

◆ GetLineType() [2/2]

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

Definition at line 554 of file paragraphs.cpp.

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

◆ Init()

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

Definition at line 526 of file paragraphs.cpp.

526  {
527  ri_ = &row;
528  lmargin_ = 0;
529  lindent_ = row.pix_ldistance;
530  rmargin_ = 0;
531  rindent_ = row.pix_rdistance;
532 }

◆ NonNullHypotheses()

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

Definition at line 624 of file paragraphs.cpp.

624  {
625  for (int h = 0; h < hypotheses_.size(); h++) {
626  if (hypotheses_[h].model != nullptr)
627  models->push_back_new(hypotheses_[h].model);
628  }
629 }

◆ OffsideIndent()

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

Definition at line 149 of file paragraphs_internal.h.

149  {
150  switch (just) {
153  default: return lindent_ > rindent_ ? lindent_ : rindent_;
154  }
155  }

◆ SetBodyLine()

void tesseract::RowScratchRegisters::SetBodyLine ( )

Definition at line 586 of file paragraphs.cpp.

586  {
587  LineType current_lt = GetLineType();
588  if (current_lt != LT_UNKNOWN && current_lt != LT_BODY) {
589  tprintf("Trying to set a line to be BODY when it's already START.\n");
590  }
591  if (current_lt == LT_UNKNOWN || current_lt == LT_START) {
592  hypotheses_.push_back_new(LineHypothesis(LT_BODY, nullptr));
593  }
594 }

◆ SetStartLine()

void tesseract::RowScratchRegisters::SetStartLine ( )

Definition at line 576 of file paragraphs.cpp.

576  {
577  LineType current_lt = GetLineType();
578  if (current_lt != LT_UNKNOWN && current_lt != LT_START) {
579  tprintf("Trying to set a line to be START when it's already BODY.\n");
580  }
581  if (current_lt == LT_UNKNOWN || current_lt == LT_BODY) {
582  hypotheses_.push_back_new(LineHypothesis(LT_START, nullptr));
583  }
584 }

◆ SetUnknown()

void tesseract::RowScratchRegisters::SetUnknown ( )
inline

Definition at line 126 of file paragraphs_internal.h.

126 { hypotheses_.truncate(0); }

◆ StartHypotheses()

void tesseract::RowScratchRegisters::StartHypotheses ( 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].ty == LT_START && StrongModel(hypotheses_[h].model))
613  models->push_back_new(hypotheses_[h].model);
614  }
615 }

◆ StrongHypotheses()

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

Definition at line 617 of file paragraphs.cpp.

617  {
618  for (int h = 0; h < hypotheses_.size(); h++) {
619  if (StrongModel(hypotheses_[h].model))
620  models->push_back_new(hypotheses_[h].model);
621  }
622 }

◆ UniqueBodyHypothesis()

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

Definition at line 637 of file paragraphs.cpp.

637  {
638  if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_BODY)
639  return nullptr;
640  return hypotheses_[0].model;
641 }

◆ UniqueStartHypothesis()

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

Definition at line 631 of file paragraphs.cpp.

631  {
632  if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_START)
633  return nullptr;
634  return hypotheses_[0].model;
635 }

Member Data Documentation

◆ lindent_

int tesseract::RowScratchRegisters::lindent_

Definition at line 181 of file paragraphs_internal.h.

◆ lmargin_

int tesseract::RowScratchRegisters::lmargin_

Definition at line 180 of file paragraphs_internal.h.

◆ ri_

const RowInfo* tesseract::RowScratchRegisters::ri_

Definition at line 173 of file paragraphs_internal.h.

◆ rindent_

int tesseract::RowScratchRegisters::rindent_

Definition at line 182 of file paragraphs_internal.h.

◆ rmargin_

int tesseract::RowScratchRegisters::rmargin_

Definition at line 183 of file paragraphs_internal.h.


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