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,如需转载请自行联系原作者


相关文章
|
8月前
ROW_NUMBER() OVER()函数用法详解 (分组排序 例子多)
ROW_NUMBER() OVER()函数用法详解 (分组排序 例子多)
124 0
|
8月前
|
索引
根据索引值计算item所在行列(row,col)索引序号(index)
根据索引值计算item所在行列(row,col)索引序号(index)
Leetcode 623. Add One Row to Tree
题目很简单,在树的第d层加一层,值为v。递归增加一层就好了。代码如下
53 0
|
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 关系型数据库 MySQL
随笔:MySQL:eq_range_index_dive_limit 索引下探接口
我的测试记录 一、概述 这个参数会影响到执行计划在评估的时候到底使用统计数据还是进行实际的所以你访问,那么很显然如下: 使用统计数据生成执行计划的效率更高。 使用索引实际访问,及索引下探会代价更高但是更加准确。
5069 0
|
索引
LeetCode 599: 两个列表的最小索引总和 Minimum Index Sum of Two Lists
题目: 假设 Andy 和 Doris 想在晚餐时选择一家餐厅,并且他们都有一个表示最喜爱餐厅的列表,每个餐厅的名字用字符串表示。 Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. 你需要帮助他们用最少的索引和找出他们共同喜爱的餐厅。
893 0
|
SQL Go
【SQL】ROW_NUMBER() OVER(partition by 分组列 order by 排序列)用法详解+经典实例
【SQL】ROW_NUMBER() OVER(partition by 分组列 order by 排序列)用法详解+经典实例目录 0、填充数据1、使用row_number()函数对订单进行编号,按照订单时间倒序。
13250 0

热门文章

最新文章

下一篇
开通oss服务