AGG lesson 16 agg::path_storage path memory
7.1 description and analysis of built-in function parameters
Path storage is used to manage paths and draw complex graphics. You can add lines, curves, and other paths at will.
Header file
# include
Type definition
Typedef path_base path_storage
Basic member function
Move_to ()
Add the vertex with the command path_cmd_move_to, meaning the next line is drawn from this point
Line_to ()
Add the vertex whose command is path_cmd_line_to, meaning to draw a line to this point
Arc_to (double rx, double ry, double angle,bool large_arc_flag, bool sweep_flag, double x, double y)
Add an arc path, the axis length is rx, ry, the angle is angle, superior / inferior arc, clockwise, the end point is (xmemy).
Curve3_to ()
Add a Bezier curve with a parameter of a control point and the coordinates of the end point
Curve4_to ()
Add a Bezier curve with the parameters of two control points and the coordinates of the end point
Join_path ()
Add a vertex source, which is a combination
Vertex (unsigned idx, double* x, double* y)
Last_vertex (double* x, double* y)
Vertex (double* x, double* y)
Take the vertex position, the former is a known step, and the latter two are obtained sequentially or in reverse order
Modify_vertex ()
Modify_command ()
Modify vertex coordinates and commands for step idx
7.2 property modification of vertex source 1) flip according to Abscissa or ordinate
Description: there are many possible places for flip_y, which flips the Y axis.
/ / Flip all vertices horizontally or vertically
/ / between x1 and x2, or between y1 and y2 respectively
/ /-
Void flip_x (double x1, double x2)
Void flip_y (double Y1, double Y2)
2) comparison of simple examples
Ras.reset ()
Agg::path_storage path
Path.move_to (40350)
Path.line_to (80350)
Path.line_to (80670)
Path.line_to (40670)
Path.end_poly ()
Path.flip_y (350450)
Ras.add_path (path)
Agg::path_storage comparepath
Comparepath.move_to (140350)
Comparepath.line_to (180350)
Comparepath.line_to (180670)
Comparepath.line_to (140670)
Comparepath.end_poly ()
Ras.add_path (comparepath)
Agg::render_scanlines_aa_solid (ras,sl,renb,agg::rgba8 (255j0pl 0))
7.3 Line segment drawing rule figure 1) Hollow figure
Disclaimer: draw line segments in MFC, simply using MoveTo and LineTo, but path_storage using AGG must go through agg::conv_stroke (Show outline) to display line segments. Try annotating agg::conv_stroke to understand the basic operation flow.
Ras.reset ()
Agg::path_storage ps
Ps.move_to (200200)
Ps.line_to (400200)
Ps.line_to (400400)
Agg::conv_stroke
Stroke (ps)
Ras.add_path (stroke)
Agg::render_scanlines_aa_solid (ras,sl,renb,agg::rgba8 (255j0pl 0))
Ras.reset ()
2) solid graphics (with fill color)
Description: need to draw fill color graphics, must be closed, path_storage provides several closed functions, you can try to replace.
Ras.reset ()
Agg::path_storage ps
Ps.move_to (200200)
Ps.line_to (400200)
Ps.line_to (400400)
Ps.end_poly ()
Ras.add_path (ps)
Agg::render_scanlines_aa_solid (ras,sl,renb,agg::rgba8 (255j0pl 0))
Ras.reset ()
7.4 points for consideration
Path_storage allocates at least one block of memory to store 256vertex sources, so creating a large number of path_storage is quite
Expensive memory overhead and easy to cause memory fragmentation. It is recommended that a class hold a static member, through the function
Remove_all empties all vertex sources and start_new_path contains a new path, storing multiple paths in the
In an object. If you want to create a path_storage that contains many vertex sources, it is best to use vertex_block_storage.
If you want to create many path_storage but contain very small vertex sources, it is best to use vertex_stl_storage
Adapter.
Code description
M_coord_blocks saves coordinates
Instructions for m_cmd_blocks to save coordinates
Template
Inline unsigned vertex_block_storage::vertex (unsigned idx
Double* x, double* y) const
{
Unsigned nb = idx > > block_shift
/ / A block block stores 256 endpoint sources. Through idx > > 8, which packet is obtained?
Const T* pv = masked code _ blocks [nb] + ((idx & block_mask)