tesseract  4.0.0-1-g2a2b
PDBLK Class Reference

page block More...

#include <pdblock.h>

Public Member Functions

 PDBLK ()
 empty constructor More...
 
 PDBLK (int16_t xmin, int16_t ymin, int16_t xmax, int16_t 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)
 
bool 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_t 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
 
class BLOCK
 

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 38 of file pdblock.h.

38  {
39  hand_poly = nullptr;
40  index_ = 0;
41  }
POLY_BLOCK * hand_poly
Definition: pdblock.h:96
int index_
Definition: pdblock.h:100

◆ PDBLK() [2/2]

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

simple constructor

Definition at line 41 of file pdblock.cpp.

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

◆ ~PDBLK()

PDBLK::~PDBLK ( )
inline

destructor

Definition at line 54 of file pdblock.h.

54 { delete hand_poly; }
POLY_BLOCK * hand_poly
Definition: pdblock.h:96

Member Function Documentation

◆ bounding_box() [1/2]

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

get box

Definition at line 60 of file pdblock.h.

61  { // topright
62  bottom_left = box.botleft();
63  top_right = box.topright();
64  }
const ICOORD & topright() const
Definition: rect.h:104
TBOX box
Definition: pdblock.h:99
const ICOORD & botleft() const
Definition: rect.h:92

◆ bounding_box() [2/2]

const TBOX& PDBLK::bounding_box ( ) const
inline

get real box

Definition at line 66 of file pdblock.h.

66 { return box; }
TBOX box
Definition: pdblock.h:99

◆ contains()

bool PDBLK::contains ( ICOORD  pt)

is pt inside block

Definition at line 89 of file pdblock.cpp.

91  {
92  BLOCK_RECT_IT it = this; //rectangle iterator
93  ICOORD bleft, tright; //corners of rectangle
94 
95  for (it.start_block(); !it.cycled_rects(); it.forward()) {
96  //get rectangle
97  it.bounding_box (bleft, tright);
98  //inside rect
99  if (pt.x() >= bleft.x() && pt.x() <= tright.x()
100  && pt.y() >= bleft.y() && pt.y() <= tright.y())
101  return true; //is inside
102  }
103  return false; //not inside
104 }
int16_t y() const
access_function
Definition: points.h:57
void forward()
next rectangle
Definition: pdblock.cpp:316
bool cycled_rects()
test end
Definition: pdblock.h:121
integer coordinate
Definition: points.h:32
int16_t x() const
access function
Definition: points.h:53
void bounding_box(ICOORD &bleft, ICOORD &tright)
Definition: pdblock.h:128
void start_block()
start iteration
Definition: pdblock.cpp:297

◆ index()

int PDBLK::index ( ) const
inline

Definition at line 68 of file pdblock.h.

68 { return index_; }
int index_
Definition: pdblock.h:100

◆ move()

void PDBLK::move ( const ICOORD  vec)

reposition block

Definition at line 113 of file pdblock.cpp.

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

◆ operator=()

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

assignment

Parameters
sourcefrom this

Definition at line 241 of file pdblock.cpp.

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

◆ plot()

void PDBLK::plot ( ScrollView window,
int32_t  serial,
ScrollView::Color  colour 
)

draw histogram

Parameters
windowwindow to draw in
serialserial number
colourcolour to draw in

Definition at line 180 of file pdblock.cpp.

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

◆ poly_block()

POLY_BLOCK* PDBLK::poly_block ( ) const
inline

Definition at line 56 of file pdblock.h.

56 { return hand_poly; }
POLY_BLOCK * hand_poly
Definition: pdblock.h:96

◆ render_mask()

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

Definition at line 131 of file pdblock.cpp.

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

◆ set_index()

void PDBLK::set_index ( int  value)
inline

Definition at line 69 of file pdblock.h.

69 { index_ = value; }
int index_
Definition: pdblock.h:100

◆ set_poly_block()

void PDBLK::set_poly_block ( POLY_BLOCK blk)
inline

set the poly block

Definition at line 58 of file pdblock.h.

58 { hand_poly = blk; }
POLY_BLOCK * hand_poly
Definition: pdblock.h:96

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

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

Friends And Related Function Documentation

◆ BLOCK

friend class BLOCK
friend

Definition at line 34 of file pdblock.h.

◆ 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 99 of file pdblock.h.

◆ hand_poly

POLY_BLOCK* PDBLK::hand_poly
protected

Definition at line 96 of file pdblock.h.

◆ index_

int PDBLK::index_
protected

Definition at line 100 of file pdblock.h.

◆ leftside

ICOORDELT_LIST PDBLK::leftside
protected

Definition at line 97 of file pdblock.h.

◆ rightside

ICOORDELT_LIST PDBLK::rightside
protected

Definition at line 98 of file pdblock.h.


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