AGG是一个轻量、灵活、可靠的图形算法库,AGG各部分之间是松耦合的,也即是说各部分可以单独使用。
The primary goal of Anti-Grain Geometry is to break this ancient as mammoth's manure tradition and show you the beauty of stability, lightness, flexibility, and freedom. The basic concepts can seem not very conventional at the beginning, but they are very close to the ones used in STL. But there's a big difference too. STL is a general C++ tool while AGG is C++ graphics. You usually use STL in your applications directly as a convenient toolkit. I wouldn't say it's a good idea to use AGG in the very same way. A good idea is to create a lightweight, problem oriented wrapper over AGG to solve your particular tasks. How can that be different from that very GDI+ then? The first thing is that you have total control upon that wrapper. Anti-Grain Geometry just provides you a set of basic algorithms and flexible design with the minimum of implicit or explitit dependencies. You and only you define the interface, conversion pipelines, and the form of output. You can even simulate a part of any existing graphical interface. For example, you can use AGG rasterizer to display graphics on the screen and direct Windows GDI calls for printing, incorporating it into a single API. Not convincing? Look at the quality of rendering in GDI+ and AGG
AGG是跨平台的
But most of all, your applications become absolutely portable, if your design is smart enough. AGG can be also a tool to combine different outputs in a uniform API. Particularly, you can use AGG to generate raster images on the server side in your Web-Based applications. And it all can be cross-platform!
AGG算法采用反走样算法和亚像素精度必须联合使用,中图为只采用了反锯齿的效果,右图为两者结合的效果。不仅提高了线条的光滑度,而且对于一些下小对象细节的表现有较大的优势。
Anti-Aliasing is a very well known technique used to improve the visual quality of images when displaying them on low resolution devices,But the point is not only in Anti-Aliasing itself. The point is we can draw primitives with Subpixel Accuracy. It's especially important for the visual thickness of the lines. First, let us see that even with simple Bresenham line interpolator we can achieve a better result if we use Subpixel Accuracy. The following picture shows enlarged results of the simple Bresenham interpolator.
AGG的操作均是基于输出设备的屏幕坐标,AGG 由于支持亚像素精度,AGG的坐标使用double表示。AGG不嵌入设备坐标到世界坐标的转换。AGG提供Transformer(用户定义),用于用户视图到设备视图的转换。
Basically, AGG operates with coordinates of the output device. On your screen there are pixels. But unlike many other libraries and APIs AGG initially supports Subpixel Accuracy. It means that the coordinates are represented as doubles, where fractional values actually take effect. AGG doesn't have an embedded conversion mechanism from world to screen coordinates in order not to restrict your freedom. It's very important where and when you do that conversion, so, different applications can require different approaches. AGG just provides you a transformer of that kind, namely, that can convert your own view port to the device one. And it's your responsibility to include it into the proper place of the pipeline. You can also write your own very simple class that will allow you to operate with millimeters, inches, or any other physical units.
AGG 设计为一组松散组织的算法模版,组件方便组合。甚至AGG可以只完成某一部分的工作,其他工作交由其他显示库实现。
Anti-Grain Geometry is designed as a set of loosely coupled algorithms and class templates united with a common idea, so that all the components can be easily combined. Also, the template based design allows you to replace any part of the library without the necessity to modify a single byte in the existing code.
AGG does not dictate you any style of its use, you are free to use any part of it. However, AGG is often associated with a tool for rendering images in memory. That is not quite true, but it can be a good starting point in studying. The tutorials describe the use of AGG starting from the low level functionality that deals with frame buffers and pixels. Then you will gradually understand how to abstract different parts of the library and how to use them separately. Remember, the raster picture is often not the only thing you want to obtain, you will probably want to print your graphics with highest possible quality and in this case you can easily combine the “vectorial” part of the library with some API like Windows GDI, having a common external interface. If that API can render multi-polygons with non-zero and even-odd filling rules it's all you need to incorporate AGG into your application. For example, Windows API PolyPolygon perfectly fits these needs, except certain advanced things like gradient filling, Gouraud shading, image transformations, and so on. Or, as an alternative, you can use all AGG algorithms producing high resolution pixel images and then to send the result to the printer as a pixel map
AGG渲染过程。AGG可以将渲染步骤中的单步抽出来和其他引擎混用,例如使用AGG光栅化,再由其他引擎进行渲染。
- 坐标源Vertex Source is some object that produces polygons or polylines as a set of consecutive 2D vertices with commands like “MoveTo”, “LineTo”. It can be a container or some other object that generates vertices on demand.
- 坐标变换Coordinate conversion pipeline consists of a number of coordinate converters. It always works with vectorial data (X,Y) represented as floating point numbers (double). For example, it can contain an affine transformer, outline (stroke) generator, some marker generator (like arrowheads/arrowtails), dashed lines generator, and so on. The pipeline can have branches and you also can have any number of different pipelines. You also can write your own converter and include it into the pipeline.
- 栅格化Scanline Rasterizer converts vectorial data into a number of horizontal scanlines. The scanlines usually (but not obligatory) carry information about Anti-Aliasing as “coverage” values.
- 渲染Renderers render scanlines, sorry for the tautology. The simplest example is solid filling. The renderer just adds a color to the scanline and writes the result into the rendering buffer. More complex renderers can produce multi-color result, like gradients, Gouraud shading, image transformations, patterns, and so on.
- 缓存Rendering Buffer is a buffer in memory that will be displayed afterwards. Usually but not obligatory it contains pixels in format that fits your video system. For example, 24 bits B-G-R, 32 bits B-G-R-A, or 15 bits R-G-B-555 for Windows. But in general, there're no restrictions on pixel formats or color space if you write your own low level class that supports that format.