AGG第三十七课 rassterizer的add_path添加顶点源受制于 cell_block_limit

简介:

场景说明:当添加顶点源到rasterizeradd_path接口的时候,实际上需要考虑顶点源可能占用的cell的总数,目前cell_block_limit in agg_rasterizer_cells_aa.h的限制是1024,这种情况下,有必要在添加一定数量的顶点源之后,即使调用render_scanline函数进行渲染到画布上!!该问题已经在项目中重现,不能够说是bug,而是一种设计的策略,避免申请内存不足,同时也避免产生内存碎片。

如下是网址:http://comments.gmane.org/gmane.comp.graphics.agg/5861

for()

{

add_path();

render_scanline();

}

 

for()

{

add_path()

}

render_scanline();

说明:

   I ran into a limit in Antigrain a while back, I think it wasthecell_block_limit in agg_rasterizer_cells_aa.h;if not, it was something verysimilar.

问题说明:

I'm trying to draw a tree with agg.

 

It worked well with a tree with a smallnumber of vertices, but it starts to malfunction if the number of vertices isgreater than 7000.

 

I thought it was a memory problem but gotnothing with valgrind or duma.

 

Is it a bug of agg? or simply i'm doingwrong?

 

My code looks like this:

 

 using pixfmt_type = agg::pixfmt_rgba32;

 using renbase_type = agg::renderer_base<pixfmt_type>;

 using renderer_type =agg::renderer_scanline_aa_solid<renbase_type>;

 using scanline_type = agg::scanline_u8;

 using rasterizer_type = agg::rasterizer_scanline_aa<>;

 

 template <class Ras, class Scanline, class Ren, class Tree>

 void draw_edge(Ras& __ras, Scanline& __sl, Ren& __ren, constTree& __tree)

  {

   __ras.reset();

   for_each_edge_from_tree {

     agg::path_storage path;

     agg::conv_stroke<agg::path_storage> stroke(path);

     stroke.width(1);

 

     path.move_to(from.x(), from.y());

     path.line_to(to.x(),   to.y());

     __ras.add_path(stroke);

    }

   __ren.color(gray);

   agg::render_scanlines(__ras, __sl, __ren);

  }

 

 template <class Ras, class Scanline, class Ren, class Tree>

 void draw_vertex(Ras& __ras, Scanline& __sl, Ren& __ren,const Tree& __tree)

  {

   __ras.reset();

   for_each_vertex_from_tree {

     agg::ellipse ell(state.x(), state.y(), 1.5, 1.5);

     __ras.add_path(ell);

    }

   __ren.color(black);

   agg::render_scanlines(__ras, __sl, __ren);

  }

解决问题的方案:

It seems like a bug of agg, since I'm using64 bit linux system.

 

I changed the drawer to callrender_scalines() for each 1000

add_path()s, and now it works well with alarge number of edges.

 

template <class Ras, class Scanline,class Ren, class Tree>

 void draw_edge(Ras& __ras, Scanline& __sl, Ren& __ren, constTree& __tree)

  {

   __ren.color(gray);

   __ras.reset();

 

   std::size_t count = 0;

   for_each_edge_from_tree {

      agg::path_storage path;

     agg::conv_stroke<agg::path_storage> stroke(path);

     stroke.width(1);

 

     path.move_to(from.x(), from.y());

     path.line_to(to.x(),   to.y());

     __ras.add_path(stroke);

 

     if(++count > 1000) {

       agg::render_scanlines(__ras, __sl, __ren);

       __ras.reset();

       count = 0;

     }

    }

   agg::render_scanlines(__ras, __sl, __ren);

  }

 

一些解释:

a) I would try to run under 64-bit OS firstto make sure there is enough memory

 

b) I would put a breakpoint into therasterizer cells allocator. Maybe it returns NULL and agg just silently passes(didn't check, can't tell, just where I would start)

 

The problem:

 

Agg doesn't merge cells while rendering,basically each cell (you can see a cell as an anti-aliased pixel) generated bythe rasterizer is added to a cell array. This means that the rasterizer itselfneeds more and more memory if you start adding vertices without sweeping (sweepis the last rasterization step which fills up spans into a scanline container).

摘自:http://comments.gmane.org/gmane.comp.graphics.agg/5861



     本文转自fengyuzaitu 51CTO博客,原文链接:http://blog.51cto.com/fengyuzaitu/1965790,如需转载请自行联系原作者


相关文章
|
4月前
|
索引
根据索引值计算item所在行列(row,col)索引序号(index)
根据索引值计算item所在行列(row,col)索引序号(index)
LeetCode Contest 178-1368. 使网格图至少有一条有效路径的最小代价 Minimum Cost to Make at Least One Valid Path in a Grid
LeetCode Contest 178-1368. 使网格图至少有一条有效路径的最小代价 Minimum Cost to Make at Least One Valid Path in a Grid
halcon模板匹配实践(2)算子find_shape_model里的参数Row, Column, Angle含义是什么?
halcon模板匹配实践(2)算子find_shape_model里的参数Row, Column, Angle含义是什么?
612 0
halcon模板匹配实践(2)算子find_shape_model里的参数Row, Column, Angle含义是什么?
|
SQL Oracle 关系型数据库
跟着吕大师(VAGE)揭密隐含参数:_db_writer_coalesce_area_size
[size=13.913043975830078px]最近在看吕大师的大作《Oracle核心揭密》,这部大作可以与Jonathan Lewis大师的《Oracle Core_ Essential Internals for DBA》相提并论,看了几天收益颇多,哈哈美国有Lewis,中国有VAGE。
跟着吕大师(VAGE)揭密隐含参数:_db_writer_coalesce_area_size
|
SQL Go
【SQL】ROW_NUMBER() OVER(partition by 分组列 order by 排序列)用法详解+经典实例
【SQL】ROW_NUMBER() OVER(partition by 分组列 order by 排序列)用法详解+经典实例目录 0、填充数据1、使用row_number()函数对订单进行编号,按照订单时间倒序。
12392 0
|
网络协议 Unix 网络安全