我们没有办法找到agg::pixfmt_bgra32,
typedef agg::pixfmt_bgra32 pixfmt;
我们可以搜索到agg::pixfmt_bgra32,但是针对用法,或许了解32更为有效
1 引言
agg::vpgen_segmentator不是一个顶点源(vertex source),因为没有实现rewind函数,编译期间出现的错误:
rewind:is not a member of agg::vpgen_segmentator
猜测作者的意图是否是毫无意义的!!没有任何地方的引用!!
2 代码分析
预备知识:1e-30就是10的-30次方
简单的代码如下:
void vpgen_segmentator::move_to(double x, double y)
{
m_x1 = x;
m_y1 = y;
m_dx = 0.0;
m_dy = 0.0;
m_dl = 2.0;
m_ddl = 2.0;
m_cmd = path_cmd_move_to;
}
void vpgen_segmentator::line_to(double x, double y)
{
m_x1 += m_dx;
m_y1 += m_dy;
m_dx = x - m_x1;
m_dy = y - m_y1;
//决定了取多少个点,并不是求两点之间的距离
double len = sqrt(m_dx * m_dx + m_dy * m_dy) * m_approximation_scale;
if(len < 1e-30) len = 1e-30;
m_ddl = 1.0 / len;
m_dl = (m_cmd == path_cmd_move_to) ? 0.0 : m_ddl;
if(m_cmd == path_cmd_stop) m_cmd = path_cmd_line_to;
}
unsigned vpgen_segmentator::vertex(double* x, double* y)
{
if(m_cmd == path_cmd_stop) return path_cmd_stop;
unsigned cmd = m_cmd;
m_cmd = path_cmd_line_to;
if(m_dl >= 1.0 - m_ddl)
{
m_dl = 1.0;
m_cmd = path_cmd_stop;
*x = m_x1 + m_dx;
*y = m_y1 + m_dy;
return cmd;
}
//求取每一个点
*x = m_x1 + m_dx * m_dl;
*y = m_y1 + m_dy * m_dl;
m_dl += m_ddl;
return cmd;
}
实际测试:
由于agg::vpgen_segmentator并不是顶点源,所以只能够将顶点的坐标传递给agg::path_storage进行描线。实际上通过agg::vpgen_segmentator::approximation_scale函数进行了设置(获取到更多的点,实际上,可以观察count_poi的个数可以了解,设置到最大的情况下,AGG失效也可以模拟)。
测试例子:
agg::vpgen_segmentator seg;
seg.move_to(150,140);
seg.approximation_scale(10);
seg.line_to(300,400);
agg::path_storage ps1;
ps1.move_to(150,140);
double x = 0;
double y = 0;
int count_poi = 0 ;
while(agg::path_cmd_stop != seg.vertex(&x, &y))
{
ps1.line_to(x, y);
count_poi++;
}
agg::conv_stroke<agg::path_storage> stroke(ps1);
/*
实际上,通过扩充轮廓线,还是没有能够观察到任何有效的
结果!!
*/
stroke.width(50);
ras.add_path(stroke);
agg::render_scanlines_aa_solid(ras,sl,renb,agg::rgba8(255,0,0));
ras.reset();
return;