tesseract  5.0.0-alpha-619-ge9db
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 36 of file seam.h.

Constructor & Destructor Documentation

◆ SEAM() [1/2]

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

Definition at line 39 of file seam.h.

41  : priority_(priority),
42  location_(location),
43  widthp_(0),
44  widthn_(0),

◆ SEAM() [2/2]

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

Definition at line 46 of file seam.h.

48  : priority_(priority),
49  location_(location),
50  widthp_(0),
51  widthn_(0),
52  num_splits_(1) {
53  splits_[0] = split;

Member Function Documentation

◆ ApplySeam()

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

Definition at line 116 of file seam.cpp.

117  {
118  for (int s = 0; s < num_splits_; ++s) {
119  splits_[s].SplitOutlineList(blob->outlines);
120  }
121  blob->ComputeBoundingBoxes();
122 
123  divide_blobs(blob, other_blob, italic_blob, location_);
124 
126  other_blob->EliminateDuplicateOutlines();
127 
128  blob->CorrectBlobOrder(other_blob);

◆ bounding_box()

TBOX SEAM::bounding_box ( ) const

Definition at line 29 of file seam.cpp.

30  {
31  TBOX box(location_.x, location_.y, location_.x, location_.y);
32  for (int s = 0; s < num_splits_; ++s) {
33  box += splits_[s].bounding_box();
34  }
35  return box;

◆ BreakPieces()

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

Definition at line 186 of file seam.cpp.

189  {
190  for (int x = first; x < last; ++x) seams[x]->Reveal();
191 
192  TESSLINE* outline = blobs[first]->outlines;
193  int next_blob = first + 1;
194 
195  while (outline != nullptr && next_blob <= last) {
196  if (outline->next == blobs[next_blob]->outlines) {
197  outline->next = nullptr;
198  outline = blobs[next_blob]->outlines;
199  ++next_blob;
200  } else {
201  outline = outline->next;
202  }
203  }

◆ CombineableWith()

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

Definition at line 38 of file seam.cpp.

40  {
41  int dist = location_.x - other.location_.x;
42  if (-max_x_dist < dist && dist < max_x_dist &&
43  num_splits_ + other.num_splits_ <= kMaxNumSplits &&
44  priority_ + other.priority_ < max_total_priority &&
45  !OverlappingSplits(other) && !SharesPosition(other)) {
46  return true;
47  } else {
48  return false;
49  }

◆ CombineWith()

void SEAM::CombineWith ( const SEAM other)

Definition at line 52 of file seam.cpp.

53  {
54  priority_ += other.priority_;
55  location_ += other.location_;
56  location_ /= 2;
57 
58  for (uint8_t s = 0; s < other.num_splits_ && num_splits_ < kMaxNumSplits; ++s)
59  splits_[num_splits_++] = other.splits_[s];

◆ ContainedByBlob()

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

Definition at line 71 of file seam.h.

72  {
73  for (int s = 0; s < num_splits_; ++s) {
74  if (!splits_[s].ContainedByBlob(blob)) return false;
75  }
76  return true;

◆ Finalize()

void SEAM::Finalize ( )
inline

Definition at line 108 of file seam.h.

109  {
110  for (int s = 0; s < num_splits_; ++s) {
111  splits_[s].point1->MarkChop();
112  splits_[s].point2->MarkChop();
113  }

◆ FindBlobWidth()

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

Definition at line 89 of file seam.cpp.

91  {
92  int num_found = 0;
93  if (modify) {
94  widthp_ = 0;
95  widthn_ = 0;
96  }
97  for (int s = 0; s < num_splits_; ++s) {
98  const SPLIT& split = splits_[s];
99  bool found_split = split.ContainedByBlob(*blobs[index]);
100  // Look right.
101  for (int b = index + 1; !found_split && b < blobs.size(); ++b) {
102  found_split = split.ContainedByBlob(*blobs[b]);
103  if (found_split && b - index > widthp_ && modify) widthp_ = b - index;
104  }
105  // Look left.
106  for (int b = index - 1; !found_split && b >= 0; --b) {
107  found_split = split.ContainedByBlob(*blobs[b]);
108  if (found_split && index - b > widthn_ && modify) widthn_ = index - b;
109  }
110  if (found_split) ++num_found;
111  }
112  return num_found == num_splits_;

◆ 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 237 of file seam.cpp.

240  {
241  if (num_splits_ == 0) return 0.0f;
242  for (int s = 1; s < num_splits_; ++s) {
243  splits_[s].SplitOutline();
244  }
245  float full_priority =
246  priority_ +
247  splits_[0].FullPriority(xmin, xmax, overlap_knob, centered_maxwidth,
248  center_knob, width_change_knob);
249  for (int s = num_splits_ - 1; s >= 1; --s) {
250  splits_[s].UnsplitOutlines();
251  }
252  return full_priority;

◆ HasAnySplits()

bool SEAM::HasAnySplits ( ) const
inline

Definition at line 59 of file seam.h.

59 { priority_ = priority; }

◆ Hide()

void SEAM::Hide ( ) const

Definition at line 223 of file seam.cpp.

224  {
225  for (int s = 0; s < num_splits_; ++s) {
226  splits_[s].Hide();
227  }

◆ IsHealthy()

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

Definition at line 64 of file seam.cpp.

65  {
66  // TODO(rays) Try testing all the splits. Duplicating original code for now,
67  // which tested only the first.
68  return num_splits_ == 0 || splits_[0].IsHealthy(blob, min_points, min_area);

◆ JoinPieces()

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

Definition at line 208 of file seam.cpp.

210  {
211  TESSLINE* outline = blobs[first]->outlines;
212  if (!outline)
213  return;
214 
215  for (int x = first; x < last; ++x) {
216  SEAM *seam = seams[x];
217  if (x - seam->widthn_ >= first && x + seam->widthp_ < last) seam->Hide();
218  while (outline->next) outline = outline->next;
219  outline->next = blobs[x + 1]->outlines;
220  }

◆ Mark()

void SEAM::Mark ( ScrollView window) const

Definition at line 178 of file seam.cpp.

179  {
180  for (int s = 0; s < num_splits_; ++s) splits_[s].Mark(window);

◆ OverlappingSplits()

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

Definition at line 95 of file seam.h.

96  {
97  for (int s = 0; s < num_splits_; ++s) {
98  TBOX split1_box = splits_[s].bounding_box();
99  for (int t = 0; t < other.num_splits_; ++t) {
100  TBOX split2_box = other.splits_[t].bounding_box();
101  if (split1_box.y_overlap(split2_box)) return true;
102  }
103  }
104  return false;

◆ PrepareToInsertSeam()

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

Definition at line 74 of file seam.cpp.

77  {
78  for (int s = 0; s < insert_index; ++s) {
79  if (!seams[s]->FindBlobWidth(blobs, s, modify)) return false;
80  }
81  if (!FindBlobWidth(blobs, insert_index, modify)) return false;
82  for (int s = insert_index; s < seams.size(); ++s) {
83  if (!seams[s]->FindBlobWidth(blobs, s + 1, modify)) return false;
84  }
85  return true;

◆ Print()

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

Definition at line 152 of file seam.cpp.

153  {
154  tprintf(label);
155  tprintf(" %6.2f @ (%d,%d), p=%d, n=%d ", priority_, location_.x, location_.y,
156  widthp_, widthn_);
157  for (int s = 0; s < num_splits_; ++s) {
158  splits_[s].Print();
159  if (s + 1 < num_splits_) tprintf(", ");
160  }
161  tprintf("\n");

◆ PrintSeams()

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

Definition at line 165 of file seam.cpp.

166  {
167  if (!seams.empty()) {
168  tprintf("%s\n", label);
169  for (int x = 0; x < seams.size(); ++x) {
170  tprintf("%2d: ", x);
171  seams[x]->Print("");
172  }
173  tprintf("\n");
174  }

◆ priority()

float SEAM::priority ( ) const
inline

Definition at line 57 of file seam.h.

58 { return priority_; }

◆ Reveal()

void SEAM::Reveal ( ) const

Definition at line 230 of file seam.cpp.

231  {
232  for (int s = 0; s < num_splits_; ++s) {
233  splits_[s].Reveal();
234  }

◆ set_priority()

void SEAM::set_priority ( float  priority)
inline

Definition at line 58 of file seam.h.

58 { return priority_; }

◆ SharesPosition()

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

Definition at line 87 of file seam.h.

88  {
89  for (int s = 0; s < num_splits_; ++s) {
90  for (int t = 0; t < other.num_splits_; ++t)
91  if (splits_[s].SharesPosition(other.splits_[t])) return true;
92  }
93  return false;

◆ UndoSeam()

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

Definition at line 132 of file seam.cpp.

133  {
134  if (blob->outlines == nullptr) {
135  blob->outlines = other_blob->outlines;
136  other_blob->outlines = nullptr;
137  }
138 
139  TESSLINE* outline = blob->outlines;
140  while (outline->next) outline = outline->next;
141  outline->next = other_blob->outlines;
142  other_blob->outlines = nullptr;
143  delete other_blob;
144 
145  for (int s = 0; s < num_splits_; ++s) {
146  splits_[s].UnsplitOutlineList(blob);
147  }
148  blob->ComputeBoundingBoxes();

◆ UsesPoint()

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

Definition at line 80 of file seam.h.

81  {
82  for (int s = 0; s < num_splits_; ++s) {
83  if (splits_[s].UsesPoint(point)) return true;
84  }
85  return false;

The documentation for this class was generated from the following files:
SEAM::OverlappingSplits
bool OverlappingSplits(const SEAM &other) const
Definition: seam.h:95
TBLOB::ComputeBoundingBoxes
void ComputeBoundingBoxes()
Definition: blobs.cpp:445
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
SEAM::ContainedByBlob
bool ContainedByBlob(const TBLOB &blob) const
Definition: seam.h:71
TBLOB::outlines
TESSLINE * outlines
Definition: blobs.h:398
SPLIT::Print
void Print() const
Definition: split.cpp:214
TESSLINE
Definition: blobs.h:201
TESSLINE::next
TESSLINE * next
Definition: blobs.h:279
EDGEPT::MarkChop
void MarkChop()
Definition: blobs.h:177
SEAM
Definition: seam.h:36
SPLIT::ContainedByBlob
bool ContainedByBlob(const TBLOB &blob) const
Definition: split.h:62
TBOX::y_overlap
bool y_overlap(const TBOX &box) const
Definition: rect.h:418
SPLIT::Hide
void Hide() const
Definition: split.cpp:49
last
LIST last(LIST var_list)
Definition: oldlist.cpp:151
TPOINT::x
int16_t x
Definition: blobs.h:91
SPLIT::UnsplitOutlines
void UnsplitOutlines() const
Definition: split.cpp:290
TPOINT::y
int16_t y
Definition: blobs.h:92
GenericVector::empty
bool empty() const
Definition: genericvector.h:86
SEAM::Reveal
void Reveal() const
Definition: seam.cpp:230
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
divide_blobs
void divide_blobs(TBLOB *blob, TBLOB *other_blob, bool italic_blob, const TPOINT &location)
Definition: blobs.cpp:958
SPLIT::UnsplitOutlineList
void UnsplitOutlineList(TBLOB *blob) const
Definition: split.cpp:274
TBLOB::EliminateDuplicateOutlines
void EliminateDuplicateOutlines()
Definition: blobs.cpp:478
SEAM::UsesPoint
bool UsesPoint(const EDGEPT *point) const
Definition: seam.h:80
TBLOB::CorrectBlobOrder
void CorrectBlobOrder(TBLOB *next)
Definition: blobs.cpp:499
SEAM::Mark
void Mark(ScrollView *window) const
Definition: seam.cpp:178
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
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
SEAM::priority
float priority() const
Definition: seam.h:57
SEAM::SharesPosition
bool SharesPosition(const SEAM &other) const
Definition: seam.h:87
SEAM::Hide
void Hide() const
Definition: seam.cpp:223
GenericVector::size
int size() const
Definition: genericvector.h:71
SEAM::FindBlobWidth
bool FindBlobWidth(const GenericVector< TBLOB * > &blobs, int index, bool modify)
Definition: seam.cpp:89
SPLIT::point1
EDGEPT * point1
Definition: split.h:100
SPLIT::Reveal
void Reveal() const
Definition: split.cpp:63
TBOX
Definition: rect.h:33