tesseract 4.1.1
Loading...
Searching...
No Matches
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 31 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 = nullptr;
39 index_ = 0;
40 }
POLY_BLOCK * hand_poly
weird as well
Definition: pdblock.h:95
int index_
Serial number of this block.
Definition: pdblock.h:99

◆ 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 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}
ICOORDELT_LIST rightside
right side vertices
Definition: pdblock.h:97
TBOX box
bounding box
Definition: pdblock.h:98
ICOORDELT_LIST leftside
left side vertices
Definition: pdblock.h:96
integer coordinate
Definition: points.h:32

◆ ~PDBLK()

PDBLK::~PDBLK ( )
inline

destructor

Definition at line 53 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 65 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 59 of file pdblock.h.

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

◆ 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}
void bounding_box(ICOORD &bleft, ICOORD &tright)
Definition: pdblock.h:127
void start_block()
start iteration
Definition: pdblock.cpp:297
bool cycled_rects()
test end
Definition: pdblock.h:120
void forward()
next rectangle
Definition: pdblock.cpp:316
int16_t y() const
access_function
Definition: points.h:56
int16_t x() const
access function
Definition: points.h:52

◆ index()

int PDBLK::index ( ) const
inline

Definition at line 67 of file pdblock.h.

67{ return index_; }

◆ 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}
void move(const ICOORD vec)
Definition: rect.h:157

◆ 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}
static ICOORDELT * deep_copy(const ICOORDELT *src)
Definition: points.h:179

◆ 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}
#define BLOCK_LABEL_HEIGHT
Definition: pdblock.cpp:30
void plot(ScrollView *window, int32_t num)
Definition: polyblk.cpp:244
void DrawTo(int x, int y)
Definition: scrollview.cpp:525
void TextAttributes(const char *font, int pixel_size, bool bold, bool italic, bool underlined)
Definition: scrollview.cpp:635
void Text(int x, int y, const char *mystring)
Definition: scrollview.cpp:652
void SetCursor(int x, int y)
Definition: scrollview.cpp:519
void Pen(Color color)
Definition: scrollview.cpp:719

◆ poly_block()

POLY_BLOCK * PDBLK::poly_block ( ) const
inline

Definition at line 55 of file pdblock.h.

55{ return hand_poly; }

◆ 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 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(),
166 PIX_SET, nullptr, 0, 0);
167 }
168 if (mask_box != nullptr) *mask_box = rotated_box;
169 return pix;
170}
ICOORDELT_LIST * points()
Definition: polyblk.h:39
PolyBlockType isA() const
Definition: polyblk.h:45
Definition: rect.h:34
int16_t top() const
Definition: rect.h:58
int16_t bottom() const
Definition: rect.h:65

◆ set_index()

void PDBLK::set_index ( int  value)
inline

Definition at line 68 of file pdblock.h.

68{ index_ = value; }

◆ 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; }

◆ 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}

Friends And Related Function Documentation

◆ BLOCK

friend class BLOCK
friend

Page Block.

Definition at line 33 of file pdblock.h.

◆ BLOCK_RECT_IT

friend class BLOCK_RECT_IT
friend

block iterator

Definition at line 32 of file pdblock.h.

Member Data Documentation

◆ box

TBOX PDBLK::box
protected

bounding box

Definition at line 98 of file pdblock.h.

◆ hand_poly

POLY_BLOCK* PDBLK::hand_poly
protected

weird as well

Definition at line 95 of file pdblock.h.

◆ index_

int PDBLK::index_
protected

Serial number of this block.

Definition at line 99 of file pdblock.h.

◆ leftside

ICOORDELT_LIST PDBLK::leftside
protected

left side vertices

Definition at line 96 of file pdblock.h.

◆ rightside

ICOORDELT_LIST PDBLK::rightside
protected

right side vertices

Definition at line 97 of file pdblock.h.


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