tesseract 4.1.1
Loading...
Searching...
No Matches
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 203 of file blobs.h.

Constructor & Destructor Documentation

◆ TESSLINE() [1/2]

TESSLINE::TESSLINE ( )
inline

Definition at line 204 of file blobs.h.

204: is_hole(false), loop(nullptr), next(nullptr) {}
EDGEPT * loop
Definition: blobs.h:280
TESSLINE * next
Definition: blobs.h:281
bool is_hole
Definition: blobs.h:279

◆ TESSLINE() [2/2]

TESSLINE::TESSLINE ( const TESSLINE src)
inline

Definition at line 205 of file blobs.h.

205 : loop(nullptr), next(nullptr) {
206 CopyFrom(src);
207 }
void CopyFrom(const TESSLINE &src)
Definition: blobs.cpp:115

◆ ~TESSLINE()

TESSLINE::~TESSLINE ( )
inline

Definition at line 208 of file blobs.h.

208 {
209 Clear();
210 }
void Clear()
Definition: blobs.cpp:142

Member Function Documentation

◆ BBArea()

int TESSLINE::BBArea ( ) const
inline

Definition at line 272 of file blobs.h.

272 {
273 return (botright.x - topleft.x) * (topleft.y - botright.y);
274 }
int16_t x
Definition: blobs.h:93
int16_t y
Definition: blobs.h:94
TPOINT topleft
Definition: blobs.h:276
TPOINT botright
Definition: blobs.h:277

◆ bounding_box()

TBOX TESSLINE::bounding_box ( ) const

Definition at line 257 of file blobs.cpp.

257 {
259}
Definition: rect.h:34

◆ BuildFromOutlineList()

TESSLINE * TESSLINE::BuildFromOutlineList ( EDGEPT outline)
static

Definition at line 94 of file blobs.cpp.

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

◆ Clear()

void TESSLINE::Clear ( )

Definition at line 142 of file blobs.cpp.

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

◆ ComputeBoundingBox()

void TESSLINE::ComputeBoundingBox ( )

Definition at line 213 of file blobs.cpp.

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

◆ Contains()

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

Definition at line 257 of file blobs.h.

257 {
258 return topleft.x <= pt.x && pt.x <= botright.x &&
259 botright.y <= pt.y && pt.y <= topleft.y;
260 }

◆ CopyFrom()

void TESSLINE::CopyFrom ( const TESSLINE src)

Definition at line 115 of file blobs.cpp.

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

◆ FindBestStartPt()

EDGEPT * TESSLINE::FindBestStartPt ( ) const

Definition at line 283 of file blobs.cpp.

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

◆ MinMaxCrossProduct()

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

Definition at line 243 of file blobs.cpp.

244 {
245 *min_xp = INT32_MAX;
246 *max_xp = INT32_MIN;
247 EDGEPT* this_edge = loop;
248 do {
249 if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
250 int product = this_edge->pos.cross(vec);
251 UpdateRange(product, min_xp, max_xp);
252 }
253 this_edge = this_edge->next;
254 } while (this_edge != loop);
255}
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:120
int cross(const TPOINT &other) const
Definition: blobs.h:79

◆ Move()

void TESSLINE::Move ( const ICOORD  vec)

Definition at line 179 of file blobs.cpp.

179 {
180 EDGEPT* pt = loop;
181 do {
182 pt->pos.x += vec.x();
183 pt->pos.y += vec.y();
184 pt = pt->next;
185 } while (pt != loop);
186 SetupFromPos();
187}
void SetupFromPos()
Definition: blobs.cpp:201
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52

◆ Normalize()

void TESSLINE::Normalize ( const DENORM denorm)

Definition at line 155 of file blobs.cpp.

155 {
156 EDGEPT* pt = loop;
157 do {
158 denorm.LocalNormTransform(pt->pos, &pt->pos);
159 pt = pt->next;
160 } while (pt != loop);
161 SetupFromPos();
162}
void LocalNormTransform(const TPOINT &pt, TPOINT *transformed) const
Definition: normalis.cpp:306

◆ operator=()

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

Definition at line 211 of file blobs.h.

211 {
212 CopyFrom(src);
213 return *this;
214 }

◆ plot()

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

Definition at line 262 of file blobs.cpp.

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

◆ Rotate()

void TESSLINE::Rotate ( const FCOORD  rotation)

Definition at line 165 of file blobs.cpp.

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

◆ SameBox()

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

Definition at line 242 of file blobs.h.

242 {
243 return topleft == other.topleft && botright == other.botright;
244 }

◆ Scale()

void TESSLINE::Scale ( float  factor)

Definition at line 190 of file blobs.cpp.

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

◆ SegmentCrosses()

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

Definition at line 246 of file blobs.h.

246 {
247 if (Contains(pt1) && Contains(pt2)) {
248 EDGEPT* pt = loop;
249 do {
250 if (TPOINT::IsCrossed(pt1, pt2, pt->pos, pt->next->pos)) return true;
251 pt = pt->next;
252 } while (pt != loop);
253 }
254 return false;
255 }
static bool IsCrossed(const TPOINT &a0, const TPOINT &a1, const TPOINT &b0, const TPOINT &b1)
Definition: blobs.cpp:66
bool Contains(const TPOINT &pt) const
Definition: blobs.h:257

◆ SetupFromPos()

void TESSLINE::SetupFromPos ( )

Definition at line 201 of file blobs.cpp.

201 {
202 EDGEPT* pt = loop;
203 do {
204 pt->vec.x = pt->next->pos.x - pt->pos.x;
205 pt->vec.y = pt->next->pos.y - pt->pos.y;
206 pt = pt->next;
207 } while (pt != loop);
208 start = pt->pos;
210}
VECTOR vec
Definition: blobs.h:187
void ComputeBoundingBox()
Definition: blobs.cpp:213

Member Data Documentation

◆ botright

TPOINT TESSLINE::botright

Definition at line 277 of file blobs.h.

◆ is_hole

bool TESSLINE::is_hole

Definition at line 279 of file blobs.h.

◆ loop

EDGEPT* TESSLINE::loop

Definition at line 280 of file blobs.h.

◆ next

TESSLINE* TESSLINE::next

Definition at line 281 of file blobs.h.

◆ start

TPOINT TESSLINE::start

Definition at line 278 of file blobs.h.

◆ topleft

TPOINT TESSLINE::topleft

Definition at line 276 of file blobs.h.


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