111 int* old_grid = grid_;
118 for (
int oldy = 0; oldy < old_height; ++oldy) {
119 FCOORD line_pos(old_bleft.x(), old_bleft.y() +
gridsize() * oldy);
120 line_pos.
rotate(rotation);
121 for (
int oldx = 0; oldx < old_width; ++oldx, line_pos += x_step, ++oldi) {
123 GridCoords(static_cast<int>(line_pos.x() + 0.5),
124 static_cast<int>(line_pos.y() + 0.5),
126 grid_[grid_y *
gridwidth() + grid_x] = old_grid[oldi];
141 for (
int yoffset = -1; yoffset <= 1; ++yoffset) {
142 for (
int xoffset = -1; xoffset <= 1; ++xoffset) {
143 int grid_x = x + xoffset;
144 int grid_y = y + yoffset;
159 int min_x, min_y, max_x, max_y;
163 for (
int y = min_y; y <= max_y; ++y) {
164 for (
int x = min_x; x <= max_x; ++x) {
166 if (value > threshold) {
170 total_area += cell_box.
area();
174 return total_area * 2 > rect.
area();
179 int min_x, min_y, max_x, max_y;
182 for (
int y = min_y; y <= max_y; ++y) {
183 for (
int x = min_x; x <= max_x; ++x) {
203 pixRasterop(pix, x * cellsize,
tright().y() - ((y + 1) * cellsize),
204 cellsize, cellsize, PIX_SET, NULL, 0, 0);
213 ICOORD bleft,
int* left,
int* bottom) {
215 int grid_left = (box.
left() - bleft.
x()) / gridsize - 1;
216 int grid_bottom = (box.
bottom() - bleft.
y()) / gridsize - 1;
217 int grid_right = (box.
right() - bleft.
x()) / gridsize + 1;
218 int grid_top = (box.
top() - bleft.
y()) / gridsize + 1;
220 *bottom = grid_bottom;
221 return pixCreate(grid_right - grid_left + 1,
222 grid_top - grid_bottom + 1,
233 ICOORD bleft,
int* left,
int* bottom) {
236 int wpl = pixGetWpl(pix);
237 l_uint32* data = pixGetData(pix);
240 for (
int i = 0; i < length; ++i) {
241 int grid_x = (pos.
x() - bleft.
x()) / gridsize - *left;
242 int grid_y = (pos.
y() - bleft.
y()) / gridsize - *bottom;
243 SET_DATA_BIT(data + grid_y * wpl, grid_x);
244 pos += outline->
step(i);
248 #if 0 // Example code shows how to use TraceOutlineOnReducedPix. 249 C_OUTLINE_IT ol_it(blob->cblob()->out_list());
250 int grid_left, grid_bottom;
252 &grid_left, &grid_bottom);
253 grid->InsertPixPtBBox(grid_left, grid_bottom, pix, blob);
259 ICOORD bleft,
int* left,
int* bottom) {
262 int wpl = pixGetWpl(pix);
263 l_uint32* data = pixGetData(pix);
265 for (it.mark_cycle_pt(); !it.cycled_list();) {
268 ICOORD next_pos = *it.data();
269 ICOORD line_vector = next_pos - pos;
271 ICOORD major_step, minor_step;
272 line_vector.
setup_render(&major_step, &minor_step, &major, &minor);
273 int accumulator = major / 2;
274 while (pos != next_pos) {
275 int grid_x = (pos.x() - bleft.
x()) / gridsize - *left;
276 int grid_y = (pos.y() - bleft.
y()) / gridsize - *bottom;
277 SET_DATA_BIT(data + grid_y * wpl, grid_x);
279 accumulator += minor;
280 if (accumulator >= major) {
281 accumulator -= major;
void rotate(const FCOORD &vec)
int GridCellValue(int grid_x, int grid_y) const
Pix * TraceOutlineOnReducedPix(C_OUTLINE *outline, int gridsize, ICOORD bleft, int *left, int *bottom)
const ICOORD & tright() const
const ICOORD & topright() const
bool AnyZeroInRect(const TBOX &rect) const
ICOORDELT_LIST * points()
bool RectMostlyOverThreshold(const TBOX &rect, int threshold) const
Pix * TraceBlockOnReducedPix(BLOCK *block, int gridsize, ICOORD bleft, int *left, int *bottom)
ICOORD step(int index) const
void Rotate(const FCOORD &rotation)
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
void setup_render(ICOORD *major_step, ICOORD *minor_step, int *major, int *minor) const
IntGrid * NeighbourhoodSum() const
POLY_BLOCK * poly_block() const
void rotate(const FCOORD vec)
inT16 x() const
access function
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
const TBOX & bounding_box() const
Pix * ThresholdToPix(int threshold) const
void ClipGridCoords(int *x, int *y) const
void GridCoords(int x, int y, int *grid_x, int *grid_y) const
void SetGridCell(int grid_x, int grid_y, int value)
Pix * GridReducedPix(const TBOX &box, int gridsize, ICOORD bleft, int *left, int *bottom)
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
const ICOORD & start_pos() const
const ICOORD & bleft() const
const ICOORD & botleft() const
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
inT16 y() const
access_function