Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
C_OUTLINE Class Reference

#include <coutln.h>

Inheritance diagram for C_OUTLINE:
ELIST_LINK

Public Member Functions

 C_OUTLINE ()
 
 C_OUTLINE (CRACKEDGE *startpt, ICOORD bot_left, ICOORD top_right, inT16 length)
 
 C_OUTLINE (ICOORD startpt, DIR128 *new_steps, inT16 length)
 
 C_OUTLINE (C_OUTLINE *srcline, FCOORD rotation)
 
 ~C_OUTLINE ()
 
BOOL8 flag (C_OUTLINE_FLAGS mask) const
 
void set_flag (C_OUTLINE_FLAGS mask, BOOL8 value)
 
C_OUTLINE_LIST * child ()
 
const TBOXbounding_box () const
 
void set_step (inT16 stepindex, inT8 stepdir)
 
void set_step (inT16 stepindex, DIR128 stepdir)
 
const ICOORDstart_pos () const
 
inT32 pathlength () const
 
DIR128 step_dir (inT16 index) const
 
ICOORD step (inT16 index) const
 
inT32 area ()
 
inT32 perimeter ()
 
inT32 outer_area ()
 
inT32 count_transitions (inT32 threshold)
 
BOOL8 operator< (const C_OUTLINE &other) const
 
BOOL8 operator> (C_OUTLINE &other) const
 
inT16 winding_number (ICOORD testpt) const
 
inT16 turn_direction () const
 
void reverse ()
 
void move (const ICOORD vec)
 
void RemoveSmallRecursive (int min_size, C_OUTLINE_IT *it)
 
void render (int left, int top, Pix *pix) const
 
void render_outline (int left, int top, Pix *pix) const
 
void plot (ScrollView *window, ScrollView::Color colour) const
 
C_OUTLINEoperator= (const C_OUTLINE &source)
 
- Public Member Functions inherited from ELIST_LINK
 ELIST_LINK ()
 
 ELIST_LINK (const ELIST_LINK &)
 
void operator= (const ELIST_LINK &)
 

Static Public Member Functions

static void FakeOutline (const TBOX &box, C_OUTLINE_LIST *outlines)
 
static C_OUTLINEdeep_copy (const C_OUTLINE *src)
 
static ICOORD chain_step (int chaindir)
 

Detailed Description

Definition at line 44 of file coutln.h.

Constructor & Destructor Documentation

C_OUTLINE::C_OUTLINE ( )
inline

Definition at line 47 of file coutln.h.

47  { //empty constructor
48  steps = NULL;
49  }
#define NULL
Definition: host.h:144
C_OUTLINE::C_OUTLINE ( CRACKEDGE startpt,
ICOORD  bot_left,
ICOORD  top_right,
inT16  length 
)

Definition at line 44 of file coutln.cpp.

49  :box (bot_left, top_right), start (startpt->pos) {
50  inT16 stepindex; //index to step
51  CRACKEDGE *edgept; //current point
52 
53  stepcount = length; //no of steps
54  if (length == 0) {
55  steps = NULL;
56  return;
57  }
58  //get memory
59  steps = (uinT8 *) alloc_mem (step_mem());
60  memset(steps, 0, step_mem());
61  edgept = startpt;
62 
63  for (stepindex = 0; stepindex < length; stepindex++) {
64  //set compact step
65  set_step (stepindex, edgept->stepdir);
66  edgept = edgept->next;
67  }
68 }
inT8 stepdir
Definition: crakedge.h:33
#define NULL
Definition: host.h:144
void * alloc_mem(inT32 count)
Definition: memry.cpp:48
ICOORD pos
Definition: crakedge.h:30
short inT16
Definition: host.h:100
unsigned char uinT8
Definition: host.h:99
CRACKEDGE * next
Definition: crakedge.h:35
void set_step(inT16 stepindex, inT8 stepdir)
Definition: coutln.h:88
C_OUTLINE::C_OUTLINE ( ICOORD  startpt,
DIR128 new_steps,
inT16  length 
)

Definition at line 76 of file coutln.cpp.

81  :start (startpt) {
82  inT8 dirdiff; //direction difference
83  DIR128 prevdir; //previous direction
84  DIR128 dir; //current direction
85  DIR128 lastdir; //dir of last step
86  TBOX new_box; //easy bounding
87  inT16 stepindex; //index to step
88  inT16 srcindex; //source steps
89  ICOORD pos; //current position
90 
91  pos = startpt;
92  stepcount = length; //no of steps
93  //get memory
94  steps = (uinT8 *) alloc_mem (step_mem());
95  memset(steps, 0, step_mem());
96 
97  lastdir = new_steps[length - 1];
98  prevdir = lastdir;
99  for (stepindex = 0, srcindex = 0; srcindex < length;
100  stepindex++, srcindex++) {
101  new_box = TBOX (pos, pos);
102  box += new_box;
103  //copy steps
104  dir = new_steps[srcindex];
105  set_step(stepindex, dir);
106  dirdiff = dir - prevdir;
107  pos += step (stepindex);
108  if ((dirdiff == 64 || dirdiff == -64) && stepindex > 0) {
109  stepindex -= 2; //cancel there-and-back
110  prevdir = stepindex >= 0 ? step_dir (stepindex) : lastdir;
111  }
112  else
113  prevdir = dir;
114  }
115  ASSERT_HOST (pos.x () == startpt.x () && pos.y () == startpt.y ());
116  do {
117  dirdiff = step_dir (stepindex - 1) - step_dir (0);
118  if (dirdiff == 64 || dirdiff == -64) {
119  start += step (0);
120  stepindex -= 2; //cancel there-and-back
121  for (int i = 0; i < stepindex; ++i)
122  set_step(i, step_dir(i + 1));
123  }
124  }
125  while (stepindex > 1 && (dirdiff == 64 || dirdiff == -64));
126  stepcount = stepindex;
127  ASSERT_HOST (stepcount >= 4);
128 }
inT16 x() const
access function
Definition: points.h:52
ICOORD step(inT16 index) const
Definition: coutln.h:120
Definition: rect.h:29
void * alloc_mem(inT32 count)
Definition: memry.cpp:48
inT16 y() const
access_function
Definition: points.h:56
Definition: mod128.h:29
DIR128 step_dir(inT16 index) const
Definition: coutln.h:115
short inT16
Definition: host.h:100
integer coordinate
Definition: points.h:30
SIGNED char inT8
Definition: host.h:98
unsigned char uinT8
Definition: host.h:99
#define ASSERT_HOST(x)
Definition: errcode.h:84
void set_step(inT16 stepindex, inT8 stepdir)
Definition: coutln.h:88
C_OUTLINE::C_OUTLINE ( C_OUTLINE srcline,
FCOORD  rotation 
)

Definition at line 136 of file coutln.cpp.

139  {
140  TBOX new_box; //easy bounding
141  inT16 stepindex; //index to step
142  inT16 dirdiff; //direction change
143  ICOORD pos; //current position
144  ICOORD prevpos; //previous dest point
145 
146  ICOORD destpos; //destination point
147  inT16 destindex; //index to step
148  DIR128 dir; //coded direction
149  uinT8 new_step;
150 
151  stepcount = srcline->stepcount * 2;
152  if (stepcount == 0) {
153  steps = NULL;
154  box = srcline->box;
155  box.rotate(rotation);
156  return;
157  }
158  //get memory
159  steps = (uinT8 *) alloc_mem (step_mem());
160  memset(steps, 0, step_mem());
161 
162  for (int iteration = 0; iteration < 2; ++iteration) {
163  DIR128 round1 = iteration == 0 ? 32 : 0;
164  DIR128 round2 = iteration != 0 ? 32 : 0;
165  pos = srcline->start;
166  prevpos = pos;
167  prevpos.rotate (rotation);
168  start = prevpos;
169  box = TBOX (start, start);
170  destindex = 0;
171  for (stepindex = 0; stepindex < srcline->stepcount; stepindex++) {
172  pos += srcline->step (stepindex);
173  destpos = pos;
174  destpos.rotate (rotation);
175  // printf("%i %i %i %i ", destpos.x(), destpos.y(), pos.x(), pos.y());
176  while (destpos.x () != prevpos.x () || destpos.y () != prevpos.y ()) {
177  dir = DIR128 (FCOORD (destpos - prevpos));
178  dir += 64; //turn to step style
179  new_step = dir.get_dir ();
180  // printf(" %i\n", new_step);
181  if (new_step & 31) {
182  set_step(destindex++, dir + round1);
183  prevpos += step(destindex - 1);
184  if (destindex < 2
185  || ((dirdiff =
186  step_dir (destindex - 1) - step_dir (destindex - 2)) !=
187  -64 && dirdiff != 64)) {
188  set_step(destindex++, dir + round2);
189  prevpos += step(destindex - 1);
190  } else {
191  prevpos -= step(destindex - 1);
192  destindex--;
193  prevpos -= step(destindex - 1);
194  set_step(destindex - 1, dir + round2);
195  prevpos += step(destindex - 1);
196  }
197  }
198  else {
199  set_step(destindex++, dir);
200  prevpos += step(destindex - 1);
201  }
202  while (destindex >= 2 &&
203  ((dirdiff =
204  step_dir (destindex - 1) - step_dir (destindex - 2)) == -64 ||
205  dirdiff == 64)) {
206  prevpos -= step(destindex - 1);
207  prevpos -= step(destindex - 2);
208  destindex -= 2; // Forget u turn
209  }
210  //ASSERT_HOST(prevpos.x() == destpos.x() && prevpos.y() == destpos.y());
211  new_box = TBOX (destpos, destpos);
212  box += new_box;
213  }
214  }
215  ASSERT_HOST (destpos.x () == start.x () && destpos.y () == start.y ());
216  dirdiff = step_dir (destindex - 1) - step_dir (0);
217  while ((dirdiff == 64 || dirdiff == -64) && destindex > 1) {
218  start += step (0);
219  destindex -= 2;
220  for (int i = 0; i < destindex; ++i)
221  set_step(i, step_dir(i + 1));
222  dirdiff = step_dir (destindex - 1) - step_dir (0);
223  }
224  if (destindex >= 4)
225  break;
226  }
227  ASSERT_HOST(destindex <= stepcount);
228  stepcount = destindex;
229  destpos = start;
230  for (stepindex = 0; stepindex < stepcount; stepindex++) {
231  destpos += step (stepindex);
232  }
233  ASSERT_HOST (destpos.x () == start.x () && destpos.y () == start.y ());
234 }
void rotate(const FCOORD &vec)
Definition: ipoints.h:241
inT8 get_dir() const
Definition: mod128.h:77
inT16 x() const
access function
Definition: points.h:52
ICOORD step(inT16 index) const
Definition: coutln.h:120
#define NULL
Definition: host.h:144
Definition: rect.h:29
void * alloc_mem(inT32 count)
Definition: memry.cpp:48
inT16 y() const
access_function
Definition: points.h:56
Definition: mod128.h:29
Definition: points.h:189
DIR128 step_dir(inT16 index) const
Definition: coutln.h:115
short inT16
Definition: host.h:100
integer coordinate
Definition: points.h:30
unsigned char uinT8
Definition: host.h:99
void rotate(const FCOORD &vec)
Definition: rect.h:182
#define ASSERT_HOST(x)
Definition: errcode.h:84
void set_step(inT16 stepindex, inT8 stepdir)
Definition: coutln.h:88
C_OUTLINE::~C_OUTLINE ( )
inline

Definition at line 64 of file coutln.h.

64  { //destructor
65  if (steps != NULL)
66  free_mem(steps);
67  steps = NULL;
68  }
#define NULL
Definition: host.h:144
void free_mem(void *oldchunk)
Definition: memry.cpp:56

Member Function Documentation

inT32 C_OUTLINE::area ( )

Definition at line 253 of file coutln.cpp.

253  { //winding number
254  int stepindex; //current step
255  inT32 total_steps; //steps to do
256  inT32 total; //total area
257  ICOORD pos; //position of point
258  ICOORD next_step; //step to next pix
259  C_OUTLINE_IT it = child ();
260 
261  pos = start_pos ();
262  total_steps = pathlength ();
263  total = 0;
264  for (stepindex = 0; stepindex < total_steps; stepindex++) {
265  //all intersected
266  next_step = step (stepindex);
267  if (next_step.x () < 0)
268  total += pos.y ();
269  else if (next_step.x () > 0)
270  total -= pos.y ();
271  pos += next_step;
272  }
273  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
274  total += it.data ()->area ();//add areas of children
275 
276  return total;
277 }
inT16 x() const
access function
Definition: points.h:52
const ICOORD & start_pos() const
Definition: coutln.h:108
ICOORD step(inT16 index) const
Definition: coutln.h:120
int inT32
Definition: host.h:102
inT16 y() const
access_function
Definition: points.h:56
inT32 pathlength() const
Definition: coutln.h:111
integer coordinate
Definition: points.h:30
C_OUTLINE_LIST * child()
Definition: coutln.h:80
const TBOX& C_OUTLINE::bounding_box ( ) const
inline

Definition at line 85 of file coutln.h.

85  {
86  return box;
87  }
ICOORD C_OUTLINE::chain_step ( int  chaindir)
static

Definition at line 723 of file coutln.cpp.

723  {
724  return step_coords[chaindir % 4];
725 }
C_OUTLINE_LIST* C_OUTLINE::child ( )
inline

Definition at line 80 of file coutln.h.

80  { //get child list
81  return &children;
82  }
inT32 C_OUTLINE::count_transitions ( inT32  threshold)

Definition at line 335 of file coutln.cpp.

337  {
338  BOOL8 first_was_max_x; //what was first
339  BOOL8 first_was_max_y;
340  BOOL8 looking_for_max_x; //what is next
341  BOOL8 looking_for_min_x;
342  BOOL8 looking_for_max_y; //what is next
343  BOOL8 looking_for_min_y;
344  int stepindex; //current step
345  inT32 total_steps; //steps to do
346  //current limits
347  inT32 max_x, min_x, max_y, min_y;
348  inT32 initial_x, initial_y; //initial limits
349  inT32 total; //total changes
350  ICOORD pos; //position of point
351  ICOORD next_step; //step to next pix
352 
353  pos = start_pos ();
354  total_steps = pathlength ();
355  total = 0;
356  max_x = min_x = pos.x ();
357  max_y = min_y = pos.y ();
358  looking_for_max_x = TRUE;
359  looking_for_min_x = TRUE;
360  looking_for_max_y = TRUE;
361  looking_for_min_y = TRUE;
362  first_was_max_x = FALSE;
363  first_was_max_y = FALSE;
364  initial_x = pos.x ();
365  initial_y = pos.y (); //stop uninit warning
366  for (stepindex = 0; stepindex < total_steps; stepindex++) {
367  //all intersected
368  next_step = step (stepindex);
369  pos += next_step;
370  if (next_step.x () < 0) {
371  if (looking_for_max_x && pos.x () < min_x)
372  min_x = pos.x ();
373  if (looking_for_min_x && max_x - pos.x () > threshold) {
374  if (looking_for_max_x) {
375  initial_x = max_x;
376  first_was_max_x = FALSE;
377  }
378  total++;
379  looking_for_max_x = TRUE;
380  looking_for_min_x = FALSE;
381  min_x = pos.x (); //reset min
382  }
383  }
384  else if (next_step.x () > 0) {
385  if (looking_for_min_x && pos.x () > max_x)
386  max_x = pos.x ();
387  if (looking_for_max_x && pos.x () - min_x > threshold) {
388  if (looking_for_min_x) {
389  initial_x = min_x; //remember first min
390  first_was_max_x = TRUE;
391  }
392  total++;
393  looking_for_max_x = FALSE;
394  looking_for_min_x = TRUE;
395  max_x = pos.x ();
396  }
397  }
398  else if (next_step.y () < 0) {
399  if (looking_for_max_y && pos.y () < min_y)
400  min_y = pos.y ();
401  if (looking_for_min_y && max_y - pos.y () > threshold) {
402  if (looking_for_max_y) {
403  initial_y = max_y; //remember first max
404  first_was_max_y = FALSE;
405  }
406  total++;
407  looking_for_max_y = TRUE;
408  looking_for_min_y = FALSE;
409  min_y = pos.y (); //reset min
410  }
411  }
412  else {
413  if (looking_for_min_y && pos.y () > max_y)
414  max_y = pos.y ();
415  if (looking_for_max_y && pos.y () - min_y > threshold) {
416  if (looking_for_min_y) {
417  initial_y = min_y; //remember first min
418  first_was_max_y = TRUE;
419  }
420  total++;
421  looking_for_max_y = FALSE;
422  looking_for_min_y = TRUE;
423  max_y = pos.y ();
424  }
425  }
426 
427  }
428  if (first_was_max_x && looking_for_min_x) {
429  if (max_x - initial_x > threshold)
430  total++;
431  else
432  total--;
433  }
434  else if (!first_was_max_x && looking_for_max_x) {
435  if (initial_x - min_x > threshold)
436  total++;
437  else
438  total--;
439  }
440  if (first_was_max_y && looking_for_min_y) {
441  if (max_y - initial_y > threshold)
442  total++;
443  else
444  total--;
445  }
446  else if (!first_was_max_y && looking_for_max_y) {
447  if (initial_y - min_y > threshold)
448  total++;
449  else
450  total--;
451  }
452 
453  return total;
454 }
inT16 x() const
access function
Definition: points.h:52
const ICOORD & start_pos() const
Definition: coutln.h:108
ICOORD step(inT16 index) const
Definition: coutln.h:120
unsigned char BOOL8
Definition: host.h:113
int inT32
Definition: host.h:102
#define FALSE
Definition: capi.h:28
inT16 y() const
access_function
Definition: points.h:56
inT32 pathlength() const
Definition: coutln.h:111
integer coordinate
Definition: points.h:30
#define TRUE
Definition: capi.h:27
static C_OUTLINE* C_OUTLINE::deep_copy ( const C_OUTLINE src)
inlinestatic

Definition at line 169 of file coutln.h.

169  {
170  C_OUTLINE* outline = new C_OUTLINE;
171  *outline = *src;
172  return outline;
173  }
C_OUTLINE()
Definition: coutln.h:47
void C_OUTLINE::FakeOutline ( const TBOX box,
C_OUTLINE_LIST *  outlines 
)
static

Definition at line 237 of file coutln.cpp.

237  {
238  C_OUTLINE_IT ol_it(outlines);
239  // Make a C_OUTLINE from the bounds. This is a bit of a hack,
240  // as there is no outline, just a bounding box, but it works nicely.
241  CRACKEDGE start;
242  start.pos = box.topleft();
243  C_OUTLINE* outline = new C_OUTLINE(&start, box.topleft(), box.botright(), 0);
244  ol_it.add_to_end(outline);
245 }
ICOORD topleft() const
Definition: rect.h:89
ICOORD botright() const
Definition: rect.h:85
ICOORD pos
Definition: crakedge.h:30
C_OUTLINE()
Definition: coutln.h:47
BOOL8 C_OUTLINE::flag ( C_OUTLINE_FLAGS  mask) const
inline

Definition at line 70 of file coutln.h.

71  { //flag to test
72  return flags.bit (mask);
73  }
BOOL8 bit(uinT8 bit_num) const
Definition: bits16.h:56
void C_OUTLINE::move ( const ICOORD  vec)

Definition at line 592 of file coutln.cpp.

594  {
595  C_OUTLINE_IT it(&children); // iterator
596 
597  box.move (vec);
598  start += vec;
599 
600  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
601  it.data ()->move (vec); // move child outlines
602 }
void move(const ICOORD vec)
Definition: rect.h:146
BOOL8 C_OUTLINE::operator< ( const C_OUTLINE other) const

Definition at line 464 of file coutln.cpp.

467 {
468  inT16 count = 0; //winding count
469  ICOORD pos; //position of point
470  inT32 stepindex; //index to cstep
471 
472  if (!box.overlap (other.box))
473  return FALSE; //can't be contained
474  if (stepcount == 0)
475  return other.box.contains(this->box);
476 
477  pos = start;
478  for (stepindex = 0; stepindex < stepcount
479  && (count = other.winding_number (pos)) == INTERSECTING; stepindex++)
480  pos += step (stepindex); //try all points
481  if (count == INTERSECTING) {
482  //all intersected
483  pos = other.start;
484  for (stepindex = 0; stepindex < other.stepcount
485  && (count = winding_number (pos)) == INTERSECTING; stepindex++)
486  //try other way round
487  pos += other.step (stepindex);
488  return count == INTERSECTING || count == 0;
489  }
490  return count != 0;
491 }
inT16 winding_number(ICOORD testpt) const
Definition: coutln.cpp:500
bool contains(const FCOORD pt) const
Definition: rect.h:323
ICOORD step(inT16 index) const
Definition: coutln.h:120
bool overlap(const TBOX &box) const
Definition: rect.h:345
int inT32
Definition: host.h:102
#define FALSE
Definition: capi.h:28
short inT16
Definition: host.h:100
integer coordinate
Definition: points.h:30
#define INTERSECTING
Definition: coutln.h:30
int count(LIST var_list)
Definition: oldlist.cpp:108
C_OUTLINE & C_OUTLINE::operator= ( const C_OUTLINE source)

Definition at line 707 of file coutln.cpp.

709  {
710  box = source.box;
711  start = source.start;
712  if (steps != NULL)
713  free_mem(steps);
714  stepcount = source.stepcount;
715  steps = (uinT8 *) alloc_mem (step_mem());
716  memmove (steps, source.steps, step_mem());
717  if (!children.empty ())
718  children.clear ();
719  children.deep_copy(&source.children, &deep_copy);
720  return *this;
721 }
#define NULL
Definition: host.h:144
void free_mem(void *oldchunk)
Definition: memry.cpp:56
void * alloc_mem(inT32 count)
Definition: memry.cpp:48
static C_OUTLINE * deep_copy(const C_OUTLINE *src)
Definition: coutln.h:169
unsigned char uinT8
Definition: host.h:99
BOOL8 C_OUTLINE::operator> ( C_OUTLINE other) const
inline

Definition at line 132 of file coutln.h.

134  {
135  return other < *this; //use the < to do it
136  }
inT32 C_OUTLINE::outer_area ( )

Definition at line 303 of file coutln.cpp.

303  { //winding number
304  int stepindex; //current step
305  inT32 total_steps; //steps to do
306  inT32 total; //total area
307  ICOORD pos; //position of point
308  ICOORD next_step; //step to next pix
309 
310  pos = start_pos ();
311  total_steps = pathlength ();
312  if (total_steps == 0)
313  return box.area();
314  total = 0;
315  for (stepindex = 0; stepindex < total_steps; stepindex++) {
316  //all intersected
317  next_step = step (stepindex);
318  if (next_step.x () < 0)
319  total += pos.y ();
320  else if (next_step.x () > 0)
321  total -= pos.y ();
322  pos += next_step;
323  }
324 
325  return total;
326 }
inT32 area() const
Definition: rect.h:111
inT16 x() const
access function
Definition: points.h:52
const ICOORD & start_pos() const
Definition: coutln.h:108
ICOORD step(inT16 index) const
Definition: coutln.h:120
int inT32
Definition: host.h:102
inT16 y() const
access_function
Definition: points.h:56
inT32 pathlength() const
Definition: coutln.h:111
integer coordinate
Definition: points.h:30
inT32 C_OUTLINE::pathlength ( ) const
inline

Definition at line 111 of file coutln.h.

111  { //get path length
112  return stepcount;
113  }
inT32 C_OUTLINE::perimeter ( )

Definition at line 285 of file coutln.cpp.

285  {
286  inT32 total_steps; // Return value.
287  C_OUTLINE_IT it = child();
288 
289  total_steps = pathlength();
290  for (it.mark_cycle_pt(); !it.cycled_list(); it.forward())
291  total_steps += it.data()->pathlength(); // Add perimeters of children.
292 
293  return total_steps;
294 }
int inT32
Definition: host.h:102
inT32 pathlength() const
Definition: coutln.h:111
C_OUTLINE_LIST * child()
Definition: coutln.h:80
void C_OUTLINE::plot ( ScrollView window,
ScrollView::Color  colour 
) const

Definition at line 667 of file coutln.cpp.

670  {
671  inT16 stepindex; // index to cstep
672  ICOORD pos; // current position
673  DIR128 stepdir; // direction of step
674 
675  pos = start; // current position
676  window->Pen(colour);
677  if (stepcount == 0) {
678  window->Rectangle(box.left(), box.top(), box.right(), box.bottom());
679  return;
680  }
681  window->SetCursor(pos.x(), pos.y());
682 
683  stepindex = 0;
684  while (stepindex < stepcount) {
685  pos += step(stepindex); // step to next
686  stepdir = step_dir(stepindex);
687  stepindex++; // count steps
688  // merge straight lines
689  while (stepindex < stepcount &&
690  stepdir.get_dir() == step_dir(stepindex).get_dir()) {
691  pos += step(stepindex);
692  stepindex++;
693  }
694  window->DrawTo(pos.x(), pos.y());
695  }
696 }
void SetCursor(int x, int y)
Definition: scrollview.cpp:520
inT8 get_dir() const
Definition: mod128.h:77
inT16 x() const
access function
Definition: points.h:52
void Pen(Color color)
Definition: scrollview.cpp:721
ICOORD step(inT16 index) const
Definition: coutln.h:120
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
inT16 y() const
access_function
Definition: points.h:56
void DrawTo(int x, int y)
Definition: scrollview.cpp:526
void Rectangle(int x1, int y1, int x2, int y2)
Definition: scrollview.cpp:601
inT16 top() const
Definition: rect.h:53
Definition: mod128.h:29
DIR128 step_dir(inT16 index) const
Definition: coutln.h:115
short inT16
Definition: host.h:100
integer coordinate
Definition: points.h:30
inT16 bottom() const
Definition: rect.h:60
void C_OUTLINE::RemoveSmallRecursive ( int  min_size,
C_OUTLINE_IT *  it 
)

Definition at line 609 of file coutln.cpp.

609  {
610  if (box.width() < min_size || box.height() < min_size) {
611  ASSERT_HOST(this == it->data());
612  delete it->extract(); // Too small so get rid of it and any children.
613  } else if (!children.empty()) {
614  // Search the children of this, deleting any that are too small.
615  C_OUTLINE_IT child_it(&children);
616  for (child_it.mark_cycle_pt(); !child_it.cycled_list();
617  child_it.forward()) {
618  C_OUTLINE* child = child_it.data();
619  child->RemoveSmallRecursive(min_size, &child_it);
620  }
621  }
622 }
inT16 width() const
Definition: rect.h:104
void RemoveSmallRecursive(int min_size, C_OUTLINE_IT *it)
Definition: coutln.cpp:609
C_OUTLINE_LIST * child()
Definition: coutln.h:80
#define ASSERT_HOST(x)
Definition: errcode.h:84
inT16 height() const
Definition: rect.h:97
void C_OUTLINE::render ( int  left,
int  top,
Pix *  pix 
) const

Definition at line 626 of file coutln.cpp.

626  {
627  ICOORD pos = start;
628  for (int stepindex = 0; stepindex < stepcount; ++stepindex) {
629  ICOORD next_step = step(stepindex);
630  if (next_step.y() < 0) {
631  pixRasterop(pix, 0, top - pos.y(), pos.x() - left, 1,
632  PIX_NOT(PIX_DST), NULL, 0, 0);
633  } else if (next_step.y() > 0) {
634  pixRasterop(pix, 0, top - pos.y() - 1, pos.x() - left, 1,
635  PIX_NOT(PIX_DST), NULL, 0, 0);
636  }
637  pos += next_step;
638  }
639 }
inT16 x() const
access function
Definition: points.h:52
ICOORD step(inT16 index) const
Definition: coutln.h:120
#define NULL
Definition: host.h:144
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
size_t top
Definition: tessarray.h:52
void C_OUTLINE::render_outline ( int  left,
int  top,
Pix *  pix 
) const

Definition at line 643 of file coutln.cpp.

643  {
644  ICOORD pos = start;
645  for (int stepindex = 0; stepindex < stepcount; ++stepindex) {
646  ICOORD next_step = step(stepindex);
647  if (next_step.y() < 0) {
648  pixSetPixel(pix, pos.x() - left, top - pos.y(), 1);
649  } else if (next_step.y() > 0) {
650  pixSetPixel(pix, pos.x() - left - 1, top - pos.y() - 1, 1);
651  } else if (next_step.x() < 0) {
652  pixSetPixel(pix, pos.x() - left - 1, top - pos.y(), 1);
653  } else if (next_step.x() > 0) {
654  pixSetPixel(pix, pos.x() - left, top - pos.y() - 1, 1);
655  }
656  pos += next_step;
657  }
658 }
inT16 x() const
access function
Definition: points.h:52
ICOORD step(inT16 index) const
Definition: coutln.h:120
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
size_t top
Definition: tessarray.h:52
void C_OUTLINE::reverse ( )

Definition at line 569 of file coutln.cpp.

569  { //reverse drection
570  DIR128 halfturn = MODULUS / 2; //amount to shift
571  DIR128 stepdir; //direction of step
572  inT16 stepindex; //index to cstep
573  inT16 farindex; //index to other side
574  inT16 halfsteps; //half of stepcount
575 
576  halfsteps = (stepcount + 1) / 2;
577  for (stepindex = 0; stepindex < halfsteps; stepindex++) {
578  farindex = stepcount - stepindex - 1;
579  stepdir = step_dir (stepindex);
580  set_step (stepindex, step_dir (farindex) + halfturn);
581  set_step (farindex, stepdir + halfturn);
582  }
583 }
#define MODULUS
Definition: mod128.h:25
Definition: mod128.h:29
DIR128 step_dir(inT16 index) const
Definition: coutln.h:115
short inT16
Definition: host.h:100
void set_step(inT16 stepindex, inT8 stepdir)
Definition: coutln.h:88
void C_OUTLINE::set_flag ( C_OUTLINE_FLAGS  mask,
BOOL8  value 
)
inline

Definition at line 74 of file coutln.h.

76  { //value to set
77  flags.set_bit (mask, value);
78  }
void set_bit(uinT8 bit_num, BOOL8 value)
Definition: bits16.h:47
void C_OUTLINE::set_step ( inT16  stepindex,
inT8  stepdir 
)
inline

Definition at line 88 of file coutln.h.

90  { //chain code
91  int shift = stepindex%4 * 2;
92  uinT8 mask = 3 << shift;
93  steps[stepindex/4] = ((stepdir << shift) & mask) |
94  (steps[stepindex/4] & ~mask);
95  //squeeze 4 into byte
96  }
unsigned char uinT8
Definition: host.h:99
void C_OUTLINE::set_step ( inT16  stepindex,
DIR128  stepdir 
)
inline

Definition at line 97 of file coutln.h.

99  { //direction
100  //clean it
101  inT8 chaindir = stepdir.get_dir() >> (DIRBITS - 2);
102  //difference
103  set_step(stepindex, chaindir);
104  //squeeze 4 into byte
105  }
inT8 get_dir() const
Definition: mod128.h:77
SIGNED char inT8
Definition: host.h:98
#define DIRBITS
Definition: mod128.h:26
void set_step(inT16 stepindex, inT8 stepdir)
Definition: coutln.h:88
const ICOORD& C_OUTLINE::start_pos ( ) const
inline

Definition at line 108 of file coutln.h.

108  {
109  return start;
110  }
ICOORD C_OUTLINE::step ( inT16  index) const
inline

Definition at line 120 of file coutln.h.

120  { //index of step
121  return step_coords[(steps[index/4] >> (index%4 * 2)) & STEP_MASK];
122  }
#define STEP_MASK
Definition: coutln.h:33
DIR128 C_OUTLINE::step_dir ( inT16  index) const
inline

Definition at line 115 of file coutln.h.

115  {
116  return DIR128((inT16)(((steps[index/4] >> (index%4 * 2)) & STEP_MASK) <<
117  (DIRBITS - 2)));
118  }
#define STEP_MASK
Definition: coutln.h:33
Definition: mod128.h:29
short inT16
Definition: host.h:100
#define DIRBITS
Definition: mod128.h:26
inT16 C_OUTLINE::turn_direction ( ) const

Definition at line 540 of file coutln.cpp.

540  { //winding number
541  DIR128 prevdir; //previous direction
542  DIR128 dir; //current direction
543  inT16 stepindex; //index to cstep
544  inT8 dirdiff; //direction difference
545  inT16 count; //winding count
546 
547  if (stepcount == 0)
548  return 128;
549  count = 0;
550  prevdir = step_dir (stepcount - 1);
551  for (stepindex = 0; stepindex < stepcount; stepindex++) {
552  dir = step_dir (stepindex);
553  dirdiff = dir - prevdir;
554  ASSERT_HOST (dirdiff == 0 || dirdiff == 32 || dirdiff == -32);
555  count += dirdiff;
556  prevdir = dir;
557  }
558  ASSERT_HOST (count == 128 || count == -128);
559  return count; //winding number
560 }
Definition: mod128.h:29
DIR128 step_dir(inT16 index) const
Definition: coutln.h:115
short inT16
Definition: host.h:100
SIGNED char inT8
Definition: host.h:98
#define ASSERT_HOST(x)
Definition: errcode.h:84
int count(LIST var_list)
Definition: oldlist.cpp:108
inT16 C_OUTLINE::winding_number ( ICOORD  testpt) const

Definition at line 500 of file coutln.cpp.

502  {
503  inT16 stepindex; //index to cstep
504  inT16 count; //winding count
505  ICOORD vec; //to current point
506  ICOORD stepvec; //step vector
507  inT32 cross; //cross product
508 
509  vec = start - point; //vector to it
510  count = 0;
511  for (stepindex = 0; stepindex < stepcount; stepindex++) {
512  stepvec = step (stepindex); //get the step
513  //crossing the line
514  if (vec.y () <= 0 && vec.y () + stepvec.y () > 0) {
515  cross = vec * stepvec; //cross product
516  if (cross > 0)
517  count++; //crossing right half
518  else if (cross == 0)
519  return INTERSECTING; //going through point
520  }
521  else if (vec.y () > 0 && vec.y () + stepvec.y () <= 0) {
522  cross = vec * stepvec;
523  if (cross < 0)
524  count--; //crossing back
525  else if (cross == 0)
526  return INTERSECTING; //illegal
527  }
528  vec += stepvec; //sum vectors
529  }
530  return count; //winding number
531 }
ICOORD step(inT16 index) const
Definition: coutln.h:120
int inT32
Definition: host.h:102
inT16 y() const
access_function
Definition: points.h:56
short inT16
Definition: host.h:100
integer coordinate
Definition: points.h:30
#define INTERSECTING
Definition: coutln.h:30
int count(LIST var_list)
Definition: oldlist.cpp:108

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