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

#include <polyblk.h>

List of all members.

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.

Additional Inherited Members


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.

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

Definition at line 50 of file polyblk.cpp.

{
vertices.clear();
ICOORDELT_IT v = &vertices;
v.move_to_first();
v.add_to_end(new ICOORDELT(box.left(), box.top()));
v.add_to_end(new ICOORDELT(box.left(), box.bottom()));
v.add_to_end(new ICOORDELT(box.right(), box.bottom()));
v.add_to_end(new ICOORDELT(box.right(), box.top()));
type = t;
}
POLY_BLOCK::POLY_BLOCK ( ICOORDELT_LIST *  points,
PolyBlockType  type 
)

Definition at line 39 of file polyblk.cpp.

{
ICOORDELT_IT v = &vertices;
vertices.clear();
v.move_to_first();
v.add_list_before(points);
type = t;
}
POLY_BLOCK::~POLY_BLOCK ( )
inline

Definition at line 37 of file polyblk.h.

{
}

Member Function Documentation

TBOX* POLY_BLOCK::bounding_box ( )
inline

Definition at line 40 of file polyblk.h.

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

Returns a color to draw the given type.

Definition at line 398 of file polyblk.cpp.

{
// Keep kPBColors in sync with PolyBlockType.
const ScrollView::Color kPBColors[PT_COUNT] = {
ScrollView::WHITE, // Type is not yet known. Keep as the 1st element.
ScrollView::BLUE, // Text that lives inside a column.
ScrollView::CYAN, // Text that spans more than one column.
ScrollView::MEDIUM_BLUE, // Text that is in a cross-column pull-out region.
ScrollView::AQUAMARINE, // Partition belonging to an equation region.
ScrollView::SKY_BLUE, // Partition belonging to an inline equation region.
ScrollView::MAGENTA, // Partition belonging to a table region.
ScrollView::GREEN, // Text-line runs vertically.
ScrollView::LIGHT_BLUE, // Text that belongs to an image.
ScrollView::RED, // Image that lives inside a column.
ScrollView::YELLOW, // Image that spans more than one column.
ScrollView::ORANGE, // Image in a cross-column pull-out region.
ScrollView::BROWN, // Horizontal Line.
ScrollView::DARK_GREEN, // Vertical Line.
ScrollView::GREY // Lies outside of any column.
};
if (type >= 0 && type < PT_COUNT) {
return kPBColors[type];
}
}
void POLY_BLOCK::compute_bb ( )

Definition at line 68 of file polyblk.cpp.

{ //constructor
ICOORD ibl, itr; //integer bb
ICOORD botleft; //bounding box
ICOORD topright;
ICOORD pos; //current pos;
ICOORDELT_IT pts = &vertices; //iterator
botleft = *pts.data ();
topright = botleft;
do {
pos = *pts.data ();
if (pos.x () < botleft.x ())
//get bounding box
botleft = ICOORD (pos.x (), botleft.y ());
if (pos.y () < botleft.y ())
botleft = ICOORD (botleft.x (), pos.y ());
if (pos.x () > topright.x ())
topright = ICOORD (pos.x (), topright.y ());
if (pos.y () > topright.y ())
topright = ICOORD (topright.x (), pos.y ());
pts.forward ();
}
while (!pts.at_first ());
ibl = ICOORD (botleft.x (), botleft.y ());
itr = ICOORD (topright.x (), topright.y ());
box = TBOX (ibl, itr);
}
bool POLY_BLOCK::contains ( POLY_BLOCK other)
Returns:
true if other is inside this.

Definition at line 142 of file polyblk.cpp.

{
inT16 count; // winding count
ICOORDELT_IT it = &vertices; // iterator
ICOORD vertex;
if (!box.overlap (*(other->bounding_box ())))
return false; // can't be contained
/* check that no vertex of this is inside other */
do {
vertex = *it.data ();
// get winding number
count = other->winding_number (vertex);
if (count != INTERSECTING)
if (count != 0)
return false;
it.forward ();
}
while (!it.at_first ());
/* check that all vertices of other are inside this */
//switch lists
it.set_to_list (other->points ());
do {
vertex = *it.data ();
//try other way round
count = winding_number (vertex);
if (count != INTERSECTING)
if (count == 0)
return false;
it.forward ();
}
while (!it.at_first ());
return true;
}
void POLY_BLOCK::fill ( ScrollView window,
ScrollView::Color  colour 
)

Definition at line 275 of file polyblk.cpp.

{
inT16 y;
inT16 width;
PB_LINE_IT *lines;
ICOORDELT_LIST *segments;
ICOORDELT_IT s_it;
lines = new PB_LINE_IT (this);
window->Pen(colour);
for (y = this->bounding_box ()->bottom ();
y <= this->bounding_box ()->top (); y++) {
segments = lines->get_line (y);
if (!segments->empty ()) {
s_it.set_to_list (segments);
for (s_it.mark_cycle_pt (); !s_it.cycled_list (); s_it.forward ()) {
// Note different use of ICOORDELT, x coord is x coord of pixel
// at the start of line segment, y coord is length of line segment
// Last pixel is start pixel + length.
width = s_it.data ()->y ();
window->SetCursor(s_it.data ()->x (), y);
window->DrawTo(s_it.data ()->x () + (float) width, y);
}
}
}
}
PolyBlockType POLY_BLOCK::isA ( ) const
inline

Definition at line 50 of file polyblk.h.

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

Definition at line 54 of file polyblk.h.

{
return PTIsTextType(type);
}
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.

{
ICOORDELT *pt; //current point
ICOORDELT_IT pts = &vertices; //iterator
do {
pt = pts.data ();
*pt += shift;
pts.forward ();
}
while (!pts.at_first ());
}
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.

{
inT16 count; // winding count
ICOORDELT_IT it = &vertices; // iterator
ICOORD vertex;
if (!box.overlap(*(other->bounding_box())))
return false; // can't be any overlap.
/* see if a vertex of this is inside other */
do {
vertex = *it.data ();
// get winding number
count = other->winding_number (vertex);
if (count != INTERSECTING)
if (count != 0)
return true;
it.forward ();
}
while (!it.at_first ());
/* see if a vertex of other is inside this */
// switch lists
it.set_to_list (other->points ());
do {
vertex = *it.data();
// try other way round
count = winding_number (vertex);
if (count != INTERSECTING)
if (count != 0)
return true;
it.forward ();
}
while (!it.at_first ());
return false;
}
void POLY_BLOCK::plot ( ScrollView window,
inT32  num 
)

Definition at line 248 of file polyblk.cpp.

{
ICOORDELT_IT v = &vertices;
window->Pen(ColorForPolyBlockType(type));
v.move_to_first ();
if (num > 0) {
window->TextAttributes("Times", 80, false, false, false);
char temp_buff[34];
#ifdef __UNIX__
sprintf(temp_buff, INT32FORMAT, num);
#else
ltoa (num, temp_buff, 10);
#endif
window->Text(v.data ()->x (), v.data ()->y (), temp_buff);
}
window->SetCursor(v.data ()->x (), v.data ()->y ());
for (v.mark_cycle_pt (); !v.cycled_list (); v.forward ()) {
window->DrawTo(v.data ()->x (), v.data ()->y ());
}
v.move_to_first ();
window->DrawTo(v.data ()->x (), v.data ()->y ());
}
ICOORDELT_LIST* POLY_BLOCK::points ( )
inline

Definition at line 44 of file polyblk.h.

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

Definition at line 212 of file polyblk.cpp.

{
ICOORDELT *pt; // current point
ICOORDELT_IT pts = &vertices; // Iterator.
do {
pt = pts.data();
pt->set_x(-pt->x());
pts.forward();
}
while (!pts.at_first());
}
void POLY_BLOCK::rotate ( FCOORD  rotation)

Definition at line 188 of file polyblk.cpp.

{
FCOORD pos; //current pos;
ICOORDELT *pt; //current point
ICOORDELT_IT pts = &vertices; //iterator
do {
pt = pts.data ();
pos.set_x (pt->x ());
pos.set_y (pt->y ());
pos.rotate (rotation);
pt->set_x ((inT16) (floor (pos.x () + 0.5)));
pt->set_y ((inT16) (floor (pos.y () + 0.5)));
pts.forward ();
}
while (!pts.at_first ());
}
inT16 POLY_BLOCK::winding_number ( const ICOORD test_pt)

Definition at line 104 of file polyblk.cpp.

{
inT16 count; //winding count
ICOORD pt; //current point
ICOORD vec; //point to current point
ICOORD vvec; //current point to next point
inT32 cross; //cross product
ICOORDELT_IT it = &vertices; //iterator
count = 0;
do {
pt = *it.data ();
vec = pt - point;
vvec = *it.data_relative (1) - pt;
//crossing the line
if (vec.y () <= 0 && vec.y () + vvec.y () > 0) {
cross = vec * vvec; //cross product
if (cross > 0)
count++; //crossing right half
else if (cross == 0)
return INTERSECTING; //going through point
}
else if (vec.y () > 0 && vec.y () + vvec.y () <= 0) {
cross = vec * vvec;
if (cross < 0)
count--; //crossing back
else if (cross == 0)
return INTERSECTING; //illegal
}
else if (vec.y () == 0 && vec.x () == 0)
return INTERSECTING;
it.forward ();
}
while (!it.at_first ());
return count; //winding number
}

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