tesseract v5.3.3.20231005
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 641 of file paragraphs.cpp.

641 {
642 push_back_new(hypotheses_, LineHypothesis(LT_BODY, model));
643 auto found = std::find(hypotheses_.begin(), hypotheses_.end(), LineHypothesis(LT_BODY, nullptr));
644 if (found != hypotheses_.end()) {
645 hypotheses_.erase(found);
646 }
647}
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 633 of file paragraphs.cpp.

633 {
634 push_back_new(hypotheses_, LineHypothesis(LT_START, model));
635 auto found = std::find(hypotheses_.begin(), hypotheses_.end(), LineHypothesis(LT_START, nullptr));
636 if (found != hypotheses_.end()) {
637 hypotheses_.erase(found);
638 }
639}

◆ 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:248
@ JUSTIFICATION_RIGHT
Definition: publictypes.h:250

◆ 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[60];
518 // The largest (positive and negative) numbers are reported for lindent & rindent.
519 // While the column header has widths 5,4,4,5, it is therefore opportune to slightly
520 // offset the widths in the format string here to allow ample space for lindent & rindent
521 // while keeping the final table output nicely readable: 4,5,5,4.
522 snprintf(s, sizeof(s), "[%4d,%5d;%5d,%4d]", lmargin_, lindent_, rindent_, rmargin_);
523 dbg.emplace_back(s);
524 std::string model_string;
525 model_string += static_cast<char>(GetLineType());
526 model_string += ":";
527
528 int model_numbers = 0;
529 for (const auto &hypothese : hypotheses_) {
530 if (hypothese.model == nullptr) {
531 continue;
532 }
533 if (model_numbers > 0) {
534 model_string += ",";
535 }
536 if (StrongModel(hypothese.model)) {
537 model_string += std::to_string(1 + theory.IndexOf(hypothese.model));
538 } else if (hypothese.model == kCrownLeft) {
539 model_string += "CrL";
540 } else if (hypothese.model == kCrownRight) {
541 model_string += "CrR";
542 }
543 model_numbers++;
544 }
545 if (model_numbers == 0) {
546 model_string += "0";
547 }
548
549 dbg.push_back(model_string);
550}
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 688 of file paragraphs.cpp.

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

◆ GetLineType() [1/2]

LineType tesseract::RowScratchRegisters::GetLineType ( ) const

Definition at line 560 of file paragraphs.cpp.

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

◆ GetLineType() [2/2]

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

Definition at line 585 of file paragraphs.cpp.

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

◆ Init()

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

Definition at line 552 of file paragraphs.cpp.

552 {
553 ri_ = &row;
554 lmargin_ = 0;
555 lindent_ = row.pix_ldistance;
556 rmargin_ = 0;
557 rindent_ = row.pix_rdistance;
558}

◆ NonNullHypotheses()

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

Definition at line 665 of file paragraphs.cpp.

665 {
666 for (const auto &hypothese : hypotheses_) {
667 if (hypothese.model != nullptr) {
668 push_back_new(*models, hypothese.model);
669 }
670 }
671}

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

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

◆ SetStartLine()

void tesseract::RowScratchRegisters::SetStartLine ( )

Definition at line 613 of file paragraphs.cpp.

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

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

649 {
650 for (const auto &hypothese : hypotheses_) {
651 if (hypothese.ty == LT_START && StrongModel(hypothese.model)) {
652 push_back_new(*models, hypothese.model);
653 }
654 }
655}

◆ StrongHypotheses()

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

Definition at line 657 of file paragraphs.cpp.

657 {
658 for (const auto &hypothese : hypotheses_) {
659 if (StrongModel(hypothese.model)) {
660 push_back_new(*models, hypothese.model);
661 }
662 }
663}

◆ UniqueBodyHypothesis()

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

Definition at line 680 of file paragraphs.cpp.

680 {
681 if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_BODY) {
682 return nullptr;
683 }
684 return hypotheses_[0].model;
685}

◆ UniqueStartHypothesis()

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

Definition at line 673 of file paragraphs.cpp.

673 {
674 if (hypotheses_.size() != 1 || hypotheses_[0].ty != LT_START) {
675 return nullptr;
676 }
677 return hypotheses_[0].model;
678}

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: