From 48c25b25a5fa5ffe94028543be29a7f3b4280c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Sat, 20 Jun 2009 18:24:49 +0000 Subject: [PATCH] Straight skeleton working :) The default polygon is used inside the ipelet --- CGAL_ipelets/demo/CGAL_ipelets/minkowski.cpp | 3 +- CGAL_ipelets/demo/CGAL_ipelets/partition.cpp | 9 +- CGAL_ipelets/demo/CGAL_ipelets/skeleton.cpp | 161 ++++++++++++------ .../doc_tex/CGAL_ipelets_ref/cgal_ipelets.tex | 2 +- CGAL_ipelets/include/CGAL/CGAL_Ipelet_base.h | 12 +- 5 files changed, 122 insertions(+), 65 deletions(-) diff --git a/CGAL_ipelets/demo/CGAL_ipelets/minkowski.cpp b/CGAL_ipelets/demo/CGAL_ipelets/minkowski.cpp index 84de168599d..c5095b8c27f 100644 --- a/CGAL_ipelets/demo/CGAL_ipelets/minkowski.cpp +++ b/CGAL_ipelets/demo/CGAL_ipelets/minkowski.cpp @@ -29,11 +29,12 @@ namespace CGAL_minkowski{ typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; -typedef CGAL::Polygon_with_holes_2 > Polygon_with_holes_2; +typedef CGAL::Polygon_with_holes_2 > Polygon_with_holes_2; typedef CGAL::Gps_circle_segment_traits_2 Gps_traits_2; typedef Gps_traits_2::Polygon_2 Offset_polygon_2; typedef Gps_traits_2::Polygon_with_holes_2 Offset_polygon_with_holes_2; + const std::string Slab[] = { "Minkowski Sum", "Polygon Offset", diff --git a/CGAL_ipelets/demo/CGAL_ipelets/partition.cpp b/CGAL_ipelets/demo/CGAL_ipelets/partition.cpp index d7a5392a9b9..a7eb94e1ff7 100644 --- a/CGAL_ipelets/demo/CGAL_ipelets/partition.cpp +++ b/CGAL_ipelets/demo/CGAL_ipelets/partition.cpp @@ -67,9 +67,11 @@ void ConvexpartitionIpelet::protected_run(int fn) } for (std::list::iterator itp=pol_list.begin();itp!=pol_list.end();++itp){ - Polygon_2 polygon=*itp; - std::list partition_polys; - + //~ Polygon_2 polygon=*itp; + //~ std::list partition_polys; + CGAL::Polygon_2 > polygon(itp->vertices_begin(),itp->vertices_end()); + std::list > > partition_polys; + if (!polygon.is_simple()){ print_error_message("Polygon must be simple"); continue; @@ -104,7 +106,6 @@ void ConvexpartitionIpelet::protected_run(int fn) break; } - std::list::const_iterator poly_it; draw_in_ipe(partition_polys.begin(),partition_polys.end()); } } diff --git a/CGAL_ipelets/demo/CGAL_ipelets/skeleton.cpp b/CGAL_ipelets/demo/CGAL_ipelets/skeleton.cpp index b3f8ba7c4ab..bb5bec7fd06 100644 --- a/CGAL_ipelets/demo/CGAL_ipelets/skeleton.cpp +++ b/CGAL_ipelets/demo/CGAL_ipelets/skeleton.cpp @@ -22,7 +22,7 @@ #include #include #include - +#include namespace CGAL_skeleton{ @@ -30,87 +30,148 @@ namespace CGAL_skeleton{ typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; const std::string Slab[] = { - "Skeleton", "Polygon offset", "Help" + "Interior skeleton", "Exterior skeleton","Interior offset","Exterior offset","Interior offsets","Exterior offsets", "Help" }; const std::string Hmsg[] = { "TODO", "TODO", + "TODO", + "TODO", + "TODO", + "TODO", + "TODO" }; + class SkeletonIpelet - : public CGAL::Ipelet_base{ - typedef CGAL::Polygon_2 Polygon_2_with_vector; + : public CGAL::Ipelet_base{ - typedef boost::shared_ptr PolygonPtr ; + typedef boost::shared_ptr PolygonPtr ; typedef std::vector PolygonPtrVector ; + typedef CGAL::Straight_skeleton_2 Skeleton ; + typedef boost::shared_ptr SkeletonPtr ; + + void draw_straight_skeleton(const Skeleton& skeleton); + public: SkeletonIpelet() - :CGAL::Ipelet_base("Skeleton and offset",Slab,Hmsg){} + :CGAL::Ipelet_base("Skeleton and offset",Slab,Hmsg){} void protected_run(int); }; +void SkeletonIpelet::draw_straight_skeleton(const Skeleton& skeleton) +{ + typedef Skeleton::Vertex_const_handle Vertex_const_handle ; + typedef Skeleton::Halfedge_const_handle Halfedge_const_handle ; + typedef Skeleton::Halfedge_const_iterator Halfedge_const_iterator ; + + Halfedge_const_handle null_halfedge ; + Vertex_const_handle null_vertex ; + + std::list seglist; + std::back_insert_iterator< std::list > out=std::back_inserter(seglist); + + for ( Halfedge_const_iterator i = skeleton.halfedges_begin(); + i != skeleton.halfedges_end(); + ++i ) + out++=Segment_2(i->opposite()->vertex()->point(),i->vertex()->point()); + draw_in_ipe(seglist.begin(),seglist.end()); +} void SkeletonIpelet::protected_run(int fn) { - if (fn==2) { + if (fn==6) { show_help(); return; } std::list pol_list; - read_active_objects( CGAL::dispatch_or_drop_output( std::back_inserter(pol_list) ) ); + Iso_rectangle_2 bbox= + read_active_objects( CGAL::dispatch_or_drop_output( std::back_inserter(pol_list) ) ); - if (pol_list.size ()==0){ - print_error_message("No polygon selected"); + if (pol_list.size()!=1){ + print_error_message("Exactly one polygon must be selected"); return; } - for (std::list::iterator itp=pol_list.begin();itp!=pol_list.end();++itp){ - Polygon_2_with_vector polygon(itp->vertices_begin(),itp->vertices_end()); - - if (!polygon.is_simple()){ - print_error_message("Polygon must be simple"); - continue; - } + Polygon_2 polygon=*pol_list.begin(); + - if (polygon.orientation()!=CGAL::COUNTERCLOCKWISE) - polygon.reverse_orientation(); - - Kernel::FT lOffset=1; - - PolygonPtrVector inner_offset_polygons = CGAL::create_interior_skeleton_and_offset_polygons_2(lOffset,polygon); - PolygonPtrVector outer_offset_polygons = CGAL::create_exterior_skeleton_and_offset_polygons_2(lOffset,polygon); - - - - typedef std::vector< boost::shared_ptr< Polygon_2_with_vector > > PolygonVector ; - for( PolygonVector::const_iterator pi = inner_offset_polygons.begin() ; pi != inner_offset_polygons.end() ; ++ pi ){ - Polygon_2_with_vector poly=**pi; - draw_in_ipe(poly); - } - - - //~ switch(fn){ - //~ case 0: - //~ CGAL::y_monotone_partition_2(polygon.vertices_begin(), - //~ polygon.vertices_end(), - //~ std::back_inserter(partition_polys)); - //~ break; - - //~ case 1: - //~ CGAL::greene_approx_convex_partition_2(polygon.vertices_begin(), - //~ polygon.vertices_end(), - //~ std::back_inserter(partition_polys)); - //~ break; - //~ } - - //~ std::list::const_iterator poly_it; - //~ draw_in_ipe(partition_polys.begin(),partition_polys.end()); + if (!polygon.is_simple()){ + print_error_message("Polygon must be simple"); + return; } + + if (polygon.orientation()!=CGAL::COUNTERCLOCKWISE) + polygon.reverse_orientation(); + + std::list offsets; + //~ "Interior skeleton", "Exterior skeleton","Interior offset","Exterior offset","Interior offsets","Exterior offsets", "Help" + SkeletonPtr ss; + double max_edge=std::max((bbox.xmax()-bbox.xmin()),(bbox.ymax()-bbox.ymin())); + double dist=0.; + int ret_val=-1; + switch(fn){ + case 3://Exterior offset + case 5://Exterior offsets + case 1://Exterior skeleton + ss = CGAL::create_exterior_straight_skeleton_2(max_edge,polygon); + break; + case 2://Interior offset + case 4://Interior offsets + case 0://Interior skeleton + ss = CGAL::create_interior_straight_skeleton_2(polygon); + break; + } + + + if (fn==0 || fn==1) + draw_straight_skeleton(*ss); + else{ + boost::tie(ret_val,dist)= + request_value_from_user( + (boost::format("Offset value (BBox %1%x%2%)") % (bbox.xmax()-bbox.xmin()) % (bbox.ymax()-bbox.ymin())).str() + ); + if (ret_val == -1){ + print_error_message("Bad value provided"); + return; + } + + if (fn==2 || fn==3) + offsets.push_back(dist); + else{ + for (unsigned i=1;i(ceil(max_edge/dist))+1;++i) + offsets.push_back(i*dist); + } + + for (std::list::iterator it=offsets.begin();it!=offsets.end();++it){ + PolygonPtrVector offset_polygons = CGAL::create_offset_polygons_2(*it,*ss); + for( PolygonPtrVector::const_iterator pi = offset_polygons.begin() ; pi != offset_polygons.end() ; ++ pi ) + draw_in_ipe(**pi); + } + } + + //~ if (fn==3) + //~ draw_straight_skeleton(*ess); + + //~ //Offset printing + //~ PolygonPtrVector offset_polygons = CGAL::create_offset_polygons_2(lOffset,*ss); + //~ for( PolygonPtrVector::const_iterator pi = offset_polygons.begin() ; pi != offset_polygons.end() ; ++ pi ) + //~ draw_in_ipe(**pi); + + + //Offset exterior printing + //~ PolygonPtrVector ext_offset_polygons = CGAL::create_offset_polygons_2(lOffset,*ess); + //~ for( PolygonPtrVector::const_iterator pi = ext_offset_polygons.begin() ; pi != ext_offset_polygons.end() ; ++ pi ) + //~ draw_in_ipe(**pi); + + //~ PolygonPtrVector Interior_offset_polygons = CGAL::create_interior_skeleton_and_offset_polygons_2(lOffset,polygon); + //~ PolygonPtrVector Exterior_offset_polygons = CGAL::create_exterior_skeleton_and_offset_polygons_2(lOffset,polygon); + } } diff --git a/CGAL_ipelets/doc_tex/CGAL_ipelets_ref/cgal_ipelets.tex b/CGAL_ipelets/doc_tex/CGAL_ipelets_ref/cgal_ipelets.tex index 58127ffe674..c3b644bd026 100644 --- a/CGAL_ipelets/doc_tex/CGAL_ipelets_ref/cgal_ipelets.tex +++ b/CGAL_ipelets/doc_tex/CGAL_ipelets_ref/cgal_ipelets.tex @@ -27,7 +27,7 @@ if the arc is the set of points on the circle from the first point to the second \ccTypedef{typedef Kernel::Line_2 Line_2;}{The line type.} \ccTypedef{typedef Kernel::Ray_2 Ray_2;}{The ray type.} \ccTypedef{typedef Kernel::Triangle_2 Triangle_2;}{The triangle type.} -\ccTypedef{typedef CGAL::Polygon_2 > Polygon_2;}{The polygon type.} +\ccTypedef{typedef CGAL::Polygon_2 Polygon_2;}{The polygon type.} \ccTypedef{typedef Kernel::Iso_rectangle_2 Iso_rectangle_2;}{A type to represent bounding boxes.} diff --git a/CGAL_ipelets/include/CGAL/CGAL_Ipelet_base.h b/CGAL_ipelets/include/CGAL/CGAL_Ipelet_base.h index e03ffcd3818..33252b94141 100644 --- a/CGAL_ipelets/include/CGAL/CGAL_Ipelet_base.h +++ b/CGAL_ipelets/include/CGAL/CGAL_Ipelet_base.h @@ -57,7 +57,8 @@ namespace CGAL{ typedef typename Kernel::Line_2 Line_2; typedef typename Kernel::Iso_rectangle_2 Iso_rectangle_2; typedef typename Kernel::Triangle_2 Triangle_2; - typedef typename CGAL::Polygon_2 > Polygon_2; + //~ typedef typename CGAL::Polygon_2 > Polygon_2; + typedef typename CGAL::Polygon_2 Polygon_2; typedef typename Kernel::Circle_2 Circle_2; typedef CGAL::cpp0x::tuple Circular_arc_2; @@ -614,14 +615,7 @@ public: template void - draw_in_ipe(const iterator begin,const iterator end,bool make_grp=true,bool deselect_all=false, - typename boost::enable_if< boost::mpl::or_< boost::is_same::value_type,Point_2> , - boost::mpl::or_< boost::is_same::value_type,Segment_2> , - boost::mpl::or_< boost::is_same::value_type,Circle_2> , - boost::mpl::or_< boost::is_same::value_type,Circular_arc_2> , - boost::is_same::value_type,Polygon_2> - > > > > - >::type* = NULL) const + draw_in_ipe(const iterator begin,const iterator end,bool make_grp=true,bool deselect_all=false) const { for (iterator it=begin;it!=end;++it) draw_in_ipe(*it);