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
TBOX box
Definition: pdblock.h:98
int index_
Definition: pdblock.h:99
ICOORDELT_LIST rightside
Definition: pdblock.h:97
integer coordinate
Definition: points.h:30
ICOORDELT_LIST leftside
Definition: pdblock.h:96

◆ ~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
TBOX box
Definition: pdblock.h:98
const ICOORD & botleft() const
Definition: rect.h:88

◆ 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
void bounding_box(ICOORD &bleft, ICOORD &tright)
Definition: pdblock.h:127
inT16 x() const
access function
Definition: points.h:52
BOOL8 cycled_rects()
test end
Definition: pdblock.h:120
#define FALSE
Definition: capi.h:46
void forward()
next rectangle
Definition: pdblock.cpp:314
inT16 y() const
access_function
Definition: points.h:56
integer coordinate
Definition: points.h:30
void start_block()
start iteration
Definition: pdblock.cpp:295

◆ 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
TBOX box
Definition: pdblock.h:98
ICOORDELT_LIST rightside
Definition: pdblock.h:97
ICOORDELT_LIST leftside
Definition: pdblock.h:96

◆ operator=()

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

assignment

Parameters
sourcefrom this

Definition at line 239 of file pdblock.cpp.

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

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

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

◆ 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(
145  lines->get_line(y));
146  if (!segments->empty()) {
147  ICOORDELT_IT s_it(segments.get());
148  // Each element of segments is a start x and x size of the
149  // run of interior pixels.
150  for (s_it.mark_cycle_pt(); !s_it.cycled_list(); s_it.forward()) {
151  int start = s_it.data()->x();
152  int xext = s_it.data()->y();
153  // Set the run of pixels to 1.
154  pixRasterop(pix, start - rotated_box.left(),
155  rotated_box.height() - 1 - (y - rotated_box.bottom()),
156  xext, 1, PIX_SET, NULL, 0, 0);
157  }
158  }
159  }
160  delete lines;
161  } else {
162  // Just fill the whole block as there is only a bounding box.
163  pixRasterop(pix, 0, 0, rotated_box.width(), rotated_box.height(),
164  PIX_SET, NULL, 0, 0);
165  }
166  if (mask_box != NULL) *mask_box = rotated_box;
167  return pix;
168 }
void rotate(FCOORD rotation)
Definition: polyblk.cpp:186
POLY_BLOCK * hand_poly
Definition: pdblock.h:95
PolyBlockType isA() const
Definition: polyblk.h:48
inT16 top() const
Definition: rect.h:54
ICOORDELT_LIST * points()
Definition: polyblk.h:42
inT16 bottom() const
Definition: rect.h:61
Definition: rect.h:30
TBOX box
Definition: pdblock.h:98
static ICOORDELT * deep_copy(const ICOORDELT *src)
Definition: points.h:180
ICOORDELT_LIST * get_line(inT16 y)
Definition: polyblk.cpp:344

◆ 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 rightside
Definition: pdblock.h:97
ICOORDELT_LIST leftside
Definition: pdblock.h:96

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: