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);
709 first_column_ = column;
712 last_column_ = column;
718 enum SpacingNeighbourhood {
731 void RefinePartnersInternal(
bool upper,
bool get_desperate,
732 ColPartitionGrid* grid);
735 void RefinePartnersByType(
bool upper, ColPartition_CLIST* partners);
740 void RefinePartnerShortcuts(
bool upper, ColPartition_CLIST* partners);
747 void RefineTextPartnersByMerge(
bool upper,
bool desperate,
748 ColPartition_CLIST* partners,
749 ColPartitionGrid* grid);
751 void RefinePartnersByOverlap(
bool upper, ColPartition_CLIST* partners);
754 bool ThisPartitionBetter(
BLOBNBOX* bbox,
const ColPartition& other);
759 static void SmoothSpacings(
int resolution,
int page_height,
760 ColPartition_LIST* parts);
765 static bool OKSpacingBlip(
int resolution,
int median_spacing,
766 ColPartition** parts);
770 bool SpacingEqual(
int spacing,
int resolution)
const;
774 bool SpacingsEqual(
const ColPartition& other,
int resolution)
const;
779 bool SummedSpacingOK(
const ColPartition& other,
780 int spacing,
int resolution)
const;
784 int BottomSpacingMargin(
int resolution)
const;
788 int TopSpacingMargin(
int resolution)
const;
792 bool SizesSimilar(
const ColPartition& other)
const;
800 static void LeftEdgeRun(ColPartition_IT* part_it,
808 static void RightEdgeRun(ColPartition_IT* part_it,
835 int good_blob_score_;
855 BLOBNBOX_CLIST boxes_;
859 ColPartition_CLIST upper_partners_;
861 ColPartition_CLIST lower_partners_;
863 WorkingPartSet* working_set_;
865 bool last_add_was_vertical_;
871 bool desperately_merged_;
882 ColPartitionSet* column_set_;
892 bool inside_table_column_;
895 ColPartition* nearest_neighbor_above_;
897 ColPartition* nearest_neighbor_below_;
911 typedef GridSearch<ColPartition,
917 #endif // TESSERACT_TEXTORD_COLPARTITION_H__
void set_last_column(int column)
int SortKey(int x, int y) const
void set_working_set(WorkingPartSet *working_set)
void set_space_below(int space)
bool IsVerticalType() const
int XAtY(int sort_key, int y) const
static bool TypesSimilar(PolyBlockType type1, PolyBlockType type2)
bool right_key_tab() const
void set_top_spacing(int spacing)
#define CLISTIZEH(CLASSNAME)
bool IsHorizontalType() const
ColPartition_CLIST * upper_partners()
int space_to_left() const
void set_median_size(int size)
bool PTIsImageType(PolyBlockType type)
bool inside_table_column()
static bool UnMergeableType(BlobRegionType type)
const TBOX & bounding_box() const
#define ELIST2IZEH(CLASSNAME)
void set_nearest_neighbor_below(ColPartition *part)
void set_bottom_spacing(int spacing)
void set_space_to_right(int space)
bool desperately_merged() const
BlobRegionType blob_type() const
ColPartition * nearest_neighbor_above() const
GridSearch< ColPartition, ColPartition_CLIST, ColPartition_C_IT > ColPartitionGridSearch
int HCoreOverlap(const ColPartition &other) const
bool ColumnContains(int x, int y) const
void set_space_to_left(int space)
void set_space_above(int space)
bool HOverlaps(const ColPartition &other) const
int median_bottom() const
int bottom_spacing() const
void set_left_margin(int margin)
void set_owns_blobs(bool owns_blobs)
static int SortKey(const ICOORD &vertical, int x, int y)
void set_right_margin(int margin)
BlobTextFlowType flow() const
bool WithinSameMargins(const ColPartition &other) const
static bool IsLineType(BlobRegionType type)
bool VOverlaps(const ColPartition &other) const
bool IsHorizontalLine() const
void set_inside_table_column(bool val)
bool IsPulloutType() const
int good_blob_score() const
int space_to_right() const
bool TypesMatch(const ColPartition &other) const
void set_blob_type(BlobRegionType t)
ColPartition_CLIST * lower_partners()
int RightAtY(int y) const
ColPartitionSet * column_set() const
int KeyWidth(int left_key, int right_key) const
void set_vertical(const ICOORD &v)
PolyBlockType type() const
void set_flow(BlobTextFlowType f)
void set_block_owned(bool owned)
static bool TypesMatch(BlobRegionType type1, BlobRegionType type2)
void set_side_step(int step)
bool IsUnMergeableType() const
bool PTIsTextType(PolyBlockType type)
int VCoreOverlap(const ColPartition &other) const
bool PTIsPulloutType(PolyBlockType type)
ColPartition * nearest_neighbor_below() const
bool IsLeftOf(const ColPartition &other) const
bool left_key_tab() const
void set_first_column(int column)
bool IsVerticalLine() const
void set_nearest_neighbor_above(ColPartition *part)
bool PTIsLineType(PolyBlockType type)
bool VSignificantCoreOverlap(const ColPartition &other) const
void set_median_width(int width)
void set_type(PolyBlockType t)