21 #ifndef TESSERACT_TEXTORD_COLPARTITION_H__
22 #define TESSERACT_TEXTORD_COLPARTITION_H__
42 class WorkingPartSet_LIST;
104 ColPartition_LIST* big_part_list);
110 return bounding_box_;
116 left_margin_ = margin;
119 return right_margin_;
122 right_margin_ = margin;
128 return median_bottom_;
134 return median_right_;
143 return median_width_;
146 median_width_ = width;
161 return good_blob_score_;
170 return left_key_tab_;
176 return right_key_tab_;
191 return boxes_.length();
197 return &upper_partners_;
200 return &lower_partners_;
203 working_set_ = working_set;
209 block_owned_ = owned;
212 return desperately_merged_;
221 return bottom_spacing_;
224 bottom_spacing_ = spacing;
230 top_spacing_ = spacing;
235 type_before_table_ = type_;
241 type_ = type_before_table_;
244 return inside_table_column_;
247 inside_table_column_ = val;
250 return nearest_neighbor_above_;
253 nearest_neighbor_above_ = part;
256 return nearest_neighbor_below_;
259 nearest_neighbor_below_ = part;
265 space_above_ = space;
271 space_below_ = space;
274 return space_to_left_;
277 space_to_left_ = space;
280 return space_to_right_;
283 space_to_right_ = space;
298 owns_blobs_ = owns_blobs;
305 return (bounding_box_.top() + bounding_box_.bottom()) / 2;
309 return (median_top_ + median_bottom_) / 2;
313 return (bounding_box_.left() + bounding_box_.right()) / 2;
320 int XAtY(
int sort_key,
int y)
const {
325 return (right_key - left_key) / vertical_.y();
329 return KeyWidth(left_key_, right_key_);
333 return SortKey(bounding_box_.left(), MidY());
337 return SortKey(bounding_box_.right(), MidY());
341 return XAtY(left_key_, y);
345 return XAtY(right_key_, y);
350 return bounding_box_.right() < other.bounding_box_.
right();
354 return LeftAtY(y) - 1 <= x && x <= RightAtY(y) + 1;
358 return boxes_.empty();
362 return boxes_.singleton();
366 return bounding_box_.x_overlap(other.bounding_box_);
371 return bounding_box_.y_gap(other.bounding_box_) < 0;
376 return MIN(median_top_, other.median_top_) -
377 MAX(median_bottom_, other.median_bottom_);
382 return MIN(median_right_, other.median_right_) -
383 MAX(median_left_, other.median_left_);
388 int overlap = VCoreOverlap(other);
389 int height =
MIN(median_top_ - median_bottom_,
390 other.median_top_ - other.median_bottom_);
391 return overlap * 3 > height;
396 return left_margin_ <= other.bounding_box_.
left() &&
397 bounding_box_.left() >= other.left_margin_ &&
398 bounding_box_.right() <= other.right_margin_ &&
399 right_margin_ >= other.bounding_box_.
right();
404 return TypesMatch(blob_type_, other.blob_type_);
413 return (type1 == type2 ||
445 return IsVerticalType() && IsLineType();
450 return IsHorizontalType() && IsLineType();
483 void ReflectInYAxis();
497 bool MatchingTextColor(
const ColPartition& other)
const;
504 bool ConfirmNoTabViolation(
const ColPartition& other)
const;
508 double fractional_tolerance,
509 double constant_tolerance)
const;
512 bool OKDiacriticMerge(
const ColPartition& candidate,
bool debug)
const;
517 void SetLeftTab(
const TabVector* tab_vector);
518 void SetRightTab(
const TabVector* tab_vector);
522 void CopyLeftTab(
const ColPartition& src,
bool take_box);
523 void CopyRightTab(
const ColPartition& src,
bool take_box);
526 int LeftBlobRule()
const;
528 int RightBlobRule()
const;
537 void SetSpecialBlobsDensity(
541 void ComputeSpecialBlobsDensity();
562 int ok_box_overlap,
bool debug);
579 void ComputeLimits();
582 int CountOverlappingBoxes(
const TBOX& box);
597 int* first_col,
int* last_col);
608 bool MarkAsLeaderIfMonospaced();
613 void SetRegionAndFlowTypesFromProjectionValue(
int value);
621 bool HasGoodBaseline();
625 void AddToWorkingSet(
const ICOORD& bleft,
const ICOORD& tright,
626 int resolution, ColPartition_LIST* used_parts,
627 WorkingPartSet_LIST* working_set);
635 static void LineSpacingBlocks(
const ICOORD& bleft,
const ICOORD& tright,
637 ColPartition_LIST* block_parts,
638 ColPartition_LIST* used_parts,
639 BLOCK_LIST* completed_blocks,
640 TO_BLOCK_LIST* to_blocks);
644 ColPartition_LIST* block_parts,
645 ColPartition_LIST* used_parts);
651 ColPartition_LIST* block_parts,
652 ColPartition_LIST* used_parts);
663 #ifndef GRAPHICS_DISABLED
666 #endif // GRAPHICS_DISABLED
674 void SmoothPartnerRun(
int working_set_count);
691 first_column_ = column;
694 last_column_ = column;
700 enum SpacingNeighbourhood {
713 void RefinePartnersInternal(
bool upper,
bool get_desperate,
714 ColPartitionGrid* grid);
717 void RefinePartnersByType(
bool upper, ColPartition_CLIST* partners);
722 void RefinePartnerShortcuts(
bool upper, ColPartition_CLIST* partners);
729 void RefineTextPartnersByMerge(
bool upper,
bool desperate,
730 ColPartition_CLIST* partners,
731 ColPartitionGrid* grid);
733 void RefinePartnersByOverlap(
bool upper, ColPartition_CLIST* partners);
736 bool ThisPartitionBetter(
BLOBNBOX* bbox,
const ColPartition& other);
741 static void SmoothSpacings(
int resolution,
int page_height,
742 ColPartition_LIST* parts);
747 static bool OKSpacingBlip(
int resolution,
int median_spacing,
748 ColPartition** parts);
752 bool SpacingEqual(
int spacing,
int resolution)
const;
756 bool SpacingsEqual(
const ColPartition& other,
int resolution)
const;
761 bool SummedSpacingOK(
const ColPartition& other,
762 int spacing,
int resolution)
const;
766 int BottomSpacingMargin(
int resolution)
const;
770 int TopSpacingMargin(
int resolution)
const;
774 bool SizesSimilar(
const ColPartition& other)
const;
782 static void LeftEdgeRun(ColPartition_IT* part_it,
790 static void RightEdgeRun(ColPartition_IT* part_it,
817 int good_blob_score_;
837 BLOBNBOX_CLIST boxes_;
841 ColPartition_CLIST upper_partners_;
843 ColPartition_CLIST lower_partners_;
845 WorkingPartSet* working_set_;
847 bool last_add_was_vertical_;
853 bool desperately_merged_;
864 ColPartitionSet* column_set_;
874 bool inside_table_column_;
877 ColPartition* nearest_neighbor_above_;
879 ColPartition* nearest_neighbor_below_;
893 typedef GridSearch<ColPartition,
899 #endif // TESSERACT_TEXTORD_COLPARTITION_H__