tesseract  4.00.00dev
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 180 of file blobs.h.

Constructor & Destructor Documentation

◆ TESSLINE() [1/2]

TESSLINE::TESSLINE ( )
inline

Definition at line 181 of file blobs.h.

181 : is_hole(false), loop(NULL), next(NULL) {}
TESSLINE * next
Definition: blobs.h:258
bool is_hole
Definition: blobs.h:256
EDGEPT * loop
Definition: blobs.h:257

◆ TESSLINE() [2/2]

TESSLINE::TESSLINE ( const TESSLINE src)
inline

Definition at line 182 of file blobs.h.

182  : loop(NULL), next(NULL) {
183  CopyFrom(src);
184  }
TESSLINE * next
Definition: blobs.h:258
EDGEPT * loop
Definition: blobs.h:257
void CopyFrom(const TESSLINE &src)
Definition: blobs.cpp:126

◆ ~TESSLINE()

TESSLINE::~TESSLINE ( )
inline

Definition at line 185 of file blobs.h.

185  {
186  Clear();
187  }
void Clear()
Definition: blobs.cpp:153

Member Function Documentation

◆ BBArea()

int TESSLINE::BBArea ( ) const
inline

Definition at line 249 of file blobs.h.

249  {
250  return (botright.x - topleft.x) * (topleft.y - botright.y);
251  }
TPOINT botright
Definition: blobs.h:254
inT16 x
Definition: blobs.h:71
TPOINT topleft
Definition: blobs.h:253
inT16 y
Definition: blobs.h:72

◆ bounding_box()

TBOX TESSLINE::bounding_box ( ) const

Definition at line 273 of file blobs.cpp.

273  {
274  return TBOX(topleft.x, botright.y, botright.x, topleft.y);
275 }
TPOINT botright
Definition: blobs.h:254
inT16 x
Definition: blobs.h:71
TPOINT topleft
Definition: blobs.h:253
inT16 y
Definition: blobs.h:72
Definition: rect.h:30

◆ 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 != NULL) {
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)
117  pt->step_count += pt->src_outline->pathlength();
118  pt = pt->next;
119  } while (pt != outline);
120  }
121  result->SetupFromPos();
122  return result;
123 }
int start_step
Definition: blobs.h:173
C_OUTLINE * src_outline
Definition: blobs.h:171
EDGEPT * loop
Definition: blobs.h:257
int step_count
Definition: blobs.h:174
void SetupFromPos()
Definition: blobs.cpp:213
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
inT32 pathlength() const
Definition: coutln.h:133
TESSLINE()
Definition: blobs.h:181

◆ Clear()

void TESSLINE::Clear ( )

Definition at line 153 of file blobs.cpp.

153  {
154  if (loop == NULL)
155  return;
156 
157  EDGEPT* this_edge = loop;
158  do {
159  EDGEPT* next_edge = this_edge->next;
160  delete this_edge;
161  this_edge = next_edge;
162  } while (this_edge != loop);
163  loop = NULL;
164 }
EDGEPT * loop
Definition: blobs.h:257
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76

◆ ComputeBoundingBox()

void TESSLINE::ComputeBoundingBox ( )

Definition at line 225 of file blobs.cpp.

225  {
226  int minx = MAX_INT32;
227  int miny = MAX_INT32;
228  int maxx = -MAX_INT32;
229  int maxy = -MAX_INT32;
230 
231  // Find boundaries.
232  start = loop->pos;
233  EDGEPT* this_edge = loop;
234  do {
235  if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
236  if (this_edge->pos.x < minx)
237  minx = this_edge->pos.x;
238  if (this_edge->pos.y < miny)
239  miny = this_edge->pos.y;
240  if (this_edge->pos.x > maxx)
241  maxx = this_edge->pos.x;
242  if (this_edge->pos.y > maxy)
243  maxy = this_edge->pos.y;
244  }
245  this_edge = this_edge->next;
246  } while (this_edge != loop);
247  // Reset bounds.
248  topleft.x = minx;
249  topleft.y = maxy;
250  botright.x = maxx;
251  botright.y = miny;
252 }
TPOINT pos
Definition: blobs.h:163
TPOINT start
Definition: blobs.h:255
#define MAX_INT32
Definition: host.h:62
EDGEPT * prev
Definition: blobs.h:170
TPOINT botright
Definition: blobs.h:254
EDGEPT * loop
Definition: blobs.h:257
bool IsHidden() const
Definition: blobs.h:153
inT16 x
Definition: blobs.h:71
TPOINT topleft
Definition: blobs.h:253
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
inT16 y
Definition: blobs.h:72

◆ Contains()

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

Definition at line 234 of file blobs.h.

234  {
235  return topleft.x <= pt.x && pt.x <= botright.x &&
236  botright.y <= pt.y && pt.y <= topleft.y;
237  }
TPOINT botright
Definition: blobs.h:254
inT16 x
Definition: blobs.h:71
TPOINT topleft
Definition: blobs.h:253
inT16 y
Definition: blobs.h:72

◆ CopyFrom()

void TESSLINE::CopyFrom ( const TESSLINE src)

Definition at line 126 of file blobs.cpp.

126  {
127  Clear();
128  topleft = src.topleft;
129  botright = src.botright;
130  start = src.start;
131  is_hole = src.is_hole;
132  if (src.loop != NULL) {
133  EDGEPT* prevpt = NULL;
134  EDGEPT* newpt = NULL;
135  EDGEPT* srcpt = src.loop;
136  do {
137  newpt = new EDGEPT(*srcpt);
138  if (prevpt == NULL) {
139  loop = newpt;
140  } else {
141  newpt->prev = prevpt;
142  prevpt->next = newpt;
143  }
144  prevpt = newpt;
145  srcpt = srcpt->next;
146  } while (srcpt != src.loop);
147  loop->prev = newpt;
148  newpt->next = loop;
149  }
150 }
TPOINT start
Definition: blobs.h:255
EDGEPT * prev
Definition: blobs.h:170
bool is_hole
Definition: blobs.h:256
TPOINT botright
Definition: blobs.h:254
void Clear()
Definition: blobs.cpp:153
EDGEPT * loop
Definition: blobs.h:257
TPOINT topleft
Definition: blobs.h:253
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76

◆ FindBestStartPt()

EDGEPT * TESSLINE::FindBestStartPt ( ) const

Definition at line 299 of file blobs.cpp.

299  {
300  EDGEPT* best_start = loop;
301  int best_step = loop->start_step;
302  // Iterate the polygon.
303  EDGEPT* pt = loop;
304  do {
305  if (pt->IsHidden()) continue;
306  if (pt->prev->IsHidden() || pt->prev->src_outline != pt->src_outline)
307  return pt; // Qualifies as the best.
308  if (pt->start_step < best_step) {
309  best_step = pt->start_step;
310  best_start = pt;
311  }
312  } while ((pt = pt->next) != loop);
313  return best_start;
314 }
int start_step
Definition: blobs.h:173
C_OUTLINE * src_outline
Definition: blobs.h:171
EDGEPT * prev
Definition: blobs.h:170
EDGEPT * loop
Definition: blobs.h:257
bool IsHidden() const
Definition: blobs.h:153
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76

◆ MinMaxCrossProduct()

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

Definition at line 259 of file blobs.cpp.

260  {
261  *min_xp = MAX_INT32;
262  *max_xp = MIN_INT32;
263  EDGEPT* this_edge = loop;
264  do {
265  if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
266  int product = CROSS(this_edge->pos, vec);
267  UpdateRange(product, min_xp, max_xp);
268  }
269  this_edge = this_edge->next;
270  } while (this_edge != loop);
271 }
TPOINT pos
Definition: blobs.h:163
#define MAX_INT32
Definition: host.h:62
EDGEPT * prev
Definition: blobs.h:170
#define CROSS(a, b)
Definition: vecfuncs.h:52
EDGEPT * loop
Definition: blobs.h:257
bool IsHidden() const
Definition: blobs.h:153
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
#define MIN_INT32
Definition: host.h:70
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:132

◆ Move()

void TESSLINE::Move ( const ICOORD  vec)

Definition at line 191 of file blobs.cpp.

191  {
192  EDGEPT* pt = loop;
193  do {
194  pt->pos.x += vec.x();
195  pt->pos.y += vec.y();
196  pt = pt->next;
197  } while (pt != loop);
198  SetupFromPos();
199 }
TPOINT pos
Definition: blobs.h:163
inT16 x() const
access function
Definition: points.h:52
EDGEPT * loop
Definition: blobs.h:257
inT16 x
Definition: blobs.h:71
inT16 y() const
access_function
Definition: points.h:56
void SetupFromPos()
Definition: blobs.cpp:213
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
inT16 y
Definition: blobs.h:72

◆ Normalize()

void TESSLINE::Normalize ( const DENORM denorm)

Definition at line 167 of file blobs.cpp.

167  {
168  EDGEPT* pt = loop;
169  do {
170  denorm.LocalNormTransform(pt->pos, &pt->pos);
171  pt = pt->next;
172  } while (pt != loop);
173  SetupFromPos();
174 }
TPOINT pos
Definition: blobs.h:163
void LocalNormTransform(const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:305
EDGEPT * loop
Definition: blobs.h:257
void SetupFromPos()
Definition: blobs.cpp:213
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76

◆ operator=()

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

Definition at line 188 of file blobs.h.

188  {
189  CopyFrom(src);
190  return *this;
191  }
void CopyFrom(const TESSLINE &src)
Definition: blobs.cpp:126

◆ plot()

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

Definition at line 278 of file blobs.cpp.

279  {
280  if (is_hole)
281  window->Pen(child_color);
282  else
283  window->Pen(color);
284  window->SetCursor(start.x, start.y);
285  EDGEPT* pt = loop;
286  do {
287  bool prev_hidden = pt->IsHidden();
288  pt = pt->next;
289  if (prev_hidden)
290  window->SetCursor(pt->pos.x, pt->pos.y);
291  else
292  window->DrawTo(pt->pos.x, pt->pos.y);
293  } while (pt != loop);
294 }
TPOINT pos
Definition: blobs.h:163
TPOINT start
Definition: blobs.h:255
void SetCursor(int x, int y)
Definition: scrollview.cpp:525
bool is_hole
Definition: blobs.h:256
EDGEPT * loop
Definition: blobs.h:257
bool IsHidden() const
Definition: blobs.h:153
inT16 x
Definition: blobs.h:71
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
inT16 y
Definition: blobs.h:72
void Pen(Color color)
Definition: scrollview.cpp:726
void DrawTo(int x, int y)
Definition: scrollview.cpp:531

◆ Rotate()

void TESSLINE::Rotate ( const FCOORD  rotation)

Definition at line 177 of file blobs.cpp.

177  {
178  EDGEPT* pt = loop;
179  do {
180  int tmp = static_cast<int>(floor(pt->pos.x * rot.x() -
181  pt->pos.y * rot.y() + 0.5));
182  pt->pos.y = static_cast<int>(floor(pt->pos.y * rot.x() +
183  pt->pos.x * rot.y() + 0.5));
184  pt->pos.x = tmp;
185  pt = pt->next;
186  } while (pt != loop);
187  SetupFromPos();
188 }
TPOINT pos
Definition: blobs.h:163
EDGEPT * loop
Definition: blobs.h:257
inT16 x
Definition: blobs.h:71
void SetupFromPos()
Definition: blobs.cpp:213
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
inT16 y
Definition: blobs.h:72

◆ SameBox()

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

Definition at line 219 of file blobs.h.

219  {
220  return topleft == other.topleft && botright == other.botright;
221  }
TPOINT botright
Definition: blobs.h:254
TPOINT topleft
Definition: blobs.h:253

◆ Scale()

void TESSLINE::Scale ( float  factor)

Definition at line 202 of file blobs.cpp.

202  {
203  EDGEPT* pt = loop;
204  do {
205  pt->pos.x = static_cast<int>(floor(pt->pos.x * factor + 0.5));
206  pt->pos.y = static_cast<int>(floor(pt->pos.y * factor + 0.5));
207  pt = pt->next;
208  } while (pt != loop);
209  SetupFromPos();
210 }
TPOINT pos
Definition: blobs.h:163
EDGEPT * loop
Definition: blobs.h:257
inT16 x
Definition: blobs.h:71
void SetupFromPos()
Definition: blobs.cpp:213
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
inT16 y
Definition: blobs.h:72

◆ SegmentCrosses()

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

Definition at line 223 of file blobs.h.

223  {
224  if (Contains(pt1) && Contains(pt2)) {
225  EDGEPT* pt = loop;
226  do {
227  if (TPOINT::IsCrossed(pt1, pt2, pt->pos, pt->next->pos)) return true;
228  pt = pt->next;
229  } while (pt != loop);
230  }
231  return false;
232  }
TPOINT pos
Definition: blobs.h:163
EDGEPT * loop
Definition: blobs.h:257
bool Contains(const TPOINT &pt) const
Definition: blobs.h:234
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
static bool IsCrossed(const TPOINT &a0, const TPOINT &a1, const TPOINT &b0, const TPOINT &b1)
Definition: blobs.cpp:73

◆ SetupFromPos()

void TESSLINE::SetupFromPos ( )

Definition at line 213 of file blobs.cpp.

213  {
214  EDGEPT* pt = loop;
215  do {
216  pt->vec.x = pt->next->pos.x - pt->pos.x;
217  pt->vec.y = pt->next->pos.y - pt->pos.y;
218  pt = pt->next;
219  } while (pt != loop);
220  start = pt->pos;
222 }
TPOINT pos
Definition: blobs.h:163
TPOINT start
Definition: blobs.h:255
VECTOR vec
Definition: blobs.h:164
EDGEPT * loop
Definition: blobs.h:257
inT16 x
Definition: blobs.h:71
EDGEPT * next
Definition: blobs.h:169
Definition: blobs.h:76
void ComputeBoundingBox()
Definition: blobs.cpp:225
inT16 y
Definition: blobs.h:72

Member Data Documentation

◆ botright

TPOINT TESSLINE::botright

Definition at line 254 of file blobs.h.

◆ is_hole

bool TESSLINE::is_hole

Definition at line 256 of file blobs.h.

◆ loop

EDGEPT* TESSLINE::loop

Definition at line 257 of file blobs.h.

◆ next

TESSLINE* TESSLINE::next

Definition at line 258 of file blobs.h.

◆ start

TPOINT TESSLINE::start

Definition at line 255 of file blobs.h.

◆ topleft

TPOINT TESSLINE::topleft

Definition at line 253 of file blobs.h.


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