Coordinate Conversion Pipeline)

Source: Internet
Author: User
Document directory
  • Transform matrix (trans_affine)
  • Coordinate Conversion Pipeline
Coordinate Conversion pipeline coordinate conversion Pipeline

The coordinate conversion pipeline is used to change the vertex generated by the vertex source, including coordinates, commands, and new vertex generation. Such as matrix transformation of vertices and insertion of vertices to form dotted lines.

Transform matrix (trans_affine)

Before learning about the conversion pipeline, let's take a look at the transformation matrix of pipeline. Through the run of vertex coordinates and matrix, we can get new coordinates. There is an article on the image matrix operation in msdn about the GDI + matrix operation. It is worth reading.

Header file

# Include <agg_trans_affine.h>
Type

Trans_affine
Member variables

Double Sx, shy, shx, Sy, TX, Ty; These six variables form a 2*3 matrix and obtain a new coordinate after coordinate calculation. For example, if the vertex (X, Y) is transformed, the new vertex (X ', y') is:

x' = x*sx  + y*shx + tx;y' = x*shy + y*sy  + ty;
Member Method
Void transform (double * X, double * Y) const; Convert the X and Y coordinates using the above formula
Const trans_affine & Scale (double S );
Const trans_affine & Scale (Double X, Double Y );
Zoom
Const trans_affine & rotate (double ); Rotate, radian unit (PI/180)
Const trans_affine & translate (Double X, Double Y) Translation
Trans_affine operator * (const trans_affine & M ); Matrix Multiplication
Const trans_affine & invert (); Inverse Matrix

There is a conv_transform converter in the coordinate conversion pipeline. It can use the Matrix to transform the Source Vertex. Let's play it here first. ^_^

Lab code (based on this code)

Add the header file # include "agg_conv_transform.h"

Rewrite the code in the on_draw () method from "// vertex source" to "// scanline Rasterizer":

  1. // Vertex Source
  2. Vertex: ellipse ell (, 50, 50); // the center of the center is in the middle.
  3. // Coordinate conversion Pipeline
  4. Authorization: trans_affine CTX;
  5. CTX. Scale (0.5, 1); // the X axis is halved.
  6. CTX. Rotate (deg: 2rad (30); // rotate for 30 degrees
  7. CTX. Translate (100,100); // Pan 100,100
  8. Typedef Syntax: conv_transform <Syntax: ellipse> ell_ct_type;
  9. Ell_ct_type ctell (Ell, CTX); // matrix transformation
  10. Typedef Syntax: conv_contour <ell_ct_type> ell_cc_type;
  11. Ell_cc_type ccell (ctell); // contour Transformation
  12. Typedef Syntax: conv_stroke <ell_cc_type> ell_cc_cs_type;
  13. Ell_cc_cs_type csccell (ccell); // convert to a multidefinition line
The resulting figure is:

Note: trans_affine is not only used for Source Vertex transformation, but can be seen in many places in the vertex library. For example, the line segment (SPAN) generator described later can freely transform the pattern filled in the polygon through the transformation matrix.

Coordinate Conversion pipeline header file
#include <agg_conv_stroke.h> // conv_stroke#include <agg_conv_dash.h> // conv_dash#include <agg_conv_marker.h> // conv_marker#include <agg_conv_curve.h> // conv_curve#include <agg_conv_contour.h> // conv_contour#include <agg_conv_smooth_poly1.h> // conv_smooth_poly1.h#include <agg_conv_bspline.h> // conv_bspline#include <agg_conv_transform.h> // conv_transform
Type (the demo program is based on the Code here)
Template <class vertexsource,
Class markers = null_markers>
Struct conv_stroke;
Change to continuous line
The construction parameter is vertexsource.
The width attribute determines the line width.
In the example of ell_cc_cs_type csccell (ccell );
Followed by csccell. Width (3); the line width will change to 3.
Template <class vertexsource,
Class markers = null_markers>
Struct conv_dash;
Dotted Line
The construction parameter is vertexsource.
Use add_dash to set the dotted line length and interval
Apply with conv_stroke
// Coordinate conversion pipelinetypedef agg::conv_contour<agg::ellipse> ell_cc_type;ell_cc_type ccell(ell);typedef agg::conv_dash<ell_cc_type> ell_cd_type;ell_cd_type cdccell(ccell);cdccell.add_dash(5,5);typedef agg::conv_stroke<ell_cd_type> ell_cc_cs_type;ell_cc_cs_type csccell(cdccell);...
Template <class markerlocator,
Class markershapes>
Class conv_marker;
Create tag See arrowhead sample code
Template <class vertexsource>
Struct conv_contour;
Contour Transformation
The construction parameter is vertexsource.
The width attribute determines whether to expand or contract the profile.
See example code
Template <class vertexsource>
Struct conv_smooth_polyw.curve;
Smooth transition polygon vertices (besell)
The construction parameter is vertexsource.
The smooth_value attribute determines the smoothness (1 by default)
Add the following code to the end of the example on_draw () method:
Triangle T (100,100, 50); // custom vertex Source
Usage: conv_smooth_polyw.curve <triangle> cspct (t); Ras. add_path (cspct); region: render_scanlines_aa_solid (Ras, SL, renb, Region: rgba8 (255, 0, 0 ));


The triangle becomes round head and round brain ^_^

Template <class vertexsource>
Struct conv_bspline;
Smooth transition to the vertices of the Multi-definition line (besell)
The construction parameter is vertexsource.
The interpolation_step attribute determines the step size.
Add the following code to the end of the example on_draw () method:
triangle t(100,100,50);agg::conv_bspline<triangle> cspct(t);ras.add_path(cspct);agg::render_scanlines_aa_solid( ras,sl,renb,agg::rgba8(255,0,0));


The triangle can also become round head and round brain

Template <class vertexsource,
Class curve3 = curve3,
Class curve4 = curve4>
Class conv_curve;
Recognizes the curve information in vertexsource.
The constructor is vertexsource. Conv_smooth_polyw.curve
Is implemented based on it.
The vertex in the routine has no curve information. Forget it,
It will be used later when it comes to text output.
Template <class vertexsource,
Class transformer = trans_affine>
Class conv_transform;
Matrix Transformation
Re-calculate the vertex position using the transform matrix
The construction parameters are vertexsource and transformation matrix.
See the example in the transformation matrix section.

Author: Mao Source: www.cppprog.com

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.