tesseract  3.05.02
POLY_BLOCK Class Reference

#include <polyblk.h>

Public Member Functions

 POLY_BLOCK ()
 
 POLY_BLOCK (const TBOX &box, PolyBlockType type)
 
 POLY_BLOCK (ICOORDELT_LIST *points, PolyBlockType type)
 
 ~POLY_BLOCK ()
 
TBOXbounding_box ()
 
ICOORDELT_LIST * points ()
 
PolyBlockType isA () const
 
bool IsText () const
 
POLY_BLOCK::compute_bb

Compute the bounding box from the outline points.

void compute_bb ()
 
POLY_BLOCK::rotate

Rotate the POLY_BLOCK.

Parameters
rotationcos, sin of angle
void rotate (FCOORD rotation)
 
POLY_BLOCK::winding_number

Return the winding number of the outline around the given point.

Parameters
pointpoint to wind around
bool contains (POLY_BLOCK *other)
 
inT16 winding_number (const ICOORD &test_pt)
 

POLY_BLOCK::reflect_in_y_axis

Reflect the coords of the polygon in the y-axis. (Flip the sign of x.)

void reflect_in_y_axis ()
 
void move (ICOORD shift)
 
void plot (ScrollView *window, inT32 num)
 
void fill (ScrollView *window, ScrollView::Color colour)
 
bool overlap (POLY_BLOCK *other)
 
static ScrollView::Color ColorForPolyBlockType (PolyBlockType type)
 Returns a color to draw the given type. More...
 

Detailed Description

Definition at line 28 of file polyblk.h.

Constructor & Destructor Documentation

◆ POLY_BLOCK() [1/3]

POLY_BLOCK::POLY_BLOCK ( )
inline

Definition at line 30 of file polyblk.h.

30  {
31  }

◆ POLY_BLOCK() [2/3]

POLY_BLOCK::POLY_BLOCK ( const TBOX box,
PolyBlockType  type 
)

Definition at line 47 of file polyblk.cpp.

47  {
48  vertices.clear();
49  ICOORDELT_IT v = &vertices;
50  v.move_to_first();
51  v.add_to_end(new ICOORDELT(box.left(), box.top()));
52  v.add_to_end(new ICOORDELT(box.left(), box.bottom()));
53  v.add_to_end(new ICOORDELT(box.right(), box.bottom()));
54  v.add_to_end(new ICOORDELT(box.right(), box.top()));
55  compute_bb();
56  type = t;
57 }
inT16 bottom() const
Definition: rect.h:61
inT16 left() const
Definition: rect.h:68
inT16 top() const
Definition: rect.h:54
void compute_bb()
Definition: polyblk.cpp:65
inT16 right() const
Definition: rect.h:75

◆ POLY_BLOCK() [3/3]

POLY_BLOCK::POLY_BLOCK ( ICOORDELT_LIST *  points,
PolyBlockType  type 
)

Definition at line 36 of file polyblk.cpp.

36  {
37  ICOORDELT_IT v = &vertices;
38 
39  vertices.clear();
40  v.move_to_first();
41  v.add_list_before(points);
42  compute_bb();
43  type = t;
44 }
ICOORDELT_LIST * points()
Definition: polyblk.h:42
void compute_bb()
Definition: polyblk.cpp:65

◆ ~POLY_BLOCK()

POLY_BLOCK::~POLY_BLOCK ( )
inline

Definition at line 35 of file polyblk.h.

35  {
36  }

Member Function Documentation

◆ bounding_box()

TBOX* POLY_BLOCK::bounding_box ( )
inline

Definition at line 38 of file polyblk.h.

38  { // access function
39  return &box;
40  }

◆ ColorForPolyBlockType()

ScrollView::Color POLY_BLOCK::ColorForPolyBlockType ( PolyBlockType  type)
static

Returns a color to draw the given type.

Definition at line 397 of file polyblk.cpp.

397  {
398  // Keep kPBColors in sync with PolyBlockType.
399  const ScrollView::Color kPBColors[PT_COUNT] = {
400  ScrollView::WHITE, // Type is not yet known. Keep as the 1st element.
401  ScrollView::BLUE, // Text that lives inside a column.
402  ScrollView::CYAN, // Text that spans more than one column.
403  ScrollView::MEDIUM_BLUE, // Text that is in a cross-column pull-out region.
404  ScrollView::AQUAMARINE, // Partition belonging to an equation region.
405  ScrollView::SKY_BLUE, // Partition belonging to an inline equation region.
406  ScrollView::MAGENTA, // Partition belonging to a table region.
407  ScrollView::GREEN, // Text-line runs vertically.
408  ScrollView::LIGHT_BLUE, // Text that belongs to an image.
409  ScrollView::RED, // Image that lives inside a column.
410  ScrollView::YELLOW, // Image that spans more than one column.
411  ScrollView::ORANGE, // Image in a cross-column pull-out region.
412  ScrollView::BROWN, // Horizontal Line.
413  ScrollView::DARK_GREEN, // Vertical Line.
414  ScrollView::GREY // Lies outside of any column.
415  };
416  if (type >= 0 && type < PT_COUNT) {
417  return kPBColors[type];
418  }
419  return ScrollView::WHITE;
420 }
Definition: capi.h:98

◆ compute_bb()

void POLY_BLOCK::compute_bb ( )

Definition at line 65 of file polyblk.cpp.

65  { //constructor
66  ICOORD ibl, itr; //integer bb
67  ICOORD botleft; //bounding box
68  ICOORD topright;
69  ICOORD pos; //current pos;
70  ICOORDELT_IT pts = &vertices; //iterator
71 
72  botleft = *pts.data ();
73  topright = botleft;
74  do {
75  pos = *pts.data ();
76  if (pos.x () < botleft.x ())
77  //get bounding box
78  botleft = ICOORD (pos.x (), botleft.y ());
79  if (pos.y () < botleft.y ())
80  botleft = ICOORD (botleft.x (), pos.y ());
81  if (pos.x () > topright.x ())
82  topright = ICOORD (pos.x (), topright.y ());
83  if (pos.y () > topright.y ())
84  topright = ICOORD (topright.x (), pos.y ());
85  pts.forward ();
86  }
87  while (!pts.at_first ());
88  ibl = ICOORD (botleft.x (), botleft.y ());
89  itr = ICOORD (topright.x (), topright.y ());
90  box = TBOX (ibl, itr);
91 }
integer coordinate
Definition: points.h:30
inT16 x() const
access function
Definition: points.h:52
Definition: rect.h:30
inT16 y() const
access_function
Definition: points.h:56

◆ contains()

bool POLY_BLOCK::contains ( POLY_BLOCK other)
Returns
true if other is inside this.

Definition at line 139 of file polyblk.cpp.

139  {
140  inT16 count; // winding count
141  ICOORDELT_IT it = &vertices; // iterator
142  ICOORD vertex;
143 
144  if (!box.overlap (*(other->bounding_box ())))
145  return false; // can't be contained
146 
147  /* check that no vertex of this is inside other */
148 
149  do {
150  vertex = *it.data ();
151  // get winding number
152  count = other->winding_number (vertex);
153  if (count != INTERSECTING)
154  if (count != 0)
155  return false;
156  it.forward ();
157  }
158  while (!it.at_first ());
159 
160  /* check that all vertices of other are inside this */
161 
162  //switch lists
163  it.set_to_list (other->points ());
164  do {
165  vertex = *it.data ();
166  //try other way round
167  count = winding_number (vertex);
168  if (count != INTERSECTING)
169  if (count == 0)
170  return false;
171  it.forward ();
172  }
173  while (!it.at_first ());
174  return true;
175 }
int count(LIST var_list)
Definition: oldlist.cpp:103
bool overlap(const TBOX &box) const
Definition: rect.h:345
#define INTERSECTING
Definition: polyblk.cpp:32
short inT16
Definition: host.h:33
integer coordinate
Definition: points.h:30
ICOORDELT_LIST * points()
Definition: polyblk.h:42
TBOX * bounding_box()
Definition: polyblk.h:38
inT16 winding_number(const ICOORD &test_pt)
Definition: polyblk.cpp:101

◆ fill()

void POLY_BLOCK::fill ( ScrollView window,
ScrollView::Color  colour 
)

Definition at line 272 of file polyblk.cpp.

272  {
273  inT16 y;
274  inT16 width;
275  PB_LINE_IT *lines;
276  ICOORDELT_LIST *segments;
277  ICOORDELT_IT s_it;
278 
279  lines = new PB_LINE_IT (this);
280  window->Pen(colour);
281 
282  for (y = this->bounding_box ()->bottom ();
283  y <= this->bounding_box ()->top (); y++) {
284  segments = lines->get_line (y);
285  if (!segments->empty ()) {
286  s_it.set_to_list (segments);
287  for (s_it.mark_cycle_pt (); !s_it.cycled_list (); s_it.forward ()) {
288  // Note different use of ICOORDELT, x coord is x coord of pixel
289  // at the start of line segment, y coord is length of line segment
290  // Last pixel is start pixel + length.
291  width = s_it.data ()->y ();
292  window->SetCursor(s_it.data ()->x (), y);
293  window->DrawTo(s_it.data ()->x () + (float) width, y);
294  }
295  }
296  }
297 
298  delete lines;
299 }
void DrawTo(int x, int y)
Definition: scrollview.cpp:531
short inT16
Definition: host.h:33
void SetCursor(int x, int y)
Definition: scrollview.cpp:525
TBOX * bounding_box()
Definition: polyblk.h:38
ICOORDELT_LIST * get_line(inT16 y)
Definition: polyblk.cpp:343
void Pen(Color color)
Definition: scrollview.cpp:726
inT16 top() const
Definition: rect.h:54

◆ isA()

PolyBlockType POLY_BLOCK::isA ( ) const
inline

Definition at line 48 of file polyblk.h.

48  {
49  return type;
50  }

◆ IsText()

bool POLY_BLOCK::IsText ( ) const
inline

Definition at line 52 of file polyblk.h.

52  {
53  return PTIsTextType(type);
54  }
bool PTIsTextType(PolyBlockType type)
Definition: publictypes.h:70

◆ move()

void POLY_BLOCK::move ( ICOORD  shift)

POLY_BLOCK::move

Move the POLY_BLOCK.

Parameters
shiftx,y translation vector

Definition at line 230 of file polyblk.cpp.

230  {
231  ICOORDELT *pt; //current point
232  ICOORDELT_IT pts = &vertices; //iterator
233 
234  do {
235  pt = pts.data ();
236  *pt += shift;
237  pts.forward ();
238  }
239  while (!pts.at_first ());
240  compute_bb();
241 }
void compute_bb()
Definition: polyblk.cpp:65

◆ overlap()

bool POLY_BLOCK::overlap ( POLY_BLOCK other)
Returns
true if the polygons of other and this overlap.

Definition at line 304 of file polyblk.cpp.

304  {
305  inT16 count; // winding count
306  ICOORDELT_IT it = &vertices; // iterator
307  ICOORD vertex;
308 
309  if (!box.overlap(*(other->bounding_box())))
310  return false; // can't be any overlap.
311 
312  /* see if a vertex of this is inside other */
313 
314  do {
315  vertex = *it.data ();
316  // get winding number
317  count = other->winding_number (vertex);
318  if (count != INTERSECTING)
319  if (count != 0)
320  return true;
321  it.forward ();
322  }
323  while (!it.at_first ());
324 
325  /* see if a vertex of other is inside this */
326 
327  // switch lists
328  it.set_to_list (other->points ());
329  do {
330  vertex = *it.data();
331  // try other way round
332  count = winding_number (vertex);
333  if (count != INTERSECTING)
334  if (count != 0)
335  return true;
336  it.forward ();
337  }
338  while (!it.at_first ());
339  return false;
340 }
int count(LIST var_list)
Definition: oldlist.cpp:103
bool overlap(const TBOX &box) const
Definition: rect.h:345
#define INTERSECTING
Definition: polyblk.cpp:32
short inT16
Definition: host.h:33
integer coordinate
Definition: points.h:30
ICOORDELT_LIST * points()
Definition: polyblk.h:42
TBOX * bounding_box()
Definition: polyblk.h:38
inT16 winding_number(const ICOORD &test_pt)
Definition: polyblk.cpp:101

◆ plot()

void POLY_BLOCK::plot ( ScrollView window,
inT32  num 
)

Definition at line 245 of file polyblk.cpp.

245  {
246  ICOORDELT_IT v = &vertices;
247 
248  window->Pen(ColorForPolyBlockType(type));
249 
250  v.move_to_first ();
251 
252  if (num > 0) {
253  window->TextAttributes("Times", 80, false, false, false);
254  char temp_buff[34];
255  #if defined(__UNIX__) || defined(MINGW)
256  sprintf(temp_buff, INT32FORMAT, num);
257  #else
258  ltoa (num, temp_buff, 10);
259  #endif
260  window->Text(v.data ()->x (), v.data ()->y (), temp_buff);
261  }
262 
263  window->SetCursor(v.data ()->x (), v.data ()->y ());
264  for (v.mark_cycle_pt (); !v.cycled_list (); v.forward ()) {
265  window->DrawTo(v.data ()->x (), v.data ()->y ());
266  }
267  v.move_to_first ();
268  window->DrawTo(v.data ()->x (), v.data ()->y ());
269 }
void DrawTo(int x, int y)
Definition: scrollview.cpp:531
void SetCursor(int x, int y)
Definition: scrollview.cpp:525
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
Definition: scrollview.cpp:641
void Text(int x, int y, const char *mystring)
Definition: scrollview.cpp:658
void Pen(Color color)
Definition: scrollview.cpp:726
#define INT32FORMAT
Definition: host.h:48
static ScrollView::Color ColorForPolyBlockType(PolyBlockType type)
Returns a color to draw the given type.
Definition: polyblk.cpp:397

◆ points()

ICOORDELT_LIST* POLY_BLOCK::points ( )
inline

Definition at line 42 of file polyblk.h.

42  { // access function
43  return &vertices;
44  }

◆ reflect_in_y_axis()

void POLY_BLOCK::reflect_in_y_axis ( )

Definition at line 209 of file polyblk.cpp.

209  {
210  ICOORDELT *pt; // current point
211  ICOORDELT_IT pts = &vertices; // Iterator.
212 
213  do {
214  pt = pts.data();
215  pt->set_x(-pt->x());
216  pts.forward();
217  }
218  while (!pts.at_first());
219  compute_bb();
220 }
inT16 x() const
access function
Definition: points.h:52
void compute_bb()
Definition: polyblk.cpp:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61

◆ rotate()

void POLY_BLOCK::rotate ( FCOORD  rotation)

Definition at line 185 of file polyblk.cpp.

185  {
186  FCOORD pos; //current pos;
187  ICOORDELT *pt; //current point
188  ICOORDELT_IT pts = &vertices; //iterator
189 
190  do {
191  pt = pts.data ();
192  pos.set_x (pt->x ());
193  pos.set_y (pt->y ());
194  pos.rotate (rotation);
195  pt->set_x ((inT16) (floor (pos.x () + 0.5)));
196  pt->set_y ((inT16) (floor (pos.y () + 0.5)));
197  pts.forward ();
198  }
199  while (!pts.at_first ());
200  compute_bb();
201 }
short inT16
Definition: host.h:33
void set_x(float xin)
rewrite function
Definition: points.h:216
void rotate(const FCOORD vec)
Definition: ipoints.h:471
inT16 x() const
access function
Definition: points.h:52
void set_y(float yin)
rewrite function
Definition: points.h:220
float y() const
Definition: points.h:212
Definition: points.h:189
void set_y(inT16 yin)
rewrite function
Definition: points.h:65
void compute_bb()
Definition: polyblk.cpp:65
void set_x(inT16 xin)
rewrite function
Definition: points.h:61
float x() const
Definition: points.h:209
inT16 y() const
access_function
Definition: points.h:56

◆ winding_number()

inT16 POLY_BLOCK::winding_number ( const ICOORD test_pt)

Definition at line 101 of file polyblk.cpp.

101  {
102  inT16 count; //winding count
103  ICOORD pt; //current point
104  ICOORD vec; //point to current point
105  ICOORD vvec; //current point to next point
106  inT32 cross; //cross product
107  ICOORDELT_IT it = &vertices; //iterator
108 
109  count = 0;
110  do {
111  pt = *it.data ();
112  vec = pt - point;
113  vvec = *it.data_relative (1) - pt;
114  //crossing the line
115  if (vec.y () <= 0 && vec.y () + vvec.y () > 0) {
116  cross = vec * vvec; //cross product
117  if (cross > 0)
118  count++; //crossing right half
119  else if (cross == 0)
120  return INTERSECTING; //going through point
121  }
122  else if (vec.y () > 0 && vec.y () + vvec.y () <= 0) {
123  cross = vec * vvec;
124  if (cross < 0)
125  count--; //crossing back
126  else if (cross == 0)
127  return INTERSECTING; //illegal
128  }
129  else if (vec.y () == 0 && vec.x () == 0)
130  return INTERSECTING;
131  it.forward ();
132  }
133  while (!it.at_first ());
134  return count; //winding number
135 }
int count(LIST var_list)
Definition: oldlist.cpp:103
#define INTERSECTING
Definition: polyblk.cpp:32
short inT16
Definition: host.h:33
integer coordinate
Definition: points.h:30
inT16 x() const
access function
Definition: points.h:52
int inT32
Definition: host.h:35
inT16 y() const
access_function
Definition: points.h:56

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