Decomposition of polygonal samples using GPC (Generic Polygon Clipper)

Source: Internet
Author: User

Decomposing polygons with GPC

(Owed by: Spring Night rain Http://blog.csdn.net/chunyexiyu reprint please indicate the source)

Gpc:generic Polygon Clipper

GPC supports decomposition polygon, polygon differential set, intersection, XOR, and set
Gpc_diff,/* difference */
Gpc_int,/* intersection */
Gpc_xor,/* Exclusive or */
Gpc_union/* UNION */

Use is more efficient, but because of the use of C writing, the grammatical structure and our usual C + + slightly different, directly look at the interface implementation will not adapt.
Because it does not provide the use of the sample, so write a simple decomposition polygon sample, interested can refer to

Inline Gpc_vertex Buildvertex (double x, double y) {Gpc_vertex vertex;  vertex.x = x;  vertex.y = y; return vertex;} void Testgpc () {//Set a shape using GPC split into triangular gpc_vertex_list vertextlist; vertextlist.num_vertices = 5; std::vector<gpc_ Vertex> Vecvertex; Vecvertex.push_back (Buildvertex (10.0, 10.0)); Vecvertex.push_back (Buildvertex (-10.0, 10.0)); Vecvertex.push_back (Buildvertex (-10.0,-10.0)); Vecvertex.push_back (Buildvertex (10.0,-10.0)); Vecvertex.push_back (Buildvertex (20, 0)); Vertextlist.vertex = & (Vecvertex[0]); Gpc_polygon MyPolygon; Mypolygon.num_contours= 1; Mypolygon.hole= NULL; Mypolygon.contour= &vertextList; Obtain the decomposed triangular or quadrilateral gpc_tristrip tristrip; tristrip.num_strips = 0; Tristrip.strip = NULL; Gpc_polygon_to_tristrip (&mypolygon, &tristrip); Store decomposed triangles or quads: the decomposed triangles are contiguous <0,1,2><1,2,3><3,4,5> std::vector< std::vector<gpc_ vertex> > Vectrisarray; Std::vector<gpc_vertex> Vectris; for (int i=0; i<tristrip.num_strips; i++{for (int j=0; j<tristrip.strip[i].num_vertices; J + +) {Vectris.push_back (tristrip.strip[i].vertex[j]); } vectrisarray.push_back (Vectris); }//Free memory Gpc_free_tristrip (&tristrip);}

Gpc:http://www.cs.man.ac.uk/~toby/alan/software/

(Owed by: Spring Night rain Http://blog.csdn.net/chunyexiyu reprint please indicate the source)


Decomposition of polygonal samples using GPC (Generic Polygon Clipper)

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.