Get the App
SLTechnology News&Howtos  ›  Servers  › 

AGG lesson 28 filling rules for rasterizer

Shulou Source: shulou.com Published: 2022-06-02 16:27:58 09月29日 Update

AGG provides a lot of additional interfaces for SVG calls, so many beginners like me need to learn SVG first, and then understand the meaning of the interface before they can really grasp the meaning of the interface, such as miter_join.

1 knowledge reserve

Literally, it is the rule of filling, isn't it the filling of graphics? There are no rules. There is no problem with a single shape, what if the area between the two rings is filled with color when rendering the ring? At this point, you need to specify a rule, a filling rule.

AGG provides two algorithms to determine whether the point is in the filled area, and if the point is in the filled area, then populate the point. For a simple path without crossover, it is very easy to judge. However, for a complex path, such as self-intersection or one path wrapping another subpath, the interior is not so easy to understand.

Nonzero

It literally means "non-zero". According to this rule, it is necessary to judge whether a point is in the graph, make a ray in any direction from that point, and then detect the intersection of the ray and the path of the graph. Counting starts at 0, and the path through the ray from left to right increases by 1, and from right to left through the ray minus 1. After the counting result is obtained, if the result is 0, the point is considered to be outside the graph, otherwise it is considered to be internal.

Evenodd

It literally means "parity". According to this rule, to determine whether a point is in the graph, make a ray in any direction from that point, and then detect the number of intersecting points between the ray and the path of the graph. If the result is odd, the point is considered to be internal, and if it is even, the point is considered to be external.

Extracted from: http://blog.csdn.net/cuixiping/article/details/7848369

2 simple example code

Void TestRasFillRule ()

{

Agg::rendering_buffer & rbuf = rbuf_window ()

Agg::pixfmt_bgr24 pixf (rbuf)

Typedef agg::renderer_base renderer_base_type

Renderer_base_type renb (pixf)

Typedef agg::renderer_scanline_bin_solidrenderder_scanline_type

Renderder_scanline_type rensl (renb)

Agg::rasterizer_scanline_aa ras

Agg::scanline_p8 sl

Ras.reset ()

Renb.clear (agg::rgba8 (255255255))

Rensl.color (agg::rgba8 (255j0pl 0))

/ / agg::filling_rule_e rule = agg::fill_non_zero

Agg::filling_rule_e rule = agg::fill_even_odd

Ras.filling_rule (rule)

Ras.move_to_d (100100)

Ras.line_to_d (200100)

Ras.line_to_d (200400)

Ras.line_to_d (100400)

Ras.close_polygon ()

Ras.move_to_d (150250)

Ras.line_to_d (180250)

Ras.line_to_d (180350)

Ras.line_to_d (150350)

Ras.close_polygon ()

Agg::render_scanlines (ras, sl, rensl)

Return

}

Tags: Graphics paths rules rays regions literals interfaces results points of intersection that is meaning direction detection complexity two size between code even beginners Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS vpn NVidia OPPO Reno Huawei