108 int* old_grid = grid_;
115 for (
int oldy = 0; oldy < old_height; ++oldy) {
116 FCOORD line_pos(old_bleft.x(), old_bleft.y() +
gridsize() * oldy);
117 line_pos.
rotate(rotation);
118 for (
int oldx = 0; oldx < old_width; ++oldx, line_pos += x_step, ++oldi) {
120 GridCoords(static_cast<int>(line_pos.x() + 0.5),
121 static_cast<int>(line_pos.y() + 0.5),
123 grid_[grid_y *
gridwidth() + grid_x] = old_grid[oldi];
138 for (
int yoffset = -1; yoffset <= 1; ++yoffset) {
139 for (
int xoffset = -1; xoffset <= 1; ++xoffset) {
140 int grid_x = x + xoffset;
141 int grid_y = y + yoffset;
156 int min_x, min_y, max_x, max_y;
160 for (
int y = min_y; y <= max_y; ++y) {
161 for (
int x = min_x; x <= max_x; ++x) {
163 if (value > threshold) {
167 total_area += cell_box.
area();
171 return total_area * 2 > rect.
area();
176 int min_x, min_y, max_x, max_y;
179 for (
int y = min_y; y <= max_y; ++y) {
180 for (
int x = min_x; x <= max_x; ++x) {
200 pixRasterop(pix, x * cellsize,
tright().y() - ((y + 1) * cellsize),
201 cellsize, cellsize, PIX_SET,
nullptr, 0, 0);
209 static Pix* GridReducedPix(
const TBOX& box,
int gridsize,
210 ICOORD bleft,
int* left,
int* bottom) {
212 int grid_left = (box.
left() - bleft.
x()) / gridsize - 1;
213 int grid_bottom = (box.
bottom() - bleft.
y()) / gridsize - 1;
214 int grid_right = (box.
right() - bleft.
x()) / gridsize + 1;
215 int grid_top = (box.
top() - bleft.
y()) / gridsize + 1;
217 *bottom = grid_bottom;
218 return pixCreate(grid_right - grid_left + 1,
219 grid_top - grid_bottom + 1,
230 ICOORD bleft,
int* left,
int* bottom) {
232 Pix* pix = GridReducedPix(box, gridsize, bleft, left, bottom);
233 int wpl = pixGetWpl(pix);
234 l_uint32* data = pixGetData(pix);
237 for (
int i = 0; i < length; ++i) {
238 int grid_x = (pos.
x() - bleft.
x()) / gridsize - *left;
239 int grid_y = (pos.
y() - bleft.
y()) / gridsize - *bottom;
240 SET_DATA_BIT(data + grid_y * wpl, grid_x);
241 pos += outline->
step(i);
245 #if 0 // Example code shows how to use TraceOutlineOnReducedPix. 246 C_OUTLINE_IT ol_it(blob->cblob()->out_list());
247 int grid_left, grid_bottom;
249 &grid_left, &grid_bottom);
250 grid->InsertPixPtBBox(grid_left, grid_bottom, pix, blob);
256 ICOORD bleft,
int* left,
int* bottom) {
258 Pix* pix = GridReducedPix(box, gridsize, bleft, left, bottom);
259 int wpl = pixGetWpl(pix);
260 l_uint32* data = pixGetData(pix);
262 for (it.mark_cycle_pt(); !it.cycled_list();) {
265 ICOORD next_pos = *it.data();
266 ICOORD line_vector = next_pos - pos;
268 ICOORD major_step, minor_step;
269 line_vector.
setup_render(&major_step, &minor_step, &major, &minor);
270 int accumulator = major / 2;
271 while (pos != next_pos) {
272 int grid_x = (pos.x() - bleft.
x()) / gridsize - *left;
273 int grid_y = (pos.y() - bleft.
y()) / gridsize - *bottom;
274 SET_DATA_BIT(data + grid_y * wpl, grid_x);
276 accumulator += minor;
277 if (accumulator >= major) {
278 accumulator -= major;
const ICOORD & topright() const
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
void rotate(const FCOORD &vec)
const ICOORD & bleft() const
void rotate(const FCOORD vec)
int16_t y() const
access_function
Pix * TraceOutlineOnReducedPix(C_OUTLINE *outline, int gridsize, ICOORD bleft, int *left, int *bottom)
const ICOORD & start_pos() const
void Rotate(const FCOORD &rotation)
int GridCellValue(int grid_x, int grid_y) const
void setup_render(ICOORD *major_step, ICOORD *minor_step, int *major, int *minor) const
bool AnyZeroInRect(const TBOX &rect) const
int16_t x() const
access function
bool RectMostlyOverThreshold(const TBOX &rect, int threshold) const
POLY_BLOCK * poly_block() const
int32_t pathlength() const
const TBOX & bounding_box() const
void SetGridCell(int grid_x, int grid_y, int value)
void GridCoords(int x, int y, int *grid_x, int *grid_y) const
Pix * TraceBlockOnReducedPix(BLOCK *block, int gridsize, ICOORD bleft, int *left, int *bottom)
void Init(int gridsize, const ICOORD &bleft, const ICOORD &tright)
const ICOORD & botleft() const
IntGrid * NeighbourhoodSum() const
void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const
get box
ICOORDELT_LIST * points()
T ClipToRange(const T &x, const T &lower_bound, const T &upper_bound)
void ClipGridCoords(int *x, int *y) const
ICOORD step(int index) const
Pix * ThresholdToPix(int threshold) const
const ICOORD & tright() const