tesseract  4.0.0-1-g2a2b
SEAM Class Reference

#include <seam.h>

Public Member Functions

 SEAM (float priority, const TPOINT &location)
 
 SEAM (float priority, const TPOINT &location, const SPLIT &split)
 
float priority () const
 
void set_priority (float priority)
 
bool HasAnySplits () const
 
TBOX bounding_box () const
 
bool CombineableWith (const SEAM &other, int max_x_dist, float max_total_priority) const
 
void CombineWith (const SEAM &other)
 
bool ContainedByBlob (const TBLOB &blob) const
 
bool UsesPoint (const EDGEPT *point) const
 
bool SharesPosition (const SEAM &other) const
 
bool OverlappingSplits (const SEAM &other) const
 
void Finalize ()
 
bool IsHealthy (const TBLOB &blob, int min_points, int min_area) const
 
bool PrepareToInsertSeam (const GenericVector< SEAM *> &seams, const GenericVector< TBLOB *> &blobs, int insert_index, bool modify)
 
bool FindBlobWidth (const GenericVector< TBLOB *> &blobs, int index, bool modify)
 
void ApplySeam (bool italic_blob, TBLOB *blob, TBLOB *other_blob) const
 
void UndoSeam (TBLOB *blob, TBLOB *other_blob) const
 
void Print (const char *label) const
 
void Mark (ScrollView *window) const
 
void Hide () const
 
void Reveal () const
 
float FullPriority (int xmin, int xmax, double overlap_knob, int centered_maxwidth, double center_knob, double width_change_knob) const
 

Static Public Member Functions

static void PrintSeams (const char *label, const GenericVector< SEAM *> &seams)
 
static void BreakPieces (const GenericVector< SEAM *> &seams, const GenericVector< TBLOB *> &blobs, int first, int last)
 
static void JoinPieces (const GenericVector< SEAM *> &seams, const GenericVector< TBLOB *> &blobs, int first, int last)
 

Detailed Description

Definition at line 44 of file seam.h.

Constructor & Destructor Documentation

◆ SEAM() [1/2]

SEAM::SEAM ( float  priority,
const TPOINT location 
)
inline

Definition at line 47 of file seam.h.

48  : priority_(priority),
49  location_(location),
50  widthp_(0),
51  widthn_(0),
52  num_splits_(0) {}
float priority() const
Definition: seam.h:65

◆ SEAM() [2/2]

SEAM::SEAM ( float  priority,
const TPOINT location,
const SPLIT split 
)
inline

Definition at line 54 of file seam.h.

55  : priority_(priority),
56  location_(location),
57  widthp_(0),
58  widthn_(0),
59  num_splits_(1) {
60  splits_[0] = split;
61  }
float priority() const
Definition: seam.h:65

Member Function Documentation

◆ ApplySeam()

void SEAM::ApplySeam ( bool  italic_blob,
TBLOB blob,
TBLOB other_blob 
) const

Definition at line 124 of file seam.cpp.

124  {
125  for (int s = 0; s < num_splits_; ++s) {
126  splits_[s].SplitOutlineList(blob->outlines);
127  }
128  blob->ComputeBoundingBoxes();
129 
130  divide_blobs(blob, other_blob, italic_blob, location_);
131 
133  other_blob->EliminateDuplicateOutlines();
134 
135  blob->CorrectBlobOrder(other_blob);
136 }
void EliminateDuplicateOutlines()
Definition: blobs.cpp:490
void ComputeBoundingBoxes()
Definition: blobs.cpp:456
void SplitOutlineList(TESSLINE *outlines) const
Definition: split.cpp:241
void CorrectBlobOrder(TBLOB *next)
Definition: blobs.cpp:511
TESSLINE * outlines
Definition: blobs.h:384
void divide_blobs(TBLOB *blob, TBLOB *other_blob, bool italic_blob, const TPOINT &location)
Definition: blobs.cpp:972

◆ bounding_box()

TBOX SEAM::bounding_box ( ) const

Definition at line 37 of file seam.cpp.

37  {
38  TBOX box(location_.x, location_.y, location_.x, location_.y);
39  for (int s = 0; s < num_splits_; ++s) {
40  box += splits_[s].bounding_box();
41  }
42  return box;
43 }
TBOX bounding_box() const
Definition: split.cpp:50
Definition: rect.h:34
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79

◆ BreakPieces()

void SEAM::BreakPieces ( const GenericVector< SEAM *> &  seams,
const GenericVector< TBLOB *> &  blobs,
int  first,
int  last 
)
static

Definition at line 194 of file seam.cpp.

196  {
197  for (int x = first; x < last; ++x) seams[x]->Reveal();
198 
199  TESSLINE* outline = blobs[first]->outlines;
200  int next_blob = first + 1;
201 
202  while (outline != nullptr && next_blob <= last) {
203  if (outline->next == blobs[next_blob]->outlines) {
204  outline->next = nullptr;
205  outline = blobs[next_blob]->outlines;
206  ++next_blob;
207  } else {
208  outline = outline->next;
209  }
210  }
211 }
TESSLINE * next
Definition: blobs.h:265
LIST last(LIST var_list)
Definition: oldlist.cpp:242
void Reveal() const
Definition: seam.cpp:238

◆ CombineableWith()

bool SEAM::CombineableWith ( const SEAM other,
int  max_x_dist,
float  max_total_priority 
) const

Definition at line 46 of file seam.cpp.

47  {
48  int dist = location_.x - other.location_.x;
49  if (-max_x_dist < dist && dist < max_x_dist &&
50  num_splits_ + other.num_splits_ <= kMaxNumSplits &&
51  priority_ + other.priority_ < max_total_priority &&
52  !OverlappingSplits(other) && !SharesPosition(other)) {
53  return true;
54  } else {
55  return false;
56  }
57 }
bool SharesPosition(const SEAM &other) const
Definition: seam.h:95
bool OverlappingSplits(const SEAM &other) const
Definition: seam.h:103
int16_t x
Definition: blobs.h:78

◆ CombineWith()

void SEAM::CombineWith ( const SEAM other)

Definition at line 60 of file seam.cpp.

60  {
61  priority_ += other.priority_;
62  location_ += other.location_;
63  location_ /= 2;
64 
65  for (uint8_t s = 0; s < other.num_splits_ && num_splits_ < kMaxNumSplits; ++s)
66  splits_[num_splits_++] = other.splits_[s];
67 }

◆ ContainedByBlob()

bool SEAM::ContainedByBlob ( const TBLOB blob) const
inline

Definition at line 79 of file seam.h.

79  {
80  for (int s = 0; s < num_splits_; ++s) {
81  if (!splits_[s].ContainedByBlob(blob)) return false;
82  }
83  return true;
84  }
bool ContainedByBlob(const TBLOB &blob) const
Definition: seam.h:79

◆ Finalize()

void SEAM::Finalize ( )
inline

Definition at line 116 of file seam.h.

116  {
117  for (int s = 0; s < num_splits_; ++s) {
118  splits_[s].point1->MarkChop();
119  splits_[s].point2->MarkChop();
120  }
121  }
EDGEPT * point2
Definition: split.h:104
EDGEPT * point1
Definition: split.h:103
void MarkChop()
Definition: blobs.h:163

◆ FindBlobWidth()

bool SEAM::FindBlobWidth ( const GenericVector< TBLOB *> &  blobs,
int  index,
bool  modify 
)

Definition at line 97 of file seam.cpp.

98  {
99  int num_found = 0;
100  if (modify) {
101  widthp_ = 0;
102  widthn_ = 0;
103  }
104  for (int s = 0; s < num_splits_; ++s) {
105  const SPLIT& split = splits_[s];
106  bool found_split = split.ContainedByBlob(*blobs[index]);
107  // Look right.
108  for (int b = index + 1; !found_split && b < blobs.size(); ++b) {
109  found_split = split.ContainedByBlob(*blobs[b]);
110  if (found_split && b - index > widthp_ && modify) widthp_ = b - index;
111  }
112  // Look left.
113  for (int b = index - 1; !found_split && b >= 0; --b) {
114  found_split = split.ContainedByBlob(*blobs[b]);
115  if (found_split && index - b > widthn_ && modify) widthn_ = index - b;
116  }
117  if (found_split) ++num_found;
118  }
119  return num_found == num_splits_;
120 }
int size() const
Definition: genericvector.h:71
Definition: split.h:37
bool ContainedByBlob(const TBLOB &blob) const
Definition: split.h:65

◆ FullPriority()

float SEAM::FullPriority ( int  xmin,
int  xmax,
double  overlap_knob,
int  centered_maxwidth,
double  center_knob,
double  width_change_knob 
) const

Definition at line 245 of file seam.cpp.

247  {
248  if (num_splits_ == 0) return 0.0f;
249  for (int s = 1; s < num_splits_; ++s) {
250  splits_[s].SplitOutline();
251  }
252  float full_priority =
253  priority_ +
254  splits_[0].FullPriority(xmin, xmax, overlap_knob, centered_maxwidth,
255  center_knob, width_change_knob);
256  for (int s = num_splits_ - 1; s >= 1; --s) {
257  splits_[s].UnsplitOutlines();
258  }
259  return full_priority;
260 }
void UnsplitOutlines() const
Definition: split.cpp:301
void SplitOutline() const
Definition: split.cpp:260
float FullPriority(int xmin, int xmax, double overlap_knob, int centered_maxwidth, double center_knob, double width_change_knob) const
Definition: split.cpp:87

◆ HasAnySplits()

bool SEAM::HasAnySplits ( ) const
inline

Definition at line 67 of file seam.h.

67 { return num_splits_ > 0; }

◆ Hide()

void SEAM::Hide ( ) const

Definition at line 231 of file seam.cpp.

231  {
232  for (int s = 0; s < num_splits_; ++s) {
233  splits_[s].Hide();
234  }
235 }
void Hide() const
Definition: split.cpp:57

◆ IsHealthy()

bool SEAM::IsHealthy ( const TBLOB blob,
int  min_points,
int  min_area 
) const

Definition at line 72 of file seam.cpp.

72  {
73  // TODO(rays) Try testing all the splits. Duplicating original code for now,
74  // which tested only the first.
75  return num_splits_ == 0 || splits_[0].IsHealthy(blob, min_points, min_area);
76 }
bool IsHealthy(const TBLOB &blob, int min_points, int min_area) const
Definition: split.cpp:121

◆ JoinPieces()

void SEAM::JoinPieces ( const GenericVector< SEAM *> &  seams,
const GenericVector< TBLOB *> &  blobs,
int  first,
int  last 
)
static

Definition at line 216 of file seam.cpp.

217  {
218  TESSLINE* outline = blobs[first]->outlines;
219  if (!outline)
220  return;
221 
222  for (int x = first; x < last; ++x) {
223  SEAM *seam = seams[x];
224  if (x - seam->widthn_ >= first && x + seam->widthp_ < last) seam->Hide();
225  while (outline->next) outline = outline->next;
226  outline->next = blobs[x + 1]->outlines;
227  }
228 }
TESSLINE * next
Definition: blobs.h:265
LIST last(LIST var_list)
Definition: oldlist.cpp:242
Definition: seam.h:44
void Hide() const
Definition: seam.cpp:231

◆ Mark()

void SEAM::Mark ( ScrollView window) const

Definition at line 186 of file seam.cpp.

186  {
187  for (int s = 0; s < num_splits_; ++s) splits_[s].Mark(window);
188 }
void Mark(ScrollView *window) const
Definition: seam.cpp:186

◆ OverlappingSplits()

bool SEAM::OverlappingSplits ( const SEAM other) const
inline

Definition at line 103 of file seam.h.

103  {
104  for (int s = 0; s < num_splits_; ++s) {
105  TBOX split1_box = splits_[s].bounding_box();
106  for (int t = 0; t < other.num_splits_; ++t) {
107  TBOX split2_box = other.splits_[t].bounding_box();
108  if (split1_box.y_overlap(split2_box)) return true;
109  }
110  }
111  return false;
112  }
TBOX bounding_box() const
Definition: split.cpp:50
Definition: rect.h:34
bool y_overlap(const TBOX &box) const
Definition: rect.h:428

◆ PrepareToInsertSeam()

bool SEAM::PrepareToInsertSeam ( const GenericVector< SEAM *> &  seams,
const GenericVector< TBLOB *> &  blobs,
int  insert_index,
bool  modify 
)

Definition at line 82 of file seam.cpp.

84  {
85  for (int s = 0; s < insert_index; ++s) {
86  if (!seams[s]->FindBlobWidth(blobs, s, modify)) return false;
87  }
88  if (!FindBlobWidth(blobs, insert_index, modify)) return false;
89  for (int s = insert_index; s < seams.size(); ++s) {
90  if (!seams[s]->FindBlobWidth(blobs, s + 1, modify)) return false;
91  }
92  return true;
93 }
int size() const
Definition: genericvector.h:71
bool FindBlobWidth(const GenericVector< TBLOB *> &blobs, int index, bool modify)
Definition: seam.cpp:97

◆ Print()

void SEAM::Print ( const char *  label) const

Definition at line 160 of file seam.cpp.

160  {
161  tprintf(label);
162  tprintf(" %6.2f @ (%d,%d), p=%d, n=%d ", priority_, location_.x, location_.y,
163  widthp_, widthn_);
164  for (int s = 0; s < num_splits_; ++s) {
165  splits_[s].Print();
166  if (s + 1 < num_splits_) tprintf(", ");
167  }
168  tprintf("\n");
169 }
void Print() const
Definition: split.cpp:225
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79

◆ PrintSeams()

void SEAM::PrintSeams ( const char *  label,
const GenericVector< SEAM *> &  seams 
)
static

Definition at line 173 of file seam.cpp.

173  {
174  if (!seams.empty()) {
175  tprintf("%s\n", label);
176  for (int x = 0; x < seams.size(); ++x) {
177  tprintf("%2d: ", x);
178  seams[x]->Print("");
179  }
180  tprintf("\n");
181  }
182 }
int size() const
Definition: genericvector.h:71
bool empty() const
Definition: genericvector.h:90
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37

◆ priority()

float SEAM::priority ( ) const
inline

Definition at line 65 of file seam.h.

65 { return priority_; }

◆ Reveal()

void SEAM::Reveal ( ) const

Definition at line 238 of file seam.cpp.

238  {
239  for (int s = 0; s < num_splits_; ++s) {
240  splits_[s].Reveal();
241  }
242 }
void Reveal() const
Definition: split.cpp:71

◆ set_priority()

void SEAM::set_priority ( float  priority)
inline

Definition at line 66 of file seam.h.

66 { priority_ = priority; }
float priority() const
Definition: seam.h:65

◆ SharesPosition()

bool SEAM::SharesPosition ( const SEAM other) const
inline

Definition at line 95 of file seam.h.

95  {
96  for (int s = 0; s < num_splits_; ++s) {
97  for (int t = 0; t < other.num_splits_; ++t)
98  if (splits_[s].SharesPosition(other.splits_[t])) return true;
99  }
100  return false;
101  }
bool SharesPosition(const SEAM &other) const
Definition: seam.h:95

◆ UndoSeam()

void SEAM::UndoSeam ( TBLOB blob,
TBLOB other_blob 
) const

Definition at line 140 of file seam.cpp.

140  {
141  if (blob->outlines == nullptr) {
142  blob->outlines = other_blob->outlines;
143  other_blob->outlines = nullptr;
144  }
145 
146  TESSLINE* outline = blob->outlines;
147  while (outline->next) outline = outline->next;
148  outline->next = other_blob->outlines;
149  other_blob->outlines = nullptr;
150  delete other_blob;
151 
152  for (int s = 0; s < num_splits_; ++s) {
153  splits_[s].UnsplitOutlineList(blob);
154  }
155  blob->ComputeBoundingBoxes();
157 }
TESSLINE * next
Definition: blobs.h:265
void UnsplitOutlineList(TBLOB *blob) const
Definition: split.cpp:285
void EliminateDuplicateOutlines()
Definition: blobs.cpp:490
void ComputeBoundingBoxes()
Definition: blobs.cpp:456
TESSLINE * outlines
Definition: blobs.h:384

◆ UsesPoint()

bool SEAM::UsesPoint ( const EDGEPT point) const
inline

Definition at line 88 of file seam.h.

88  {
89  for (int s = 0; s < num_splits_; ++s) {
90  if (splits_[s].UsesPoint(point)) return true;
91  }
92  return false;
93  }
bool UsesPoint(const EDGEPT *point) const
Definition: seam.h:88

The documentation for this class was generated from the following files: