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)