tesseract  5.0.0-alpha-619-ge9db
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
 weird as well More...
 
ICOORDELT_LIST leftside
 left side vertices More...
 
ICOORDELT_LIST rightside
 right side vertices More...
 
TBOX box
 bounding box More...
 
int index_
 Serial number of this block. More...
 

Friends

class BLOCK_RECT_IT
 block iterator More...
 
class BLOCK
 Page Block. More...
 

Detailed Description

page block

Definition at line 30 of file pdblock.h.

Constructor & Destructor Documentation

◆ PDBLK() [1/2]

PDBLK::PDBLK ( )
inline

empty constructor

Definition at line 36 of file pdblock.h.

37  {
38  hand_poly = nullptr;
39  index_ = 0;

◆ PDBLK() [2/2]

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

simple constructor

Parameters
xminbottom left
xmaxtop right

Definition at line 39 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));

◆ ~PDBLK()

PDBLK::~PDBLK ( )
inline

destructor

Definition at line 52 of file pdblock.h.

53 { delete hand_poly; }

Member Function Documentation

◆ bounding_box() [1/2]

const TBOX& PDBLK::bounding_box ( ) const
inline

get real box

Definition at line 64 of file pdblock.h.

65 { return box; }

◆ bounding_box() [2/2]

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

get box

Definition at line 58 of file pdblock.h.

60  { // topright
61  bottom_left = box.botleft();
62  top_right = box.topright();

◆ contains()

bool PDBLK::contains ( ICOORD  pt)

is pt inside block

Definition at line 85 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())

◆ index()

int PDBLK::index ( ) const
inline

Definition at line 66 of file pdblock.h.

67 { return index_; }

◆ move()

void PDBLK::move ( const ICOORD  vec)

reposition block

Definition at line 108 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 

◆ operator=()

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

assignment

Parameters
sourcefrom this

Definition at line 234 of file pdblock.cpp.

243  {
244  // this->ELIST_LINK::operator=(source);
245  if (!leftside.empty ())
246  leftside.clear ();

◆ 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 174 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 ());

◆ poly_block()

POLY_BLOCK* PDBLK::poly_block ( ) const
inline

Definition at line 54 of file pdblock.h.

55 { return hand_poly; }

◆ render_mask()

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

Definition at line 126 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  auto *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(),

◆ set_index()

void PDBLK::set_index ( int  value)
inline

Definition at line 67 of file pdblock.h.

67 { return index_; }

◆ set_poly_block()

void PDBLK::set_poly_block ( POLY_BLOCK blk)
inline

set the poly block

Definition at line 56 of file pdblock.h.

57 { hand_poly = blk; }

◆ 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 64 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();

Friends And Related Function Documentation

◆ BLOCK

friend class BLOCK
friend

Page Block.

Definition at line 32 of file pdblock.h.

◆ BLOCK_RECT_IT

friend class BLOCK_RECT_IT
friend

block iterator

Definition at line 31 of file pdblock.h.

Member Data Documentation

◆ box

TBOX PDBLK::box
protected

bounding box

Definition at line 97 of file pdblock.h.

◆ hand_poly

POLY_BLOCK* PDBLK::hand_poly
protected

weird as well

Definition at line 94 of file pdblock.h.

◆ index_

int PDBLK::index_
protected

Serial number of this block.

Definition at line 98 of file pdblock.h.

◆ leftside

ICOORDELT_LIST PDBLK::leftside
protected

left side vertices

Definition at line 95 of file pdblock.h.

◆ rightside

ICOORDELT_LIST PDBLK::rightside
protected

right side vertices

Definition at line 96 of file pdblock.h.


The documentation for this class was generated from the following files:
BLOCK_RECT_IT::bounding_box
void bounding_box(ICOORD &bleft, ICOORD &tright)
Definition: pdblock.h:126
ICOORD
integer coordinate
Definition: points.h:30
TBOX::top
int16_t top() const
Definition: rect.h:57
PB_LINE_IT
Definition: polyblk.h:90
BLOCK_RECT_IT::cycled_rects
bool cycled_rects()
test end
Definition: pdblock.h:119
ScrollView::Pen
void Pen(Color color)
Definition: scrollview.cpp:717
ScrollView::DrawTo
void DrawTo(int x, int y)
Definition: scrollview.cpp:524
PDBLK::rightside
ICOORDELT_LIST rightside
right side vertices
Definition: pdblock.h:96
ICOORD::x
int16_t x() const
access function
Definition: points.h:51
PDBLK::leftside
ICOORDELT_LIST leftside
left side vertices
Definition: pdblock.h:95
POLY_BLOCK::rotate
void rotate(FCOORD rotation)
Definition: polyblk.cpp:183
POLY_BLOCK::plot
void plot(ScrollView *window, int32_t num)
Definition: polyblk.cpp:243
BLOCK_LABEL_HEIGHT
#define BLOCK_LABEL_HEIGHT
Definition: pdblock.cpp:29
ICOORDELT::deep_copy
static ICOORDELT * deep_copy(const ICOORDELT *src)
Definition: points.h:178
TBOX::bottom
int16_t bottom() const
Definition: rect.h:64
TBOX::topright
const ICOORD & topright() const
Definition: rect.h:103
BLOCK_RECT_IT::forward
void forward()
next rectangle
Definition: pdblock.cpp:305
TBOX::botleft
const ICOORD & botleft() const
Definition: rect.h:91
POLY_BLOCK::points
ICOORDELT_LIST * points()
Definition: polyblk.h:52
PDBLK::box
TBOX box
bounding box
Definition: pdblock.h:97
ScrollView::TextAttributes
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
Definition: scrollview.cpp:634
PDBLK::index_
int index_
Serial number of this block.
Definition: pdblock.h:98
POLY_BLOCK
Definition: polyblk.h:26
PDBLK::hand_poly
POLY_BLOCK * hand_poly
weird as well
Definition: pdblock.h:94
ScrollView::SetCursor
void SetCursor(int x, int y)
Definition: scrollview.cpp:518
ScrollView::Text
void Text(int x, int y, const char *mystring)
Definition: scrollview.cpp:651
POLY_BLOCK::isA
PolyBlockType isA() const
Definition: polyblk.h:58
ICOORDELT
Definition: points.h:160
BLOCK_RECT_IT
Definition: pdblock.h:101
BLOCK_RECT_IT::start_block
void start_block()
start iteration
Definition: pdblock.cpp:287
ICOORD::y
int16_t y() const
access_function
Definition: points.h:55
TBOX
Definition: rect.h:33