tesseract  5.0.0
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, std::vector< std::string > &dbg) const
 

Static Public Member Functions

static void AppendDebugHeaderFields (std::vector< std::string > &header)
 

Public Attributes

const RowInfori_
 
int lmargin_
 
int lindent_
 
int rindent_
 
int rmargin_
 

Detailed Description

Definition at line 95 of file paragraphs_internal.h.

Member Function Documentation

◆ AddBodyLine()

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

Definition at line 637 of file paragraphs.cpp.

637  {
638  push_back_new(hypotheses_, LineHypothesis(LT_BODY, model));
639  auto found = std::find(hypotheses_.begin(), hypotheses_.end(), LineHypothesis(LT_BODY, nullptr));
640  if (found != hypotheses_.end()) {
641  hypotheses_.erase(found);
642  }
643 }
void push_back_new(std::vector< T > &vector, const T &data)
Definition: paragraphs.cpp:418

◆ AddStartLine()

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

Definition at line 629 of file paragraphs.cpp.

629  {
630  push_back_new(hypotheses_, LineHypothesis(LT_START, model));
631  auto found = std::find(hypotheses_.begin(), hypotheses_.end(), LineHypothesis(LT_START, nullptr));
632  if (found != hypotheses_.end()) {
633  hypotheses_.erase(found);
634  }
635 }

◆ AlignsideIndent()

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

Definition at line 155 of file paragraphs_internal.h.

155  {
156  switch (just) {
158  return rindent_;
160  return lindent_;
161  default:
162  return lindent_ > rindent_ ? lindent_ : rindent_;
163  }
164  }
@ JUSTIFICATION_LEFT
Definition: publictypes.h:250
@ JUSTIFICATION_RIGHT
Definition: publictypes.h:252

◆ AppendDebugHeaderFields()

void tesseract::RowScratchRegisters::AppendDebugHeaderFields ( std::vector< std::string > &  header)
static

Definition at line 510 of file paragraphs.cpp.

510  {
511  header.emplace_back("[lmarg,lind;rind,rmarg]");
512  header.emplace_back("model");
513 }

◆ AppendDebugInfo()

void tesseract::RowScratchRegisters::AppendDebugInfo ( const ParagraphTheory theory,
std::vector< std::string > &  dbg 
) const

Definition at line 515 of file paragraphs.cpp.

516  {
517  char s[30];
518  snprintf(s, sizeof(s), "[%3d,%3d;%3d,%3d]", lmargin_, lindent_, rindent_, rmargin_);
519  dbg.emplace_back(s);
520  std::string model_string;
521  model_string += static_cast<char>(GetLineType());
522  model_string += ":";
523 
524  int model_numbers = 0;
525  for (const auto &hypothese : hypotheses_) {
526  if (hypothese.model == nullptr) {
527  continue;
528  }
529  if (model_numbers > 0) {
530  model_string += ",";
531  }
532  if (StrongModel(hypothese.model)) {
533  model_string += std::to_string(1 + theory.IndexOf(hypothese.model));
534  } else if (hypothese.model == kCrownLeft) {
535  model_string += "CrL";
536  } else if (hypothese.model == kCrownRight) {
537  model_string += "CrR";
538  }
539  model_numbers++;
540  }
541  if (model_numbers == 0) {
542  model_string += "0";
543  }
544 
545  dbg.push_back(model_string);
546 }
bool StrongModel(const ParagraphModel *model)
const ParagraphModel * kCrownLeft
Definition: paragraphs.cpp:56
const ParagraphModel * kCrownRight
Definition: paragraphs.cpp:58

◆ DiscardNonMatchingHypotheses()

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

Definition at line 684 of file paragraphs.cpp.

684  {
685  if (models.empty()) {
686  return;
687  }
688  for (int h = hypotheses_.size() - 1; h >= 0; h--) {
689  if (!contains(models, hypotheses_[h].model)) {
690  hypotheses_.erase(hypotheses_.begin() + h);
691  }
692  }
693 }
bool contains(const std::vector< T > &data, const T &value)
Definition: helpers.h:37

◆ GetLineType() [1/2]

LineType tesseract::RowScratchRegisters::GetLineType ( ) const

Definition at line 556 of file paragraphs.cpp.

556  {
557  if (hypotheses_.empty()) {
558  return LT_UNKNOWN;
559  }
560  bool has_start = false;
561  bool has_body = false;
562  for (const auto &hypothese : hypotheses_) {
563  switch (hypothese.ty) {
564  case LT_START:
565  has_start = true;
566  break;
567  case LT_BODY:
568  has_body = true;
569  break;
570  default:
571  tprintf("Encountered bad value in hypothesis list: %c\n", hypothese.ty);
572  break;
573  }
574  }
575  if (has_start && has_body) {
576  return LT_MULTIPLE;
577  }
578  return has_start ? LT_START : LT_BODY;
579 }
void tprintf(const char *format,...)
Definition: tprintf.cpp:41

◆ GetLineType() [2/2]

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

Definition at line 581 of file paragraphs.cpp.

581  {
582  if (hypotheses_.empty()) {
583  return LT_UNKNOWN;
584  }
585  bool has_start = false;
586  bool has_body = false;
587  for (const auto &hypothese : hypotheses_) {
588  if (hypothese.model != model) {
589  continue;
590  }
591  switch (hypothese.ty) {
592  case LT_START:
593  has_start = true;
594  break;
595  case LT_BODY:
596  has_body = true;
597  break;
598  default:
599  tprintf("Encountered bad value in hypothesis list: %c\n", hypothese.ty);
600  break;
601  }
602  }
603  if (has_start && has_body) {
604  return LT_MULTIPLE;
605  }
606  return has_start ? LT_START : LT_BODY;
607 }

◆ Init()

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

Definition at line 548 of file paragraphs.cpp.

548  {
549  ri_ = &row;
550  lmargin_ = 0;
551  lindent_ = row.pix_ldistance;
552  rmargin_ = 0;
553  rindent_ = row.pix_rdistance;
554 }

◆ NonNullHypotheses()

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

Definition at line 661 of file paragraphs.cpp.

661  {
662  for (const auto &hypothese : hypotheses_) {
663  if (hypothese.model != nullptr) {
664  push_back_new(*models, hypothese.model);
665  }
666  }
667 }

◆ OffsideIndent()

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

Definition at line 143 of file paragraphs_internal.h.

143  {
144  switch (just) {
146  return lindent_;
148  return rindent_;
149  default:
150  return lindent_ > rindent_ ? lindent_ : rindent_;
151  }
152  }

◆ SetBodyLine()

void tesseract::RowScratchRegisters::SetBodyLine ( )

Definition at line 619 of file paragraphs.cpp.

619  {
620  LineType current_lt = GetLineType();
621  if (current_lt != LT_UNKNOWN && current_lt != LT_BODY) {
622  tprintf("Trying to set a line to be BODY when it's already START.\n");
623  }
624  if (current_lt == LT_UNKNOWN || current_lt == LT_START) {
625  push_back_new(hypotheses_, LineHypothesis(LT_BODY, nullptr));
626  }
627 }

◆ SetStartLine()

void tesseract::RowScratchRegisters::SetStartLine ( )

Definition at line 609 of file paragraphs.cpp.

609  {
610  LineType current_lt = GetLineType();
611  if (current_lt != LT_UNKNOWN && current_lt != LT_START) {
612  tprintf("Trying to set a line to be START when it's already BODY.\n");
613  }
614  if (current_lt == LT_UNKNOWN || current_lt == LT_BODY) {
615  push_back_new(hypotheses_, LineHypothesis(LT_START, nullptr));
616  }
617 }

◆ SetUnknown()

void tesseract::RowScratchRegisters::SetUnknown ( )
inline

Definition at line 118 of file paragraphs_internal.h.

118  {
119  hypotheses_.clear();
120  }

◆ StartHypotheses()

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

Definition at line 645 of file paragraphs.cpp.

645  {
646  for (const auto &hypothese : hypotheses_) {
647  if (hypothese.ty == LT_START && StrongModel(hypothese.model)) {
648  push_back_new(*models, hypothese.model);
649  }
650  }
651 }

◆ StrongHypotheses()

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

Definition at line 653 of file paragraphs.cpp.

653  {
654  for (const auto &hypothese : hypotheses_) {
655  if (StrongModel(hypothese.model)) {
656  push_back_new(*models, hypothese.model);
657  }
658  }
659 }

◆ UniqueBodyHypothesis()

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

Definition at line 676 of file paragraphs.cpp.

676  {
677  if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_BODY) {
678  return nullptr;
679  }
680  return hypotheses_[0].model;
681 }

◆ UniqueStartHypothesis()

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

Definition at line 669 of file paragraphs.cpp.

669  {
670  if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_START) {
671  return nullptr;
672  }
673  return hypotheses_[0].model;
674 }

Member Data Documentation

◆ lindent_

int tesseract::RowScratchRegisters::lindent_

Definition at line 180 of file paragraphs_internal.h.

◆ lmargin_

int tesseract::RowScratchRegisters::lmargin_

Definition at line 179 of file paragraphs_internal.h.

◆ ri_

const RowInfo* tesseract::RowScratchRegisters::ri_

Definition at line 172 of file paragraphs_internal.h.

◆ rindent_

int tesseract::RowScratchRegisters::rindent_

Definition at line 181 of file paragraphs_internal.h.

◆ rmargin_

int tesseract::RowScratchRegisters::rmargin_

Definition at line 182 of file paragraphs_internal.h.


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