Straight skeleton working :)

The default polygon is used inside the ipelet
This commit is contained in:
Sébastien Loriot 2009-06-20 18:24:49 +00:00
parent 1e377ae99d
commit 48c25b25a5
5 changed files with 122 additions and 65 deletions

View File

@ -29,11 +29,12 @@
namespace CGAL_minkowski{
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef CGAL::Polygon_with_holes_2<Kernel,std::list<Kernel::Point_2> > Polygon_with_holes_2;
typedef CGAL::Polygon_with_holes_2<Kernel,std::vector<Kernel::Point_2> > Polygon_with_holes_2;
typedef CGAL::Gps_circle_segment_traits_2<Kernel> 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",

View File

@ -67,8 +67,10 @@ void ConvexpartitionIpelet::protected_run(int fn)
}
for (std::list<Polygon_2>::iterator itp=pol_list.begin();itp!=pol_list.end();++itp){
Polygon_2 polygon=*itp;
std::list<Polygon_2> partition_polys;
//~ Polygon_2 polygon=*itp;
//~ std::list<Polygon_2> partition_polys;
CGAL::Polygon_2<Kernel,std::list<Kernel::Point_2> > polygon(itp->vertices_begin(),itp->vertices_end());
std::list<CGAL::Polygon_2<Kernel,std::list<Kernel::Point_2> > > partition_polys;
if (!polygon.is_simple()){
print_error_message("Polygon must be simple");
@ -104,7 +106,6 @@ void ConvexpartitionIpelet::protected_run(int fn)
break;
}
std::list<Polygon_2>::const_iterator poly_it;
draw_in_ipe(partition_polys.begin(),partition_polys.end());
}
}

View File

@ -22,7 +22,7 @@
#include<boost/shared_ptr.hpp>
#include <CGAL/CGAL_Ipelet_base.h>
#include<CGAL/create_offset_polygons_2.h>
#include <boost/format.hpp>
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<Kernel,3>{
typedef CGAL::Polygon_2<Kernel> Polygon_2_with_vector;
typedef boost::shared_ptr<Polygon_2_with_vector> PolygonPtr ;
class SkeletonIpelet
: public CGAL::Ipelet_base<Kernel,7>{
typedef boost::shared_ptr<Polygon_2> PolygonPtr ;
typedef std::vector<PolygonPtr> PolygonPtrVector ;
typedef CGAL::Straight_skeleton_2<Kernel> Skeleton ;
typedef boost::shared_ptr<Skeleton> SkeletonPtr ;
void draw_straight_skeleton(const Skeleton& skeleton);
public:
SkeletonIpelet()
:CGAL::Ipelet_base<Kernel,3>("Skeleton and offset",Slab,Hmsg){}
:CGAL::Ipelet_base<Kernel,7>("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<Segment_2> seglist;
std::back_insert_iterator< std::list<Segment_2> > 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<Polygon_2> pol_list;
Iso_rectangle_2 bbox=
read_active_objects( CGAL::dispatch_or_drop_output<Polygon_2>( 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<Polygon_2>::iterator itp=pol_list.begin();itp!=pol_list.end();++itp){
Polygon_2_with_vector polygon(itp->vertices_begin(),itp->vertices_end());
Polygon_2 polygon=*pol_list.begin();
if (!polygon.is_simple()){
print_error_message("Polygon must be simple");
continue;
return;
}
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);
std::list<double> 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;
}
//~ 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<Polygon_2>::const_iterator poly_it;
//~ draw_in_ipe(partition_polys.begin(),partition_polys.end());
if (fn==0 || fn==1)
draw_straight_skeleton(*ss);
else{
boost::tie(ret_val,dist)=
request_value_from_user<double>(
(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<static_cast<int>(ceil(max_edge/dist))+1;++i)
offsets.push_back(i*dist);
}
for (std::list<double>::iterator it=offsets.begin();it!=offsets.end();++it){
PolygonPtrVector offset_polygons = CGAL::create_offset_polygons_2<Polygon_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<Polygon_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<Polygon_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);
}
}

View File

@ -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<Kernel, std::list<Point_2> > Polygon_2;}{The polygon type.}
\ccTypedef{typedef CGAL::Polygon_2<Kernel> Polygon_2;}{The polygon type.}
\ccTypedef{typedef Kernel::Iso_rectangle_2 Iso_rectangle_2;}{A type to represent bounding boxes.}

View File

@ -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<Kernel,std::list<Point_2> > Polygon_2;
//~ typedef typename CGAL::Polygon_2<Kernel,std::list<Point_2> > Polygon_2;
typedef typename CGAL::Polygon_2<Kernel> Polygon_2;
typedef typename Kernel::Circle_2 Circle_2;
typedef CGAL::cpp0x::tuple<Circle_2,Point_2,Point_2,CGAL::Sign> Circular_arc_2;
@ -614,14 +615,7 @@ public:
template<class iterator>
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<typename std::iterator_traits<iterator>::value_type,Point_2> ,
boost::mpl::or_< boost::is_same<typename std::iterator_traits<iterator>::value_type,Segment_2> ,
boost::mpl::or_< boost::is_same<typename std::iterator_traits<iterator>::value_type,Circle_2> ,
boost::mpl::or_< boost::is_same<typename std::iterator_traits<iterator>::value_type,Circular_arc_2> ,
boost::is_same<typename std::iterator_traits<iterator>::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);