tesseract  4.1.0
TESSLINE Struct Reference

#include <blobs.h>

Public Member Functions

 TESSLINE ()
 
 TESSLINE (const TESSLINE &src)
 
 ~TESSLINE ()
 
TESSLINEoperator= (const TESSLINE &src)
 
void CopyFrom (const TESSLINE &src)
 
void Clear ()
 
void Normalize (const DENORM &denorm)
 
void Rotate (const FCOORD rotation)
 
void Move (const ICOORD vec)
 
void Scale (float factor)
 
void SetupFromPos ()
 
void ComputeBoundingBox ()
 
void MinMaxCrossProduct (const TPOINT vec, int *min_xp, int *max_xp) const
 
TBOX bounding_box () const
 
bool SameBox (const TESSLINE &other) const
 
bool SegmentCrosses (const TPOINT &pt1, const TPOINT &pt2) const
 
bool Contains (const TPOINT &pt) const
 
void plot (ScrollView *window, ScrollView::Color color, ScrollView::Color child_color)
 
EDGEPTFindBestStartPt () const
 
int BBArea () const
 

Static Public Member Functions

static TESSLINEBuildFromOutlineList (EDGEPT *outline)
 

Public Attributes

TPOINT topleft
 
TPOINT botright
 
TPOINT start
 
bool is_hole
 
EDGEPTloop
 
TESSLINEnext
 

Detailed Description

Definition at line 182 of file blobs.h.

Constructor & Destructor Documentation

TESSLINE::TESSLINE ( )
inline

Definition at line 183 of file blobs.h.

183 : is_hole(false), loop(nullptr), next(nullptr) {}
TESSLINE * next
Definition: blobs.h:260
EDGEPT * loop
Definition: blobs.h:259
bool is_hole
Definition: blobs.h:258
TESSLINE::TESSLINE ( const TESSLINE src)
inline

Definition at line 184 of file blobs.h.

184  : loop(nullptr), next(nullptr) {
185  CopyFrom(src);
186  }
TESSLINE * next
Definition: blobs.h:260
void CopyFrom(const TESSLINE &src)
Definition: blobs.cpp:119
EDGEPT * loop
Definition: blobs.h:259
TESSLINE::~TESSLINE ( )
inline

Definition at line 187 of file blobs.h.

187  {
188  Clear();
189  }
void Clear()
Definition: blobs.cpp:146

Member Function Documentation

int TESSLINE::BBArea ( ) const
inline

Definition at line 251 of file blobs.h.

251  {
252  return (botright.x - topleft.x) * (topleft.y - botright.y);
253  }
int16_t x
Definition: blobs.h:73
TPOINT topleft
Definition: blobs.h:255
TPOINT botright
Definition: blobs.h:256
int16_t y
Definition: blobs.h:74
TBOX TESSLINE::bounding_box ( ) const

Definition at line 261 of file blobs.cpp.

261  {
262  return TBOX(topleft.x, botright.y, botright.x, topleft.y);
263 }
Definition: rect.h:34
int16_t x
Definition: blobs.h:73
TPOINT topleft
Definition: blobs.h:255
TPOINT botright
Definition: blobs.h:256
int16_t y
Definition: blobs.h:74
TESSLINE * TESSLINE::BuildFromOutlineList ( EDGEPT outline)
static

Definition at line 98 of file blobs.cpp.

98  {
99  auto* result = new TESSLINE;
100  result->loop = outline;
101  if (outline->src_outline != nullptr) {
102  // ASSUMPTION: This function is only ever called from ApproximateOutline
103  // and therefore either all points have a src_outline or all do not.
104  // Just as SetupFromPos sets the vectors from the vertices, setup the
105  // step_count members to indicate the (positive) number of original
106  // C_OUTLINE steps to the next vertex.
107  EDGEPT* pt = outline;
108  do {
109  pt->step_count = pt->next->start_step - pt->start_step;
110  if (pt->step_count < 0) pt->step_count += pt->src_outline->pathlength();
111  pt = pt->next;
112  } while (pt != outline);
113  }
114  result->SetupFromPos();
115  return result;
116 }
int step_count
Definition: blobs.h:176
TESSLINE()
Definition: blobs.h:183
EDGEPT * next
Definition: blobs.h:171
int start_step
Definition: blobs.h:175
Definition: blobs.h:78
int32_t pathlength() const
Definition: coutln.h:135
C_OUTLINE * src_outline
Definition: blobs.h:173
void TESSLINE::Clear ( )

Definition at line 146 of file blobs.cpp.

146  {
147  if (loop == nullptr) return;
148 
149  EDGEPT* this_edge = loop;
150  do {
151  EDGEPT* next_edge = this_edge->next;
152  delete this_edge;
153  this_edge = next_edge;
154  } while (this_edge != loop);
155  loop = nullptr;
156 }
EDGEPT * next
Definition: blobs.h:171
EDGEPT * loop
Definition: blobs.h:259
Definition: blobs.h:78
void TESSLINE::ComputeBoundingBox ( )

Definition at line 217 of file blobs.cpp.

217  {
218  int minx = INT32_MAX;
219  int miny = INT32_MAX;
220  int maxx = -INT32_MAX;
221  int maxy = -INT32_MAX;
222 
223  // Find boundaries.
224  start = loop->pos;
225  EDGEPT* this_edge = loop;
226  do {
227  if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
228  if (this_edge->pos.x < minx) minx = this_edge->pos.x;
229  if (this_edge->pos.y < miny) miny = this_edge->pos.y;
230  if (this_edge->pos.x > maxx) maxx = this_edge->pos.x;
231  if (this_edge->pos.y > maxy) maxy = this_edge->pos.y;
232  }
233  this_edge = this_edge->next;
234  } while (this_edge != loop);
235  // Reset bounds.
236  topleft.x = minx;
237  topleft.y = maxy;
238  botright.x = maxx;
239  botright.y = miny;
240 }
int16_t x
Definition: blobs.h:73
bool IsHidden() const
Definition: blobs.h:155
EDGEPT * next
Definition: blobs.h:171
EDGEPT * loop
Definition: blobs.h:259
TPOINT pos
Definition: blobs.h:165
TPOINT topleft
Definition: blobs.h:255
TPOINT botright
Definition: blobs.h:256
int16_t y
Definition: blobs.h:74
Definition: blobs.h:78
TPOINT start
Definition: blobs.h:257
EDGEPT * prev
Definition: blobs.h:172
bool TESSLINE::Contains ( const TPOINT pt) const
inline

Definition at line 236 of file blobs.h.

236  {
237  return topleft.x <= pt.x && pt.x <= botright.x &&
238  botright.y <= pt.y && pt.y <= topleft.y;
239  }
int16_t x
Definition: blobs.h:73
TPOINT topleft
Definition: blobs.h:255
TPOINT botright
Definition: blobs.h:256
int16_t y
Definition: blobs.h:74
void TESSLINE::CopyFrom ( const TESSLINE src)

Definition at line 119 of file blobs.cpp.

119  {
120  Clear();
121  topleft = src.topleft;
122  botright = src.botright;
123  start = src.start;
124  is_hole = src.is_hole;
125  if (src.loop != nullptr) {
126  EDGEPT* prevpt = nullptr;
127  EDGEPT* newpt = nullptr;
128  EDGEPT* srcpt = src.loop;
129  do {
130  newpt = new EDGEPT(*srcpt);
131  if (prevpt == nullptr) {
132  loop = newpt;
133  } else {
134  newpt->prev = prevpt;
135  prevpt->next = newpt;
136  }
137  prevpt = newpt;
138  srcpt = srcpt->next;
139  } while (srcpt != src.loop);
140  loop->prev = newpt;
141  newpt->next = loop;
142  }
143 }
EDGEPT * next
Definition: blobs.h:171
EDGEPT * loop
Definition: blobs.h:259
TPOINT topleft
Definition: blobs.h:255
void Clear()
Definition: blobs.cpp:146
TPOINT botright
Definition: blobs.h:256
Definition: blobs.h:78
bool is_hole
Definition: blobs.h:258
TPOINT start
Definition: blobs.h:257
EDGEPT * prev
Definition: blobs.h:172
EDGEPT * TESSLINE::FindBestStartPt ( ) const

Definition at line 287 of file blobs.cpp.

287  {
288  EDGEPT* best_start = loop;
289  int best_step = loop->start_step;
290  // Iterate the polygon.
291  EDGEPT* pt = loop;
292  do {
293  if (pt->IsHidden()) continue;
294  if (pt->prev->IsHidden() || pt->prev->src_outline != pt->src_outline)
295  return pt; // Qualifies as the best.
296  if (pt->start_step < best_step) {
297  best_step = pt->start_step;
298  best_start = pt;
299  }
300  } while ((pt = pt->next) != loop);
301  return best_start;
302 }
bool IsHidden() const
Definition: blobs.h:155
EDGEPT * next
Definition: blobs.h:171
EDGEPT * loop
Definition: blobs.h:259
int start_step
Definition: blobs.h:175
Definition: blobs.h:78
C_OUTLINE * src_outline
Definition: blobs.h:173
EDGEPT * prev
Definition: blobs.h:172
void TESSLINE::MinMaxCrossProduct ( const TPOINT  vec,
int *  min_xp,
int *  max_xp 
) const

Definition at line 247 of file blobs.cpp.

248  {
249  *min_xp = INT32_MAX;
250  *max_xp = INT32_MIN;
251  EDGEPT* this_edge = loop;
252  do {
253  if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
254  int product = CROSS(this_edge->pos, vec);
255  UpdateRange(product, min_xp, max_xp);
256  }
257  this_edge = this_edge->next;
258  } while (this_edge != loop);
259 }
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:120
bool IsHidden() const
Definition: blobs.h:155
EDGEPT * next
Definition: blobs.h:171
EDGEPT * loop
Definition: blobs.h:259
TPOINT pos
Definition: blobs.h:165
Definition: blobs.h:78
#define CROSS(a, b)
Definition: vecfuncs.h:47
EDGEPT * prev
Definition: blobs.h:172
void TESSLINE::Move ( const ICOORD  vec)

Definition at line 183 of file blobs.cpp.

183  {
184  EDGEPT* pt = loop;
185  do {
186  pt->pos.x += vec.x();
187  pt->pos.y += vec.y();
188  pt = pt->next;
189  } while (pt != loop);
190  SetupFromPos();
191 }
void SetupFromPos()
Definition: blobs.cpp:205
int16_t x
Definition: blobs.h:73
EDGEPT * next
Definition: blobs.h:171
EDGEPT * loop
Definition: blobs.h:259
TPOINT pos
Definition: blobs.h:165
int16_t y() const
access_function
Definition: points.h:56
int16_t y
Definition: blobs.h:74
Definition: blobs.h:78
int16_t x() const
access function
Definition: points.h:52
void TESSLINE::Normalize ( const DENORM denorm)

Definition at line 159 of file blobs.cpp.

159  {
160  EDGEPT* pt = loop;
161  do {
162  denorm.LocalNormTransform(pt->pos, &pt->pos);
163  pt = pt->next;
164  } while (pt != loop);
165  SetupFromPos();
166 }
void SetupFromPos()
Definition: blobs.cpp:205
EDGEPT * next
Definition: blobs.h:171
EDGEPT * loop
Definition: blobs.h:259
TPOINT pos
Definition: blobs.h:165
Definition: blobs.h:78
void LocalNormTransform(const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:306
TESSLINE& TESSLINE::operator= ( const TESSLINE src)
inline

Definition at line 190 of file blobs.h.

190  {
191  CopyFrom(src);
192  return *this;
193  }
void CopyFrom(const TESSLINE &src)
Definition: blobs.cpp:119
void TESSLINE::plot ( ScrollView window,
ScrollView::Color  color,
ScrollView::Color  child_color 
)

Definition at line 266 of file blobs.cpp.

267  {
268  if (is_hole)
269  window->Pen(child_color);
270  else
271  window->Pen(color);
272  window->SetCursor(start.x, start.y);
273  EDGEPT* pt = loop;
274  do {
275  bool prev_hidden = pt->IsHidden();
276  pt = pt->next;
277  if (prev_hidden)
278  window->SetCursor(pt->pos.x, pt->pos.y);
279  else
280  window->DrawTo(pt->pos.x, pt->pos.y);
281  } while (pt != loop);
282 }
int16_t x
Definition: blobs.h:73
bool IsHidden() const
Definition: blobs.h:155
EDGEPT * next
Definition: blobs.h:171
void DrawTo(int x, int y)
Definition: scrollview.cpp:525
EDGEPT * loop
Definition: blobs.h:259
TPOINT pos
Definition: blobs.h:165
int16_t y
Definition: blobs.h:74
Definition: blobs.h:78
void Pen(Color color)
Definition: scrollview.cpp:719
bool is_hole
Definition: blobs.h:258
void SetCursor(int x, int y)
Definition: scrollview.cpp:519
TPOINT start
Definition: blobs.h:257
void TESSLINE::Rotate ( const FCOORD  rotation)

Definition at line 169 of file blobs.cpp.

169  {
170  EDGEPT* pt = loop;
171  do {
172  int tmp = static_cast<int>(
173  floor(pt->pos.x * rot.x() - pt->pos.y * rot.y() + 0.5));
174  pt->pos.y = static_cast<int>(
175  floor(pt->pos.y * rot.x() + pt->pos.x * rot.y() + 0.5));
176  pt->pos.x = tmp;
177  pt = pt->next;
178  } while (pt != loop);
179  SetupFromPos();
180 }
void SetupFromPos()
Definition: blobs.cpp:205
int16_t x
Definition: blobs.h:73
EDGEPT * next
Definition: blobs.h:171
EDGEPT * loop
Definition: blobs.h:259
TPOINT pos
Definition: blobs.h:165
int16_t y
Definition: blobs.h:74
Definition: blobs.h:78
bool TESSLINE::SameBox ( const TESSLINE other) const
inline

Definition at line 221 of file blobs.h.

221  {
222  return topleft == other.topleft && botright == other.botright;
223  }
TPOINT topleft
Definition: blobs.h:255
TPOINT botright
Definition: blobs.h:256
void TESSLINE::Scale ( float  factor)

Definition at line 194 of file blobs.cpp.

194  {
195  EDGEPT* pt = loop;
196  do {
197  pt->pos.x = static_cast<int>(floor(pt->pos.x * factor + 0.5));
198  pt->pos.y = static_cast<int>(floor(pt->pos.y * factor + 0.5));
199  pt = pt->next;
200  } while (pt != loop);
201  SetupFromPos();
202 }
void SetupFromPos()
Definition: blobs.cpp:205
int16_t x
Definition: blobs.h:73
EDGEPT * next
Definition: blobs.h:171
EDGEPT * loop
Definition: blobs.h:259
TPOINT pos
Definition: blobs.h:165
int16_t y
Definition: blobs.h:74
Definition: blobs.h:78
bool TESSLINE::SegmentCrosses ( const TPOINT pt1,
const TPOINT pt2 
) const
inline

Definition at line 225 of file blobs.h.

225  {
226  if (Contains(pt1) && Contains(pt2)) {
227  EDGEPT* pt = loop;
228  do {
229  if (TPOINT::IsCrossed(pt1, pt2, pt->pos, pt->next->pos)) return true;
230  pt = pt->next;
231  } while (pt != loop);
232  }
233  return false;
234  }
EDGEPT * next
Definition: blobs.h:171
EDGEPT * loop
Definition: blobs.h:259
TPOINT pos
Definition: blobs.h:165
bool Contains(const TPOINT &pt) const
Definition: blobs.h:236
Definition: blobs.h:78
static bool IsCrossed(const TPOINT &a0, const TPOINT &a1, const TPOINT &b0, const TPOINT &b1)
Definition: blobs.cpp:67
void TESSLINE::SetupFromPos ( )

Definition at line 205 of file blobs.cpp.

205  {
206  EDGEPT* pt = loop;
207  do {
208  pt->vec.x = pt->next->pos.x - pt->pos.x;
209  pt->vec.y = pt->next->pos.y - pt->pos.y;
210  pt = pt->next;
211  } while (pt != loop);
212  start = pt->pos;
214 }
int16_t x
Definition: blobs.h:73
EDGEPT * next
Definition: blobs.h:171
void ComputeBoundingBox()
Definition: blobs.cpp:217
EDGEPT * loop
Definition: blobs.h:259
TPOINT pos
Definition: blobs.h:165
int16_t y
Definition: blobs.h:74
Definition: blobs.h:78
TPOINT start
Definition: blobs.h:257
VECTOR vec
Definition: blobs.h:166

Member Data Documentation

TPOINT TESSLINE::botright

Definition at line 256 of file blobs.h.

bool TESSLINE::is_hole

Definition at line 258 of file blobs.h.

EDGEPT* TESSLINE::loop

Definition at line 259 of file blobs.h.

TESSLINE* TESSLINE::next

Definition at line 260 of file blobs.h.

TPOINT TESSLINE::start

Definition at line 257 of file blobs.h.

TPOINT TESSLINE::topleft

Definition at line 255 of file blobs.h.


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