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 ||
449 return IsVerticalType() && IsLineType();
454 return IsHorizontalType() && IsLineType();
483 void DisownBoxesNoAssert();
488 bool ReleaseNonLeaderBoxes();
497 void ReflectInYAxis();
511 bool MatchingTextColor(
const ColPartition& other)
const;
518 bool ConfirmNoTabViolation(
const ColPartition& other)
const;
522 double fractional_tolerance,
523 double constant_tolerance)
const;
526 bool OKDiacriticMerge(
const ColPartition& candidate,
bool debug)
const;
531 void SetLeftTab(
const TabVector* tab_vector);
532 void SetRightTab(
const TabVector* tab_vector);
536 void CopyLeftTab(
const ColPartition& src,
bool take_box);
537 void CopyRightTab(
const ColPartition& src,
bool take_box);
540 int LeftBlobRule()
const;
542 int RightBlobRule()
const;
551 void SetSpecialBlobsDensity(
555 void ComputeSpecialBlobsDensity();
576 int ok_box_overlap,
bool debug);
593 void ComputeLimits();
596 int CountOverlappingBoxes(
const TBOX& box);
611 int* first_col,
int* last_col);
622 bool MarkAsLeaderIfMonospaced();
627 void SetRegionAndFlowTypesFromProjectionValue(
int value);
635 bool HasGoodBaseline();
639 void AddToWorkingSet(
const ICOORD& bleft,
const ICOORD& tright,
640 int resolution, ColPartition_LIST* used_parts,
641 WorkingPartSet_LIST* working_set);
649 static void LineSpacingBlocks(
const ICOORD& bleft,
const ICOORD& tright,
651 ColPartition_LIST* block_parts,
652 ColPartition_LIST* used_parts,
653 BLOCK_LIST* completed_blocks,
654 TO_BLOCK_LIST* to_blocks);
658 ColPartition_LIST* block_parts,
659 ColPartition_LIST* used_parts);
665 ColPartition_LIST* block_parts,
666 ColPartition_LIST* used_parts);
681 #ifndef GRAPHICS_DISABLED 684 #endif // GRAPHICS_DISABLED 692 void SmoothPartnerRun(
int working_set_count);
713 int mid_y1 = part1->bounding_box_.
y_middle();
714 int mid_y2 = part2->bounding_box_.
y_middle();
715 if ((part2->bounding_box_.
bottom() <= mid_y1 &&
716 mid_y1 <= part2->bounding_box_.
top()) ||
717 (part1->bounding_box_.
bottom() <= mid_y2 &&
718 mid_y2 <= part1->bounding_box_.
top())) {
723 return mid_y2 - mid_y1;
728 first_column_ = column;
731 last_column_ = column;
737 enum SpacingNeighbourhood {
750 void RefinePartnersInternal(
bool upper,
bool get_desperate,
751 ColPartitionGrid* grid);
754 void RefinePartnersByType(
bool upper, ColPartition_CLIST* partners);
759 void RefinePartnerShortcuts(
bool upper, ColPartition_CLIST* partners);
766 void RefineTextPartnersByMerge(
bool upper,
bool desperate,
767 ColPartition_CLIST* partners,
768 ColPartitionGrid* grid);
770 void RefinePartnersByOverlap(
bool upper, ColPartition_CLIST* partners);
773 bool ThisPartitionBetter(
BLOBNBOX* bbox,
const ColPartition& other);
778 static void SmoothSpacings(
int resolution,
int page_height,
779 ColPartition_LIST* parts);
784 static bool OKSpacingBlip(
int resolution,
int median_spacing,
785 ColPartition** parts);
789 bool SpacingEqual(
int spacing,
int resolution)
const;
793 bool SpacingsEqual(
const ColPartition& other,
int resolution)
const;
798 bool SummedSpacingOK(
const ColPartition& other,
799 int spacing,
int resolution)
const;
803 int BottomSpacingMargin(
int resolution)
const;
807 int TopSpacingMargin(
int resolution)
const;
811 bool SizesSimilar(
const ColPartition& other)
const;
819 static void LeftEdgeRun(ColPartition_IT* part_it,
827 static void RightEdgeRun(ColPartition_IT* part_it,
854 int good_blob_score_;
874 BLOBNBOX_CLIST boxes_;
878 ColPartition_CLIST upper_partners_;
880 ColPartition_CLIST lower_partners_;
882 WorkingPartSet* working_set_;
884 bool last_add_was_vertical_;
890 bool desperately_merged_;
901 ColPartitionSet* column_set_;
911 bool inside_table_column_;
914 ColPartition* nearest_neighbor_above_;
916 ColPartition* nearest_neighbor_below_;
930 typedef GridSearch<ColPartition,
936 #endif // TESSERACT_TEXTORD_COLPARTITION_H__ bool left_key_tab() const
void set_flow(BlobTextFlowType f)
bool VOverlaps(const ColPartition &other) const
static bool IsLineType(BlobRegionType type)
int space_to_right() const
static bool UnMergeableType(BlobRegionType type)
void set_bottom_spacing(int spacing)
#define CLISTIZEH(CLASSNAME)
bool IsVerticalType() const
bool WithinSameMargins(const ColPartition &other) const
bool PTIsImageType(PolyBlockType type)
GridSearch< ColPartition, ColPartition_CLIST, ColPartition_C_IT > ColPartitionGridSearch
void set_owns_blobs(bool owns_blobs)
void set_left_margin(int margin)
void set_block_owned(bool owned)
PolyBlockType type() const
int bottom_spacing() const
void set_inside_table_column(bool val)
bool IsUnMergeableType() const
void set_working_set(WorkingPartSet *working_set)
bool inside_table_column()
ColPartition * nearest_neighbor_above() const
static int SortKey(const ICOORD &vertical, int x, int y)
bool PTIsLineType(PolyBlockType type)
void set_side_step(int step)
static int SortByBBox(const void *p1, const void *p2)
bool ColumnContains(int x, int y) const
bool IsLeftOf(const ColPartition &other) const
bool PTIsTextType(PolyBlockType type)
void set_right_margin(int margin)
void set_first_column(int column)
void set_space_above(int space)
void set_space_to_left(int space)
void set_space_to_right(int space)
ColPartition * nearest_neighbor_below() const
bool desperately_merged() const
void set_last_column(int column)
void set_top_spacing(int spacing)
bool right_key_tab() const
void set_nearest_neighbor_below(ColPartition *part)
int space_to_left() const
static bool TypesMatch(BlobRegionType type1, BlobRegionType type2)
int XAtY(int sort_key, int y) const
int good_blob_score() const
void set_median_width(int width)
int RightAtY(int y) const
int HCoreOverlap(const ColPartition &other) const
bool VSignificantCoreOverlap(const ColPartition &other) const
#define ELIST2IZEH(CLASSNAME)
bool IsHorizontalType() const
int median_bottom() const
void set_nearest_neighbor_above(ColPartition *part)
bool IsHorizontalLine() const
int VCoreOverlap(const ColPartition &other) const
int SortKey(int x, int y) const
bool HOverlaps(const ColPartition &other) const
bool IsVerticalLine() const
bool IsPulloutType() const
ColPartition_CLIST * lower_partners()
ColPartition_CLIST * upper_partners()
void set_space_below(int space)
void set_vertical(const ICOORD &v)
BlobTextFlowType flow() const
bool PTIsPulloutType(PolyBlockType type)
bool TypesMatch(const ColPartition &other) const
int KeyWidth(int left_key, int right_key) const
void set_blob_type(BlobRegionType t)
const TBOX & bounding_box() const
static bool TypesSimilar(PolyBlockType type1, PolyBlockType type2)
BlobRegionType blob_type() const
void set_type(PolyBlockType t)
void set_median_size(int size)
ColPartitionSet * column_set() const