Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
agg::rasterizer_cells_aa< Cell > Class Template Reference

#include <src/agg/agg_rasterizer_cells_aa.h>

+ Inheritance diagram for agg::rasterizer_cells_aa< Cell >:
+ Collaboration diagram for agg::rasterizer_cells_aa< Cell >:

Classes

struct  sorted_y
 

Public Types

typedef Cell cell_type
 
typedef rasterizer_cells_aa< Cell > self_type
 

Public Member Functions

 ~rasterizer_cells_aa ()
 
 rasterizer_cells_aa ()
 
void reset ()
 
void style (const cell_type &style_cell)
 
void line (int x1, int y1, int x2, int y2)
 
int min_x () const
 
int min_y () const
 
int max_x () const
 
int max_y () const
 
void sort_cells ()
 
unsigned total_cells () const
 
unsigned scanline_num_cells (unsigned y) const
 
const cell_type *constscanline_cells (unsigned y) const
 
bool sorted () const
 

Private Types

enum  cell_block_scale_e {
  cell_block_shift = 12 , cell_block_size = 1 << cell_block_shift , cell_block_mask = cell_block_size - 1 , cell_block_pool = 256 ,
  cell_block_limit = 1024
}
 

Private Member Functions

 rasterizer_cells_aa (const self_type &)
 
const self_typeoperator= (const self_type &)
 
void set_curr_cell (int x, int y)
 
void add_curr_cell ()
 
void render_hline (int ey, int x1, int y1, int x2, int y2)
 
void allocate_block ()
 

Private Attributes

unsigned m_num_blocks
 
unsigned m_max_blocks
 
unsigned m_curr_block
 
unsigned m_num_cells
 
cell_type ** m_cells
 
cell_typem_curr_cell_ptr
 
pod_vector< cell_type * > m_sorted_cells
 
pod_vector< sorted_ym_sorted_y
 
cell_type m_curr_cell
 
cell_type m_style_cell
 
int m_min_x
 
int m_min_y
 
int m_max_x
 
int m_max_y
 
bool m_sorted
 

Detailed Description

template<class Cell>
class agg::rasterizer_cells_aa< Cell >

Class Documentation

◆ agg::rasterizer_cells_aa::sorted_y

struct agg::rasterizer_cells_aa::sorted_y
template<class Cell>
struct agg::rasterizer_cells_aa< Cell >::sorted_y
Class Members
unsigned num
unsigned start

Member Typedef Documentation

◆ cell_type

template<class Cell >
typedef Cell agg::rasterizer_cells_aa< Cell >::cell_type

◆ self_type

template<class Cell >
typedef rasterizer_cells_aa<Cell> agg::rasterizer_cells_aa< Cell >::self_type

Member Enumeration Documentation

◆ cell_block_scale_e

template<class Cell >
enum agg::rasterizer_cells_aa::cell_block_scale_e
private
Enumerator
cell_block_shift 
cell_block_size 
cell_block_mask 
cell_block_pool 
cell_block_limit 
48 {
52 cell_block_pool = 256,
53 cell_block_limit = 1024
54 };
@ cell_block_limit
Definition agg_rasterizer_cells_aa.h:53
@ cell_block_pool
Definition agg_rasterizer_cells_aa.h:52
@ cell_block_mask
Definition agg_rasterizer_cells_aa.h:51
@ cell_block_shift
Definition agg_rasterizer_cells_aa.h:49
@ cell_block_size
Definition agg_rasterizer_cells_aa.h:50

Constructor & Destructor Documentation

◆ ~rasterizer_cells_aa()

template<class Cell >
agg::rasterizer_cells_aa< Cell >::~rasterizer_cells_aa
130 {
131 if(m_num_blocks)
132 {
133 cell_type** ptr = m_cells + m_num_blocks - 1;
134 while(m_num_blocks--)
135 {
137 ptr--;
138 }
140 }
141 }
Cell cell_type
Definition agg_rasterizer_cells_aa.h:63
cell_type ** m_cells
Definition agg_rasterizer_cells_aa.h:111
unsigned m_num_blocks
Definition agg_rasterizer_cells_aa.h:107
unsigned m_max_blocks
Definition agg_rasterizer_cells_aa.h:108
static void deallocate(T *ptr, unsigned)
Definition agg_basics.h:39

References agg::pod_allocator< T >::deallocate().

+ Here is the call graph for this function:

◆ rasterizer_cells_aa() [1/2]

template<class Cell >
agg::rasterizer_cells_aa< Cell >::rasterizer_cells_aa
145 :
146 m_num_blocks(0),
147 m_max_blocks(0),
148 m_curr_block(0),
149 m_num_cells(0),
150 m_cells(0),
153 m_sorted_y(),
154 m_min_x(std::numeric_limits<int>::max()),
155 m_min_y(std::numeric_limits<int>::max()),
156 m_max_x(std::numeric_limits<int>::min()),
157 m_max_y(std::numeric_limits<int>::min()),
158 m_sorted(false)
159 {
160 m_style_cell.initial();
161 m_curr_cell.initial();
162 }
pod_vector< sorted_y > m_sorted_y
Definition agg_rasterizer_cells_aa.h:114
int m_min_x
Definition agg_rasterizer_cells_aa.h:117
cell_type m_style_cell
Definition agg_rasterizer_cells_aa.h:116
cell_type m_curr_cell
Definition agg_rasterizer_cells_aa.h:115
int m_max_x
Definition agg_rasterizer_cells_aa.h:119
int m_min_y
Definition agg_rasterizer_cells_aa.h:118
bool m_sorted
Definition agg_rasterizer_cells_aa.h:121
unsigned m_num_cells
Definition agg_rasterizer_cells_aa.h:110
pod_vector< cell_type * > m_sorted_cells
Definition agg_rasterizer_cells_aa.h:113
unsigned m_curr_block
Definition agg_rasterizer_cells_aa.h:109
int m_max_y
Definition agg_rasterizer_cells_aa.h:120
cell_type * m_curr_cell_ptr
Definition agg_rasterizer_cells_aa.h:112

References agg::rasterizer_cells_aa< Cell >::m_curr_cell, and agg::rasterizer_cells_aa< Cell >::m_style_cell.

◆ rasterizer_cells_aa() [2/2]

template<class Cell >
agg::rasterizer_cells_aa< Cell >::rasterizer_cells_aa ( const self_type )
private

Member Function Documentation

◆ add_curr_cell()

template<class Cell >
AGG_INLINE void agg::rasterizer_cells_aa< Cell >::add_curr_cell
private
182 {
183 if(m_curr_cell.area | m_curr_cell.cover)
184 {
185 if((m_num_cells & cell_block_mask) == 0)
186 {
187 if(m_num_blocks >= cell_block_limit) return;
189 }
191 ++m_num_cells;
192 }
193 }
void allocate_block()
Definition agg_rasterizer_cells_aa.h:470

◆ allocate_block()

template<class Cell >
void agg::rasterizer_cells_aa< Cell >::allocate_block
private
471 {
473 {
475 {
476 cell_type** new_cells =
479
480 if(m_cells)
481 {
482 memcpy(new_cells, m_cells, m_max_blocks * sizeof(cell_type*));
484 }
485 m_cells = new_cells;
487 }
488
491
492 }
494 }
static T * allocate(unsigned num)
Definition agg_basics.h:38

References agg::pod_allocator< T >::allocate(), and agg::pod_allocator< T >::deallocate().

+ Here is the call graph for this function:

◆ line()

template<class Cell >
void agg::rasterizer_cells_aa< Cell >::line ( int  x1,
int  y1,
int  x2,
int  y2 
)
319 {
320 enum dx_limit_e { dx_limit = 16384 << poly_subpixel_shift };
321
322 long long dx = (long long)x2 - (long long)x1;
323
324 if(dx >= dx_limit || dx <= -dx_limit)
325 {
326 int cx = (int)(((long long)x1 + (long long)x2) >> 1);
327 int cy = (int)(((long long)y1 + (long long)y2) >> 1);
328 line(x1, y1, cx, cy);
329 line(cx, cy, x2, y2);
330 }
331
332 long long dy = (long long)y2 - (long long)y1;
333 int ex1 = x1 >> poly_subpixel_shift;
334 int ex2 = x2 >> poly_subpixel_shift;
335 int ey1 = y1 >> poly_subpixel_shift;
336 int ey2 = y2 >> poly_subpixel_shift;
337 int fy1 = y1 & poly_subpixel_mask;
338 int fy2 = y2 & poly_subpixel_mask;
339
340 int x_from, x_to;
341 int rem, mod, lift, delta, first, incr;
342 long long p;
343
344 if(ex1 < m_min_x) m_min_x = ex1;
345 if(ex1 > m_max_x) m_max_x = ex1;
346 if(ey1 < m_min_y) m_min_y = ey1;
347 if(ey1 > m_max_y) m_max_y = ey1;
348 if(ex2 < m_min_x) m_min_x = ex2;
349 if(ex2 > m_max_x) m_max_x = ex2;
350 if(ey2 < m_min_y) m_min_y = ey2;
351 if(ey2 > m_max_y) m_max_y = ey2;
352
353 set_curr_cell(ex1, ey1);
354
355 //everything is on a single hline
356 if(ey1 == ey2)
357 {
358 render_hline(ey1, x1, fy1, x2, fy2);
359 return;
360 }
361
362 //Vertical line - we have to calculate start and end cells,
363 //and then - the common values of the area and coverage for
364 //all cells of the line. We know exactly there's only one
365 //cell, so, we don't have to call render_hline().
366 incr = 1;
367 if(dx == 0)
368 {
369 int ex = x1 >> poly_subpixel_shift;
370 int two_fx = (x1 - (ex << poly_subpixel_shift)) << 1;
371 int area;
372
373 first = poly_subpixel_scale;
374 if(dy < 0)
375 {
376 first = 0;
377 incr = -1;
378 }
379
380 x_from = x1;
381
382 //render_hline(ey1, x_from, fy1, x_from, first);
383 delta = first - fy1;
384 m_curr_cell.cover += delta;
385 m_curr_cell.area += two_fx * delta;
386
387 ey1 += incr;
388 set_curr_cell(ex, ey1);
389
390 delta = first + first - poly_subpixel_scale;
391 area = two_fx * delta;
392 while(ey1 != ey2)
393 {
394 //render_hline(ey1, x_from, poly_subpixel_scale - first, x_from, first);
395 m_curr_cell.cover = delta;
396 m_curr_cell.area = area;
397 ey1 += incr;
398 set_curr_cell(ex, ey1);
399 }
400 //render_hline(ey1, x_from, poly_subpixel_scale - first, x_from, fy2);
401 delta = fy2 - poly_subpixel_scale + first;
402 m_curr_cell.cover += delta;
403 m_curr_cell.area += two_fx * delta;
404 return;
405 }
406
407 //ok, we have to render several hlines
408 p = (poly_subpixel_scale - fy1) * dx;
409 first = poly_subpixel_scale;
410
411 if(dy < 0)
412 {
413 p = fy1 * dx;
414 first = 0;
415 incr = -1;
416 dy = -dy;
417 }
418
419 delta = (int)(p / dy);
420 mod = (int)(p % dy);
421
422 if(mod < 0)
423 {
424 delta--;
425 mod += static_cast<int>(dy);
426 }
427
428 x_from = x1 + delta;
429 render_hline(ey1, x1, fy1, x_from, first);
430
431 ey1 += incr;
432 set_curr_cell(x_from >> poly_subpixel_shift, ey1);
433
434 if(ey1 != ey2)
435 {
436 p = poly_subpixel_scale * dx;
437 lift = (int)(p / dy);
438 rem = (int)(p % dy);
439
440 if(rem < 0)
441 {
442 lift--;
443 rem += static_cast<int>(dy);
444 }
445 mod -= static_cast<int>(dy);
446
447 while(ey1 != ey2)
448 {
449 delta = lift;
450 mod += rem;
451 if (mod >= 0)
452 {
453 mod -= static_cast<int>(dy);
454 delta++;
455 }
456
457 x_to = x_from + delta;
458 render_hline(ey1, x_from, poly_subpixel_scale - first, x_to, first);
459 x_from = x_to;
460
461 ey1 += incr;
462 set_curr_cell(x_from >> poly_subpixel_shift, ey1);
463 }
464 }
465 render_hline(ey1, x_from, poly_subpixel_scale - first, x2, fy2);
466 }
void render_hline(int ey, int x1, int y1, int x2, int y2)
Definition agg_rasterizer_cells_aa.h:212
void line(int x1, int y1, int x2, int y2)
Definition agg_rasterizer_cells_aa.h:318
void set_curr_cell(int x, int y)
Definition agg_rasterizer_cells_aa.h:197
@ poly_subpixel_shift
Definition agg_basics.h:255
@ poly_subpixel_scale
Definition agg_basics.h:256
@ poly_subpixel_mask
Definition agg_basics.h:257
IGL_INLINE void mod(const Eigen::PlainObjectBase< DerivedA > &A, const int base, Eigen::PlainObjectBase< DerivedB > &B)
Definition mod.cpp:11
Unit area(const Cntr &poly, const PathTag &)
Definition geometry_traits.hpp:971
ConstItemRange< typename Container::const_iterator > rem(typename Container::const_iterator it, const Container &cont)
Definition nester.hpp:534
wchar_t const wchar_t unsigned long
Definition windows.hpp:29

References long, agg::poly_subpixel_mask, agg::poly_subpixel_scale, and agg::poly_subpixel_shift.

◆ max_x()

template<class Cell >
int agg::rasterizer_cells_aa< Cell >::max_x ( ) const
inline

◆ max_y()

template<class Cell >
int agg::rasterizer_cells_aa< Cell >::max_y ( ) const
inline

◆ min_x()

template<class Cell >
int agg::rasterizer_cells_aa< Cell >::min_x ( ) const
inline

◆ min_y()

template<class Cell >
int agg::rasterizer_cells_aa< Cell >::min_y ( ) const
inline

◆ operator=()

template<class Cell >
const self_type & agg::rasterizer_cells_aa< Cell >::operator= ( const self_type )
private

◆ render_hline()

template<class Cell >
AGG_INLINE void agg::rasterizer_cells_aa< Cell >::render_hline ( int  ey,
int  x1,
int  y1,
int  x2,
int  y2 
)
private
215 {
216 int ex1 = x1 >> poly_subpixel_shift;
217 int ex2 = x2 >> poly_subpixel_shift;
218 int fx1 = x1 & poly_subpixel_mask;
219 int fx2 = x2 & poly_subpixel_mask;
220
221 int delta, p, first;
222 long long dx;
223 int incr, lift, mod, rem;
224
225 //trivial case. Happens often
226 if(y1 == y2)
227 {
228 set_curr_cell(ex2, ey);
229 return;
230 }
231
232 //everything is located in a single cell. That is easy!
233 if(ex1 == ex2)
234 {
235 delta = y2 - y1;
236 m_curr_cell.cover += delta;
237 m_curr_cell.area += (fx1 + fx2) * delta;
238 return;
239 }
240
241 //ok, we'll have to render a run of adjacent cells on the same
242 //hline...
243 p = (poly_subpixel_scale - fx1) * (y2 - y1);
244 first = poly_subpixel_scale;
245 incr = 1;
246
247 dx = (long long)x2 - (long long)x1;
248
249 if(dx < 0)
250 {
251 p = fx1 * (y2 - y1);
252 first = 0;
253 incr = -1;
254 dx = -dx;
255 }
256
257 delta = (int)(p / dx);
258 mod = (int)(p % dx);
259
260 if(mod < 0)
261 {
262 delta--;
263 mod += static_cast<int>(dx);
264 }
265
266 m_curr_cell.cover += delta;
267 m_curr_cell.area += (fx1 + first) * delta;
268
269 ex1 += incr;
270 set_curr_cell(ex1, ey);
271 y1 += delta;
272
273 if(ex1 != ex2)
274 {
275 p = poly_subpixel_scale * (y2 - y1 + delta);
276 lift = (int)(p / dx);
277 rem = (int)(p % dx);
278
279 if (rem < 0)
280 {
281 lift--;
282 rem += static_cast<int>(dx);
283 }
284
285 mod -= static_cast<int>(dx);
286
287 while (ex1 != ex2)
288 {
289 delta = lift;
290 mod += rem;
291 if(mod >= 0)
292 {
293 mod -= static_cast<int>(dx);
294 delta++;
295 }
296
297 m_curr_cell.cover += delta;
298 m_curr_cell.area += poly_subpixel_scale * delta;
299 y1 += delta;
300 ex1 += incr;
301 set_curr_cell(ex1, ey);
302 }
303 }
304 delta = y2 - y1;
305 m_curr_cell.cover += delta;
306 m_curr_cell.area += (fx2 + poly_subpixel_scale - first) * delta;
307 }

References long, agg::poly_subpixel_mask, agg::poly_subpixel_scale, and agg::poly_subpixel_shift.

◆ reset()

template<class Cell >
void agg::rasterizer_cells_aa< Cell >::reset
167 {
168 m_num_cells = 0;
169 m_curr_block = 0;
170 m_curr_cell.initial();
171 m_style_cell.initial();
172 m_sorted = false;
173 m_min_x = std::numeric_limits<int>::max();
174 m_min_y = std::numeric_limits<int>::max();
175 m_max_x = std::numeric_limits<int>::min();
176 m_max_y = std::numeric_limits<int>::min();
177 }

◆ scanline_cells()

template<class Cell >
const cell_type *const * agg::rasterizer_cells_aa< Cell >::scanline_cells ( unsigned  y) const
inline
91 {
92 return m_sorted_cells.data() + m_sorted_y[y - m_min_y].start;
93 }
const T * data() const
Definition agg_array.h:205
const Scalar & y
Definition MathFunctions.h:552

References agg::pod_vector< T >::data(), agg::rasterizer_cells_aa< Cell >::m_min_y, agg::rasterizer_cells_aa< Cell >::m_sorted_cells, and agg::rasterizer_cells_aa< Cell >::m_sorted_y.

+ Here is the call graph for this function:

◆ scanline_num_cells()

template<class Cell >
unsigned agg::rasterizer_cells_aa< Cell >::scanline_num_cells ( unsigned  y) const
inline

◆ set_curr_cell()

template<class Cell >
AGG_INLINE void agg::rasterizer_cells_aa< Cell >::set_curr_cell ( int  x,
int  y 
)
private
198 {
199 if(m_curr_cell.not_equal(x, y, m_style_cell))
200 {
203 m_curr_cell.x = x;
204 m_curr_cell.y = y;
205 m_curr_cell.cover = 0;
206 m_curr_cell.area = 0;
207 }
208 }
void add_curr_cell()
Definition agg_rasterizer_cells_aa.h:181
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297

◆ sort_cells()

template<class Cell >
void agg::rasterizer_cells_aa< Cell >::sort_cells
627 {
628 if(m_sorted) return; //Perform sort only the first time.
629
631 m_curr_cell.x = std::numeric_limits<int>::max();
632 m_curr_cell.y = std::numeric_limits<int>::max();
633 m_curr_cell.cover = 0;
634 m_curr_cell.area = 0;
635
636 if(m_num_cells == 0) return;
637
638// DBG: Check to see if min/max works well.
639//for(unsigned nc = 0; nc < m_num_cells; nc++)
640//{
641// cell_type* cell = m_cells[nc >> cell_block_shift] + (nc & cell_block_mask);
642// if(cell->x < m_min_x ||
643// cell->y < m_min_y ||
644// cell->x > m_max_x ||
645// cell->y > m_max_y)
646// {
647// cell = cell; // Breakpoint here
648// }
649//}
650 // Allocate the array of cell pointers
652
653 // Allocate and zero the Y array
654 m_sorted_y.allocate(m_max_y - m_min_y + 1, 16);
655 m_sorted_y.zero();
656
657 // Create the Y-histogram (count the numbers of cells for each Y)
658 cell_type** block_ptr = m_cells;
659 cell_type* cell_ptr;
660 unsigned nb = m_num_cells;
661 unsigned i;
662 while(nb)
663 {
664 cell_ptr = *block_ptr++;
665 i = (nb > cell_block_size) ? unsigned(cell_block_size) : nb;
666 nb -= i;
667 while(i--)
668 {
669 m_sorted_y[cell_ptr->y - m_min_y].start++;
670 ++cell_ptr;
671 }
672 }
673
674 // Convert the Y-histogram into the array of starting indexes
675 unsigned start = 0;
676 for(i = 0; i < m_sorted_y.size(); i++)
677 {
678 unsigned v = m_sorted_y[i].start;
679 m_sorted_y[i].start = start;
680 start += v;
681 }
682
683 // Fill the cell pointer array sorted by Y
684 block_ptr = m_cells;
685 nb = m_num_cells;
686 while(nb)
687 {
688 cell_ptr = *block_ptr++;
689 i = (nb > cell_block_size) ? unsigned(cell_block_size) : nb;
690 nb -= i;
691 while(i--)
692 {
693 sorted_y& curr_y = m_sorted_y[cell_ptr->y - m_min_y];
694 m_sorted_cells[curr_y.start + curr_y.num] = cell_ptr;
695 ++curr_y.num;
696 ++cell_ptr;
697 }
698 }
699
700 // Finally arrange the X-arrays
701 for(i = 0; i < m_sorted_y.size(); i++)
702 {
703 const sorted_y& curr_y = m_sorted_y[i];
704 if(curr_y.num)
705 {
706 qsort_cells(m_sorted_cells.data() + curr_y.start, curr_y.num);
707 }
708 }
709 m_sorted = true;
710 }
void allocate(unsigned size, unsigned extra_tail=0)
Definition agg_array.h:233
void qsort_cells(Cell **start, unsigned num)
Definition agg_rasterizer_cells_aa.h:516

References agg::rasterizer_cells_aa< Cell >::sorted_y::num, agg::qsort_cells(), and agg::rasterizer_cells_aa< Cell >::sorted_y::start.

+ Here is the call graph for this function:

◆ sorted()

template<class Cell >
bool agg::rasterizer_cells_aa< Cell >::sorted ( ) const
inline

◆ style()

template<class Cell >
AGG_INLINE void agg::rasterizer_cells_aa< Cell >::style ( const cell_type style_cell)
312 {
313 m_style_cell.style(style_cell);
314 }

◆ total_cells()

template<class Cell >
unsigned agg::rasterizer_cells_aa< Cell >::total_cells ( ) const
inline

Member Data Documentation

◆ m_cells

template<class Cell >
cell_type** agg::rasterizer_cells_aa< Cell >::m_cells
private

◆ m_curr_block

template<class Cell >
unsigned agg::rasterizer_cells_aa< Cell >::m_curr_block
private

◆ m_curr_cell

template<class Cell >
cell_type agg::rasterizer_cells_aa< Cell >::m_curr_cell
private

◆ m_curr_cell_ptr

template<class Cell >
cell_type* agg::rasterizer_cells_aa< Cell >::m_curr_cell_ptr
private

◆ m_max_blocks

template<class Cell >
unsigned agg::rasterizer_cells_aa< Cell >::m_max_blocks
private

◆ m_max_x

template<class Cell >
int agg::rasterizer_cells_aa< Cell >::m_max_x
private

◆ m_max_y

template<class Cell >
int agg::rasterizer_cells_aa< Cell >::m_max_y
private

◆ m_min_x

template<class Cell >
int agg::rasterizer_cells_aa< Cell >::m_min_x
private

◆ m_min_y

◆ m_num_blocks

template<class Cell >
unsigned agg::rasterizer_cells_aa< Cell >::m_num_blocks
private

◆ m_num_cells

template<class Cell >
unsigned agg::rasterizer_cells_aa< Cell >::m_num_cells
private

◆ m_sorted

template<class Cell >
bool agg::rasterizer_cells_aa< Cell >::m_sorted
private

◆ m_sorted_cells

template<class Cell >
pod_vector<cell_type*> agg::rasterizer_cells_aa< Cell >::m_sorted_cells
private

◆ m_sorted_y

◆ m_style_cell

template<class Cell >
cell_type agg::rasterizer_cells_aa< Cell >::m_style_cell
private

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