21 #ifndef TESSERACT_TEXTORD_COLPARTITION_H_ 22 #define TESSERACT_TEXTORD_COLPARTITION_H_ 28 #include "scrollview.h" 30 #include "tabvector.h" 43 class WorkingPartSet_LIST;
84 static ColPartition* MakeLinePartition(BlobRegionType blob_type,
95 PolyBlockType block_type,
96 BlobRegionType blob_type,
97 BlobTextFlowType flow);
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;
155 BlobTextFlowType
flow()
const {
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;
235 if (type_ != PT_TABLE) {
236 type_before_table_ = type_;
241 if (type_ == PT_TABLE)
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;
298 ASSERT_HOST(boxes_.empty());
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);
355 return LeftAtY(y) - 1 <= x && x <= RightAtY(y) + 1;
359 return boxes_.empty();
363 return boxes_.singleton();
377 if (median_bottom_ == INT32_MAX || other.
median_bottom_ == INT32_MAX) {
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_,
398 return overlap * 3 > height;
411 return TypesMatch(blob_type_, other.
blob_type_);
413 static bool TypesMatch(BlobRegionType type1, BlobRegionType type2) {
414 return (type1 == type2 || type1 == BRT_UNKNOWN || type2 == BRT_UNKNOWN) &&
420 return (type1 == type2 ||
421 (type1 == PT_FLOWING_TEXT && type2 == PT_INLINE_EQUATION) ||
422 (type2 == PT_FLOWING_TEXT && type1 == PT_INLINE_EQUATION));
427 return PTIsLineType(type_);
431 return PTIsImageType(type_);
435 return PTIsTextType(type_);
439 return PTIsPulloutType(type_);
443 return blob_type_ == BRT_VERT_TEXT || blob_type_ == BRT_VLINE;
447 return blob_type_ == BRT_TEXT || blob_type_ == BRT_HLINE;
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;
552 float SpecialBlobsDensity(
const BlobSpecialTextType type)
const;
554 int SpecialBlobsCount(
const BlobSpecialTextType type);
558 void SetSpecialBlobsDensity(
559 const BlobSpecialTextType type,
const float density);
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);
705 void RefinePartners(PolyBlockType type,
bool get_desperate,
728 return mid_y2 - mid_y1;
733 first_column_ = column;
736 last_column_ = column;
755 void RefinePartnersInternal(
bool upper,
bool get_desperate,
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,
775 void RefinePartnersByOverlap(
bool upper, ColPartition_CLIST* partners);
783 static void SmoothSpacings(
int resolution,
int page_height,
784 ColPartition_LIST* parts);
789 static bool OKSpacingBlip(
int resolution,
int median_spacing,
794 bool SpacingEqual(
int spacing,
int resolution)
const;
798 bool SpacingsEqual(
const ColPartition& other,
int resolution)
const;
804 int spacing,
int resolution)
const;
808 int BottomSpacingMargin(
int resolution)
const;
812 int TopSpacingMargin(
int resolution)
const;
824 static void LeftEdgeRun(ColPartition_IT* part_it,
832 static void RightEdgeRun(ColPartition_IT* part_it,
930 float special_blobs_densities_[BSTT_COUNT];
940 #endif // TESSERACT_TEXTORD_COLPARTITION_H_ bool desperately_merged_
Definition: colpartition.h:894
bool left_key_tab() const
Definition: colpartition.h:170
void set_space_to_right(int space)
Definition: colpartition.h:283
Definition: colpartitiongrid.h:33
static bool UnMergeableType(BlobRegionType type)
Definition: blobbox.h:431
bool IsUnMergeableType() const
Definition: colpartition.h:450
Definition: workingpartset.h:32
void set_nearest_neighbor_below(ColPartition *part)
Definition: colpartition.h:259
void set_owns_blobs(bool owns_blobs)
Definition: colpartition.h:295
int top_spacing_
Definition: colpartition.h:908
int median_bottom_
Definition: colpartition.h:845
bool good_width_
Definition: colpartition.h:860
ColPartition * nearest_neighbor_below_
Definition: colpartition.h:920
int median_width_
Definition: colpartition.h:853
void set_type(PolyBlockType t)
Definition: colpartition.h:185
int right_key() const
Definition: colpartition.h:179
int right_margin_
Definition: colpartition.h:841
void set_space_to_left(int space)
Definition: colpartition.h:277
int16_t right() const
Definition: rect.h:79
BlobRegionType blob_type_
Definition: colpartition.h:855
int median_height() const
Definition: colpartition.h:137
int median_right() const
Definition: colpartition.h:134
Definition: colpartition.h:52
bool VOverlaps(const ColPartition &other) const
Definition: colpartition.h:371
int x_middle() const
Definition: rect.h:85
int median_width() const
Definition: colpartition.h:143
ColPartition_CLIST * lower_partners()
Definition: colpartition.h:200
bool IsHorizontalLine() const
Definition: colpartition.h:460
static int SortByBBox(const void *p1, const void *p2)
Definition: colpartition.h:715
Definition: colpartitionset.h:40
void set_median_height(int height)
Definition: colpartition.h:140
int space_to_right() const
Definition: colpartition.h:280
int LeftAtY(int y) const
Definition: colpartition.h:341
bool IsImageType() const
Definition: colpartition.h:430
int median_top() const
Definition: colpartition.h:125
int ColumnWidth() const
Definition: colpartition.h:329
Definition: tabvector.h:112
int XAtY(int y) const
Definition: tabvector.h:189
bool owns_blobs_
Definition: colpartition.h:928
ColPartitionSet * column_set_
Definition: colpartition.h:905
bool right_key_tab_
Definition: colpartition.h:866
uint8_t * color1()
Definition: colpartition.h:286
int space_above_
Definition: colpartition.h:921
void set_right_margin(int margin)
Definition: colpartition.h:122
void set_nearest_neighbor_above(ColPartition *part)
Definition: colpartition.h:253
PolyBlockType type_before_table_
Definition: colpartition.h:914
bool right_key_tab() const
Definition: colpartition.h:176
PolyBlockType type_
Definition: colpartition.h:876
ColPartition_CLIST * upper_partners()
Definition: colpartition.h:197
int median_height_
Definition: colpartition.h:848
void set_blob_type(BlobRegionType t)
Definition: colpartition.h:152
ColPartition_CLIST upper_partners_
Definition: colpartition.h:882
int first_column_
Definition: colpartition.h:902
int left_margin_
Definition: colpartition.h:839
bool IsVerticalType() const
Definition: colpartition.h:442
int BoxLeftKey() const
Definition: colpartition.h:333
Definition: baseapi.cpp:94
int good_blob_score_
Definition: colpartition.h:858
int boxes_count() const
Definition: colpartition.h:191
bool good_column_
Definition: colpartition.h:862
bool HOverlaps(const ColPartition &other) const
Definition: colpartition.h:366
int space_below_
Definition: colpartition.h:922
int space_to_left() const
Definition: colpartition.h:274
void set_vertical(const ICOORD &v)
Definition: colpartition.h:194
void set_block_owned(bool owned)
Definition: colpartition.h:209
int16_t bottom() const
Definition: rect.h:65
bool left_key_tab_
Definition: colpartition.h:864
bool IsEmpty() const
Definition: colpartition.h:358
void set_bottom_spacing(int spacing)
Definition: colpartition.h:224
const TBOX & bounding_box() const
Definition: colpartition.h:110
int median_bottom() const
Definition: colpartition.h:128
ColPartition * nearest_neighbor_below() const
Definition: colpartition.h:256
bool good_width() const
Definition: colpartition.h:164
bool ColumnContains(int x, int y) const
Definition: colpartition.h:354
int KeyWidth(int left_key, int right_key) const
Definition: colpartition.h:325
bool TypesMatch(const ColPartition &other) const
Definition: colpartition.h:410
bool IsSingleton() const
Definition: colpartition.h:362
int RightAtY(int y) const
Definition: colpartition.h:345
ColPartition * nearest_neighbor_above_
Definition: colpartition.h:918
Definition: colpartition.h:743
static bool IsLineType(BlobRegionType type)
Definition: blobbox.h:427
void set_working_set(WorkingPartSet *working_set)
Definition: colpartition.h:203
int side_step_
Definition: colpartition.h:907
bool VSignificantCoreOverlap(const ColPartition &other) const
Definition: colpartition.h:391
Definition: blobbox.h:144
int left_margin() const
Definition: colpartition.h:113
Definition: colpartition.h:745
void set_inside_table_column(bool val)
Definition: colpartition.h:247
BLOBNBOX_CLIST boxes_
Definition: colpartition.h:878
void set_median_width(int width)
Definition: colpartition.h:146
void set_first_column(int column)
Definition: colpartition.h:732
int bottom_spacing_
Definition: colpartition.h:909
ICOORD vertical_
Definition: colpartition.h:880
int space_above() const
Definition: colpartition.h:262
bool IsPulloutType() const
Definition: colpartition.h:438
bool WithinSameMargins(const ColPartition &other) const
Definition: colpartition.h:402
uint8_t * color2()
Definition: colpartition.h:289
bool desperately_merged() const
Definition: colpartition.h:212
int right_margin() const
Definition: colpartition.h:119
BlobTextFlowType flow() const
Definition: colpartition.h:155
int SortKey(int x, int y) const
Definition: colpartition.h:317
WorkingPartSet * working_set_
Definition: colpartition.h:886
Definition: tesscallback.h:1673
int median_left_
Definition: colpartition.h:850
Definition: colpartition.h:746
ColPartition * nearest_neighbor_above() const
Definition: colpartition.h:250
int XAtY(int sort_key, int y) const
Definition: colpartition.h:321
static bool TypesSimilar(PolyBlockType type1, PolyBlockType type2)
Definition: colpartition.h:419
int y_middle() const
Definition: rect.h:88
void clear_table_type()
Definition: colpartition.h:240
void set_flow(BlobTextFlowType f)
Definition: colpartition.h:158
int median_top_
Definition: colpartition.h:846
bool good_column() const
Definition: colpartition.h:167
int bottom_spacing() const
Definition: colpartition.h:221
ColPartitionSet * column_set() const
Definition: colpartition.h:215
Definition: blobbox.h:556
bool block_owned() const
Definition: colpartition.h:206
int left_key_
Definition: colpartition.h:873
integer coordinate
Definition: points.h:32
bool inside_table_column()
Definition: colpartition.h:244
int16_t top() const
Definition: rect.h:58
void set_table_type()
Definition: colpartition.h:234
bool IsTextType() const
Definition: colpartition.h:434
Definition: colpartition.h:53
void set_space_above(int space)
Definition: colpartition.h:265
int space_below() const
Definition: colpartition.h:268
bool last_add_was_vertical_
Definition: colpartition.h:888
int MidX() const
Definition: colpartition.h:313
int median_right_
Definition: colpartition.h:851
Definition: colpartition.h:51
void set_top_spacing(int spacing)
Definition: colpartition.h:230
bool block_owned_
Definition: colpartition.h:891
int top_spacing() const
Definition: colpartition.h:227
int HCoreOverlap(const ColPartition &other) const
Definition: colpartition.h:385
void set_last_column(int column)
Definition: colpartition.h:735
int16_t left() const
Definition: rect.h:72
bool IsLineType() const
Definition: colpartition.h:426
int VCoreOverlap(const ColPartition &other) const
Definition: colpartition.h:376
Definition: colpartition.h:744
void set_space_below(int space)
Definition: colpartition.h:271
static int SortKey(const ICOORD &vertical, int x, int y)
Definition: tabvector.h:280
Definition: colpartition.h:49
int MidY() const
Definition: colpartition.h:305
SpacingNeighbourhood
Definition: colpartition.h:742
bool IsVerticalLine() const
Definition: colpartition.h:455
int BoxRightKey() const
Definition: colpartition.h:337
void set_side_step(int step)
Definition: colpartition.h:218
Definition: blobbox.h:705
const int kRGBRMSColors
Definition: colpartition.h:37
int MedianY() const
Definition: colpartition.h:309
int space_to_right_
Definition: colpartition.h:924
BlobTextFlowType flow_
Definition: colpartition.h:856
ColPartition_CLIST lower_partners_
Definition: colpartition.h:884
BLOBNBOX_CLIST * boxes()
Definition: colpartition.h:188
PolyBlockType type() const
Definition: colpartition.h:182
bool IsLeftOf(const ColPartition &other) const
Definition: colpartition.h:350
bool inside_table_column_
Definition: colpartition.h:915
TBOX bounding_box_
Definition: colpartition.h:843
BlobRegionType blob_type() const
Definition: colpartition.h:149
void set_left_margin(int margin)
Definition: colpartition.h:116
ColumnSpanningType
Definition: colpartition.h:48
int median_left() const
Definition: colpartition.h:131
Definition: colpartition.h:50
bool owns_blobs() const
Definition: colpartition.h:292
int good_blob_score() const
Definition: colpartition.h:161
Definition: colpartition.h:747
bool IsHorizontalType() const
Definition: colpartition.h:446
int last_column_
Definition: colpartition.h:903
Definition: colpartition.h:68
Definition: colpartition.h:748
int right_key_
Definition: colpartition.h:874
static bool TypesMatch(BlobRegionType type1, BlobRegionType type2)
Definition: colpartition.h:413
int left_key() const
Definition: colpartition.h:173
int space_to_left_
Definition: colpartition.h:923