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

Constructor & Destructor Documentation

◆ TESSLINE() [1/2]

TESSLINE::TESSLINE ( )
inline

Definition at line 202 of file blobs.h.

202 {

◆ TESSLINE() [2/2]

TESSLINE::TESSLINE ( const TESSLINE src)
inline

Definition at line 203 of file blobs.h.

203  : is_hole(false), loop(nullptr), next(nullptr) {}
204  TESSLINE(const TESSLINE& src) : loop(nullptr), next(nullptr) {
205  CopyFrom(src);

◆ ~TESSLINE()

TESSLINE::~TESSLINE ( )
inline

Definition at line 206 of file blobs.h.

207  {
208  Clear();

Member Function Documentation

◆ BBArea()

int TESSLINE::BBArea ( ) const
inline

Definition at line 270 of file blobs.h.

271  {
272  return (botright.x - topleft.x) * (topleft.y - botright.y);

◆ bounding_box()

TBOX TESSLINE::bounding_box ( ) const

Definition at line 256 of file blobs.cpp.

256  {
257  return TBOX(topleft.x, botright.y, botright.x, topleft.y);
258 }

◆ BuildFromOutlineList()

TESSLINE * TESSLINE::BuildFromOutlineList ( EDGEPT outline)
static

Definition at line 93 of file blobs.cpp.

93  {
94  auto* result = new TESSLINE;
95  result->loop = outline;
96  if (outline->src_outline != nullptr) {
97  // ASSUMPTION: This function is only ever called from ApproximateOutline
98  // and therefore either all points have a src_outline or all do not.
99  // Just as SetupFromPos sets the vectors from the vertices, setup the
100  // step_count members to indicate the (positive) number of original
101  // C_OUTLINE steps to the next vertex.
102  EDGEPT* pt = outline;
103  do {
104  pt->step_count = pt->next->start_step - pt->start_step;
105  if (pt->step_count < 0) pt->step_count += pt->src_outline->pathlength();
106  pt = pt->next;
107  } while (pt != outline);
108  }
109  result->SetupFromPos();
110  return result;
111 }

◆ Clear()

void TESSLINE::Clear ( )

Definition at line 141 of file blobs.cpp.

141  {
142  if (loop == nullptr) return;
143 
144  EDGEPT* this_edge = loop;
145  do {
146  EDGEPT* next_edge = this_edge->next;
147  delete this_edge;
148  this_edge = next_edge;
149  } while (this_edge != loop);
150  loop = nullptr;
151 }

◆ ComputeBoundingBox()

void TESSLINE::ComputeBoundingBox ( )

Definition at line 212 of file blobs.cpp.

212  {
213  int minx = INT32_MAX;
214  int miny = INT32_MAX;
215  int maxx = -INT32_MAX;
216  int maxy = -INT32_MAX;
217 
218  // Find boundaries.
219  start = loop->pos;
220  EDGEPT* this_edge = loop;
221  do {
222  if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
223  if (this_edge->pos.x < minx) minx = this_edge->pos.x;
224  if (this_edge->pos.y < miny) miny = this_edge->pos.y;
225  if (this_edge->pos.x > maxx) maxx = this_edge->pos.x;
226  if (this_edge->pos.y > maxy) maxy = this_edge->pos.y;
227  }
228  this_edge = this_edge->next;
229  } while (this_edge != loop);
230  // Reset bounds.
231  topleft.x = minx;
232  topleft.y = maxy;
233  botright.x = maxx;
234  botright.y = miny;
235 }

◆ Contains()

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

Definition at line 255 of file blobs.h.

256  {
257  return topleft.x <= pt.x && pt.x <= botright.x &&
258  botright.y <= pt.y && pt.y <= topleft.y;

◆ CopyFrom()

void TESSLINE::CopyFrom ( const TESSLINE src)

Definition at line 114 of file blobs.cpp.

114  {
115  Clear();
116  topleft = src.topleft;
117  botright = src.botright;
118  start = src.start;
119  is_hole = src.is_hole;
120  if (src.loop != nullptr) {
121  EDGEPT* prevpt = nullptr;
122  EDGEPT* newpt = nullptr;
123  EDGEPT* srcpt = src.loop;
124  do {
125  newpt = new EDGEPT(*srcpt);
126  if (prevpt == nullptr) {
127  loop = newpt;
128  } else {
129  newpt->prev = prevpt;
130  prevpt->next = newpt;
131  }
132  prevpt = newpt;
133  srcpt = srcpt->next;
134  } while (srcpt != src.loop);
135  loop->prev = newpt;
136  newpt->next = loop;
137  }
138 }

◆ FindBestStartPt()

EDGEPT * TESSLINE::FindBestStartPt ( ) const

Definition at line 282 of file blobs.cpp.

282  {
283  EDGEPT* best_start = loop;
284  int best_step = loop->start_step;
285  // Iterate the polygon.
286  EDGEPT* pt = loop;
287  do {
288  if (pt->IsHidden()) continue;
289  if (pt->prev->IsHidden() || pt->prev->src_outline != pt->src_outline)
290  return pt; // Qualifies as the best.
291  if (pt->start_step < best_step) {
292  best_step = pt->start_step;
293  best_start = pt;
294  }
295  } while ((pt = pt->next) != loop);
296  return best_start;
297 }

◆ MinMaxCrossProduct()

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

Definition at line 242 of file blobs.cpp.

243  {
244  *min_xp = INT32_MAX;
245  *max_xp = INT32_MIN;
246  EDGEPT* this_edge = loop;
247  do {
248  if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
249  int product = this_edge->pos.cross(vec);
250  UpdateRange(product, min_xp, max_xp);
251  }
252  this_edge = this_edge->next;
253  } while (this_edge != loop);
254 }

◆ Move()

void TESSLINE::Move ( const ICOORD  vec)

Definition at line 178 of file blobs.cpp.

178  {
179  EDGEPT* pt = loop;
180  do {
181  pt->pos.x += vec.x();
182  pt->pos.y += vec.y();
183  pt = pt->next;
184  } while (pt != loop);
185  SetupFromPos();
186 }

◆ Normalize()

void TESSLINE::Normalize ( const DENORM denorm)

Definition at line 154 of file blobs.cpp.

154  {
155  EDGEPT* pt = loop;
156  do {
157  denorm.LocalNormTransform(pt->pos, &pt->pos);
158  pt = pt->next;
159  } while (pt != loop);
160  SetupFromPos();
161 }

◆ operator=()

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

Definition at line 209 of file blobs.h.

210  {
211  CopyFrom(src);
212  return *this;

◆ plot()

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

Definition at line 261 of file blobs.cpp.

262  {
263  if (is_hole)
264  window->Pen(child_color);
265  else
266  window->Pen(color);
267  window->SetCursor(start.x, start.y);
268  EDGEPT* pt = loop;
269  do {
270  bool prev_hidden = pt->IsHidden();
271  pt = pt->next;
272  if (prev_hidden)
273  window->SetCursor(pt->pos.x, pt->pos.y);
274  else
275  window->DrawTo(pt->pos.x, pt->pos.y);
276  } while (pt != loop);
277 }

◆ Rotate()

void TESSLINE::Rotate ( const FCOORD  rotation)

Definition at line 164 of file blobs.cpp.

164  {
165  EDGEPT* pt = loop;
166  do {
167  int tmp = static_cast<int>(
168  floor(pt->pos.x * rot.x() - pt->pos.y * rot.y() + 0.5));
169  pt->pos.y = static_cast<int>(
170  floor(pt->pos.y * rot.x() + pt->pos.x * rot.y() + 0.5));
171  pt->pos.x = tmp;
172  pt = pt->next;
173  } while (pt != loop);
174  SetupFromPos();
175 }

◆ SameBox()

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

Definition at line 240 of file blobs.h.

241  {
242  return topleft == other.topleft && botright == other.botright;

◆ Scale()

void TESSLINE::Scale ( float  factor)

Definition at line 189 of file blobs.cpp.

189  {
190  EDGEPT* pt = loop;
191  do {
192  pt->pos.x = static_cast<int>(floor(pt->pos.x * factor + 0.5));
193  pt->pos.y = static_cast<int>(floor(pt->pos.y * factor + 0.5));
194  pt = pt->next;
195  } while (pt != loop);
196  SetupFromPos();
197 }

◆ SegmentCrosses()

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

Definition at line 244 of file blobs.h.

245  {
246  if (Contains(pt1) && Contains(pt2)) {
247  EDGEPT* pt = loop;
248  do {
249  if (TPOINT::IsCrossed(pt1, pt2, pt->pos, pt->next->pos)) return true;
250  pt = pt->next;
251  } while (pt != loop);
252  }
253  return false;

◆ SetupFromPos()

void TESSLINE::SetupFromPos ( )

Definition at line 200 of file blobs.cpp.

200  {
201  EDGEPT* pt = loop;
202  do {
203  pt->vec.x = pt->next->pos.x - pt->pos.x;
204  pt->vec.y = pt->next->pos.y - pt->pos.y;
205  pt = pt->next;
206  } while (pt != loop);
207  start = pt->pos;
209 }

Member Data Documentation

◆ botright

TPOINT TESSLINE::botright

Definition at line 275 of file blobs.h.

◆ is_hole

bool TESSLINE::is_hole

Definition at line 277 of file blobs.h.

◆ loop

EDGEPT* TESSLINE::loop

Definition at line 278 of file blobs.h.

◆ next

TESSLINE* TESSLINE::next

Definition at line 279 of file blobs.h.

◆ start

TPOINT TESSLINE::start

Definition at line 276 of file blobs.h.

◆ topleft

TPOINT TESSLINE::topleft

Definition at line 274 of file blobs.h.


The documentation for this struct was generated from the following files:
TBOX
Definition: cleanapi_test.cc:19
TESSLINE::start
TPOINT start
Definition: blobs.h:276
TESSLINE::botright
TPOINT botright
Definition: blobs.h:275
TESSLINE::ComputeBoundingBox
void ComputeBoundingBox()
Definition: blobs.cpp:212
TESSLINE::Clear
void Clear()
Definition: blobs.cpp:141
TESSLINE::loop
EDGEPT * loop
Definition: blobs.h:278
TESSLINE::CopyFrom
void CopyFrom(const TESSLINE &src)
Definition: blobs.cpp:114
EDGEPT::src_outline
C_OUTLINE * src_outline
Definition: blobs.h:192
EDGEPT::step_count
int step_count
Definition: blobs.h:195
EDGEPT::IsHidden
bool IsHidden() const
Definition: blobs.h:174
TESSLINE
Definition: blobs.h:201
TESSLINE::topleft
TPOINT topleft
Definition: blobs.h:274
ScrollView::Pen
void Pen(Color color)
Definition: scrollview.cpp:717
ScrollView::DrawTo
void DrawTo(int x, int y)
Definition: scrollview.cpp:524
TESSLINE::Contains
bool Contains(const TPOINT &pt) const
Definition: blobs.h:255
TESSLINE::next
TESSLINE * next
Definition: blobs.h:279
ICOORD::x
int16_t x() const
access function
Definition: points.h:51
TESSLINE::SetupFromPos
void SetupFromPos()
Definition: blobs.cpp:200
TESSLINE::TESSLINE
TESSLINE()
Definition: blobs.h:202
EDGEPT::prev
EDGEPT * prev
Definition: blobs.h:191
EDGEPT::start_step
int start_step
Definition: blobs.h:194
TPOINT::x
int16_t x
Definition: blobs.h:91
TPOINT::y
int16_t y
Definition: blobs.h:92
TPOINT::IsCrossed
static bool IsCrossed(const TPOINT &a0, const TPOINT &a1, const TPOINT &b0, const TPOINT &b1)
Definition: blobs.cpp:65
EDGEPT::vec
VECTOR vec
Definition: blobs.h:185
TPOINT::cross
int cross(const TPOINT &other) const
Definition: blobs.h:77
EDGEPT
Definition: blobs.h:97
DENORM::LocalNormTransform
void LocalNormTransform(const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:305
ScrollView::SetCursor
void SetCursor(int x, int y)
Definition: scrollview.cpp:518
C_OUTLINE::pathlength
int32_t pathlength() const
Definition: coutln.h:134
UpdateRange
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:118
TESSLINE::is_hole
bool is_hole
Definition: blobs.h:277
EDGEPT::pos
TPOINT pos
Definition: blobs.h:184
EDGEPT::next
EDGEPT * next
Definition: blobs.h:190
ICOORD::y
int16_t y() const
access_function
Definition: points.h:55