tesseract v5.3.3.20231005
tesseract::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 211 of file blobs.h.

Constructor & Destructor Documentation

◆ TESSLINE() [1/2]

tesseract::TESSLINE::TESSLINE ( )
inline

Definition at line 212 of file blobs.h.

212: is_hole(false), loop(nullptr), next(nullptr) {}
EDGEPT * loop
Definition: blobs.h:287
TESSLINE * next
Definition: blobs.h:288

◆ TESSLINE() [2/2]

tesseract::TESSLINE::TESSLINE ( const TESSLINE src)
inline

Definition at line 213 of file blobs.h.

213 : loop(nullptr), next(nullptr) {
214 CopyFrom(src);
215 }
void CopyFrom(const TESSLINE &src)
Definition: blobs.cpp:114

◆ ~TESSLINE()

tesseract::TESSLINE::~TESSLINE ( )
inline

Definition at line 216 of file blobs.h.

216 {
217 Clear();
218 }

Member Function Documentation

◆ BBArea()

int tesseract::TESSLINE::BBArea ( ) const
inline

Definition at line 279 of file blobs.h.

279 {
280 return (botright.x - topleft.x) * (topleft.y - botright.y);
281 }
TDimension x
Definition: blobs.h:89
TDimension y
Definition: blobs.h:90
TPOINT botright
Definition: blobs.h:284
TPOINT topleft
Definition: blobs.h:283

◆ bounding_box()

TBOX tesseract::TESSLINE::bounding_box ( ) const

Definition at line 263 of file blobs.cpp.

263 {
265}
@ TBOX

◆ BuildFromOutlineList()

TESSLINE * tesseract::TESSLINE::BuildFromOutlineList ( EDGEPT outline)
static

Definition at line 91 of file blobs.cpp.

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

◆ Clear()

void tesseract::TESSLINE::Clear ( )

Definition at line 141 of file blobs.cpp.

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

◆ ComputeBoundingBox()

void tesseract::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) {
224 minx = this_edge->pos.x;
225 }
226 if (this_edge->pos.y < miny) {
227 miny = this_edge->pos.y;
228 }
229 if (this_edge->pos.x > maxx) {
230 maxx = this_edge->pos.x;
231 }
232 if (this_edge->pos.y > maxy) {
233 maxy = this_edge->pos.y;
234 }
235 }
236 this_edge = this_edge->next;
237 } while (this_edge != loop);
238 // Reset bounds.
239 topleft.x = minx;
240 topleft.y = maxy;
241 botright.x = maxx;
242 botright.y = miny;
243}
TPOINT pos
Definition: blobs.h:194

◆ Contains()

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

Definition at line 267 of file blobs.h.

267 {
268 return topleft.x <= pt.x && pt.x <= botright.x && botright.y <= pt.y && pt.y <= topleft.y;
269 }

◆ CopyFrom()

void tesseract::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}
EDGEPT * prev
Definition: blobs.h:201

◆ FindBestStartPt()

EDGEPT * tesseract::TESSLINE::FindBestStartPt ( ) const

Definition at line 290 of file blobs.cpp.

290 {
291 EDGEPT *best_start = loop;
292 int best_step = loop->start_step;
293 // Iterate the polygon.
294 EDGEPT *pt = loop;
295 do {
296 if (pt->IsHidden()) {
297 continue;
298 }
299 if (pt->prev->IsHidden() || pt->prev->src_outline != pt->src_outline) {
300 return pt; // Qualifies as the best.
301 }
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}

◆ MinMaxCrossProduct()

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

Definition at line 250 of file blobs.cpp.

250 {
251 *min_xp = INT32_MAX;
252 *max_xp = INT32_MIN;
253 EDGEPT *this_edge = loop;
254 do {
255 if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
256 int product = this_edge->pos.cross(vec);
257 UpdateRange(product, min_xp, max_xp);
258 }
259 this_edge = this_edge->next;
260 } while (this_edge != loop);
261}
void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)
Definition: helpers.h:117
int cross(const TPOINT &other) const
Definition: blobs.h:75

◆ Move()

void tesseract::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}
void SetupFromPos()
Definition: blobs.cpp:200

◆ Normalize()

void tesseract::TESSLINE::Normalize ( const DENORM denorm)

Definition at line 156 of file blobs.cpp.

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

◆ operator=()

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

Definition at line 219 of file blobs.h.

219 {
220 CopyFrom(src);
221 return *this;
222 }

◆ plot()

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

Definition at line 268 of file blobs.cpp.

268 {
269 if (is_hole) {
270 window->Pen(child_color);
271 } else {
272 window->Pen(color);
273 }
274 window->SetCursor(start.x, start.y);
275 EDGEPT *pt = loop;
276 do {
277 bool prev_hidden = pt->IsHidden();
278 pt = pt->next;
279 if (prev_hidden) {
280 window->SetCursor(pt->pos.x, pt->pos.y);
281 } else {
282 window->DrawTo(pt->pos.x, pt->pos.y);
283 }
284 } while (pt != loop);
285}
bool IsHidden() const
Definition: blobs.h:184

◆ Rotate()

void tesseract::TESSLINE::Rotate ( const FCOORD  rotation)

Definition at line 166 of file blobs.cpp.

166 {
167 EDGEPT *pt = loop;
168 do {
169 int tmp = static_cast<int>(floor(pt->pos.x * rot.x() - pt->pos.y * rot.y() + 0.5));
170 pt->pos.y = static_cast<int>(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 tesseract::TESSLINE::SameBox ( const TESSLINE other) const
inline

Definition at line 250 of file blobs.h.

250 {
251 return topleft == other.topleft && botright == other.botright;
252 }

◆ Scale()

void tesseract::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 tesseract::TESSLINE::SegmentCrosses ( const TPOINT pt1,
const TPOINT pt2 
) const
inline

Definition at line 254 of file blobs.h.

254 {
255 if (Contains(pt1) && Contains(pt2)) {
256 EDGEPT *pt = loop;
257 do {
258 if (TPOINT::IsCrossed(pt1, pt2, pt->pos, pt->next->pos)) {
259 return true;
260 }
261 pt = pt->next;
262 } while (pt != loop);
263 }
264 return false;
265 }
static bool IsCrossed(const TPOINT &a0, const TPOINT &a1, const TPOINT &b0, const TPOINT &b1)
Definition: blobs.cpp:65
bool Contains(const TPOINT &pt) const
Definition: blobs.h:267

◆ SetupFromPos()

void tesseract::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}
VECTOR vec
Definition: blobs.h:195
void ComputeBoundingBox()
Definition: blobs.cpp:212

Member Data Documentation

◆ botright

TPOINT tesseract::TESSLINE::botright

Definition at line 284 of file blobs.h.

◆ is_hole

bool tesseract::TESSLINE::is_hole

Definition at line 286 of file blobs.h.

◆ loop

EDGEPT* tesseract::TESSLINE::loop

Definition at line 287 of file blobs.h.

◆ next

TESSLINE* tesseract::TESSLINE::next

Definition at line 288 of file blobs.h.

◆ start

TPOINT tesseract::TESSLINE::start

Definition at line 285 of file blobs.h.

◆ topleft

TPOINT tesseract::TESSLINE::topleft

Definition at line 283 of file blobs.h.


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