21 #ifndef TESSERACT_TEXTORD_COLPARTITION_H_ 22 #define TESSERACT_TEXTORD_COLPARTITION_H_ 43 class WorkingPartSet_LIST;
105 ColPartition_LIST* big_part_list);
111 return bounding_box_;
117 left_margin_ = margin;
120 return right_margin_;
123 right_margin_ = margin;
129 return median_bottom_;
135 return median_right_;
138 return median_height_;
141 median_height_ = height;
144 return median_width_;
147 median_width_ = width;
162 return good_blob_score_;
171 return left_key_tab_;
177 return right_key_tab_;
192 return boxes_.length();
198 return &upper_partners_;
201 return &lower_partners_;
204 working_set_ = working_set;
210 block_owned_ = owned;
213 return desperately_merged_;
222 return bottom_spacing_;
225 bottom_spacing_ = spacing;
231 top_spacing_ = spacing;
236 type_before_table_ = type_;
242 type_ = type_before_table_;
245 return inside_table_column_;
248 inside_table_column_ = val;
251 return nearest_neighbor_above_;
254 nearest_neighbor_above_ = part;
257 return nearest_neighbor_below_;
260 nearest_neighbor_below_ = part;
266 space_above_ = space;
272 space_below_ = space;
275 return space_to_left_;
278 space_to_left_ = space;
281 return space_to_right_;
284 space_to_right_ = space;
299 owns_blobs_ = owns_blobs;
306 return (bounding_box_.top() + bounding_box_.bottom()) / 2;
310 return (median_top_ + median_bottom_) / 2;
314 return (bounding_box_.left() + bounding_box_.right()) / 2;
321 int XAtY(
int sort_key,
int y)
const {
326 return (right_key - left_key) / vertical_.y();
330 return KeyWidth(left_key_, right_key_);
334 return SortKey(bounding_box_.left(), MidY());
338 return SortKey(bounding_box_.right(), MidY());
342 return XAtY(left_key_, y);
346 return XAtY(right_key_, y);
351 return bounding_box_.right() < other.bounding_box_.
right();
355 return LeftAtY(y) - 1 <= x && x <= RightAtY(y) + 1;
359 return boxes_.empty();
363 return boxes_.singleton();
367 return bounding_box_.x_overlap(other.bounding_box_);
372 return bounding_box_.y_gap(other.bounding_box_) < 0;
377 if (median_bottom_ == INT32_MAX || other.median_bottom_ == INT32_MAX) {
380 return std::min(median_top_, other.median_top_) -
381 std::max(median_bottom_, other.median_bottom_);
386 return std::min(median_right_, other.median_right_) -
387 std::max(median_left_, other.median_left_);
392 if (median_bottom_ == INT32_MAX || other.median_bottom_ == INT32_MAX) {
395 int overlap = VCoreOverlap(other);
396 int height = std::min(median_top_ - median_bottom_,
397 other.median_top_ - other.median_bottom_);
398 return overlap * 3 > height;
403 return left_margin_ <= other.bounding_box_.
left() &&
404 bounding_box_.left() >= other.left_margin_ &&
405 bounding_box_.right() <= other.right_margin_ &&
406 right_margin_ >= other.bounding_box_.
right();
411 return TypesMatch(blob_type_, other.blob_type_);
420 return (type1 == type2 ||
456 return IsVerticalType() && IsLineType();
461 return IsHorizontalType() && IsLineType();
490 void DisownBoxesNoAssert();
495 bool ReleaseNonLeaderBoxes();
504 void ReflectInYAxis();
518 bool MatchingTextColor(
const ColPartition& other)
const;
525 bool ConfirmNoTabViolation(
const ColPartition& other)
const;
529 double fractional_tolerance,
530 double constant_tolerance)
const;
533 bool OKDiacriticMerge(
const ColPartition& candidate,
bool debug)
const;
538 void SetLeftTab(
const TabVector* tab_vector);
539 void SetRightTab(
const TabVector* tab_vector);
543 void CopyLeftTab(
const ColPartition& src,
bool take_box);
544 void CopyRightTab(
const ColPartition& src,
bool take_box);
547 int LeftBlobRule()
const;
549 int RightBlobRule()
const;
558 void SetSpecialBlobsDensity(
562 void ComputeSpecialBlobsDensity();
583 int ok_box_overlap,
bool debug);
600 void ComputeLimits();
603 int CountOverlappingBoxes(
const TBOX& box);
618 int* first_col,
int* last_col);
629 bool MarkAsLeaderIfMonospaced();
634 void SetRegionAndFlowTypesFromProjectionValue(
int value);
642 bool HasGoodBaseline();
646 void AddToWorkingSet(
const ICOORD& bleft,
const ICOORD& tright,
647 int resolution, ColPartition_LIST* used_parts,
648 WorkingPartSet_LIST* working_set);
656 static void LineSpacingBlocks(
const ICOORD& bleft,
const ICOORD& tright,
658 ColPartition_LIST* block_parts,
659 ColPartition_LIST* used_parts,
660 BLOCK_LIST* completed_blocks,
661 TO_BLOCK_LIST* to_blocks);
665 ColPartition_LIST* block_parts,
666 ColPartition_LIST* used_parts);
672 ColPartition_LIST* block_parts,
673 ColPartition_LIST* used_parts);
688 #ifndef GRAPHICS_DISABLED 691 #endif // GRAPHICS_DISABLED 699 void SmoothPartnerRun(
int working_set_count);
718 int mid_y1 = part1->bounding_box_.
y_middle();
719 int mid_y2 = part2->bounding_box_.
y_middle();
720 if ((part2->bounding_box_.
bottom() <= mid_y1 &&
721 mid_y1 <= part2->bounding_box_.
top()) ||
722 (part1->bounding_box_.
bottom() <= mid_y2 &&
723 mid_y2 <= part1->bounding_box_.
top())) {
728 return mid_y2 - mid_y1;
733 first_column_ = column;
736 last_column_ = column;
742 enum SpacingNeighbourhood {
755 void RefinePartnersInternal(
bool upper,
bool get_desperate,
756 ColPartitionGrid* grid);
759 void RefinePartnersByType(
bool upper, ColPartition_CLIST* partners);
764 void RefinePartnerShortcuts(
bool upper, ColPartition_CLIST* partners);
771 void RefineTextPartnersByMerge(
bool upper,
bool desperate,
772 ColPartition_CLIST* partners,
773 ColPartitionGrid* grid);
775 void RefinePartnersByOverlap(
bool upper, ColPartition_CLIST* partners);
778 bool ThisPartitionBetter(
BLOBNBOX* bbox,
const ColPartition& other);
783 static void SmoothSpacings(
int resolution,
int page_height,
784 ColPartition_LIST* parts);
789 static bool OKSpacingBlip(
int resolution,
int median_spacing,
790 ColPartition** parts);
794 bool SpacingEqual(
int spacing,
int resolution)
const;
798 bool SpacingsEqual(
const ColPartition& other,
int resolution)
const;
803 bool SummedSpacingOK(
const ColPartition& other,
804 int spacing,
int resolution)
const;
808 int BottomSpacingMargin(
int resolution)
const;
812 int TopSpacingMargin(
int resolution)
const;
816 bool SizesSimilar(
const ColPartition& other)
const;
824 static void LeftEdgeRun(ColPartition_IT* part_it,
832 static void RightEdgeRun(ColPartition_IT* part_it,
858 int good_blob_score_;
878 BLOBNBOX_CLIST boxes_;
882 ColPartition_CLIST upper_partners_;
884 ColPartition_CLIST lower_partners_;
886 WorkingPartSet* working_set_;
888 bool last_add_was_vertical_;
894 bool desperately_merged_;
905 ColPartitionSet* column_set_;
915 bool inside_table_column_;
918 ColPartition* nearest_neighbor_above_;
920 ColPartition* nearest_neighbor_below_;
940 #endif // TESSERACT_TEXTORD_COLPARTITION_H_
bool PTIsLineType(PolyBlockType type)
bool TypesMatch(const ColPartition &other) const
bool IsHorizontalType() const
void set_right_margin(int margin)
void set_top_spacing(int spacing)
void set_vertical(const ICOORD &v)
void set_space_to_right(int space)
int space_to_left() const
void set_median_height(int height)
BlobRegionType blob_type() const
bool PTIsPulloutType(PolyBlockType type)
void set_working_set(WorkingPartSet *working_set)
int median_height() const
static bool UnMergeableType(BlobRegionType type)
bool IsLeftOf(const ColPartition &other) const
void set_last_column(int column)
void set_space_above(int space)
int bottom_spacing() const
int HCoreOverlap(const ColPartition &other) const
static bool TypesSimilar(PolyBlockType type1, PolyBlockType type2)
bool HOverlaps(const ColPartition &other) const
ColPartitionSet * column_set() const
ColPartition_CLIST * lower_partners()
void set_inside_table_column(bool val)
bool desperately_merged() const
void set_nearest_neighbor_above(ColPartition *part)
bool WithinSameMargins(const ColPartition &other) const
void set_blob_type(BlobRegionType t)
void set_flow(BlobTextFlowType f)
int RightAtY(int y) const
int good_blob_score() const
int SortKey(int x, int y) const
GridSearch< ColPartition, ColPartition_CLIST, ColPartition_C_IT > ColPartitionGridSearch
bool inside_table_column()
void set_space_to_left(int space)
CLISTIZEH(STRING) CLISTIZE(STRING) namespace tesseract
int median_bottom() const
void set_left_margin(int margin)
void set_owns_blobs(bool owns_blobs)
bool ColumnContains(int x, int y) const
bool left_key_tab() const
void set_side_step(int step)
#define ELIST2IZEH(CLASSNAME)
static int SortByBBox(const void *p1, const void *p2)
ColPartition_CLIST * upper_partners()
void set_bottom_spacing(int spacing)
void set_nearest_neighbor_below(ColPartition *part)
bool IsPulloutType() const
int XAtY(int sort_key, int y) const
bool IsUnMergeableType() const
void set_median_width(int width)
static int SortKey(const ICOORD &vertical, int x, int y)
ColPartition * nearest_neighbor_below() const
BlobTextFlowType flow() const
void set_space_below(int space)
const TBOX & bounding_box() const
bool VSignificantCoreOverlap(const ColPartition &other) const
bool right_key_tab() const
int VCoreOverlap(const ColPartition &other) const
bool IsVerticalLine() const
bool PTIsImageType(PolyBlockType type)
bool PTIsTextType(PolyBlockType type)
int space_to_right() const
bool IsVerticalType() const
void set_first_column(int column)
bool IsHorizontalLine() const
bool VOverlaps(const ColPartition &other) const
void set_type(PolyBlockType t)
int KeyWidth(int left_key, int right_key) const
static bool TypesMatch(BlobRegionType type1, BlobRegionType type2)
void set_block_owned(bool owned)
PolyBlockType type() const
static bool IsLineType(BlobRegionType type)
ColPartition * nearest_neighbor_above() const