tesseract  4.0.0-1-g2a2b
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 187 of file blobs.h.

Constructor & Destructor Documentation

◆ TESSLINE() [1/2]

TESSLINE::TESSLINE ( )
inline

Definition at line 188 of file blobs.h.

188 : is_hole(false), loop(nullptr), next(nullptr) {}
TESSLINE * next
Definition: blobs.h:265
EDGEPT * loop
Definition: blobs.h:264
bool is_hole
Definition: blobs.h:263

◆ TESSLINE() [2/2]

TESSLINE::TESSLINE ( const TESSLINE src)
inline

Definition at line 189 of file blobs.h.

189  : loop(nullptr), next(nullptr) {
190  CopyFrom(src);
191  }
TESSLINE * next
Definition: blobs.h:265
EDGEPT * loop
Definition: blobs.h:264
void CopyFrom(const TESSLINE &src)
Definition: blobs.cpp:125

◆ ~TESSLINE()

TESSLINE::~TESSLINE ( )
inline

Definition at line 192 of file blobs.h.

192  {
193  Clear();
194  }
void Clear()
Definition: blobs.cpp:152

Member Function Documentation

◆ BBArea()

int TESSLINE::BBArea ( ) const
inline

Definition at line 256 of file blobs.h.

256  {
257  return (botright.x - topleft.x) * (topleft.y - botright.y);
258  }
TPOINT botright
Definition: blobs.h:261
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79
TPOINT topleft
Definition: blobs.h:260

◆ bounding_box()

TBOX TESSLINE::bounding_box ( ) const

Definition at line 267 of file blobs.cpp.

267  {
268  return TBOX(topleft.x, botright.y, botright.x, topleft.y);
269 }
TPOINT botright
Definition: blobs.h:261
Definition: rect.h:34
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79
TPOINT topleft
Definition: blobs.h:260

◆ BuildFromOutlineList()

TESSLINE * TESSLINE::BuildFromOutlineList ( EDGEPT outline)
static

Definition at line 104 of file blobs.cpp.

104  {
105  TESSLINE* result = new TESSLINE;
106  result->loop = outline;
107  if (outline->src_outline != nullptr) {
108  // ASSUMPTION: This function is only ever called from ApproximateOutline
109  // and therefore either all points have a src_outline or all do not.
110  // Just as SetupFromPos sets the vectors from the vertices, setup the
111  // step_count members to indicate the (positive) number of original
112  // C_OUTLINE steps to the next vertex.
113  EDGEPT* pt = outline;
114  do {
115  pt->step_count = pt->next->start_step - pt->start_step;
116  if (pt->step_count < 0) pt->step_count += pt->src_outline->pathlength();
117  pt = pt->next;
118  } while (pt != outline);
119  }
120  result->SetupFromPos();
121  return result;
122 }
int step_count
Definition: blobs.h:181
int start_step
Definition: blobs.h:180
EDGEPT * loop
Definition: blobs.h:264
Definition: blobs.h:83
int32_t pathlength() const
Definition: coutln.h:135
C_OUTLINE * src_outline
Definition: blobs.h:178
EDGEPT * next
Definition: blobs.h:176
TESSLINE()
Definition: blobs.h:188
void SetupFromPos()
Definition: blobs.cpp:211

◆ Clear()

void TESSLINE::Clear ( )

Definition at line 152 of file blobs.cpp.

152  {
153  if (loop == nullptr) return;
154 
155  EDGEPT* this_edge = loop;
156  do {
157  EDGEPT* next_edge = this_edge->next;
158  delete this_edge;
159  this_edge = next_edge;
160  } while (this_edge != loop);
161  loop = nullptr;
162 }
EDGEPT * loop
Definition: blobs.h:264
Definition: blobs.h:83
EDGEPT * next
Definition: blobs.h:176

◆ ComputeBoundingBox()

void TESSLINE::ComputeBoundingBox ( )

Definition at line 223 of file blobs.cpp.

223  {
224  int minx = INT32_MAX;
225  int miny = INT32_MAX;
226  int maxx = -INT32_MAX;
227  int maxy = -INT32_MAX;
228 
229  // Find boundaries.
230  start = loop->pos;
231  EDGEPT* this_edge = loop;
232  do {
233  if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
234  if (this_edge->pos.x < minx) minx = this_edge->pos.x;
235  if (this_edge->pos.y < miny) miny = this_edge->pos.y;
236  if (this_edge->pos.x > maxx) maxx = this_edge->pos.x;
237  if (this_edge->pos.y > maxy) maxy = this_edge->pos.y;
238  }
239  this_edge = this_edge->next;
240  } while (this_edge != loop);
241  // Reset bounds.
242  topleft.x = minx;
243  topleft.y = maxy;
244  botright.x = maxx;
245  botright.y = miny;
246 }
TPOINT pos
Definition: blobs.h:170
TPOINT botright
Definition: blobs.h:261
bool IsHidden() const
Definition: blobs.h:160
TPOINT start
Definition: blobs.h:262
EDGEPT * loop
Definition: blobs.h:264
Definition: blobs.h:83
EDGEPT * prev
Definition: blobs.h:177
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79
TPOINT topleft
Definition: blobs.h:260
EDGEPT * next
Definition: blobs.h:176

◆ Contains()

bool TESSLINE::Contains ( const TPOINT pt) const
inline

Definition at line 241 of file blobs.h.

241  {
242  return topleft.x <= pt.x && pt.x <= botright.x &&
243  botright.y <= pt.y && pt.y <= topleft.y;
244  }
TPOINT botright
Definition: blobs.h:261
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79
TPOINT topleft
Definition: blobs.h:260

◆ CopyFrom()

void TESSLINE::CopyFrom ( const TESSLINE src)

Definition at line 125 of file blobs.cpp.

125  {
126  Clear();
127  topleft = src.topleft;
128  botright = src.botright;
129  start = src.start;
130  is_hole = src.is_hole;
131  if (src.loop != nullptr) {
132  EDGEPT* prevpt = nullptr;
133  EDGEPT* newpt = nullptr;
134  EDGEPT* srcpt = src.loop;
135  do {
136  newpt = new EDGEPT(*srcpt);
137  if (prevpt == nullptr) {
138  loop = newpt;
139  } else {
140  newpt->prev = prevpt;
141  prevpt->next = newpt;
142  }
143  prevpt = newpt;
144  srcpt = srcpt->next;
145  } while (srcpt != src.loop);
146  loop->prev = newpt;
147  newpt->next = loop;
148  }
149 }
TPOINT botright
Definition: blobs.h:261
TPOINT start
Definition: blobs.h:262
EDGEPT * loop
Definition: blobs.h:264
Definition: blobs.h:83
EDGEPT * prev
Definition: blobs.h:177
bool is_hole
Definition: blobs.h:263
void Clear()
Definition: blobs.cpp:152
TPOINT topleft
Definition: blobs.h:260
EDGEPT * next
Definition: blobs.h:176

◆ FindBestStartPt()

EDGEPT * TESSLINE::FindBestStartPt ( ) const

Definition at line 293 of file blobs.cpp.

293  {
294  EDGEPT* best_start = loop;
295  int best_step = loop->start_step;
296  // Iterate the polygon.
297  EDGEPT* pt = loop;
298  do {
299  if (pt->IsHidden()) continue;
300  if (pt->prev->IsHidden() || pt->prev->src_outline != pt->src_outline)
301  return pt; // Qualifies as the best.
302  if (pt->start_step < best_step) {
303  best_step = pt->start_step;
304  best_start = pt;
305  }
306  } while ((pt = pt->next) != loop);
307  return best_start;
308 }
bool IsHidden() const
Definition: blobs.h:160
int start_step
Definition: blobs.h:180
EDGEPT * loop
Definition: blobs.h:264
Definition: blobs.h:83
EDGEPT * prev
Definition: blobs.h:177
C_OUTLINE * src_outline
Definition: blobs.h:178
EDGEPT * next
Definition: blobs.h:176

◆ MinMaxCrossProduct()

void TESSLINE::MinMaxCrossProduct ( const TPOINT  vec,
int *  min_xp,
int *  max_xp 
) const

Definition at line 253 of file blobs.cpp.

254  {
255  *min_xp = INT32_MAX;
256  *max_xp = INT32_MIN;
257  EDGEPT* this_edge = loop;
258  do {
259  if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
260  int product = CROSS(this_edge->pos, vec);
261  UpdateRange(product, min_xp, max_xp);
262  }
263  this_edge = this_edge->next;
264  } while (this_edge != loop);
265 }
TPOINT pos
Definition: blobs.h:170
#define CROSS(a, b)
Definition: vecfuncs.h:52
bool IsHidden() const
Definition: blobs.h:160
EDGEPT * loop
Definition: blobs.h:264
Definition: blobs.h:83
EDGEPT * prev
Definition: blobs.h:177
EDGEPT * next
Definition: blobs.h:176
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:121

◆ Move()

void TESSLINE::Move ( const ICOORD  vec)

Definition at line 189 of file blobs.cpp.

189  {
190  EDGEPT* pt = loop;
191  do {
192  pt->pos.x += vec.x();
193  pt->pos.y += vec.y();
194  pt = pt->next;
195  } while (pt != loop);
196  SetupFromPos();
197 }
TPOINT pos
Definition: blobs.h:170
int16_t y() const
access_function
Definition: points.h:57
EDGEPT * loop
Definition: blobs.h:264
int16_t x() const
access function
Definition: points.h:53
Definition: blobs.h:83
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79
EDGEPT * next
Definition: blobs.h:176
void SetupFromPos()
Definition: blobs.cpp:211

◆ Normalize()

void TESSLINE::Normalize ( const DENORM denorm)

Definition at line 165 of file blobs.cpp.

165  {
166  EDGEPT* pt = loop;
167  do {
168  denorm.LocalNormTransform(pt->pos, &pt->pos);
169  pt = pt->next;
170  } while (pt != loop);
171  SetupFromPos();
172 }
TPOINT pos
Definition: blobs.h:170
void LocalNormTransform(const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:306
EDGEPT * loop
Definition: blobs.h:264
Definition: blobs.h:83
EDGEPT * next
Definition: blobs.h:176
void SetupFromPos()
Definition: blobs.cpp:211

◆ operator=()

TESSLINE& TESSLINE::operator= ( const TESSLINE src)
inline

Definition at line 195 of file blobs.h.

195  {
196  CopyFrom(src);
197  return *this;
198  }
void CopyFrom(const TESSLINE &src)
Definition: blobs.cpp:125

◆ plot()

void TESSLINE::plot ( ScrollView window,
ScrollView::Color  color,
ScrollView::Color  child_color 
)

Definition at line 272 of file blobs.cpp.

273  {
274  if (is_hole)
275  window->Pen(child_color);
276  else
277  window->Pen(color);
278  window->SetCursor(start.x, start.y);
279  EDGEPT* pt = loop;
280  do {
281  bool prev_hidden = pt->IsHidden();
282  pt = pt->next;
283  if (prev_hidden)
284  window->SetCursor(pt->pos.x, pt->pos.y);
285  else
286  window->DrawTo(pt->pos.x, pt->pos.y);
287  } while (pt != loop);
288 }
void DrawTo(int x, int y)
Definition: scrollview.cpp:527
TPOINT pos
Definition: blobs.h:170
bool IsHidden() const
Definition: blobs.h:160
void SetCursor(int x, int y)
Definition: scrollview.cpp:521
TPOINT start
Definition: blobs.h:262
EDGEPT * loop
Definition: blobs.h:264
Definition: blobs.h:83
bool is_hole
Definition: blobs.h:263
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79
void Pen(Color color)
Definition: scrollview.cpp:722
EDGEPT * next
Definition: blobs.h:176

◆ Rotate()

void TESSLINE::Rotate ( const FCOORD  rotation)

Definition at line 175 of file blobs.cpp.

175  {
176  EDGEPT* pt = loop;
177  do {
178  int tmp = static_cast<int>(
179  floor(pt->pos.x * rot.x() - pt->pos.y * rot.y() + 0.5));
180  pt->pos.y = static_cast<int>(
181  floor(pt->pos.y * rot.x() + pt->pos.x * rot.y() + 0.5));
182  pt->pos.x = tmp;
183  pt = pt->next;
184  } while (pt != loop);
185  SetupFromPos();
186 }
TPOINT pos
Definition: blobs.h:170
EDGEPT * loop
Definition: blobs.h:264
Definition: blobs.h:83
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79
EDGEPT * next
Definition: blobs.h:176
void SetupFromPos()
Definition: blobs.cpp:211

◆ SameBox()

bool TESSLINE::SameBox ( const TESSLINE other) const
inline

Definition at line 226 of file blobs.h.

226  {
227  return topleft == other.topleft && botright == other.botright;
228  }
TPOINT botright
Definition: blobs.h:261
TPOINT topleft
Definition: blobs.h:260

◆ Scale()

void TESSLINE::Scale ( float  factor)

Definition at line 200 of file blobs.cpp.

200  {
201  EDGEPT* pt = loop;
202  do {
203  pt->pos.x = static_cast<int>(floor(pt->pos.x * factor + 0.5));
204  pt->pos.y = static_cast<int>(floor(pt->pos.y * factor + 0.5));
205  pt = pt->next;
206  } while (pt != loop);
207  SetupFromPos();
208 }
TPOINT pos
Definition: blobs.h:170
EDGEPT * loop
Definition: blobs.h:264
Definition: blobs.h:83
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79
EDGEPT * next
Definition: blobs.h:176
void SetupFromPos()
Definition: blobs.cpp:211

◆ SegmentCrosses()

bool TESSLINE::SegmentCrosses ( const TPOINT pt1,
const TPOINT pt2 
) const
inline

Definition at line 230 of file blobs.h.

230  {
231  if (Contains(pt1) && Contains(pt2)) {
232  EDGEPT* pt = loop;
233  do {
234  if (TPOINT::IsCrossed(pt1, pt2, pt->pos, pt->next->pos)) return true;
235  pt = pt->next;
236  } while (pt != loop);
237  }
238  return false;
239  }
TPOINT pos
Definition: blobs.h:170
bool Contains(const TPOINT &pt) const
Definition: blobs.h:241
EDGEPT * loop
Definition: blobs.h:264
static bool IsCrossed(const TPOINT &a0, const TPOINT &a1, const TPOINT &b0, const TPOINT &b1)
Definition: blobs.cpp:73
Definition: blobs.h:83
EDGEPT * next
Definition: blobs.h:176

◆ SetupFromPos()

void TESSLINE::SetupFromPos ( )

Definition at line 211 of file blobs.cpp.

211  {
212  EDGEPT* pt = loop;
213  do {
214  pt->vec.x = pt->next->pos.x - pt->pos.x;
215  pt->vec.y = pt->next->pos.y - pt->pos.y;
216  pt = pt->next;
217  } while (pt != loop);
218  start = pt->pos;
220 }
TPOINT pos
Definition: blobs.h:170
void ComputeBoundingBox()
Definition: blobs.cpp:223
TPOINT start
Definition: blobs.h:262
EDGEPT * loop
Definition: blobs.h:264
VECTOR vec
Definition: blobs.h:171
Definition: blobs.h:83
int16_t x
Definition: blobs.h:78
int16_t y
Definition: blobs.h:79
EDGEPT * next
Definition: blobs.h:176

Member Data Documentation

◆ botright

TPOINT TESSLINE::botright

Definition at line 261 of file blobs.h.

◆ is_hole

bool TESSLINE::is_hole

Definition at line 263 of file blobs.h.

◆ loop

EDGEPT* TESSLINE::loop

Definition at line 264 of file blobs.h.

◆ next

TESSLINE* TESSLINE::next

Definition at line 265 of file blobs.h.

◆ start

TPOINT TESSLINE::start

Definition at line 262 of file blobs.h.

◆ topleft

TPOINT TESSLINE::topleft

Definition at line 260 of file blobs.h.


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