tesseract  5.0.0-alpha-619-ge9db
split.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * File: split.h
4  * Author: Mark Seaman, SW Productivity
5  * Status: Reusable Software Component
6  *
7  * (c) Copyright 1987, Hewlett-Packard Company.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  *****************************************************************************/
19 #ifndef SPLIT_H
20 #define SPLIT_H
21 
22 /*----------------------------------------------------------------------
23  I n c l u d e s
24 ----------------------------------------------------------------------*/
25 
26 #include "blobs.h" // for EDGEPT, TBLOB, TESSLINE
27 #include "params.h" // for BOOL_VAR_H, BoolParam
28 #include "rect.h" // for TBOX
29 
30 class ScrollView;
31 
32 /*----------------------------------------------------------------------
33  T y p e s
34 ----------------------------------------------------------------------*/
35 struct SPLIT {
36  SPLIT() : point1(nullptr), point2(nullptr) {}
37  SPLIT(EDGEPT* pt1, EDGEPT* pt2) : point1(pt1), point2(pt2) {}
38 
39  // Returns the bounding box of all the points in the split.
40  TBOX bounding_box() const;
41  // Returns the bounding box of the outline from point1 to point2.
42  TBOX Box12() const { return point1->SegmentBox(point2); }
43  // Returns the bounding box of the outline from point1 to point1.
44  TBOX Box21() const { return point2->SegmentBox(point1); }
45  // Returns the bounding box of the out
46 
47  // Hides the SPLIT so the outlines appear not to be cut by it.
48  void Hide() const;
49  // Undoes hide, so the outlines are cut by the SPLIT.
50  void Reveal() const;
51 
52  // Returns true if the given EDGEPT is used by this SPLIT, checking only
53  // the EDGEPT pointer, not the coordinates.
54  bool UsesPoint(const EDGEPT* point) const {
55  return point1 == point || point2 == point;
56  }
57  // Returns true if the other SPLIT has any position shared with *this.
58  bool SharesPosition(const SPLIT& other) const {
59  return point1->EqualPos(*other.point1) || point1->EqualPos(*other.point2) ||
60  point2->EqualPos(*other.point1) || point2->EqualPos(*other.point2);
61  }
62  // Returns true if both points are contained within the blob.
63  bool ContainedByBlob(const TBLOB& blob) const {
64  return blob.Contains(point1->pos) && blob.Contains(point2->pos);
65  }
66  // Returns true if both points are contained within the outline.
67  bool ContainedByOutline(const TESSLINE& outline) const {
68  return outline.Contains(point1->pos) && outline.Contains(point2->pos);
69  }
70  // Compute a split priority based on the bounding boxes of the parts.
71  // The arguments here are config parameters defined in Wordrec. Add chop_
72  // to the beginning of the name.
73  float FullPriority(int xmin, int xmax, double overlap_knob,
74  int centered_maxwidth, double center_knob,
75  double width_change_knob) const;
76  // Returns true if *this SPLIT appears OK in the sense that it does not cross
77  // any outlines and does not chop off any ridiculously small pieces.
78  bool IsHealthy(const TBLOB& blob, int min_points, int min_area) const;
79  // Returns true if the split generates a small chunk in terms of either area
80  // or number of points.
81  bool IsLittleChunk(int min_points, int min_area) const;
82 
83  void Print() const;
84 #ifndef GRAPHICS_DISABLED
85  // Draws the split in the given window.
86  void Mark(ScrollView* window) const;
87 #endif
88 
89  // Creates two outlines out of one by splitting the original one in half.
90  // Inserts the resulting outlines into the given list.
91  void SplitOutlineList(TESSLINE* outlines) const;
92  // Makes a split between these two edge points, but does not affect the
93  // outlines to which they belong.
94  void SplitOutline() const;
95  // Undoes the effect of SplitOutlineList, correcting the outlines for undoing
96  // the split, but possibly leaving some duplicate outlines.
97  void UnsplitOutlineList(TBLOB* blob) const;
98  // Removes the split that was put between these two points.
99  void UnsplitOutlines() const;
100 
102  EDGEPT *point2;
103 };
104 
105 /*----------------------------------------------------------------------
106  V a r i a b l e s
107 ----------------------------------------------------------------------*/
108 
109 extern BOOL_VAR_H(wordrec_display_splits, 0, "Display splits");
110 
111 /*----------------------------------------------------------------------
112  F u n c t i o n s
113 ----------------------------------------------------------------------*/
114 EDGEPT *make_edgept(int x, int y, EDGEPT *next, EDGEPT *prev);
115 
116 void remove_edgept(EDGEPT *point);
117 
118 #endif
ScrollView
Definition: scrollview.h:97
SPLIT::UsesPoint
bool UsesPoint(const EDGEPT *point) const
Definition: split.h:53
wordrec_display_splits
bool wordrec_display_splits
Definition: split.cpp:39
SPLIT::IsHealthy
bool IsHealthy(const TBLOB &blob, int min_points, int min_area) const
Definition: split.cpp:113
SPLIT::SplitOutlineList
void SplitOutlineList(TESSLINE *outlines) const
Definition: split.cpp:230
SPLIT::point2
EDGEPT * point2
Definition: split.h:101
EDGEPT::EqualPos
bool EqualPos(const EDGEPT &other) const
Definition: blobs.h:126
SPLIT::IsLittleChunk
bool IsLittleChunk(int min_points, int min_area) const
Definition: split.cpp:120
SPLIT::Print
void Print() const
Definition: split.cpp:214
params.h
TESSLINE
Definition: blobs.h:201
TESSLINE::Contains
bool Contains(const TPOINT &pt) const
Definition: blobs.h:255
rect.h
blobs.h
TBLOB::Contains
bool Contains(const TPOINT &pt) const
Definition: blobs.h:345
SPLIT::ContainedByBlob
bool ContainedByBlob(const TBLOB &blob) const
Definition: split.h:62
SPLIT::Hide
void Hide() const
Definition: split.cpp:49
SPLIT::Mark
void Mark(ScrollView *window) const
Definition: split.cpp:221
SPLIT::UnsplitOutlines
void UnsplitOutlines() const
Definition: split.cpp:290
SPLIT::Box12
TBOX Box12() const
Definition: split.h:41
SPLIT::ContainedByOutline
bool ContainedByOutline(const TESSLINE &outline) const
Definition: split.h:66
EDGEPT::SegmentBox
TBOX SegmentBox(const EDGEPT *end) const
Definition: blobs.h:129
SPLIT::FullPriority
float FullPriority(int xmin, int xmax, double overlap_knob, int centered_maxwidth, double center_knob, double width_change_knob) const
Definition: split.cpp:79
SPLIT::SPLIT
SPLIT(EDGEPT *pt1, EDGEPT *pt2)
Definition: split.h:36
SPLIT::UnsplitOutlineList
void UnsplitOutlineList(TBLOB *blob) const
Definition: split.cpp:274
SPLIT::Box21
TBOX Box21() const
Definition: split.h:43
TBLOB
Definition: blobs.h:282
BOOL_VAR_H
#define BOOL_VAR_H(name, val, comment)
Definition: params.h:294
SPLIT
Definition: split.h:34
SPLIT::SplitOutline
void SplitOutline() const
Definition: split.cpp:249
SPLIT::bounding_box
TBOX bounding_box() const
Definition: split.cpp:42
EDGEPT
Definition: blobs.h:97
remove_edgept
void remove_edgept(EDGEPT *point)
Definition: split.cpp:196
SPLIT::SPLIT
SPLIT()
Definition: split.h:35
SPLIT::SharesPosition
bool SharesPosition(const SPLIT &other) const
Definition: split.h:57
make_edgept
EDGEPT * make_edgept(int x, int y, EDGEPT *next, EDGEPT *prev)
Definition: split.cpp:136
SPLIT::point1
EDGEPT * point1
Definition: split.h:100
SPLIT::Reveal
void Reveal() const
Definition: split.cpp:63
EDGEPT::pos
TPOINT pos
Definition: blobs.h:184
TBOX
Definition: rect.h:33