tesseract v5.3.3.20231005
tesseract::PDBLK Class Reference

page block More...

#include <pdblock.h>

Public Member Functions

 PDBLK ()
 empty constructor More...
 
 PDBLK (TDimension xmin, TDimension ymin, TDimension xmax, TDimension 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...
 
Image 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 33 of file pdblock.h.

Constructor & Destructor Documentation

◆ PDBLK() [1/2]

tesseract::PDBLK::PDBLK ( )
inline

empty constructor

Definition at line 39 of file pdblock.h.

39 {
40 hand_poly = nullptr;
41 index_ = 0;
42 }
int index_
Serial number of this block.
Definition: pdblock.h:113
POLY_BLOCK * hand_poly
weird as well
Definition: pdblock.h:109

◆ PDBLK() [2/2]

tesseract::PDBLK::PDBLK ( TDimension  xmin,
TDimension  ymin,
TDimension  xmax,
TDimension  ymax 
)

simple constructor

Parameters
xminbottom left
xmaxtop right

Definition at line 44 of file pdblock.cpp.

49 : box(ICOORD(xmin, ymin), ICOORD(xmax, ymax)) {
50 // boundaries
51 ICOORDELT_IT left_it = &leftside;
52 ICOORDELT_IT right_it = &rightside;
53
54 hand_poly = nullptr;
55 left_it.set_to_list(&leftside);
56 right_it.set_to_list(&rightside);
57 // make default box
58 left_it.add_to_end(new ICOORDELT(xmin, ymin));
59 left_it.add_to_end(new ICOORDELT(xmin, ymax));
60 right_it.add_to_end(new ICOORDELT(xmax, ymin));
61 right_it.add_to_end(new ICOORDELT(xmax, ymax));
62 index_ = 0;
63}
ICOORDELT_LIST rightside
right side vertices
Definition: pdblock.h:111
TBOX box
bounding box
Definition: pdblock.h:112
ICOORDELT_LIST leftside
left side vertices
Definition: pdblock.h:110

◆ ~PDBLK()

tesseract::PDBLK::~PDBLK ( )
inline

destructor

Definition at line 55 of file pdblock.h.

55 {
56 delete hand_poly;
57 }

Member Function Documentation

◆ bounding_box() [1/2]

const TBOX & tesseract::PDBLK::bounding_box ( ) const
inline

get real box

Definition at line 73 of file pdblock.h.

73 {
74 return box;
75 }

◆ bounding_box() [2/2]

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

get box

Definition at line 67 of file pdblock.h.

68 { // topright
69 bottom_left = box.botleft();
70 top_right = box.topright();
71 }
const ICOORD & botleft() const
Definition: rect.h:102
const ICOORD & topright() const
Definition: rect.h:114

◆ contains()

bool tesseract::PDBLK::contains ( ICOORD  pt)

is pt inside block

Definition at line 93 of file pdblock.cpp.

95 {
96 BLOCK_RECT_IT it = this; // rectangle iterator
97 ICOORD bleft, tright; // corners of rectangle
98
99 for (it.start_block(); !it.cycled_rects(); it.forward()) {
100 // get rectangle
101 it.bounding_box(bleft, tright);
102 // inside rect
103 if (pt.x() >= bleft.x() && pt.x() <= tright.x() && pt.y() >= bleft.y() &&
104 pt.y() <= tright.y()) {
105 return true; // is inside
106 }
107 }
108 return false; // not inside
109}
friend class BLOCK_RECT_IT
block iterator
Definition: pdblock.h:34

◆ index()

int tesseract::PDBLK::index ( ) const
inline

Definition at line 77 of file pdblock.h.

77 {
78 return index_;
79 }

◆ move()

void tesseract::PDBLK::move ( const ICOORD  vec)

reposition block

Definition at line 117 of file pdblock.cpp.

119 {
120 ICOORDELT_IT it(&leftside);
121
122 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
123 *(it.data()) += vec;
124 }
125
126 it.set_to_list(&rightside);
127
128 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
129 *(it.data()) += vec;
130 }
131
132 box.move(vec);
133}
void move(const ICOORD vec)
Definition: rect.h:170

◆ operator=()

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

assignment

Parameters
sourcefrom this

Definition at line 245 of file pdblock.cpp.

247 {
248 // this->ELIST_LINK::operator=(source);
249 if (!leftside.empty()) {
250 leftside.clear();
251 }
252 if (!rightside.empty()) {
253 rightside.clear();
254 }
255 leftside.deep_copy(&source.leftside, &ICOORDELT::deep_copy);
256 rightside.deep_copy(&source.rightside, &ICOORDELT::deep_copy);
257 box = source.box;
258 return *this;
259}
static ICOORDELT * deep_copy(const ICOORDELT *src)
Definition: points.h:180

◆ plot()

void tesseract::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 185 of file pdblock.cpp.

189 {
190 ICOORD startpt; // start of outline
191 ICOORD endpt; // end of outline
192 ICOORD prevpt; // previous point
193 ICOORDELT_IT it = &leftside; // iterator
194
195 // set the colour
196 window->Pen(colour);
197 window->TextAttributes("Times", BLOCK_LABEL_HEIGHT, false, false, false);
198
199 if (hand_poly != nullptr) {
200 hand_poly->plot(window, serial);
201 } else if (!leftside.empty()) {
202 startpt = *(it.data()); // bottom left corner
203 // tprintf("Block %d bottom left is (%d,%d)\n",
204 // serial,startpt.x(),startpt.y());
205 char temp_buff[34];
206# if !defined(_WIN32) || defined(__MINGW32__)
207 snprintf(temp_buff, sizeof(temp_buff), "%" PRId32, serial);
208# else
209 _ultoa(serial, temp_buff, 10);
210# endif
211 window->Text(startpt.x(), startpt.y(), temp_buff);
212
213 window->SetCursor(startpt.x(), startpt.y());
214 do {
215 prevpt = *(it.data()); // previous point
216 it.forward(); // move to next point
217 // draw round corner
218 window->DrawTo(prevpt.x(), it.data()->y());
219 window->DrawTo(it.data()->x(), it.data()->y());
220 } while (!it.at_last()); // until end of list
221 endpt = *(it.data()); // end point
222
223 // other side of boundary
224 window->SetCursor(startpt.x(), startpt.y());
225 it.set_to_list(&rightside);
226 prevpt = startpt;
227 for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {
228 // draw round corner
229 window->DrawTo(prevpt.x(), it.data()->y());
230 window->DrawTo(it.data()->x(), it.data()->y());
231 prevpt = *(it.data()); // previous point
232 }
233 // close boundary
234 window->DrawTo(endpt.x(), endpt.y());
235 }
236}
#define BLOCK_LABEL_HEIGHT
Definition: pdblock.cpp:34
void plot(ScrollView *window, int32_t num)
Definition: polyblk.cpp:246

◆ poly_block()

POLY_BLOCK * tesseract::PDBLK::poly_block ( ) const
inline

Definition at line 59 of file pdblock.h.

59 {
60 return hand_poly;
61 }

◆ render_mask()

Image tesseract::PDBLK::render_mask ( const FCOORD rerotation,
TBOX mask_box 
)

Definition at line 137 of file pdblock.cpp.

137 {
138 TBOX rotated_box(box);
139 rotated_box.rotate(rerotation);
140 Image pix = pixCreate(rotated_box.width(), rotated_box.height(), 1);
141 if (hand_poly != nullptr) {
142 // We are going to rotate, so get a deep copy of the points and
143 // make a new POLY_BLOCK with it.
144 ICOORDELT_LIST polygon;
145 polygon.deep_copy(hand_poly->points(), ICOORDELT::deep_copy);
146 POLY_BLOCK image_block(&polygon, hand_poly->isA());
147 image_block.rotate(rerotation);
148 // Block outline is a polygon, so use a PB_LINE_IT to get the
149 // rasterized interior. (Runs of interior pixels on a line.)
150 auto *lines = new PB_LINE_IT(&image_block);
151 for (int y = box.bottom(); y < box.top(); ++y) {
152 const std::unique_ptr</*non-const*/ ICOORDELT_LIST> segments(lines->get_line(y));
153 if (!segments->empty()) {
154 ICOORDELT_IT s_it(segments.get());
155 // Each element of segments is a start x and x size of the
156 // run of interior pixels.
157 for (s_it.mark_cycle_pt(); !s_it.cycled_list(); s_it.forward()) {
158 int start = s_it.data()->x();
159 int xext = s_it.data()->y();
160 // Set the run of pixels to 1.
161 pixRasterop(pix, start - rotated_box.left(),
162 rotated_box.height() - 1 - (y - rotated_box.bottom()), xext, 1, PIX_SET,
163 nullptr, 0, 0);
164 }
165 }
166 }
167 delete lines;
168 } else {
169 // Just fill the whole block as there is only a bounding box.
170 pixRasterop(pix, 0, 0, rotated_box.width(), rotated_box.height(), PIX_SET, nullptr, 0, 0);
171 }
172 if (mask_box != nullptr) {
173 *mask_box = rotated_box;
174 }
175 return pix;
176}
@ TBOX
const double y
ICOORDELT_LIST * points()
Definition: polyblk.h:42
PolyBlockType isA() const
Definition: polyblk.h:48
TDimension top() const
Definition: rect.h:68
TDimension bottom() const
Definition: rect.h:75

◆ set_index()

void tesseract::PDBLK::set_index ( int  value)
inline

Definition at line 80 of file pdblock.h.

80 {
81 index_ = value;
82 }
int value

◆ set_poly_block()

void tesseract::PDBLK::set_poly_block ( POLY_BLOCK blk)
inline

set the poly block

Definition at line 63 of file pdblock.h.

63 {
64 hand_poly = blk;
65 }

◆ set_sides()

void tesseract::PDBLK::set_sides ( ICOORDELT_LIST *  left,
ICOORDELT_LIST *  right 
)

set vertex lists

Parameters
leftlist of left vertices
rightlist of right vertices

Definition at line 71 of file pdblock.cpp.

74 {
75 // boundaries
76 ICOORDELT_IT left_it = &leftside;
77 ICOORDELT_IT right_it = &rightside;
78
79 leftside.clear();
80 left_it.move_to_first();
81 left_it.add_list_before(left);
82 rightside.clear();
83 right_it.move_to_first();
84 right_it.add_list_before(right);
85}

Friends And Related Function Documentation

◆ BLOCK

friend class BLOCK
friend

Page Block.

Definition at line 35 of file pdblock.h.

◆ BLOCK_RECT_IT

friend class BLOCK_RECT_IT
friend

block iterator

Definition at line 34 of file pdblock.h.

Member Data Documentation

◆ box

TBOX tesseract::PDBLK::box
protected

bounding box

Definition at line 112 of file pdblock.h.

◆ hand_poly

POLY_BLOCK* tesseract::PDBLK::hand_poly
protected

weird as well

Definition at line 109 of file pdblock.h.

◆ index_

int tesseract::PDBLK::index_
protected

Serial number of this block.

Definition at line 113 of file pdblock.h.

◆ leftside

ICOORDELT_LIST tesseract::PDBLK::leftside
protected

left side vertices

Definition at line 110 of file pdblock.h.

◆ rightside

ICOORDELT_LIST tesseract::PDBLK::rightside
protected

right side vertices

Definition at line 111 of file pdblock.h.


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