Tesseract  3.02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 30 of file polyblk.h.

Constructor & Destructor Documentation

POLY_BLOCK::POLY_BLOCK ( )
inline

Definition at line 32 of file polyblk.h.

32  {
33  }
POLY_BLOCK::POLY_BLOCK ( const TBOX box,
PolyBlockType  type 
)

Definition at line 50 of file polyblk.cpp.

50  {
51  vertices.clear();
52  ICOORDELT_IT v = &vertices;
53  v.move_to_first();
54  v.add_to_end(new ICOORDELT(box.left(), box.top()));
55  v.add_to_end(new ICOORDELT(box.left(), box.bottom()));
56  v.add_to_end(new ICOORDELT(box.right(), box.bottom()));
57  v.add_to_end(new ICOORDELT(box.right(), box.top()));
58  compute_bb();
59  type = t;
60 }
void compute_bb()
Definition: polyblk.cpp:68
inT16 left() const
Definition: rect.h:67
inT16 right() const
Definition: rect.h:74
inT16 top() const
Definition: rect.h:53
inT16 bottom() const
Definition: rect.h:60
POLY_BLOCK::POLY_BLOCK ( ICOORDELT_LIST *  points,
PolyBlockType  type 
)

Definition at line 39 of file polyblk.cpp.

39  {
40  ICOORDELT_IT v = &vertices;
41 
42  vertices.clear();
43  v.move_to_first();
44  v.add_list_before(points);
45  compute_bb();
46  type = t;
47 }
void compute_bb()
Definition: polyblk.cpp:68
ICOORDELT_LIST * points()
Definition: polyblk.h:44
POLY_BLOCK::~POLY_BLOCK ( )
inline

Definition at line 37 of file polyblk.h.

37  {
38  }

Member Function Documentation

TBOX* POLY_BLOCK::bounding_box ( )
inline

Definition at line 40 of file polyblk.h.

40  { // access function
41  return &box;
42  }
ScrollView::Color POLY_BLOCK::ColorForPolyBlockType ( PolyBlockType  type)
static

Returns a color to draw the given type.

Definition at line 398 of file polyblk.cpp.

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

Definition at line 68 of file polyblk.cpp.

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

Definition at line 142 of file polyblk.cpp.

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

Definition at line 275 of file polyblk.cpp.

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

Definition at line 50 of file polyblk.h.

50  {
51  return type;
52  }
bool POLY_BLOCK::IsText ( ) const
inline

Definition at line 54 of file polyblk.h.

54  {
55  return PTIsTextType(type);
56  }
bool PTIsTextType(PolyBlockType type)
Definition: publictypes.h:70
void POLY_BLOCK::move ( ICOORD  shift)

POLY_BLOCK::move

Move the POLY_BLOCK.

Parameters
shiftx,y translation vector

Definition at line 233 of file polyblk.cpp.

233  {
234  ICOORDELT *pt; //current point
235  ICOORDELT_IT pts = &vertices; //iterator
236 
237  do {
238  pt = pts.data ();
239  *pt += shift;
240  pts.forward ();
241  }
242  while (!pts.at_first ());
243  compute_bb();
244 }
void compute_bb()
Definition: polyblk.cpp:68
bool POLY_BLOCK::overlap ( POLY_BLOCK other)
Returns
true if the polygons of other and this overlap.

Definition at line 305 of file polyblk.cpp.

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

Definition at line 248 of file polyblk.cpp.

248  {
249  ICOORDELT_IT v = &vertices;
250 
251  window->Pen(ColorForPolyBlockType(type));
252 
253  v.move_to_first ();
254 
255  if (num > 0) {
256  window->TextAttributes("Times", 80, false, false, false);
257  char temp_buff[34];
258  #ifdef __UNIX__
259  sprintf(temp_buff, INT32FORMAT, num);
260  #else
261  ltoa (num, temp_buff, 10);
262  #endif
263  window->Text(v.data ()->x (), v.data ()->y (), temp_buff);
264  }
265 
266  window->SetCursor(v.data ()->x (), v.data ()->y ());
267  for (v.mark_cycle_pt (); !v.cycled_list (); v.forward ()) {
268  window->DrawTo(v.data ()->x (), v.data ()->y ());
269  }
270  v.move_to_first ();
271  window->DrawTo(v.data ()->x (), v.data ()->y ());
272 }
void SetCursor(int x, int y)
Definition: scrollview.cpp:520
void Pen(Color color)
Definition: scrollview.cpp:721
#define INT32FORMAT
Definition: host.h:115
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
Definition: scrollview.cpp:636
static ScrollView::Color ColorForPolyBlockType(PolyBlockType type)
Returns a color to draw the given type.
Definition: polyblk.cpp:398
void DrawTo(int x, int y)
Definition: scrollview.cpp:526
void Text(int x, int y, const char *mystring)
Definition: scrollview.cpp:653
ICOORDELT_LIST* POLY_BLOCK::points ( )
inline

Definition at line 44 of file polyblk.h.

44  { // access function
45  return &vertices;
46  }
void POLY_BLOCK::reflect_in_y_axis ( )

Definition at line 212 of file polyblk.cpp.

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

Definition at line 188 of file polyblk.cpp.

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

Definition at line 104 of file polyblk.cpp.

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

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