Subject: CGAL users discussion list
List archive
Re: [cgal-discuss] Re: How to get one boundary and one hole from a self-intersected polygon
Chronological Thread
- From: Ben Supnik <>
- To:
- Subject: Re: [cgal-discuss] Re: How to get one boundary and one hole from a self-intersected polygon
- Date: Fri, 14 May 2010 11:53:41 -0400
Have you edited the "contained" flags at all? A face is either contained or not contained in a general polygon set built off of an arrangement. (The contained property becomes part of faces due to the use of the GPS traits bases...)
Anyway, if you don't (1) set contained how you want it and (2) remove redundant edges (edges where faces on either side are both contained, or edges that have the same face on both sides) I think you will not get correct results.
When working ONLY with the polygon ops code, this is done for you, but if you want to put a bunch of segments in yourself, you must do this!
I do this by doing a traversal of the face from the outside in, toggling containment each time I cross a halfedge. This gives me a "toggling" property. My code is here but it might be too muddled to be useful.
http://dev.x-plane.com/cgit/cgit.cgi/xptools.git/tree/src/XESCore/MapTopology.h
http://dev.x-plane.com/cgit/cgit.cgi/xptools.git/tree/src/XESCore/MapTopology.cpp
There may also be better CGAL utils to do what I am doing...I wrote that code a while ago.
cheers
ben
Jo wrote:
Ben Supnik's first hint using the "Arr_bfs_scanner" class.
I'm not sure the result. 1 polygon to have 3 holes.
#include <CGAL/Gmpq.h>
#include <CGAL/Lazy_exact_nt.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/Boolean_set_operations_2/Gps_default_dcel.h>
#include <CGAL/Gps_segment_traits_2.h>
#include <CGAL/General_polygon_set_2.h>
#include <CGAL/General_polygon_with_holes_2.h>
#include <list>
typedef CGAL::Gmpq Number_type;
typedef CGAL::Lazy_exact_nt<Number_type> Lazy_exact_nt;
typedef CGAL::Cartesian<Lazy_exact_nt>
Kernel;
typedef Kernel::Point_2 Point_2;
typedef Kernel::Segment_2 Segment_2;
typedef CGAL::Gps_segment_traits_2<Kernel> Traits_2;
typedef CGAL::Gps_default_dcel<Traits_2> Dcel;
typedef CGAL::Arrangement_2<Traits_2, Dcel> Arrangement2;
typedef CGAL::General_polygon_set_2<Traits_2> Polygon_set_2;
typedef Traits_2::General_polygon_with_holes_2 Polygon_with_holes_2;
typedef std::back_insert_iterator<std::list<Polygon_with_holes_2> > OutputIterator;
typedef CGAL::Arr_bfs_scanner<Arrangement2, OutputIterator> Arr_bfs_scanner;
int main()
{
Arrangement2 arr;
std::list<Segment_2> segments;
segments.push_back(Segment_2(Point_2(0,0), Point_2(50,0)));
segments.push_back(Segment_2(Point_2(50,0), Point_2(50,30)));
segments.push_back(Segment_2(Point_2(50,30), Point_2(30,30)));
segments.push_back(Segment_2(Point_2(30,30), Point_2(30,10)));
segments.push_back(Segment_2(Point_2(30,10), Point_2(10,10)));
segments.push_back(Segment_2(Point_2(10,10), Point_2(10,40)));
segments.push_back(Segment_2(Point_2(10,40), Point_2(20,40)));
segments.push_back(Segment_2(Point_2(20,40), Point_2(20,20)));
segments.push_back(Segment_2(Point_2(20,20), Point_2(40,20)));
segments.push_back(Segment_2(Point_2(40,20), Point_2(40,50)));
segments.push_back(Segment_2(Point_2(40,50), Point_2(0,50)));
segments.push_back(Segment_2(Point_2(0,50), Point_2(0,0)));
insert(arr, segments.begin(), segments.end());
Polygon_set_2 s;
std::list<Polygon_with_holes_2> res;
OutputIterator out = std::back_inserter(res);
Traits_2 trait;
Arr_bfs_scanner scanner(&trait, out);
scanner.scan(arr);
std::cout<<std::endl;
std::cout<<"Number of polygon : "<<res.size()<<std::endl;
std::list<Polygon_with_holes_2>::const_iterator it;
int i=1;
for (it=res.begin(); it!=res.end(); ++it, ++i)
std::cout<<"#"<<i<<" Number of holes :
"<<it->number_of_holes()<<std::endl;
return 0;
}
I hope that somebody draw the shapes on a screen to confirm the result.
Thans.
--
Scenery Home Page: http://scenery.x-plane.com/
Scenery blog: http://xplanescenery.blogspot.com/
Plugin SDK: http://www.xsquawkbox.net/xpsdk/
X-Plane Wiki: http://wiki.x-plane.com/
Scenery mailing list:
Developer mailing list:
- [cgal-discuss] How to get one boundary and one hole from a self-intersected polygon, Hyungon Kim, 05/06/2010
- Re: [cgal-discuss] How to get one boundary and one hole from a self-intersected polygon, efif, 05/08/2010
- Re: [cgal-discuss] How to get one boundary and one hole from a self-intersected polygon, Ben Supnik, 05/08/2010
- [cgal-discuss] Re: How to get one boundary and one hole from a self-intersected polygon, Hyungon Kim, 05/10/2010
- Re: [cgal-discuss] Re: How to get one boundary and one hole from a self-intersected polygon, Jo, 05/14/2010
- Re: [cgal-discuss] Re: How to get one boundary and one hole from a self-intersected polygon, Ben Supnik, 05/14/2010
- Re: [cgal-discuss] Re: How to get one boundary and one hole from a self-intersected polygon, Jo, 05/14/2010
- [cgal-discuss] Re: How to get one boundary and one hole from a self-intersected polygon, Hyungon Kim, 05/10/2010
- Re: [cgal-discuss] How to get one boundary and one hole from a self-intersected polygon, Ben Supnik, 05/08/2010
- Re: [cgal-discuss] How to get one boundary and one hole from a self-intersected polygon, efif, 05/08/2010
Archive powered by MHonArc 2.6.16.