tesseract  4.00.00dev
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, TBOX *mask_box)
 
void plot (ScrollView *window, inT32 serial, ScrollView::Color colour)
 
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 32 of file pdblock.h.

Constructor & Destructor Documentation

◆ PDBLK() [1/2]

PDBLK::PDBLK ( )
inline

empty constructor

Definition at line 37 of file pdblock.h.

37  {
38  hand_poly = NULL;
39  index_ = 0;
40  }
POLY_BLOCK * hand_poly
Definition: pdblock.h:95
int index_
Definition: pdblock.h:99

◆ PDBLK() [2/2]

PDBLK::PDBLK ( inT16  xmin,
inT16  ymin,
inT16  xmax,
inT16  ymax 
)

simple constructor

Definition at line 39 of file pdblock.cpp.

42  : box (ICOORD (xmin, ymin), ICOORD (xmax, ymax)) {
43  //boundaries
44  ICOORDELT_IT left_it = &leftside;
45  ICOORDELT_IT right_it = &rightside;
46 
47  hand_poly = NULL;
48  left_it.set_to_list (&leftside);
49  right_it.set_to_list (&rightside);
50  //make default box
51  left_it.add_to_end (new ICOORDELT (xmin, ymin));
52  left_it.add_to_end (new ICOORDELT (xmin, ymax));
53  right_it.add_to_end (new ICOORDELT (xmax, ymin));
54  right_it.add_to_end (new ICOORDELT (xmax, ymax));
55  index_ = 0;
56 }
POLY_BLOCK * hand_poly
Definition: pdblock.h:95
ICOORDELT_LIST leftside
Definition: pdblock.h:96
TBOX box
Definition: pdblock.h:98
ICOORDELT_LIST rightside
Definition: pdblock.h:97
integer coordinate
Definition: points.h:30
int index_
Definition: pdblock.h:99

◆ ~PDBLK()

PDBLK::~PDBLK ( )
inline

destructor

Definition at line 53 of file pdblock.h.

53 { delete hand_poly; }
POLY_BLOCK * hand_poly
Definition: pdblock.h:95

Member Function Documentation

◆ bounding_box() [1/2]

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

get box

Definition at line 59 of file pdblock.h.

60  { // topright
61  bottom_left = box.botleft();
62  top_right = box.topright();
63  }
const ICOORD & topright() const
Definition: rect.h:100
const ICOORD & botleft() const
Definition: rect.h:88
TBOX box
Definition: pdblock.h:98

◆ bounding_box() [2/2]

const TBOX& PDBLK::bounding_box ( ) const
inline

get real box

Definition at line 65 of file pdblock.h.

65 { return box; }
TBOX box
Definition: pdblock.h:98

◆ contains()

BOOL8 PDBLK::contains ( ICOORD  pt)

is pt inside block

Definition at line 87 of file pdblock.cpp.

89  {
90  BLOCK_RECT_IT it = this; //rectangle iterator
91  ICOORD bleft, tright; //corners of rectangle
92 
93  for (it.start_block (); !it.cycled_rects (); it.forward ()) {
94  //get rectangle
95  it.bounding_box (bleft, tright);
96  //inside rect
97  if (pt.x () >= bleft.x () && pt.x () <= tright.x ()
98  && pt.y () >= bleft.y () && pt.y () <= tright.y ())
99  return TRUE; //is inside
100  }
101  return FALSE; //not inside
102 }
#define TRUE
Definition: capi.h:45
inT16 x() const
access function
Definition: points.h:52
void bounding_box(ICOORD &bleft, ICOORD &tright)
Definition: pdblock.h:127
#define FALSE
Definition: capi.h:46
inT16 y() const
access_function
Definition: points.h:56
BOOL8 cycled_rects()
test end
Definition: pdblock.h:120
void forward()
next rectangle
Definition: pdblock.cpp:313
void start_block()
start iteration
Definition: pdblock.cpp:294
integer coordinate
Definition: points.h:30

◆ index()

int PDBLK::index ( ) const
inline

Definition at line 67 of file pdblock.h.

67 { return index_; }
int index_
Definition: pdblock.h:99

◆ move()

void PDBLK::move ( const ICOORD  vec)

reposition block

Definition at line 111 of file pdblock.cpp.

113  {
114  ICOORDELT_IT it(&leftside);
115 
116  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
117  *(it.data ()) += vec;
118 
119  it.set_to_list (&rightside);
120 
121  for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
122  *(it.data ()) += vec;
123 
124  box.move (vec);
125 }
void move(const ICOORD vec)
Definition: rect.h:153
ICOORDELT_LIST leftside
Definition: pdblock.h:96
TBOX box
Definition: pdblock.h:98
ICOORDELT_LIST rightside
Definition: pdblock.h:97

◆ operator=()

PDBLK & PDBLK::operator= ( const PDBLK source)

assignment

Parameters
sourcefrom this

Definition at line 238 of file pdblock.cpp.

240  {
241  // this->ELIST_LINK::operator=(source);
242  if (!leftside.empty ())
243  leftside.clear ();
244  if (!rightside.empty ())
245  rightside.clear ();
246  leftside.deep_copy(&source.leftside, &ICOORDELT::deep_copy);
247  rightside.deep_copy(&source.rightside, &ICOORDELT::deep_copy);
248  box = source.box;
249  return *this;
250 }
static ICOORDELT * deep_copy(const ICOORDELT *src)
Definition: points.h:180
ICOORDELT_LIST leftside
Definition: pdblock.h:96
TBOX box
Definition: pdblock.h:98
ICOORDELT_LIST rightside
Definition: pdblock.h:97

◆ plot()

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 177 of file pdblock.cpp.

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

◆ poly_block()

POLY_BLOCK* PDBLK::poly_block ( ) const
inline

Definition at line 55 of file pdblock.h.

55 { return hand_poly; }
POLY_BLOCK * hand_poly
Definition: pdblock.h:95

◆ render_mask()

Pix * PDBLK::render_mask ( const FCOORD rerotation,
TBOX mask_box 
)

Definition at line 129 of file pdblock.cpp.

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

◆ set_index()

void PDBLK::set_index ( int  value)
inline

Definition at line 68 of file pdblock.h.

68 { index_ = value; }
int index_
Definition: pdblock.h:99

◆ set_poly_block()

void PDBLK::set_poly_block ( POLY_BLOCK blk)
inline

set the poly block

Definition at line 57 of file pdblock.h.

57 { hand_poly = blk; }
POLY_BLOCK * hand_poly
Definition: pdblock.h:95

◆ set_sides()

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 65 of file pdblock.cpp.

68  {
69  //boundaries
70  ICOORDELT_IT left_it = &leftside;
71  ICOORDELT_IT right_it = &rightside;
72 
73  leftside.clear ();
74  left_it.move_to_first ();
75  left_it.add_list_before (left);
76  rightside.clear ();
77  right_it.move_to_first ();
78  right_it.add_list_before (right);
79 }
ICOORDELT_LIST leftside
Definition: pdblock.h:96
ICOORDELT_LIST rightside
Definition: pdblock.h:97

Friends And Related Function Documentation

◆ BLOCK_RECT_IT

friend class BLOCK_RECT_IT
friend

Definition at line 33 of file pdblock.h.

Member Data Documentation

◆ box

TBOX PDBLK::box
protected

Definition at line 98 of file pdblock.h.

◆ hand_poly

POLY_BLOCK* PDBLK::hand_poly
protected

Definition at line 95 of file pdblock.h.

◆ index_

int PDBLK::index_
protected

Definition at line 99 of file pdblock.h.

◆ leftside

ICOORDELT_LIST PDBLK::leftside
protected

Definition at line 96 of file pdblock.h.

◆ rightside

ICOORDELT_LIST PDBLK::rightside
protected

Definition at line 97 of file pdblock.h.


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