agg::ellipse 方法approximation_scale()

摘自:http://franko.github.io/agg-intro/vertex-source.html

In the previous section we have seen agg::path_storage object. While this object is very flexible and can be used to describe all kind of geometric shapes there are a few other vertex source primitive types. Actually there are not so many of them and we will just discuss the agg::ellipse object because it will be also useful to illustrate some important idea.

The agg::ellipse does not share anything with a agg::path_storage in term of C++ class hierarchy, all the they have in common is that they implement the basic methods of a vertex source. You may wonder why the ellipse object can be useful if you can describe it with a agg::path_storage. The answer is that this latter needs to store a fixed number of vertices that approximate the ellipse for all the possible resolution of the image. The problem is that if you draw a small circle a few vertices can be enough but if the circle is big you are going to need a lot of vertices to have a decent approximation. We will see that with an agg::ellipse object the number of points will be adapted on the fly, you just need to use the approximation_scale()method. Actually the agg::ellipse does not store all the coordinates of the vertices but generetes them on the fly when needed using the mathematical equations. As a side effect you will have also a benefit in term of memory usage because an ellipse object will use a very small amount of memory indipendently of the approximation level that you may request.

At this point we need to explain the approximation_scale() method. approximation_scale() we need to go back to the coordinates specifications. The coordinates are actually given as double precision floating point number and they may or may not map directly to pixel coordinates. For example we can map some logical coordinates ranging from 0 to 1 to an huge viewport of size 1280x1280. The problem at this point is that an agg::ellipse object does not know the mapping between logical coordinates and viewport coordinates. So the idea is that to let agg::ellipse adjust correctly the level of approximation you should call the method approximation_scale() and pass as an argument the ratio between the viewport coordinates and the logical coordinates. So in the example of the viewport of size 1280x1280 we would need to use approximation_scale() with an scale argument of 1280.

We will see later that the approximation_scale() is also important with some kind of transformation like Bezier curves that are supposed to generate smooth curves based on a few vertices and some mathematical equations.

时间: 2024-11-10 07:04:36

agg::ellipse 方法approximation_scale()的相关文章

AGG第二十课 agg::ellipse 方法approximation_scale()

献给:任何一种方案都是一种折中的选择,任何一种替代方案都可能会实现同样的效果.而这完全取决于你是如何思考定位的.请教是学,自学是学,只不过可以站在巨人的肩膀上,你可以看的更加清楚或许走的更远. 摘自:http://franko.github.io/agg-intro/vertex-source.html In the previous section we have seen agg::path_storage object. While this object is very flexible

agg::ellipse画圆(扩展)

引言:在刚开始的时候对agg::conv_stroke不了解,认为她与agg::conv_dash是一路的货色,并且分别代表实线和虚线,其实不然,agg::conv_stroke此类存储线的位置,宽度,线端点形状,线连接方式等信息  ,通过使用虚线渲染圆,充分理解了,她们之间如何配合使用. 小节一:虚线的使用方法 例子如下:     //Vertex Source顶点源,我更喜欢称之为端点集合,或者点集合矩阵     //第一个参数是圆形圆心的X坐标,第二个参数是圆形圆心的Y坐标     //第

agg::ellipse画圆

前言: path_storage是一个非常重要的顶点容器,并且也提供了很多的形状,在这里,我们看看path_storage是否可以描绘圆形,没有找到任何相关的函数支持直接画圆形,由于项目中并没有使用到任何贝塞尔曲线,所以也并不展开讨论相关的话题.因此引入了其他的顶点源,agg::ellipse去描绘一个圆形.该实例代码并没有引入坐标转换管道,该专业术语将会在一章描述.     //Vertex Source顶点源,我更喜欢称之为端点集合,或者点集合矩阵     //第一个参数是圆形圆心的X坐标,

如何使用canvas绘制椭圆,扩展非chrome浏览器中的ellipse方法

这篇博文主要针对浏览器中绘制椭圆的方法扩展.在网上搜索了很多,发现他们绘制椭圆的方式都有缺陷.其中有压缩法,计算法,贝塞尔曲线法等多种方式.但是都不能很好的绘制出椭圆.所有我就对这个绘制椭圆的方式进行了研究,发现压缩法是可以完美实现椭圆绘制的.废话不多说,直接上代码了. 1 if (!CanvasRenderingContext2D.prototype.ellipse) { 2 CanvasRenderingContext2D.prototype.ellipse = function(x, y,

renderer_scanline_bin_solid PK agg::renderer_scanline_aa_solid

Scanline Renderer 头文件 #include<agg_renderer_scanline.h> 类型 template<classBaseRenderer> class renderer_scanline_aa_solid;//实色AA渲染 template<classBaseRenderer> class renderer_scanline_bin_solid;//实色原始渲染 AA是什么??实色是什么??原始是什么?? template<cla

agg::render_scanlines的不同

附上代码: agg::rendering_buffer &rbuf = rbuf_window();//获取渲染缓存 agg::pixfmt_bgr24 pixf(rbuf);//组成像素 typedef agg::renderer_base<agg::pixfmt_bgr24> renderer_base_type;    renderer_base_type renb(pixf);//提供裁剪区域,只有在裁剪区域内才渲染有效 typedef agg::renderer_scanli

(转)用AGG实现高质量图形输出(二)

本文上接<用AGG实现高质量图形输出(一)>,分别介绍了AGG显示流程中的各个环节. 上次讲了AGG的显示原理并举了一个简单的例子,这一篇文章开始讲AGG工作流程里的每个环节.为了方便对照,再放一次AGG显示流程 图 另外,上一篇文章里的例程也很重要,后面的例子都将基于这个代码. 下面,我们来考察AGG显示流程中的每个环节.理解每个环节最好的方法是编写实验代码,建议先参照这里建 立一个可以运行的AGG实验环境. 顶点源(Vertex Source) 顶点源是一种可以产生多边形所需要的“带命令的

agg::conv_stroke的shorten妙用

1 前言 I added the possibility to shorten paths in converters conv_stroke and conv_dash. It's good for drawing arroheads with rather thick strokes. Also thre's a converter agg_conv_shoren_path.h that can be used independently.  I also added agg_conv_co

agg::trans_affine坐标转换

实例代码如下: ras.reset(); agg::ellipse ell(400,400,20,70); //坐标转换 agg::trans_affine mtx; //mtx.scale(0.5,1); //x轴缩小到原来的一半 mtx.rotate(agg::deg2rad(30));//旋转30度 //mtx.translate(200,200);//X,Y坐标分别平移100 typedef agg::conv_transform<agg::ellipse> ell_ct_type;