tesseract  4.0.0-1-g2a2b
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 604 of file paragraphs.cpp.

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

◆ AddStartLine()

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

Definition at line 597 of file paragraphs.cpp.

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

◆ AlignsideIndent()

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

◆ AppendDebugHeaderFields()

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

Definition at line 490 of file paragraphs.cpp.

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

◆ AppendDebugInfo()

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

Definition at line 496 of file paragraphs.cpp.

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

◆ DiscardNonMatchingHypotheses()

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

Definition at line 645 of file paragraphs.cpp.

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

◆ GetLineType() [1/2]

LineType tesseract::RowScratchRegisters::GetLineType ( ) const

Definition at line 535 of file paragraphs.cpp.

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

◆ GetLineType() [2/2]

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

Definition at line 555 of file paragraphs.cpp.

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

◆ Init()

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

Definition at line 527 of file paragraphs.cpp.

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

◆ NonNullHypotheses()

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

Definition at line 625 of file paragraphs.cpp.

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

◆ OffsideIndent()

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

◆ SetBodyLine()

void tesseract::RowScratchRegisters::SetBodyLine ( )

Definition at line 587 of file paragraphs.cpp.

587  {
588  LineType current_lt = GetLineType();
589  if (current_lt != LT_UNKNOWN && current_lt != LT_BODY) {
590  tprintf("Trying to set a line to be BODY when it's already START.\n");
591  }
592  if (current_lt == LT_UNKNOWN || current_lt == LT_START) {
593  hypotheses_.push_back_new(LineHypothesis(LT_BODY, nullptr));
594  }
595 }
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37

◆ SetStartLine()

void tesseract::RowScratchRegisters::SetStartLine ( )

Definition at line 577 of file paragraphs.cpp.

577  {
578  LineType current_lt = GetLineType();
579  if (current_lt != LT_UNKNOWN && current_lt != LT_START) {
580  tprintf("Trying to set a line to be START when it's already BODY.\n");
581  }
582  if (current_lt == LT_UNKNOWN || current_lt == LT_BODY) {
583  hypotheses_.push_back_new(LineHypothesis(LT_START, nullptr));
584  }
585 }
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37

◆ 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 611 of file paragraphs.cpp.

611  {
612  for (int h = 0; h < hypotheses_.size(); h++) {
613  if (hypotheses_[h].ty == LT_START && StrongModel(hypotheses_[h].model))
614  models->push_back_new(hypotheses_[h].model);
615  }
616 }
bool StrongModel(const ParagraphModel *model)

◆ StrongHypotheses()

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

Definition at line 618 of file paragraphs.cpp.

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

◆ UniqueBodyHypothesis()

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

Definition at line 638 of file paragraphs.cpp.

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

◆ UniqueStartHypothesis()

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

Definition at line 632 of file paragraphs.cpp.

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

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: