Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tesseract::TabVector Class Reference

#include <tabvector.h>

Inheritance diagram for tesseract::TabVector:
ELIST2_LINK

Public Member Functions

 TabVector ()
 
 ~TabVector ()
 
 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 111 of file tabvector.h.

Constructor & Destructor Documentation

tesseract::TabVector::TabVector ( )
inline

Definition at line 113 of file tabvector.h.

113  {
114  // TODO(rays) fix this in elst.h line 1076, where it should use the
115  // copy constructor instead of operator=.
116  }
tesseract::TabVector::~TabVector ( )

Definition at line 171 of file tabvector.cpp.

171  {
172 }
tesseract::TabVector::TabVector ( const TabVector src,
TabAlignment  alignment,
const ICOORD vertical_skew,
BLOBNBOX blob 
)

Definition at line 205 of file tabvector.cpp.

207  : extended_ymin_(src.extended_ymin_), extended_ymax_(src.extended_ymax_),
208  sort_key_(0), percent_score_(0), mean_width_(0),
209  needs_refit_(true), needs_evaluation_(true), intersects_other_lines_(false),
210  alignment_(alignment),
211  top_constraints_(NULL), bottom_constraints_(NULL) {
212  BLOBNBOX_C_IT it(&boxes_);
213  it.add_to_end(blob);
214  TBOX box = blob->bounding_box();
215  if (IsLeftTab()) {
216  startpt_ = box.botleft();
217  endpt_ = box.topleft();
218  } else {
219  startpt_ = box.botright();
220  endpt_ = box.topright();
221  }
222  sort_key_ = SortKey(vertical_skew,
223  (startpt_.x() + endpt_.x()) / 2,
224  (startpt_.y() + endpt_.y()) / 2);
225  if (textord_debug_tabfind > 3)
226  Print("Constructed a new tab vector:");
227 }
inT16 x() const
access function
Definition: points.h:52
ICOORD topleft() const
Definition: rect.h:89
const TBOX & bounding_box() const
Definition: blobbox.h:208
#define NULL
Definition: host.h:144
Definition: rect.h:29
int textord_debug_tabfind
Definition: alignedblob.cpp:28
inT16 y() const
access_function
Definition: points.h:56
ICOORD botright() const
Definition: rect.h:85
const ICOORD & topright() const
Definition: rect.h:93
static int SortKey(const ICOORD &vertical, int x, int y)
Definition: tabvector.h:280
const ICOORD & botleft() const
Definition: rect.h:81
void Print(const char *prefix)
Definition: tabvector.cpp:526
bool IsLeftTab() const
Definition: tabvector.h:213

Member Function Documentation

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

Definition at line 493 of file tabvector.cpp.

493  {
494  if (IsSeparator() || partner->IsSeparator())
495  return;
496  TabVector_C_IT it(&partners_);
497  if (!it.empty()) {
498  it.move_to_last();
499  if (it.data() == partner)
500  return;
501  }
502  it.add_after_then_move(partner);
503 }
bool IsSeparator() const
Definition: tabvector.h:221
void tesseract::TabVector::ApplyConstraints ( )

Definition at line 354 of file tabvector.cpp.

354  {
355  if (top_constraints_ != NULL)
356  TabConstraint::ApplyConstraints(top_constraints_);
357  if (bottom_constraints_ != NULL)
358  TabConstraint::ApplyConstraints(bottom_constraints_);
359 }
static void ApplyConstraints(TabConstraint_LIST *constraints)
Definition: tabvector.cpp:120
#define NULL
Definition: host.h:144
int tesseract::TabVector::BoxCount ( )
inline

Definition at line 245 of file tabvector.h.

245  {
246  return boxes_.length();
247  }
void tesseract::TabVector::Debug ( const char *  prefix)

Definition at line 540 of file tabvector.cpp.

540  {
541  Print(prefix);
542  BLOBNBOX_C_IT it(&boxes_);
543  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
544  BLOBNBOX* bbox = it.data();
545  const TBOX& box = bbox->bounding_box();
546  tprintf("Box at (%d,%d)->(%d,%d)\n",
547  box.left(), box.bottom(), box.right(), box.top());
548  }
549 }
const TBOX & bounding_box() const
Definition: blobbox.h:208
inT16 left() const
Definition: rect.h:67
Definition: rect.h:29
inT16 right() const
Definition: rect.h:74
inT16 top() const
Definition: rect.h:53
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
void Print(const char *prefix)
Definition: tabvector.cpp:526
inT16 bottom() const
Definition: rect.h:60
void tesseract::TabVector::Display ( ScrollView tab_win)

Definition at line 552 of file tabvector.cpp.

552  {
553 #ifndef GRAPHICS_DISABLED
555  tab_win->Pen(ScrollView::BLUE);
556  else if (alignment_ == TA_LEFT_ALIGNED)
557  tab_win->Pen(ScrollView::LIME_GREEN);
558  else if (alignment_ == TA_LEFT_RAGGED)
559  tab_win->Pen(ScrollView::DARK_GREEN);
560  else if (alignment_ == TA_RIGHT_ALIGNED)
561  tab_win->Pen(ScrollView::PINK);
562  else if (alignment_ == TA_RIGHT_RAGGED)
563  tab_win->Pen(ScrollView::CORAL);
564  else
565  tab_win->Pen(ScrollView::WHITE);
566  tab_win->Line(startpt_.x(), startpt_.y(), endpt_.x(), endpt_.y());
567  tab_win->Pen(ScrollView::GREY);
568  tab_win->Line(startpt_.x(), startpt_.y(), startpt_.x(), extended_ymin_);
569  tab_win->Line(endpt_.x(), extended_ymax_, endpt_.x(), endpt_.y());
570  char score_buf[64];
571  snprintf(score_buf, sizeof(score_buf), "%d", percent_score_);
572  tab_win->TextAttributes("Times", 50, false, false, false);
573  tab_win->Text(startpt_.x(), startpt_.y(), score_buf);
574 #endif
575 }
inT16 x() const
access function
Definition: points.h:52
void Pen(Color color)
Definition: scrollview.cpp:721
inT16 y() const
access_function
Definition: points.h:56
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
Definition: scrollview.cpp:636
bool textord_debug_printable
Definition: alignedblob.cpp:35
void Text(int x, int y, const char *mystring)
Definition: scrollview.cpp:653
void Line(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:533
const ICOORD& tesseract::TabVector::endpt ( ) const
inline

Definition at line 149 of file tabvector.h.

149  {
150  return endpt_;
151  }
void tesseract::TabVector::Evaluate ( const ICOORD vertical,
TabFind finder 
)

Definition at line 592 of file tabvector.cpp.

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

Definition at line 152 of file tabvector.h.

152  {
153  return extended_ymax_;
154  }
int tesseract::TabVector::extended_ymin ( ) const
inline

Definition at line 155 of file tabvector.h.

155  {
156  return extended_ymin_;
157  }
int tesseract::TabVector::ExtendedOverlap ( int  top_y,
int  bottom_y 
) const
inline

Definition at line 208 of file tabvector.h.

208  {
209  return MIN(top_y, extended_ymax_) - MAX(bottom_y, extended_ymin_);
210  }
#define MIN(x, y)
Definition: ndminx.h:28
#define MAX(x, y)
Definition: ndminx.h:24
void tesseract::TabVector::ExtendToBox ( BLOBNBOX blob)

Definition at line 247 of file tabvector.cpp.

247  {
248  TBOX new_box = new_blob->bounding_box();
249  BLOBNBOX_C_IT it(&boxes_);
250  if (!it.empty()) {
251  BLOBNBOX* blob = it.data();
252  TBOX box = blob->bounding_box();
253  while (!it.at_last() && box.top() <= new_box.top()) {
254  if (blob == new_blob)
255  return; // We have it already.
256  it.forward();
257  blob = it.data();
258  box = blob->bounding_box();
259  }
260  if (box.top() >= new_box.top()) {
261  it.add_before_stay_put(new_blob);
262  needs_refit_ = true;
263  return;
264  }
265  }
266  needs_refit_ = true;
267  it.add_after_stay_put(new_blob);
268 }
const TBOX & bounding_box() const
Definition: blobbox.h:208
Definition: rect.h:29
inT16 top() const
Definition: rect.h:53
bool tesseract::TabVector::Fit ( ICOORD  vertical,
bool  force_parallel 
)

Definition at line 793 of file tabvector.cpp.

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

Definition at line 578 of file tabvector.cpp.

579  {
580  if (needs_refit_)
581  Fit(vertical, true);
582  if (needs_evaluation_)
583  Evaluate(vertical, finder);
584 }
void Evaluate(const ICOORD &vertical, TabFind *finder)
Definition: tabvector.cpp:592
bool Fit(ICOORD vertical, bool force_parallel)
Definition: tabvector.cpp:793
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 183 of file tabvector.cpp.

186  {
187  TabVector* vector = new TabVector(extended_start_y, extended_end_y,
188  alignment, good_points);
189  if (!vector->Fit(vertical, false)) {
190  delete vector;
191  return NULL;
192  }
193  if (!vector->IsRagged()) {
194  vertical = vector->endpt_ - vector->startpt_;
195  int weight = vector->BoxCount();
196  *vertical_x += vertical.x() * weight;
197  *vertical_y += vertical.y() * weight;
198  }
199  return vector;
200 }
inT16 x() const
access function
Definition: points.h:52
#define NULL
Definition: host.h:144
inT16 y() const
access_function
Definition: points.h:56
void tesseract::TabVector::Freeze ( )
inline

Definition at line 250 of file tabvector.h.

250  {
251  boxes_.shallow_clear();
252  }
TabVector * tesseract::TabVector::GetSinglePartner ( )

Definition at line 879 of file tabvector.cpp.

879  {
880  if (!partners_.singleton())
881  return NULL;
882  TabVector_C_IT partner_it(&partners_);
883  TabVector* partner = partner_it.data();
884  return partner;
885 }
#define NULL
Definition: host.h:144
bool tesseract::TabVector::intersects_other_lines ( ) const
inline

Definition at line 179 of file tabvector.h.

179  {
180  return intersects_other_lines_;
181  }
bool tesseract::TabVector::IsAPartner ( const TabVector other)

Definition at line 506 of file tabvector.cpp.

506  {
507  TabVector_C_IT it(&partners_);
508  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
509  if (it.data() == other)
510  return true;
511  }
512  return false;
513 }
bool tesseract::TabVector::IsCenterTab ( ) const
inline

Definition at line 225 of file tabvector.h.

225  {
226  return alignment_ == TA_CENTER_JUSTIFIED;
227  }
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  }
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  }
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  }
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  }
bool tesseract::TabVector::IsSeparator ( ) const
inline

Definition at line 221 of file tabvector.h.

221  {
222  return alignment_ == TA_SEPARATOR;
223  }
int tesseract::TabVector::mean_width ( ) const
inline

Definition at line 161 of file tabvector.h.

161  {
162  return mean_width_;
163  }
void tesseract::TabVector::MergeSimilarTabVectors ( const ICOORD vertical,
TabVector_LIST *  vectors,
BlobGrid grid 
)
static

Definition at line 362 of file tabvector.cpp.

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

Definition at line 459 of file tabvector.cpp.

459  {
460  extended_ymin_ = MIN(extended_ymin_, other->extended_ymin_);
461  extended_ymax_ = MAX(extended_ymax_, other->extended_ymax_);
462  if (other->IsRagged()) {
463  alignment_ = other->alignment_;
464  }
465  // Merge sort the two lists of boxes.
466  BLOBNBOX_C_IT it1(&boxes_);
467  BLOBNBOX_C_IT it2(&other->boxes_);
468  while (!it2.empty()) {
469  BLOBNBOX* bbox2 = it2.extract();
470  it2.forward();
471  TBOX box2 = bbox2->bounding_box();
472  BLOBNBOX* bbox1 = it1.data();
473  TBOX box1 = bbox1->bounding_box();
474  while (box1.bottom() < box2.bottom() && !it1.at_last()) {
475  it1.forward();
476  bbox1 = it1.data();
477  box1 = bbox1->bounding_box();
478  }
479  if (box1.bottom() < box2.bottom()) {
480  it1.add_to_end(bbox2);
481  } else if (bbox1 != bbox2) {
482  it1.add_before_stay_put(bbox2);
483  }
484  }
485  Fit(vertical, true);
486  other->Delete(this);
487 }
const TBOX & bounding_box() const
Definition: blobbox.h:208
Definition: rect.h:29
#define MIN(x, y)
Definition: ndminx.h:28
#define MAX(x, y)
Definition: ndminx.h:24
bool Fit(ICOORD vertical, bool force_parallel)
Definition: tabvector.cpp:793
inT16 bottom() const
Definition: rect.h:60
bool tesseract::TabVector::Partnerless ( )
inline

Definition at line 240 of file tabvector.h.

240  {
241  return partners_.empty();
242  }
TabVector_CLIST* tesseract::TabVector::partners ( )
inline

Definition at line 170 of file tabvector.h.

170  {
171  return &partners_;
172  }
void tesseract::TabVector::Print ( const char *  prefix)

Definition at line 526 of file tabvector.cpp.

526  {
527  if (this == NULL) {
528  tprintf("%s <null>\n", prefix);
529  } else {
530  tprintf("%s %s (%d,%d)->(%d,%d) w=%d s=%d, sort key=%d, boxes=%d,"
531  " partners=%d\n",
532  prefix, kAlignmentNames[alignment_],
533  startpt_.x(), startpt_.y(), endpt_.x(), endpt_.y(),
534  mean_width_, percent_score_, sort_key_,
535  boxes_.length(), partners_.length());
536  }
537 }
inT16 x() const
access function
Definition: points.h:52
const char * kAlignmentNames[]
Definition: tabvector.cpp:516
#define NULL
Definition: host.h:144
inT16 y() const
access_function
Definition: points.h:56
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
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  }
inT16 x() const
access function
Definition: points.h:52
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
void tesseract::TabVector::Rotate ( const FCOORD rotation)

Definition at line 282 of file tabvector.cpp.

282  {
283  startpt_.rotate(rotation);
284  endpt_.rotate(rotation);
285  int dx = endpt_.x() - startpt_.x();
286  int dy = endpt_.y() - startpt_.y();
287  if ((dy < 0 && abs(dy) > abs(dx)) || (dx < 0 && abs(dx) > abs(dy))) {
288  // Need to flip start/end.
289  ICOORD tmp = startpt_;
290  startpt_ = endpt_;
291  endpt_ = tmp;
292  }
293 }
void rotate(const FCOORD &vec)
Definition: ipoints.h:241
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
void tesseract::TabVector::set_bottom_constraints ( TabConstraint_LIST *  constraints)
inline

Definition at line 167 of file tabvector.h.

167  {
168  bottom_constraints_ = constraints;
169  }
void tesseract::TabVector::set_endpt ( const ICOORD end)
inline

Definition at line 176 of file tabvector.h.

176  {
177  endpt_ = end;
178  }
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  }
void tesseract::TabVector::set_startpt ( const ICOORD start)
inline

Definition at line 173 of file tabvector.h.

173  {
174  startpt_ = start;
175  }
void tesseract::TabVector::set_top_constraints ( TabConstraint_LIST *  constraints)
inline

Definition at line 164 of file tabvector.h.

164  {
165  top_constraints_ = constraints;
166  }
void tesseract::TabVector::SetupConstraints ( )

Definition at line 297 of file tabvector.cpp.

297  {
298  TabConstraint::CreateConstraint(this, false);
300 }
static void CreateConstraint(TabVector *vector, bool is_top)
Definition: tabvector.cpp:67
void tesseract::TabVector::SetupPartnerConstraints ( )

Definition at line 303 of file tabvector.cpp.

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

Definition at line 342 of file tabvector.cpp.

342  {
343  if (TabConstraint::CompatibleConstraints(bottom_constraints_,
344  partner->bottom_constraints_))
345  TabConstraint::MergeConstraints(bottom_constraints_,
346  partner->bottom_constraints_);
347  if (TabConstraint::CompatibleConstraints(top_constraints_,
348  partner->top_constraints_))
349  TabConstraint::MergeConstraints(top_constraints_,
350  partner->top_constraints_);
351 }
static bool CompatibleConstraints(TabConstraint_LIST *list1, TabConstraint_LIST *list2)
Definition: tabvector.cpp:79
static void MergeConstraints(TabConstraint_LIST *list1, TabConstraint_LIST *list2)
Definition: tabvector.cpp:96
void tesseract::TabVector::SetYEnd ( int  end_y)

Definition at line 276 of file tabvector.cpp.

276  {
277  endpt_.set_x(XAtY(end_y));
278  endpt_.set_y(end_y);
279 }
int XAtY(int y) const
Definition: tabvector.h:189
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
void tesseract::TabVector::SetYStart ( int  start_y)

Definition at line 271 of file tabvector.cpp.

271  {
272  startpt_.set_x(XAtY(start_y));
273  startpt_.set_y(start_y);
274 }
int XAtY(int y) const
Definition: tabvector.h:189
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
TabVector * tesseract::TabVector::ShallowCopy ( ) const

Definition at line 234 of file tabvector.cpp.

234  {
235  TabVector* copy = new TabVector();
236  copy->startpt_ = startpt_;
237  copy->endpt_ = endpt_;
238  copy->alignment_ = alignment_;
239  copy->extended_ymax_ = extended_ymax_;
240  copy->extended_ymin_ = extended_ymin_;
241  copy->intersects_other_lines_ = intersects_other_lines_;
242  return copy;
243 }
bool tesseract::TabVector::SimilarTo ( const ICOORD vertical,
const TabVector other,
BlobGrid grid 
) const

Definition at line 395 of file tabvector.cpp.

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

Definition at line 158 of file tabvector.h.

158  {
159  return sort_key_;
160  }
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:30
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 = *reinterpret_cast<const TabVector* const *>(v1);
296  const TabVector* tv2 = *reinterpret_cast<const TabVector* const *>(v2);
297  return tv1->sort_key_ - tv2->sort_key_;
298  }
const ICOORD& tesseract::TabVector::startpt ( ) const
inline

Definition at line 146 of file tabvector.h.

146  {
147  return startpt_;
148  }
TabVector * tesseract::TabVector::VerticalTextlinePartner ( )

Definition at line 889 of file tabvector.cpp.

889  {
890  if (!partners_.singleton())
891  return NULL;
892  TabVector_C_IT partner_it(&partners_);
893  TabVector* partner = partner_it.data();
894  BLOBNBOX_C_IT box_it1(&boxes_);
895  BLOBNBOX_C_IT box_it2(&partner->boxes_);
896  // Count how many boxes are also in the other list.
897  // At the same time, gather the mean width and median vertical gap.
898  if (textord_debug_tabfind > 1) {
899  Print("Testing for vertical text");
900  partner->Print(" partner");
901  }
902  int num_matched = 0;
903  int num_unmatched = 0;
904  int total_widths = 0;
905  int width = startpt().x() - partner->startpt().x();
906  if (width < 0)
907  width = -width;
908  STATS gaps(0, width * 2);
909  BLOBNBOX* prev_bbox = NULL;
910  box_it2.mark_cycle_pt();
911  for (box_it1.mark_cycle_pt(); !box_it1.cycled_list(); box_it1.forward()) {
912  BLOBNBOX* bbox = box_it1.data();
913  TBOX box = bbox->bounding_box();
914  if (prev_bbox != NULL) {
915  gaps.add(box.bottom() - prev_bbox->bounding_box().top(), 1);
916  }
917  while (!box_it2.cycled_list() && box_it2.data() != bbox &&
918  box_it2.data()->bounding_box().bottom() < box.bottom()) {
919  box_it2.forward();
920  }
921  if (!box_it2.cycled_list() && box_it2.data() == bbox &&
922  bbox->region_type() >= BRT_UNKNOWN &&
923  (prev_bbox == NULL || prev_bbox->region_type() >= BRT_UNKNOWN))
924  ++num_matched;
925  else
926  ++num_unmatched;
927  total_widths += box.width();
928  prev_bbox = bbox;
929  }
930  double avg_width = total_widths * 1.0 / (num_unmatched + num_matched);
931  double max_gap = textord_tabvector_vertical_gap_fraction * avg_width;
932  int min_box_match = static_cast<int>((num_matched + num_unmatched) *
934  bool is_vertical = (gaps.get_total() > 0 &&
935  num_matched >= min_box_match &&
936  gaps.median() <= max_gap);
937  if (textord_debug_tabfind > 1) {
938  tprintf("gaps=%d, matched=%d, unmatched=%d, min_match=%d "
939  "median gap=%.2f, width=%.2f max_gap=%.2f Vertical=%s\n",
940  gaps.get_total(), num_matched, num_unmatched, min_box_match,
941  gaps.median(), avg_width, max_gap, is_vertical?"Yes":"No");
942  }
943  return (is_vertical) ? partner : NULL;
944 }
const ICOORD & startpt() const
Definition: tabvector.h:146
inT16 x() const
access function
Definition: points.h:52
const TBOX & bounding_box() const
Definition: blobbox.h:208
BlobRegionType region_type() const
Definition: blobbox.h:260
#define NULL
Definition: host.h:144
inT16 width() const
Definition: rect.h:104
Definition: rect.h:29
int textord_debug_tabfind
Definition: alignedblob.cpp:28
inT16 top() const
Definition: rect.h:53
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:41
double textord_tabvector_vertical_box_ratio
Definition: tabvector.cpp:62
Definition: statistc.h:29
void Print(const char *prefix)
Definition: tabvector.cpp:526
double textord_tabvector_vertical_gap_fraction
Definition: tabvector.cpp:59
inT16 bottom() const
Definition: rect.h:60
int tesseract::TabVector::VOverlap ( const TabVector other) const
inline

Definition at line 199 of file tabvector.h.

199  {
200  return MIN(other.endpt_.y(), endpt_.y()) -
201  MAX(other.startpt_.y(), startpt_.y());
202  }
inT16 y() const
access_function
Definition: points.h:56
#define MIN(x, y)
Definition: ndminx.h:28
#define MAX(x, y)
Definition: ndminx.h:24
int tesseract::TabVector::VOverlap ( int  top_y,
int  bottom_y 
) const
inline

Definition at line 204 of file tabvector.h.

204  {
205  return MIN(top_y, endpt_.y()) - MAX(bottom_y, startpt_.y());
206  }
inT16 y() const
access_function
Definition: points.h:56
#define MIN(x, y)
Definition: ndminx.h:28
#define MAX(x, y)
Definition: ndminx.h:24
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 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
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 x() const
access function
Definition: points.h:52
int sort_key() const
Definition: tabvector.h:158
inT16 y() const
access_function
Definition: points.h:56
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  }
inT16 x() const
access function
Definition: points.h:52
inT16 y() const
access_function
Definition: points.h:56
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61

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