tesseract  4.0.0-1-g2a2b
tesseract::TabVector Class Reference

#include <tabvector.h>

Inheritance diagram for tesseract::TabVector:
ELIST2_LINK

Public Member Functions

 TabVector ()=default
 
 ~TabVector ()=default
 
 TabVector (const TabVector &src, TabAlignment alignment, const ICOORD &vertical_skew, BLOBNBOX *blob)
 
TabVectorShallowCopy () const
 
const ICOORDstartpt () const
 
const ICOORDendpt () const
 
int extended_ymax () const
 
int extended_ymin () const
 
int sort_key () const
 
int mean_width () const
 
void set_top_constraints (TabConstraint_LIST *constraints)
 
void set_bottom_constraints (TabConstraint_LIST *constraints)
 
TabVector_CLIST * partners ()
 
void set_startpt (const ICOORD &start)
 
void set_endpt (const ICOORD &end)
 
bool intersects_other_lines () const
 
void set_intersects_other_lines (bool value)
 
int XAtY (int y) const
 
int VOverlap (const TabVector &other) const
 
int VOverlap (int top_y, int bottom_y) const
 
int ExtendedOverlap (int top_y, int bottom_y) const
 
bool IsLeftTab () const
 
bool IsRightTab () const
 
bool IsSeparator () const
 
bool IsCenterTab () const
 
bool IsRagged () const
 
bool IsLeftOf (const TabVector &other) const
 
bool Partnerless ()
 
int BoxCount ()
 
void Freeze ()
 
void XYFlip ()
 
void ReflectInYAxis ()
 
void ExtendToBox (BLOBNBOX *blob)
 
void SetYStart (int start_y)
 
void SetYEnd (int end_y)
 
void Rotate (const FCOORD &rotation)
 
void SetupConstraints ()
 
void SetupPartnerConstraints ()
 
void SetupPartnerConstraints (TabVector *partner)
 
void ApplyConstraints ()
 
bool SimilarTo (const ICOORD &vertical, const TabVector &other, BlobGrid *grid) const
 
void MergeWith (const ICOORD &vertical, TabVector *other)
 
void AddPartner (TabVector *partner)
 
bool IsAPartner (const TabVector *other)
 
void Print (const char *prefix)
 
void Debug (const char *prefix)
 
void Display (ScrollView *tab_win)
 
void FitAndEvaluateIfNeeded (const ICOORD &vertical, TabFind *finder)
 
void Evaluate (const ICOORD &vertical, TabFind *finder)
 
bool Fit (ICOORD vertical, bool force_parallel)
 
TabVectorVerticalTextlinePartner ()
 
TabVectorGetSinglePartner ()
 
- Public Member Functions inherited from ELIST2_LINK
 ELIST2_LINK ()
 
 ELIST2_LINK (const ELIST2_LINK &)
 
void operator= (const ELIST2_LINK &)
 

Static Public Member Functions

static TabVectorFitVector (TabAlignment alignment, ICOORD vertical, int extended_start_y, int extended_end_y, BLOBNBOX_CLIST *good_points, int *vertical_x, int *vertical_y)
 
static int SortKey (const ICOORD &vertical, int x, int y)
 
static int XAtY (const ICOORD &vertical, int sort_key, int y)
 
static int SortVectorsByKey (const void *v1, const void *v2)
 
static void MergeSimilarTabVectors (const ICOORD &vertical, TabVector_LIST *vectors, BlobGrid *grid)
 

Detailed Description

Definition at line 112 of file tabvector.h.

Constructor & Destructor Documentation

◆ TabVector() [1/2]

tesseract::TabVector::TabVector ( )
default

◆ ~TabVector()

tesseract::TabVector::~TabVector ( )
default

◆ TabVector() [2/2]

tesseract::TabVector::TabVector ( const TabVector src,
TabAlignment  alignment,
const ICOORD vertical_skew,
BLOBNBOX blob 
)

Definition at line 199 of file tabvector.cpp.

201  : extended_ymin_(src.extended_ymin_), extended_ymax_(src.extended_ymax_),
202  sort_key_(0), percent_score_(0), mean_width_(0),
203  needs_refit_(true), needs_evaluation_(true), intersects_other_lines_(false),
204  alignment_(alignment),
205  top_constraints_(nullptr), bottom_constraints_(nullptr) {
206  BLOBNBOX_C_IT it(&boxes_);
207  it.add_to_end(blob);
208  TBOX box = blob->bounding_box();
209  if (IsLeftTab()) {
210  startpt_ = box.botleft();
211  endpt_ = box.topleft();
212  } else {
213  startpt_ = box.botright();
214  endpt_ = box.topright();
215  }
216  sort_key_ = SortKey(vertical_skew,
217  (startpt_.x() + endpt_.x()) / 2,
218  (startpt_.y() + endpt_.y()) / 2);
219  if (textord_debug_tabfind > 3)
220  Print("Constructed a new tab vector:");
221 }
const ICOORD & topright() const
Definition: rect.h:104
int16_t y() const
access_function
Definition: points.h:57
Definition: rect.h:34
bool IsLeftTab() const
Definition: tabvector.h:213
int16_t x() const
access function
Definition: points.h:53
int textord_debug_tabfind
Definition: alignedblob.cpp:28
const ICOORD & botleft() const
Definition: rect.h:92
static int SortKey(const ICOORD &vertical, int x, int y)
Definition: tabvector.h:280
ICOORD topleft() const
Definition: rect.h:100
const TBOX & bounding_box() const
Definition: blobbox.h:231
ICOORD botright() const
Definition: rect.h:96
void Print(const char *prefix)
Definition: tabvector.cpp:520

Member Function Documentation

◆ AddPartner()

void tesseract::TabVector::AddPartner ( TabVector partner)

Definition at line 487 of file tabvector.cpp.

487  {
488  if (IsSeparator() || partner->IsSeparator())
489  return;
490  TabVector_C_IT it(&partners_);
491  if (!it.empty()) {
492  it.move_to_last();
493  if (it.data() == partner)
494  return;
495  }
496  it.add_after_then_move(partner);
497 }
bool IsSeparator() const
Definition: tabvector.h:221

◆ ApplyConstraints()

void tesseract::TabVector::ApplyConstraints ( )

Definition at line 348 of file tabvector.cpp.

348  {
349  if (top_constraints_ != nullptr)
350  TabConstraint::ApplyConstraints(top_constraints_);
351  if (bottom_constraints_ != nullptr)
352  TabConstraint::ApplyConstraints(bottom_constraints_);
353 }
static void ApplyConstraints(TabConstraint_LIST *constraints)
Definition: tabvector.cpp:117

◆ BoxCount()

int tesseract::TabVector::BoxCount ( )
inline

Definition at line 245 of file tabvector.h.

245  {
246  return boxes_.length();
247  }

◆ Debug()

void tesseract::TabVector::Debug ( const char *  prefix)

Definition at line 530 of file tabvector.cpp.

530  {
531  Print(prefix);
532  BLOBNBOX_C_IT it(&boxes_);
533  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
534  BLOBNBOX* bbox = it.data();
535  const TBOX& box = bbox->bounding_box();
536  tprintf("Box at (%d,%d)->(%d,%d)\n",
537  box.left(), box.bottom(), box.right(), box.top());
538  }
539 }
Definition: rect.h:34
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
const TBOX & bounding_box() const
Definition: blobbox.h:231
int16_t right() const
Definition: rect.h:79
int16_t bottom() const
Definition: rect.h:65
void Print(const char *prefix)
Definition: tabvector.cpp:520

◆ Display()

void tesseract::TabVector::Display ( ScrollView tab_win)

Definition at line 542 of file tabvector.cpp.

542  {
543 #ifndef GRAPHICS_DISABLED
545  tab_win->Pen(ScrollView::BLUE);
546  else if (alignment_ == TA_LEFT_ALIGNED)
547  tab_win->Pen(ScrollView::LIME_GREEN);
548  else if (alignment_ == TA_LEFT_RAGGED)
549  tab_win->Pen(ScrollView::DARK_GREEN);
550  else if (alignment_ == TA_RIGHT_ALIGNED)
551  tab_win->Pen(ScrollView::PINK);
552  else if (alignment_ == TA_RIGHT_RAGGED)
553  tab_win->Pen(ScrollView::CORAL);
554  else
555  tab_win->Pen(ScrollView::WHITE);
556  tab_win->Line(startpt_.x(), startpt_.y(), endpt_.x(), endpt_.y());
557  tab_win->Pen(ScrollView::GREY);
558  tab_win->Line(startpt_.x(), startpt_.y(), startpt_.x(), extended_ymin_);
559  tab_win->Line(endpt_.x(), extended_ymax_, endpt_.x(), endpt_.y());
560  char score_buf[64];
561  snprintf(score_buf, sizeof(score_buf), "%d", percent_score_);
562  tab_win->TextAttributes("Times", 50, false, false, false);
563  tab_win->Text(startpt_.x(), startpt_.y(), score_buf);
564 #endif
565 }
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
Definition: scrollview.cpp:637
int16_t y() const
access_function
Definition: points.h:57
bool textord_debug_printable
Definition: alignedblob.cpp:34
int16_t x() const
access function
Definition: points.h:53
void Text(int x, int y, const char *mystring)
Definition: scrollview.cpp:654
void Pen(Color color)
Definition: scrollview.cpp:722
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:534

◆ endpt()

const ICOORD& tesseract::TabVector::endpt ( ) const
inline

Definition at line 149 of file tabvector.h.

149  {
150  return endpt_;
151  }

◆ Evaluate()

void tesseract::TabVector::Evaluate ( const ICOORD vertical,
TabFind finder 
)

Definition at line 582 of file tabvector.cpp.

582  {
583  bool debug = false;
584  needs_evaluation_ = false;
585  int length = endpt_.y() - startpt_.y();
586  if (length == 0 || boxes_.empty()) {
587  percent_score_ = 0;
588  Print("Zero length in evaluate");
589  return;
590  }
591  // Compute the mean box height.
592  BLOBNBOX_C_IT it(&boxes_);
593  int mean_height = 0;
594  int height_count = 0;
595  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
596  BLOBNBOX* bbox = it.data();
597  const TBOX& box = bbox->bounding_box();
598  int height = box.height();
599  mean_height += height;
600  ++height_count;
601  }
602  if (height_count > 0) mean_height /= height_count;
603  int max_gutter = kGutterMultiple * mean_height;
604  if (IsRagged()) {
605  // Ragged edges face a tougher test in that the gap must always be within
606  // the height of the blob.
607  max_gutter = kGutterToNeighbourRatio * mean_height;
608  }
609 
610  STATS gutters(0, max_gutter + 1);
611  // Evaluate the boxes for their goodness, calculating the coverage as we go.
612  // Remove boxes that are not good and shorten the list to the first and
613  // last good boxes.
614  int num_deleted_boxes = 0;
615  bool text_on_image = false;
616  int good_length = 0;
617  const TBOX* prev_good_box = nullptr;
618  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
619  BLOBNBOX* bbox = it.data();
620  const TBOX& box = bbox->bounding_box();
621  int mid_y = (box.top() + box.bottom()) / 2;
622  if (TabFind::WithinTestRegion(2, XAtY(box.bottom()), box.bottom())) {
623  if (!debug) {
624  tprintf("After already deleting %d boxes, ", num_deleted_boxes);
625  Print("Starting evaluation");
626  }
627  debug = true;
628  }
629  // A good box is one where the nearest neighbour on the inside is closer
630  // than half the distance to the nearest neighbour on the outside
631  // (of the putative column).
632  bool left = IsLeftTab();
633  int tab_x = XAtY(mid_y);
634  int gutter_width;
635  int neighbour_gap;
636  finder->GutterWidthAndNeighbourGap(tab_x, mean_height, max_gutter, left,
637  bbox, &gutter_width, &neighbour_gap);
638  if (debug) {
639  tprintf("Box (%d,%d)->(%d,%d) has gutter %d, ndist %d\n",
640  box.left(), box.bottom(), box.right(), box.top(),
641  gutter_width, neighbour_gap);
642  }
643  // Now we can make the test.
644  if (neighbour_gap * kGutterToNeighbourRatio <= gutter_width) {
645  // A good box contributes its height to the good_length.
646  good_length += box.top() - box.bottom();
647  gutters.add(gutter_width, 1);
648  // Two good boxes together contribute the gap between them
649  // to the good_length as well, as long as the gap is not
650  // too big.
651  if (prev_good_box != nullptr) {
652  int vertical_gap = box.bottom() - prev_good_box->top();
653  double size1 = sqrt(static_cast<double>(prev_good_box->area()));
654  double size2 = sqrt(static_cast<double>(box.area()));
655  if (vertical_gap < kMaxFillinMultiple * std::min(size1, size2))
656  good_length += vertical_gap;
657  if (debug) {
658  tprintf("Box and prev good, gap=%d, target %g, goodlength=%d\n",
659  vertical_gap, kMaxFillinMultiple * std::min(size1, size2),
660  good_length);
661  }
662  } else {
663  // Adjust the start to the first good box.
664  SetYStart(box.bottom());
665  }
666  prev_good_box = &box;
667  if (bbox->flow() == BTFT_TEXT_ON_IMAGE)
668  text_on_image = true;
669  } else {
670  // Get rid of boxes that are not good.
671  if (debug) {
672  tprintf("Bad Box (%d,%d)->(%d,%d) with gutter %d, ndist %d\n",
673  box.left(), box.bottom(), box.right(), box.top(),
674  gutter_width, neighbour_gap);
675  }
676  it.extract();
677  ++num_deleted_boxes;
678  }
679  }
680  if (debug) {
681  Print("Evaluating:");
682  }
683  // If there are any good boxes, do it again, except this time get rid of
684  // boxes that have a gutter that is a small fraction of the mean gutter.
685  // This filters out ends that run into a coincidental gap in the text.
686  int search_top = endpt_.y();
687  int search_bottom = startpt_.y();
688  int median_gutter = IntCastRounded(gutters.median());
689  if (gutters.get_total() > 0) {
690  prev_good_box = nullptr;
691  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
692  BLOBNBOX* bbox = it.data();
693  const TBOX& box = bbox->bounding_box();
694  int mid_y = (box.top() + box.bottom()) / 2;
695  // A good box is one where the gutter width is at least some constant
696  // fraction of the mean gutter width.
697  bool left = IsLeftTab();
698  int tab_x = XAtY(mid_y);
699  int max_gutter = kGutterMultiple * mean_height;
700  if (IsRagged()) {
701  // Ragged edges face a tougher test in that the gap must always be
702  // within the height of the blob.
703  max_gutter = kGutterToNeighbourRatio * mean_height;
704  }
705  int gutter_width;
706  int neighbour_gap;
707  finder->GutterWidthAndNeighbourGap(tab_x, mean_height, max_gutter, left,
708  bbox, &gutter_width, &neighbour_gap);
709  // Now we can make the test.
710  if (gutter_width >= median_gutter * kMinGutterFraction) {
711  if (prev_good_box == nullptr) {
712  // Adjust the start to the first good box.
713  SetYStart(box.bottom());
714  search_bottom = box.top();
715  }
716  prev_good_box = &box;
717  search_top = box.bottom();
718  } else {
719  // Get rid of boxes that are not good.
720  if (debug) {
721  tprintf("Bad Box (%d,%d)->(%d,%d) with gutter %d, mean gutter %d\n",
722  box.left(), box.bottom(), box.right(), box.top(),
723  gutter_width, median_gutter);
724  }
725  it.extract();
726  ++num_deleted_boxes;
727  }
728  }
729  }
730  // If there has been a good box, adjust the end.
731  if (prev_good_box != nullptr) {
732  SetYEnd(prev_good_box->top());
733  // Compute the percentage of the vector that is occupied by good boxes.
734  int length = endpt_.y() - startpt_.y();
735  percent_score_ = 100 * good_length / length;
736  if (num_deleted_boxes > 0) {
737  needs_refit_ = true;
738  FitAndEvaluateIfNeeded(vertical, finder);
739  if (boxes_.empty())
740  return;
741  }
742  // Test the gutter over the whole vector, instead of just at the boxes.
743  int required_shift;
744  if (search_bottom > search_top) {
745  search_bottom = startpt_.y();
746  search_top = endpt_.y();
747  }
748  double min_gutter_width = kLineCountReciprocal / boxes_.length();
749  min_gutter_width += IsRagged() ? kMinRaggedGutter : kMinAlignedGutter;
750  min_gutter_width *= mean_height;
751  int max_gutter_width = IntCastRounded(min_gutter_width) + 1;
752  if (median_gutter > max_gutter_width)
753  max_gutter_width = median_gutter;
754  int gutter_width = finder->GutterWidth(search_bottom, search_top, *this,
755  text_on_image, max_gutter_width,
756  &required_shift);
757  if (gutter_width < min_gutter_width) {
758  if (debug) {
759  tprintf("Rejecting bad tab Vector with %d gutter vs %g min\n",
760  gutter_width, min_gutter_width);
761  }
762  boxes_.shallow_clear();
763  percent_score_ = 0;
764  } else if (debug) {
765  tprintf("Final gutter %d, vs limit of %g, required shift = %d\n",
766  gutter_width, min_gutter_width, required_shift);
767  }
768  } else {
769  // There are no good boxes left, so score is 0.
770  percent_score_ = 0;
771  }
772 
773  if (debug) {
774  Print("Evaluation complete:");
775  }
776 }
void SetYEnd(int end_y)
Definition: tabvector.cpp:270
int XAtY(int y) const
Definition: tabvector.h:189
int16_t y() const
access_function
Definition: points.h:57
const double kMinGutterFraction
Definition: tabvector.cpp:47
Definition: rect.h:34
BlobTextFlowType flow() const
Definition: blobbox.h:296
static bool WithinTestRegion(int detail_level, int x, int y)
Definition: statistc.h:33
bool IsLeftTab() const
Definition: tabvector.h:213
const int kGutterMultiple
Definition: tabvector.cpp:36
const double kMinAlignedGutter
Definition: tabvector.cpp:51
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
int IntCastRounded(double x)
Definition: helpers.h:168
const double kMinRaggedGutter
Definition: tabvector.cpp:53
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
int32_t area() const
Definition: rect.h:122
const double kLineCountReciprocal
Definition: tabvector.cpp:49
const int kGutterToNeighbourRatio
Definition: tabvector.cpp:38
const TBOX & bounding_box() const
Definition: blobbox.h:231
int16_t right() const
Definition: rect.h:79
const int kMaxFillinMultiple
Definition: tabvector.cpp:45
void FitAndEvaluateIfNeeded(const ICOORD &vertical, TabFind *finder)
Definition: tabvector.cpp:568
bool IsRagged() const
Definition: tabvector.h:229
void SetYStart(int start_y)
Definition: tabvector.cpp:265
int16_t bottom() const
Definition: rect.h:65
void Print(const char *prefix)
Definition: tabvector.cpp:520
int16_t height() const
Definition: rect.h:108

◆ extended_ymax()

int tesseract::TabVector::extended_ymax ( ) const
inline

Definition at line 152 of file tabvector.h.

152  {
153  return extended_ymax_;
154  }

◆ extended_ymin()

int tesseract::TabVector::extended_ymin ( ) const
inline

Definition at line 155 of file tabvector.h.

155  {
156  return extended_ymin_;
157  }

◆ ExtendedOverlap()

int tesseract::TabVector::ExtendedOverlap ( int  top_y,
int  bottom_y 
) const
inline

Definition at line 208 of file tabvector.h.

208  {
209  return std::min(top_y, extended_ymax_) - std::max(bottom_y, extended_ymin_);
210  }

◆ ExtendToBox()

void tesseract::TabVector::ExtendToBox ( BLOBNBOX blob)

Definition at line 241 of file tabvector.cpp.

241  {
242  TBOX new_box = new_blob->bounding_box();
243  BLOBNBOX_C_IT it(&boxes_);
244  if (!it.empty()) {
245  BLOBNBOX* blob = it.data();
246  TBOX box = blob->bounding_box();
247  while (!it.at_last() && box.top() <= new_box.top()) {
248  if (blob == new_blob)
249  return; // We have it already.
250  it.forward();
251  blob = it.data();
252  box = blob->bounding_box();
253  }
254  if (box.top() >= new_box.top()) {
255  it.add_before_stay_put(new_blob);
256  needs_refit_ = true;
257  return;
258  }
259  }
260  needs_refit_ = true;
261  it.add_after_stay_put(new_blob);
262 }
Definition: rect.h:34
int16_t top() const
Definition: rect.h:58
const TBOX & bounding_box() const
Definition: blobbox.h:231

◆ Fit()

bool tesseract::TabVector::Fit ( ICOORD  vertical,
bool  force_parallel 
)

Definition at line 783 of file tabvector.cpp.

783  {
784  needs_refit_ = false;
785  if (boxes_.empty()) {
786  // Don't refit something with no boxes, as that only happens
787  // in Evaluate, and we don't want to end up with a zero vector.
788  if (!force_parallel)
789  return false;
790  // If we are forcing parallel, then we just need to set the sort_key_.
791  ICOORD midpt = startpt_;
792  midpt += endpt_;
793  midpt /= 2;
794  sort_key_ = SortKey(vertical, midpt.x(), midpt.y());
795  return startpt_.y() != endpt_.y();
796  }
797  if (!force_parallel && !IsRagged()) {
798  // Use a fitted line as the vertical.
799  DetLineFit linepoints;
800  BLOBNBOX_C_IT it(&boxes_);
801  // Fit a line to all the boxes in the list.
802  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
803  BLOBNBOX* bbox = it.data();
804  const TBOX& box = bbox->bounding_box();
805  int x1 = IsRightTab() ? box.right() : box.left();
806  ICOORD boxpt(x1, box.bottom());
807  linepoints.Add(boxpt);
808  if (it.at_last()) {
809  ICOORD top_pt(x1, box.top());
810  linepoints.Add(top_pt);
811  }
812  }
813  linepoints.Fit(&startpt_, &endpt_);
814  if (startpt_.y() != endpt_.y()) {
815  vertical = endpt_;
816  vertical -= startpt_;
817  }
818  }
819  int start_y = startpt_.y();
820  int end_y = endpt_.y();
821  sort_key_ = IsLeftTab() ? INT32_MAX : -INT32_MAX;
822  BLOBNBOX_C_IT it(&boxes_);
823  // Choose a line parallel to the vertical such that all boxes are on the
824  // correct side of it.
825  mean_width_ = 0;
826  int width_count = 0;
827  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
828  BLOBNBOX* bbox = it.data();
829  const TBOX& box = bbox->bounding_box();
830  mean_width_ += box.width();
831  ++width_count;
832  int x1 = IsRightTab() ? box.right() : box.left();
833  // Test both the bottom and the top, as one will be more extreme, depending
834  // on the direction of skew.
835  int bottom_y = box.bottom();
836  int top_y = box.top();
837  int key = SortKey(vertical, x1, bottom_y);
838  if (IsLeftTab() == (key < sort_key_)) {
839  sort_key_ = key;
840  startpt_ = ICOORD(x1, bottom_y);
841  }
842  key = SortKey(vertical, x1, top_y);
843  if (IsLeftTab() == (key < sort_key_)) {
844  sort_key_ = key;
845  startpt_ = ICOORD(x1, top_y);
846  }
847  if (it.at_first())
848  start_y = bottom_y;
849  if (it.at_last())
850  end_y = top_y;
851  }
852  if (width_count > 0) {
853  mean_width_ = (mean_width_ + width_count - 1) / width_count;
854  }
855  endpt_ = startpt_ + vertical;
856  needs_evaluation_ = true;
857  if (start_y != end_y) {
858  // Set the ends of the vector to fully include the first and last blobs.
859  startpt_.set_x(XAtY(vertical, sort_key_, start_y));
860  startpt_.set_y(start_y);
861  endpt_.set_x(XAtY(vertical, sort_key_, end_y));
862  endpt_.set_y(end_y);
863  return true;
864  }
865  return false;
866 }
bool IsRightTab() const
Definition: tabvector.h:217
int XAtY(int y) const
Definition: tabvector.h:189
void set_x(int16_t xin)
rewrite function
Definition: points.h:62
int16_t y() const
access_function
Definition: points.h:57
Definition: rect.h:34
bool IsLeftTab() const
Definition: tabvector.h:213
int16_t width() const
Definition: rect.h:115
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
integer coordinate
Definition: points.h:32
int16_t x() const
access function
Definition: points.h:53
static int SortKey(const ICOORD &vertical, int x, int y)
Definition: tabvector.h:280
const TBOX & bounding_box() const
Definition: blobbox.h:231
int16_t right() const
Definition: rect.h:79
bool IsRagged() const
Definition: tabvector.h:229
void set_y(int16_t yin)
rewrite function
Definition: points.h:66
int16_t bottom() const
Definition: rect.h:65

◆ FitAndEvaluateIfNeeded()

void tesseract::TabVector::FitAndEvaluateIfNeeded ( const ICOORD vertical,
TabFind finder 
)

Definition at line 568 of file tabvector.cpp.

569  {
570  if (needs_refit_)
571  Fit(vertical, true);
572  if (needs_evaluation_)
573  Evaluate(vertical, finder);
574 }
bool Fit(ICOORD vertical, bool force_parallel)
Definition: tabvector.cpp:783
void Evaluate(const ICOORD &vertical, TabFind *finder)
Definition: tabvector.cpp:582

◆ FitVector()

TabVector * tesseract::TabVector::FitVector ( TabAlignment  alignment,
ICOORD  vertical,
int  extended_start_y,
int  extended_end_y,
BLOBNBOX_CLIST *  good_points,
int *  vertical_x,
int *  vertical_y 
)
static

Definition at line 177 of file tabvector.cpp.

180  {
181  TabVector* vector = new TabVector(extended_start_y, extended_end_y,
182  alignment, good_points);
183  if (!vector->Fit(vertical, false)) {
184  delete vector;
185  return nullptr;
186  }
187  if (!vector->IsRagged()) {
188  vertical = vector->endpt_ - vector->startpt_;
189  int weight = vector->BoxCount();
190  *vertical_x += vertical.x() * weight;
191  *vertical_y += vertical.y() * weight;
192  }
193  return vector;
194 }
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53

◆ Freeze()

void tesseract::TabVector::Freeze ( )
inline

Definition at line 250 of file tabvector.h.

250  {
251  boxes_.shallow_clear();
252  }

◆ GetSinglePartner()

TabVector * tesseract::TabVector::GetSinglePartner ( )

Definition at line 869 of file tabvector.cpp.

869  {
870  if (!partners_.singleton())
871  return nullptr;
872  TabVector_C_IT partner_it(&partners_);
873  TabVector* partner = partner_it.data();
874  return partner;
875 }

◆ intersects_other_lines()

bool tesseract::TabVector::intersects_other_lines ( ) const
inline

Definition at line 179 of file tabvector.h.

179  {
180  return intersects_other_lines_;
181  }

◆ IsAPartner()

bool tesseract::TabVector::IsAPartner ( const TabVector other)

Definition at line 500 of file tabvector.cpp.

500  {
501  TabVector_C_IT it(&partners_);
502  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
503  if (it.data() == other)
504  return true;
505  }
506  return false;
507 }

◆ IsCenterTab()

bool tesseract::TabVector::IsCenterTab ( ) const
inline

Definition at line 225 of file tabvector.h.

225  {
226  return alignment_ == TA_CENTER_JUSTIFIED;
227  }

◆ IsLeftOf()

bool tesseract::TabVector::IsLeftOf ( const TabVector other) const
inline

Definition at line 235 of file tabvector.h.

235  {
236  return sort_key_ < other.sort_key_;
237  }

◆ IsLeftTab()

bool tesseract::TabVector::IsLeftTab ( ) const
inline

Definition at line 213 of file tabvector.h.

213  {
214  return alignment_ == TA_LEFT_ALIGNED || alignment_ == TA_LEFT_RAGGED;
215  }

◆ IsRagged()

bool tesseract::TabVector::IsRagged ( ) const
inline

Definition at line 229 of file tabvector.h.

229  {
230  return alignment_ == TA_LEFT_RAGGED || alignment_ == TA_RIGHT_RAGGED;
231  }

◆ IsRightTab()

bool tesseract::TabVector::IsRightTab ( ) const
inline

Definition at line 217 of file tabvector.h.

217  {
218  return alignment_ == TA_RIGHT_ALIGNED || alignment_ == TA_RIGHT_RAGGED;
219  }

◆ IsSeparator()

bool tesseract::TabVector::IsSeparator ( ) const
inline

Definition at line 221 of file tabvector.h.

221  {
222  return alignment_ == TA_SEPARATOR;
223  }

◆ mean_width()

int tesseract::TabVector::mean_width ( ) const
inline

Definition at line 161 of file tabvector.h.

161  {
162  return mean_width_;
163  }

◆ MergeSimilarTabVectors()

void tesseract::TabVector::MergeSimilarTabVectors ( const ICOORD vertical,
TabVector_LIST *  vectors,
BlobGrid grid 
)
static

Definition at line 356 of file tabvector.cpp.

358  {
359  TabVector_IT it1(vectors);
360  for (it1.mark_cycle_pt(); !it1.cycled_list(); it1.forward()) {
361  TabVector* v1 = it1.data();
362  TabVector_IT it2(it1);
363  for (it2.forward(); !it2.at_first(); it2.forward()) {
364  TabVector* v2 = it2.data();
365  if (v2->SimilarTo(vertical, *v1, grid)) {
366  // Merge into the forward one, in case the combined vector now
367  // overlaps one in between.
368  if (textord_debug_tabfind) {
369  v2->Print("Merging");
370  v1->Print("by deleting");
371  }
372  v2->MergeWith(vertical, it1.extract());
373  if (textord_debug_tabfind) {
374  v2->Print("Producing");
375  }
376  ICOORD merged_vector = v2->endpt();
377  merged_vector -= v2->startpt();
378  if (textord_debug_tabfind && abs(merged_vector.x()) > 100) {
379  v2->Print("Garbage result of merge?");
380  }
381  break;
382  }
383  }
384  }
385 }
integer coordinate
Definition: points.h:32
int16_t x() const
access function
Definition: points.h:53
int textord_debug_tabfind
Definition: alignedblob.cpp:28

◆ MergeWith()

void tesseract::TabVector::MergeWith ( const ICOORD vertical,
TabVector other 
)

Definition at line 453 of file tabvector.cpp.

453  {
454  extended_ymin_ = std::min(extended_ymin_, other->extended_ymin_);
455  extended_ymax_ = std::max(extended_ymax_, other->extended_ymax_);
456  if (other->IsRagged()) {
457  alignment_ = other->alignment_;
458  }
459  // Merge sort the two lists of boxes.
460  BLOBNBOX_C_IT it1(&boxes_);
461  BLOBNBOX_C_IT it2(&other->boxes_);
462  while (!it2.empty()) {
463  BLOBNBOX* bbox2 = it2.extract();
464  it2.forward();
465  TBOX box2 = bbox2->bounding_box();
466  BLOBNBOX* bbox1 = it1.data();
467  TBOX box1 = bbox1->bounding_box();
468  while (box1.bottom() < box2.bottom() && !it1.at_last()) {
469  it1.forward();
470  bbox1 = it1.data();
471  box1 = bbox1->bounding_box();
472  }
473  if (box1.bottom() < box2.bottom()) {
474  it1.add_to_end(bbox2);
475  } else if (bbox1 != bbox2) {
476  it1.add_before_stay_put(bbox2);
477  }
478  }
479  Fit(vertical, true);
480  other->Delete(this);
481 }
bool Fit(ICOORD vertical, bool force_parallel)
Definition: tabvector.cpp:783
Definition: rect.h:34
const TBOX & bounding_box() const
Definition: blobbox.h:231
int16_t bottom() const
Definition: rect.h:65

◆ Partnerless()

bool tesseract::TabVector::Partnerless ( )
inline

Definition at line 240 of file tabvector.h.

240  {
241  return partners_.empty();
242  }

◆ partners()

TabVector_CLIST* tesseract::TabVector::partners ( )
inline

Definition at line 170 of file tabvector.h.

170  {
171  return &partners_;
172  }

◆ Print()

void tesseract::TabVector::Print ( const char *  prefix)

Definition at line 520 of file tabvector.cpp.

520  {
521  tprintf(
522  "%s %s (%d,%d)->(%d,%d) w=%d s=%d, sort key=%d, boxes=%d,"
523  " partners=%d\n",
524  prefix, kAlignmentNames[alignment_], startpt_.x(), startpt_.y(),
525  endpt_.x(), endpt_.y(), mean_width_, percent_score_, sort_key_,
526  boxes_.length(), partners_.length());
527 }
const char * kAlignmentNames[]
Definition: tabvector.cpp:510
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37

◆ ReflectInYAxis()

void tesseract::TabVector::ReflectInYAxis ( )
inline

Definition at line 265 of file tabvector.h.

265  {
266  startpt_.set_x(-startpt_.x());
267  endpt_.set_x(-endpt_.x());
268  sort_key_ = -sort_key_;
269  if (alignment_ == TA_LEFT_ALIGNED)
270  alignment_ = TA_RIGHT_ALIGNED;
271  else if (alignment_ == TA_RIGHT_ALIGNED)
272  alignment_ = TA_LEFT_ALIGNED;
273  if (alignment_ == TA_LEFT_RAGGED)
274  alignment_ = TA_RIGHT_RAGGED;
275  else if (alignment_ == TA_RIGHT_RAGGED)
276  alignment_ = TA_LEFT_RAGGED;
277  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:62
int16_t x() const
access function
Definition: points.h:53

◆ Rotate()

void tesseract::TabVector::Rotate ( const FCOORD rotation)

Definition at line 276 of file tabvector.cpp.

276  {
277  startpt_.rotate(rotation);
278  endpt_.rotate(rotation);
279  int dx = endpt_.x() - startpt_.x();
280  int dy = endpt_.y() - startpt_.y();
281  if ((dy < 0 && abs(dy) > abs(dx)) || (dx < 0 && abs(dx) > abs(dy))) {
282  // Need to flip start/end.
283  ICOORD tmp = startpt_;
284  startpt_ = endpt_;
285  endpt_ = tmp;
286  }
287 }
int16_t y() const
access_function
Definition: points.h:57
integer coordinate
Definition: points.h:32
int16_t x() const
access function
Definition: points.h:53
void rotate(const FCOORD &vec)
Definition: points.h:537

◆ set_bottom_constraints()

void tesseract::TabVector::set_bottom_constraints ( TabConstraint_LIST *  constraints)
inline

Definition at line 167 of file tabvector.h.

167  {
168  bottom_constraints_ = constraints;
169  }

◆ set_endpt()

void tesseract::TabVector::set_endpt ( const ICOORD end)
inline

Definition at line 176 of file tabvector.h.

176  {
177  endpt_ = end;
178  }

◆ set_intersects_other_lines()

void tesseract::TabVector::set_intersects_other_lines ( bool  value)
inline

Definition at line 182 of file tabvector.h.

182  {
183  intersects_other_lines_ = value;
184  }

◆ set_startpt()

void tesseract::TabVector::set_startpt ( const ICOORD start)
inline

Definition at line 173 of file tabvector.h.

173  {
174  startpt_ = start;
175  }

◆ set_top_constraints()

void tesseract::TabVector::set_top_constraints ( TabConstraint_LIST *  constraints)
inline

Definition at line 164 of file tabvector.h.

164  {
165  top_constraints_ = constraints;
166  }

◆ SetupConstraints()

void tesseract::TabVector::SetupConstraints ( )

Definition at line 291 of file tabvector.cpp.

291  {
292  TabConstraint::CreateConstraint(this, false);
294 }
static void CreateConstraint(TabVector *vector, bool is_top)
Definition: tabvector.cpp:64

◆ SetupPartnerConstraints() [1/2]

void tesseract::TabVector::SetupPartnerConstraints ( )

Definition at line 297 of file tabvector.cpp.

297  {
298  // With the first and last partner, we want a common bottom and top,
299  // respectively, and for each change of partner, we want a common
300  // top of first with bottom of next.
301  TabVector_C_IT it(&partners_);
302  TabVector* prev_partner = nullptr;
303  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
304  TabVector* partner = it.data();
305  if (partner->top_constraints_ == nullptr ||
306  partner->bottom_constraints_ == nullptr) {
307  partner->Print("Impossible: has no constraints");
308  Print("This vector has it as a partner");
309  continue;
310  }
311  if (prev_partner == nullptr) {
312  // This is the first partner, so common bottom.
313  if (TabConstraint::CompatibleConstraints(bottom_constraints_,
314  partner->bottom_constraints_))
315  TabConstraint::MergeConstraints(bottom_constraints_,
316  partner->bottom_constraints_);
317  } else {
318  // We need prev top to be common with partner bottom.
319  if (TabConstraint::CompatibleConstraints(prev_partner->top_constraints_,
320  partner->bottom_constraints_))
321  TabConstraint::MergeConstraints(prev_partner->top_constraints_,
322  partner->bottom_constraints_);
323  }
324  prev_partner = partner;
325  if (it.at_last()) {
326  // This is the last partner, so common top.
327  if (TabConstraint::CompatibleConstraints(top_constraints_,
328  partner->top_constraints_))
329  TabConstraint::MergeConstraints(top_constraints_,
330  partner->top_constraints_);
331  }
332  }
333 }
static bool CompatibleConstraints(TabConstraint_LIST *list1, TabConstraint_LIST *list2)
Definition: tabvector.cpp:76
static void MergeConstraints(TabConstraint_LIST *list1, TabConstraint_LIST *list2)
Definition: tabvector.cpp:93
void Print(const char *prefix)
Definition: tabvector.cpp:520

◆ SetupPartnerConstraints() [2/2]

void tesseract::TabVector::SetupPartnerConstraints ( TabVector partner)

Definition at line 336 of file tabvector.cpp.

336  {
337  if (TabConstraint::CompatibleConstraints(bottom_constraints_,
338  partner->bottom_constraints_))
339  TabConstraint::MergeConstraints(bottom_constraints_,
340  partner->bottom_constraints_);
341  if (TabConstraint::CompatibleConstraints(top_constraints_,
342  partner->top_constraints_))
343  TabConstraint::MergeConstraints(top_constraints_,
344  partner->top_constraints_);
345 }
static bool CompatibleConstraints(TabConstraint_LIST *list1, TabConstraint_LIST *list2)
Definition: tabvector.cpp:76
static void MergeConstraints(TabConstraint_LIST *list1, TabConstraint_LIST *list2)
Definition: tabvector.cpp:93

◆ SetYEnd()

void tesseract::TabVector::SetYEnd ( int  end_y)

Definition at line 270 of file tabvector.cpp.

270  {
271  endpt_.set_x(XAtY(end_y));
272  endpt_.set_y(end_y);
273 }
int XAtY(int y) const
Definition: tabvector.h:189
void set_x(int16_t xin)
rewrite function
Definition: points.h:62
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

◆ SetYStart()

void tesseract::TabVector::SetYStart ( int  start_y)

Definition at line 265 of file tabvector.cpp.

265  {
266  startpt_.set_x(XAtY(start_y));
267  startpt_.set_y(start_y);
268 }
int XAtY(int y) const
Definition: tabvector.h:189
void set_x(int16_t xin)
rewrite function
Definition: points.h:62
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

◆ ShallowCopy()

TabVector * tesseract::TabVector::ShallowCopy ( ) const

Definition at line 228 of file tabvector.cpp.

228  {
229  TabVector* copy = new TabVector();
230  copy->startpt_ = startpt_;
231  copy->endpt_ = endpt_;
232  copy->alignment_ = alignment_;
233  copy->extended_ymax_ = extended_ymax_;
234  copy->extended_ymin_ = extended_ymin_;
235  copy->intersects_other_lines_ = intersects_other_lines_;
236  return copy;
237 }

◆ SimilarTo()

bool tesseract::TabVector::SimilarTo ( const ICOORD vertical,
const TabVector other,
BlobGrid grid 
) const

Definition at line 389 of file tabvector.cpp.

390  {
391  if ((IsRightTab() && other.IsRightTab()) ||
392  (IsLeftTab() && other.IsLeftTab())) {
393  // If they don't overlap, at least in extensions, then there is no chance.
394  if (ExtendedOverlap(other.extended_ymax_, other.extended_ymin_) < 0)
395  return false;
396  // A fast approximation to the scale factor of the sort_key_.
397  int v_scale = abs(vertical.y());
398  if (v_scale == 0)
399  v_scale = 1;
400  // If they are close enough, then OK.
401  if (sort_key_ + kSimilarVectorDist * v_scale >= other.sort_key_ &&
402  sort_key_ - kSimilarVectorDist * v_scale <= other.sort_key_)
403  return true;
404  // Ragged tabs get a bigger threshold.
405  if (!IsRagged() || !other.IsRagged() ||
406  sort_key_ + kSimilarRaggedDist * v_scale < other.sort_key_ ||
407  sort_key_ - kSimilarRaggedDist * v_scale > other.sort_key_)
408  return false;
409  if (grid == nullptr) {
410  // There is nothing else to test!
411  return true;
412  }
413  // If there is nothing in the rectangle between the vector that is going to
414  // move, and the place it is moving to, then they can be merged.
415  // Setup a vertical search for any blob.
416  const TabVector* mover = (IsRightTab() &&
417  sort_key_ < other.sort_key_) ? this : &other;
418  int top_y = mover->endpt_.y();
419  int bottom_y = mover->startpt_.y();
420  int left = std::min(mover->XAtY(top_y), mover->XAtY(bottom_y));
421  int right = std::max(mover->XAtY(top_y), mover->XAtY(bottom_y));
422  int shift = abs(sort_key_ - other.sort_key_) / v_scale;
423  if (IsRightTab()) {
424  right += shift;
425  } else {
426  left -= shift;
427  }
428 
429  GridSearch<BLOBNBOX, BLOBNBOX_CLIST, BLOBNBOX_C_IT> vsearch(grid);
430  vsearch.StartVerticalSearch(left, right, top_y);
431  BLOBNBOX* blob;
432  while ((blob = vsearch.NextVerticalSearch(true)) != nullptr) {
433  const TBOX& box = blob->bounding_box();
434  if (box.top() > bottom_y)
435  return true; // Nothing found.
436  if (box.bottom() < top_y)
437  continue; // Doesn't overlap.
438  int left_at_box = XAtY(box.bottom());
439  int right_at_box = left_at_box;
440  if (IsRightTab())
441  right_at_box += shift;
442  else
443  left_at_box -= shift;
444  if (std::min(right_at_box, static_cast<int>(box.right())) > std::max(left_at_box, static_cast<int>(box.left())))
445  return false;
446  }
447  return true; // Nothing found.
448  }
449  return false;
450 }
bool IsRightTab() const
Definition: tabvector.h:217
int XAtY(int y) const
Definition: tabvector.h:189
int16_t y() const
access_function
Definition: points.h:57
Definition: rect.h:34
bool IsLeftTab() const
Definition: tabvector.h:213
int16_t left() const
Definition: rect.h:72
int16_t top() const
Definition: rect.h:58
int ExtendedOverlap(int top_y, int bottom_y) const
Definition: tabvector.h:208
const TBOX & bounding_box() const
Definition: blobbox.h:231
const int kSimilarRaggedDist
Definition: tabvector.cpp:43
int16_t right() const
Definition: rect.h:79
bool IsRagged() const
Definition: tabvector.h:229
const int kSimilarVectorDist
Definition: tabvector.cpp:40
int16_t bottom() const
Definition: rect.h:65

◆ sort_key()

int tesseract::TabVector::sort_key ( ) const
inline

Definition at line 158 of file tabvector.h.

158  {
159  return sort_key_;
160  }

◆ SortKey()

static int tesseract::TabVector::SortKey ( const ICOORD vertical,
int  x,
int  y 
)
inlinestatic

Definition at line 280 of file tabvector.h.

280  {
281  ICOORD pt(x, y);
282  return pt * vertical;
283  }
integer coordinate
Definition: points.h:32

◆ SortVectorsByKey()

static int tesseract::TabVector::SortVectorsByKey ( const void *  v1,
const void *  v2 
)
inlinestatic

Definition at line 294 of file tabvector.h.

294  {
295  const TabVector* tv1 = *static_cast<const TabVector* const*>(v1);
296  const TabVector* tv2 = *static_cast<const TabVector* const*>(v2);
297  return tv1->sort_key_ - tv2->sort_key_;
298  }

◆ startpt()

const ICOORD& tesseract::TabVector::startpt ( ) const
inline

Definition at line 146 of file tabvector.h.

146  {
147  return startpt_;
148  }

◆ VerticalTextlinePartner()

TabVector * tesseract::TabVector::VerticalTextlinePartner ( )

Definition at line 879 of file tabvector.cpp.

879  {
880  if (!partners_.singleton())
881  return nullptr;
882  TabVector_C_IT partner_it(&partners_);
883  TabVector* partner = partner_it.data();
884  BLOBNBOX_C_IT box_it1(&boxes_);
885  BLOBNBOX_C_IT box_it2(&partner->boxes_);
886  // Count how many boxes are also in the other list.
887  // At the same time, gather the mean width and median vertical gap.
888  if (textord_debug_tabfind > 1) {
889  Print("Testing for vertical text");
890  partner->Print(" partner");
891  }
892  int num_matched = 0;
893  int num_unmatched = 0;
894  int total_widths = 0;
895  int width = startpt().x() - partner->startpt().x();
896  if (width < 0)
897  width = -width;
898  STATS gaps(0, width * 2);
899  BLOBNBOX* prev_bbox = nullptr;
900  box_it2.mark_cycle_pt();
901  for (box_it1.mark_cycle_pt(); !box_it1.cycled_list(); box_it1.forward()) {
902  BLOBNBOX* bbox = box_it1.data();
903  TBOX box = bbox->bounding_box();
904  if (prev_bbox != nullptr) {
905  gaps.add(box.bottom() - prev_bbox->bounding_box().top(), 1);
906  }
907  while (!box_it2.cycled_list() && box_it2.data() != bbox &&
908  box_it2.data()->bounding_box().bottom() < box.bottom()) {
909  box_it2.forward();
910  }
911  if (!box_it2.cycled_list() && box_it2.data() == bbox &&
912  bbox->region_type() >= BRT_UNKNOWN &&
913  (prev_bbox == nullptr || prev_bbox->region_type() >= BRT_UNKNOWN))
914  ++num_matched;
915  else
916  ++num_unmatched;
917  total_widths += box.width();
918  prev_bbox = bbox;
919  }
920  if (num_unmatched + num_matched == 0) return nullptr;
921  double avg_width = total_widths * 1.0 / (num_unmatched + num_matched);
922  double max_gap = textord_tabvector_vertical_gap_fraction * avg_width;
923  int min_box_match = static_cast<int>((num_matched + num_unmatched) *
925  bool is_vertical = (gaps.get_total() > 0 &&
926  num_matched >= min_box_match &&
927  gaps.median() <= max_gap);
928  if (textord_debug_tabfind > 1) {
929  tprintf("gaps=%d, matched=%d, unmatched=%d, min_match=%d "
930  "median gap=%.2f, width=%.2f max_gap=%.2f Vertical=%s\n",
931  gaps.get_total(), num_matched, num_unmatched, min_box_match,
932  gaps.median(), avg_width, max_gap, is_vertical?"Yes":"No");
933  }
934  return (is_vertical) ? partner : nullptr;
935 }
const ICOORD & startpt() const
Definition: tabvector.h:146
double textord_tabvector_vertical_box_ratio
Definition: tabvector.cpp:59
Definition: rect.h:34
Definition: statistc.h:33
int16_t width() const
Definition: rect.h:115
double textord_tabvector_vertical_gap_fraction
Definition: tabvector.cpp:56
int16_t top() const
Definition: rect.h:58
int16_t x() const
access function
Definition: points.h:53
BlobRegionType region_type() const
Definition: blobbox.h:284
int textord_debug_tabfind
Definition: alignedblob.cpp:28
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
const TBOX & bounding_box() const
Definition: blobbox.h:231
int16_t bottom() const
Definition: rect.h:65
void Print(const char *prefix)
Definition: tabvector.cpp:520

◆ VOverlap() [1/2]

int tesseract::TabVector::VOverlap ( const TabVector other) const
inline

Definition at line 199 of file tabvector.h.

199  {
200  return std::min(other.endpt_.y(), endpt_.y()) -
201  std::max(other.startpt_.y(), startpt_.y());
202  }
int16_t y() const
access_function
Definition: points.h:57

◆ VOverlap() [2/2]

int tesseract::TabVector::VOverlap ( int  top_y,
int  bottom_y 
) const
inline

Definition at line 204 of file tabvector.h.

204  {
205  return std::min(top_y, static_cast<int>(endpt_.y())) - std::max(bottom_y, static_cast<int>(startpt_.y()));
206  }
int16_t y() const
access_function
Definition: points.h:57

◆ XAtY() [1/2]

int tesseract::TabVector::XAtY ( int  y) const
inline

Definition at line 189 of file tabvector.h.

189  {
190  int height = endpt_.y() - startpt_.y();
191  if (height != 0)
192  return (y - startpt_.y()) * (endpt_.x() - startpt_.x()) / height +
193  startpt_.x();
194  else
195  return startpt_.x();
196  }
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53

◆ XAtY() [2/2]

static int tesseract::TabVector::XAtY ( const ICOORD vertical,
int  sort_key,
int  y 
)
inlinestatic

Definition at line 286 of file tabvector.h.

286  {
287  if (vertical.y() != 0)
288  return (vertical.x() * y + sort_key) / vertical.y();
289  else
290  return sort_key;
291  }
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53
int sort_key() const
Definition: tabvector.h:158

◆ XYFlip()

void tesseract::TabVector::XYFlip ( )
inline

Definition at line 255 of file tabvector.h.

255  {
256  int x = startpt_.y();
257  startpt_.set_y(startpt_.x());
258  startpt_.set_x(x);
259  x = endpt_.y();
260  endpt_.set_y(endpt_.x());
261  endpt_.set_x(x);
262  }
void set_x(int16_t xin)
rewrite function
Definition: points.h:62
int16_t y() const
access_function
Definition: points.h:57
int16_t x() const
access function
Definition: points.h:53
void set_y(int16_t yin)
rewrite function
Definition: points.h:66

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