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

page block More...

#include <pdblock.h>

Inheritance diagram for PDBLK:
BLOCK

Public Member Functions

 PDBLK ()
 empty constructor More...
 
 PDBLK (inT16 xmin, inT16 ymin, inT16 xmax, inT16 ymax)
 simple constructor More...
 
void set_sides (ICOORDELT_LIST *left, ICOORDELT_LIST *right)
 
 ~PDBLK ()
 destructor More...
 
POLY_BLOCKpoly_block () const
 
void set_poly_block (POLY_BLOCK *blk)
 set the poly block More...
 
void bounding_box (ICOORD &bottom_left, ICOORD &top_right) const
 get box More...
 
const TBOXbounding_box () const
 get real box More...
 
int index () const
 
void set_index (int value)
 
BOOL8 contains (ICOORD pt)
 is pt inside block More...
 
void move (const ICOORD vec)
 reposition block More...
 
Pix * render_mask (const FCOORD &rerotation)
 
void plot (ScrollView *window, inT32 serial, ScrollView::Color colour)
 
void show (IMAGE *image, ScrollView *window)
 
PDBLKoperator= (const PDBLK &source)
 

Protected Attributes

POLY_BLOCKhand_poly
 
ICOORDELT_LIST leftside
 
ICOORDELT_LIST rightside
 
TBOX box
 
int index_
 

Friends

class BLOCK_RECT_IT
 

Detailed Description

page block

Definition at line 35 of file pdblock.h.

Constructor & Destructor Documentation

PDBLK::PDBLK ( )
inline

empty constructor

Definition at line 41 of file pdblock.h.

41  {
42  hand_poly = NULL;
43  index_ = 0;
44  }
int index_
Definition: pdblock.h:121
#define NULL
Definition: host.h:144
POLY_BLOCK * hand_poly
Definition: pdblock.h:117
PDBLK::PDBLK ( inT16  xmin,
inT16  ymin,
inT16  xmax,
inT16  ymax 
)

simple constructor

Definition at line 42 of file pdblock.cpp.

45  : box (ICOORD (xmin, ymin), ICOORD (xmax, ymax)) {
46  //boundaries
47  ICOORDELT_IT left_it = &leftside;
48  ICOORDELT_IT right_it = &rightside;
49 
50  hand_poly = NULL;
51  left_it.set_to_list (&leftside);
52  right_it.set_to_list (&rightside);
53  //make default box
54  left_it.add_to_end (new ICOORDELT (xmin, ymin));
55  left_it.add_to_end (new ICOORDELT (xmin, ymax));
56  right_it.add_to_end (new ICOORDELT (xmax, ymin));
57  right_it.add_to_end (new ICOORDELT (xmax, ymax));
58  index_ = 0;
59 }
ICOORDELT_LIST rightside
Definition: pdblock.h:119
int index_
Definition: pdblock.h:121
#define NULL
Definition: host.h:144
ICOORDELT_LIST leftside
Definition: pdblock.h:118
integer coordinate
Definition: points.h:30
TBOX box
Definition: pdblock.h:120
POLY_BLOCK * hand_poly
Definition: pdblock.h:117
PDBLK::~PDBLK ( )
inline

destructor

Definition at line 58 of file pdblock.h.

58  {
59  if (hand_poly) delete hand_poly;
60  }
POLY_BLOCK * hand_poly
Definition: pdblock.h:117

Member Function Documentation

void PDBLK::bounding_box ( ICOORD bottom_left,
ICOORD top_right 
) const
inline

get box

Definition at line 70 of file pdblock.h.

71  { //topright
72  bottom_left = box.botleft ();
73  top_right = box.topright ();
74  }
const ICOORD & topright() const
Definition: rect.h:93
const ICOORD & botleft() const
Definition: rect.h:81
TBOX box
Definition: pdblock.h:120
const TBOX& PDBLK::bounding_box ( ) const
inline

get real box

Definition at line 76 of file pdblock.h.

76  {
77  return box;
78  }
TBOX box
Definition: pdblock.h:120
BOOL8 PDBLK::contains ( ICOORD  pt)

is pt inside block

Definition at line 91 of file pdblock.cpp.

93  {
94  BLOCK_RECT_IT it = this; //rectangle iterator
95  ICOORD bleft, tright; //corners of rectangle
96 
97  for (it.start_block (); !it.cycled_rects (); it.forward ()) {
98  //get rectangle
99  it.bounding_box (bleft, tright);
100  //inside rect
101  if (pt.x () >= bleft.x () && pt.x () <= tright.x ()
102  && pt.y () >= bleft.y () && pt.y () <= tright.y ())
103  return TRUE; //is inside
104  }
105  return FALSE; //not inside
106 }
inT16 x() const
access function
Definition: points.h:52
#define FALSE
Definition: capi.h:28
void start_block()
start iteration
Definition: pdblock.cpp:325
inT16 y() const
access_function
Definition: points.h:56
BOOL8 cycled_rects()
test end
Definition: pdblock.h:142
integer coordinate
Definition: points.h:30
void bounding_box(ICOORD &bleft, ICOORD &tright)
Definition: pdblock.h:149
#define TRUE
Definition: capi.h:27
void forward()
next rectangle
Definition: pdblock.cpp:344
int PDBLK::index ( ) const
inline

Definition at line 80 of file pdblock.h.

80  {
81  return index_;
82  }
int index_
Definition: pdblock.h:121
void PDBLK::move ( const ICOORD  vec)

reposition block

Definition at line 115 of file pdblock.cpp.

117  {
118  ICOORDELT_IT it(&leftside);
119 
120  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
121  *(it.data ()) += vec;
122 
123  it.set_to_list (&rightside);
124 
125  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
126  *(it.data ()) += vec;
127 
128  box.move (vec);
129 }
ICOORDELT_LIST rightside
Definition: pdblock.h:119
ICOORDELT_LIST leftside
Definition: pdblock.h:118
void move(const ICOORD vec)
Definition: rect.h:146
TBOX box
Definition: pdblock.h:120
PDBLK & PDBLK::operator= ( const PDBLK source)

assignment

Parameters
sourcefrom this

Definition at line 269 of file pdblock.cpp.

271  {
272  // this->ELIST_LINK::operator=(source);
273  if (!leftside.empty ())
274  leftside.clear ();
275  if (!rightside.empty ())
276  rightside.clear ();
277  leftside.deep_copy(&source.leftside, &ICOORDELT::deep_copy);
278  rightside.deep_copy(&source.rightside, &ICOORDELT::deep_copy);
279  box = source.box;
280  return *this;
281 }
ICOORDELT_LIST rightside
Definition: pdblock.h:119
ICOORDELT_LIST leftside
Definition: pdblock.h:118
TBOX box
Definition: pdblock.h:120
static ICOORDELT * deep_copy(const ICOORDELT *src)
Definition: points.h:180
void PDBLK::plot ( ScrollView window,
inT32  serial,
ScrollView::Color  colour 
)

draw histogram

Parameters
windowwindow to draw in
serialserial number
colourcolour to draw in

Definition at line 181 of file pdblock.cpp.

185  {
186  ICOORD startpt; //start of outline
187  ICOORD endpt; //end of outline
188  ICOORD prevpt; //previous point
189  ICOORDELT_IT it = &leftside; //iterator
190 
191  //set the colour
192  window->Pen(colour);
193  window->TextAttributes("Times", BLOCK_LABEL_HEIGHT, false, false, false);
194 
195  if (hand_poly != NULL) {
196  hand_poly->plot(window, serial);
197  } else if (!leftside.empty ()) {
198  startpt = *(it.data ()); //bottom left corner
199  // tprintf("Block %d bottom left is (%d,%d)\n",
200  // serial,startpt.x(),startpt.y());
201  char temp_buff[34];
202  #ifdef __UNIX__
203  sprintf(temp_buff, INT32FORMAT, serial);
204  #else
205  ultoa (serial, temp_buff, 10);
206  #endif
207  window->Text(startpt.x (), startpt.y (), temp_buff);
208 
209  window->SetCursor(startpt.x (), startpt.y ());
210  do {
211  prevpt = *(it.data ()); //previous point
212  it.forward (); //move to next point
213  //draw round corner
214  window->DrawTo(prevpt.x (), it.data ()->y ());
215  window->DrawTo(it.data ()->x (), it.data ()->y ());
216  }
217  while (!it.at_last ()); //until end of list
218  endpt = *(it.data ()); //end point
219 
220  //other side of boundary
221  window->SetCursor(startpt.x (), startpt.y ());
222  it.set_to_list (&rightside);
223  prevpt = startpt;
224  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
225  //draw round corner
226  window->DrawTo(prevpt.x (), it.data ()->y ());
227  window->DrawTo(it.data ()->x (), it.data ()->y ());
228  prevpt = *(it.data ()); //previous point
229  }
230  //close boundary
231  window->DrawTo(endpt.x(), endpt.y());
232  }
233 }
ICOORDELT_LIST rightside
Definition: pdblock.h:119
void SetCursor(int x, int y)
Definition: scrollview.cpp:520
inT16 x() const
access function
Definition: points.h:52
void Pen(Color color)
Definition: scrollview.cpp:721
#define NULL
Definition: host.h:144
#define INT32FORMAT
Definition: host.h:115
inT16 y() const
access_function
Definition: points.h:56
ICOORDELT_LIST leftside
Definition: pdblock.h:118
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
Definition: scrollview.cpp:636
void DrawTo(int x, int y)
Definition: scrollview.cpp:526
void Text(int x, int y, const char *mystring)
Definition: scrollview.cpp:653
#define BLOCK_LABEL_HEIGHT
Definition: pdblock.cpp:34
integer coordinate
Definition: points.h:30
POLY_BLOCK * hand_poly
Definition: pdblock.h:117
void plot(ScrollView *window, inT32 num)
Definition: polyblk.cpp:248
POLY_BLOCK* PDBLK::poly_block ( ) const
inline

Definition at line 62 of file pdblock.h.

62  {
63  return hand_poly;
64  }
POLY_BLOCK * hand_poly
Definition: pdblock.h:117
Pix * PDBLK::render_mask ( const FCOORD rerotation)

Definition at line 133 of file pdblock.cpp.

133  {
134  TBOX rotated_box(box);
135  rotated_box.rotate(rerotation);
136  Pix* pix = pixCreate(rotated_box.width(), rotated_box.height(), 1);
137  if (hand_poly != NULL) {
138  // We are going to rotate, so get a deep copy of the points and
139  // make a new POLY_BLOCK with it.
140  ICOORDELT_LIST polygon;
141  polygon.deep_copy(hand_poly->points(), ICOORDELT::deep_copy);
142  POLY_BLOCK image_block(&polygon, hand_poly->isA());
143  image_block.rotate(rerotation);
144  // Block outline is a polygon, so use a PB_LINE_IT to get the
145  // rasterized interior. (Runs of interior pixels on a line.)
146  PB_LINE_IT *lines = new PB_LINE_IT(&image_block);
147  for (int y = box.bottom(); y < box.top(); ++y) {
148  ICOORDELT_LIST* segments = lines->get_line(y);
149  if (!segments->empty()) {
150  ICOORDELT_IT s_it(segments);
151  // Each element of segments is a start x and x size of the
152  // run of interior pixels.
153  for (s_it.mark_cycle_pt(); !s_it.cycled_list(); s_it.forward()) {
154  int start = s_it.data()->x();
155  int xext = s_it.data()->y();
156  // Set the run of pixels to 1.
157  pixRasterop(pix, start - rotated_box.left(),
158  rotated_box.height() - 1 - (y - rotated_box.bottom()),
159  xext, 1, PIX_SET, NULL, 0, 0);
160  }
161  }
162  delete segments;
163  }
164  delete lines;
165  } else {
166  // Just fill the whole block as there is only a bounding box.
167  pixRasterop(pix, 0, 0, rotated_box.width(), rotated_box.height(),
168  PIX_SET, NULL, 0, 0);
169  }
170  return pix;
171 }
ICOORDELT_LIST * get_line(inT16 y)
Definition: polyblk.cpp:344
void rotate(FCOORD rotation)
Definition: polyblk.cpp:188
PolyBlockType isA() const
Definition: polyblk.h:50
#define NULL
Definition: host.h:144
Definition: rect.h:29
inT16 top() const
Definition: rect.h:53
TBOX box
Definition: pdblock.h:120
static ICOORDELT * deep_copy(const ICOORDELT *src)
Definition: points.h:180
POLY_BLOCK * hand_poly
Definition: pdblock.h:117
inT16 bottom() const
Definition: rect.h:60
ICOORDELT_LIST * points()
Definition: polyblk.h:44
void PDBLK::set_index ( int  value)
inline

Definition at line 83 of file pdblock.h.

83  {
84  index_ = value;
85  }
int index_
Definition: pdblock.h:121
void PDBLK::set_poly_block ( POLY_BLOCK blk)
inline

set the poly block

Definition at line 66 of file pdblock.h.

66  {
67  hand_poly = blk;
68  }
POLY_BLOCK * hand_poly
Definition: pdblock.h:117
void PDBLK::set_sides ( ICOORDELT_LIST *  left,
ICOORDELT_LIST *  right 
)

set vertex lists

Parameters
leftlist of left vertices
rightlist of right vertices

Definition at line 68 of file pdblock.cpp.

71  {
72  //boundaries
73  ICOORDELT_IT left_it = &leftside;
74  ICOORDELT_IT right_it = &rightside;
75 
76  leftside.clear ();
77  left_it.move_to_first ();
78  left_it.add_list_before (left);
79  rightside.clear ();
80  right_it.move_to_first ();
81  right_it.add_list_before (right);
82 }
ICOORDELT_LIST rightside
Definition: pdblock.h:119
ICOORDELT_LIST leftside
Definition: pdblock.h:118
void PDBLK::show ( IMAGE image,
ScrollView window 
)

show image

Parameters
imageimage to show
windowwindow to show in

Definition at line 244 of file pdblock.cpp.

247  {
248  BLOCK_RECT_IT it = this; //rectangle iterator
249  ICOORD bleft, tright; //corners of rectangle
250 
251  for (it.start_block (); !it.cycled_rects (); it.forward ()) {
252  //get rectangle
253  it.bounding_box (bleft, tright);
254  // tprintf("Drawing a block with a bottom left of (%d,%d)\n",
255  // bleft.x(),bleft.y());
256  //show it
257  sv_show_sub_image (image, bleft.x (), bleft.y (), tright.x () - bleft.x (), tright.y () - bleft.y (), window, bleft.x (), bleft.y ());
258  }
259 }
inT16 x() const
access function
Definition: points.h:52
void sv_show_sub_image(IMAGE *source, inT32 xstart, inT32 ystart, inT32 xext, inT32 yext, ScrollView *window, inT32 xpos, inT32 ypos)
Definition: svshowim.cpp:19
void start_block()
start iteration
Definition: pdblock.cpp:325
inT16 y() const
access_function
Definition: points.h:56
BOOL8 cycled_rects()
test end
Definition: pdblock.h:142
integer coordinate
Definition: points.h:30
void bounding_box(ICOORD &bleft, ICOORD &tright)
Definition: pdblock.h:149
void forward()
next rectangle
Definition: pdblock.cpp:344

Friends And Related Function Documentation

friend class BLOCK_RECT_IT
friend

Definition at line 37 of file pdblock.h.

Member Data Documentation

TBOX PDBLK::box
protected

Definition at line 120 of file pdblock.h.

POLY_BLOCK* PDBLK::hand_poly
protected

Definition at line 117 of file pdblock.h.

int PDBLK::index_
protected

Definition at line 121 of file pdblock.h.

ICOORDELT_LIST PDBLK::leftside
protected

Definition at line 118 of file pdblock.h.

ICOORDELT_LIST PDBLK::rightside
protected

Definition at line 119 of file pdblock.h.


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