mirror of https://github.com/CGAL/cgal
Straight skeleton working :)
The default polygon is used inside the ipelet
This commit is contained in:
parent
1e377ae99d
commit
48c25b25a5
|
|
@ -29,11 +29,12 @@
|
||||||
namespace CGAL_minkowski{
|
namespace CGAL_minkowski{
|
||||||
|
|
||||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
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 CGAL::Gps_circle_segment_traits_2<Kernel> Gps_traits_2;
|
||||||
typedef Gps_traits_2::Polygon_2 Offset_polygon_2;
|
typedef Gps_traits_2::Polygon_2 Offset_polygon_2;
|
||||||
typedef Gps_traits_2::Polygon_with_holes_2 Offset_polygon_with_holes_2;
|
typedef Gps_traits_2::Polygon_with_holes_2 Offset_polygon_with_holes_2;
|
||||||
|
|
||||||
|
|
||||||
const std::string Slab[] = {
|
const std::string Slab[] = {
|
||||||
"Minkowski Sum",
|
"Minkowski Sum",
|
||||||
"Polygon Offset",
|
"Polygon Offset",
|
||||||
|
|
|
||||||
|
|
@ -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){
|
for (std::list<Polygon_2>::iterator itp=pol_list.begin();itp!=pol_list.end();++itp){
|
||||||
Polygon_2 polygon=*itp;
|
//~ Polygon_2 polygon=*itp;
|
||||||
std::list<Polygon_2> partition_polys;
|
//~ 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()){
|
if (!polygon.is_simple()){
|
||||||
print_error_message("Polygon must be simple");
|
print_error_message("Polygon must be simple");
|
||||||
|
|
@ -104,7 +106,6 @@ void ConvexpartitionIpelet::protected_run(int fn)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<Polygon_2>::const_iterator poly_it;
|
|
||||||
draw_in_ipe(partition_polys.begin(),partition_polys.end());
|
draw_in_ipe(partition_polys.begin(),partition_polys.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
#include<boost/shared_ptr.hpp>
|
#include<boost/shared_ptr.hpp>
|
||||||
#include <CGAL/CGAL_Ipelet_base.h>
|
#include <CGAL/CGAL_Ipelet_base.h>
|
||||||
#include<CGAL/create_offset_polygons_2.h>
|
#include<CGAL/create_offset_polygons_2.h>
|
||||||
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
|
|
||||||
namespace CGAL_skeleton{
|
namespace CGAL_skeleton{
|
||||||
|
|
@ -30,87 +30,148 @@ namespace CGAL_skeleton{
|
||||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||||
|
|
||||||
const std::string Slab[] = {
|
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[] = {
|
const std::string Hmsg[] = {
|
||||||
"TODO",
|
"TODO",
|
||||||
"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 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:
|
public:
|
||||||
SkeletonIpelet()
|
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 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)
|
void SkeletonIpelet::protected_run(int fn)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (fn==2) {
|
if (fn==6) {
|
||||||
show_help();
|
show_help();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<Polygon_2> pol_list;
|
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) ) );
|
read_active_objects( CGAL::dispatch_or_drop_output<Polygon_2>( std::back_inserter(pol_list) ) );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (pol_list.size ()==0){
|
if (pol_list.size()!=1){
|
||||||
print_error_message("No polygon selected");
|
print_error_message("Exactly one polygon must be selected");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::list<Polygon_2>::iterator itp=pol_list.begin();itp!=pol_list.end();++itp){
|
Polygon_2 polygon=*pol_list.begin();
|
||||||
Polygon_2_with_vector polygon(itp->vertices_begin(),itp->vertices_end());
|
|
||||||
|
|
||||||
if (!polygon.is_simple()){
|
if (!polygon.is_simple()){
|
||||||
print_error_message("Polygon must be simple");
|
print_error_message("Polygon must be simple");
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (polygon.orientation()!=CGAL::COUNTERCLOCKWISE)
|
if (polygon.orientation()!=CGAL::COUNTERCLOCKWISE)
|
||||||
polygon.reverse_orientation();
|
polygon.reverse_orientation();
|
||||||
|
|
||||||
Kernel::FT lOffset=1;
|
std::list<double> offsets;
|
||||||
|
//~ "Interior skeleton", "Exterior skeleton","Interior offset","Exterior offset","Interior offsets","Exterior offsets", "Help"
|
||||||
PolygonPtrVector inner_offset_polygons = CGAL::create_interior_skeleton_and_offset_polygons_2(lOffset,polygon);
|
SkeletonPtr ss;
|
||||||
PolygonPtrVector outer_offset_polygons = CGAL::create_exterior_skeleton_and_offset_polygons_2(lOffset,polygon);
|
double max_edge=std::max((bbox.xmax()-bbox.xmin()),(bbox.ymax()-bbox.ymin()));
|
||||||
|
double dist=0.;
|
||||||
|
int ret_val=-1;
|
||||||
|
switch(fn){
|
||||||
typedef std::vector< boost::shared_ptr< Polygon_2_with_vector > > PolygonVector ;
|
case 3://Exterior offset
|
||||||
for( PolygonVector::const_iterator pi = inner_offset_polygons.begin() ; pi != inner_offset_polygons.end() ; ++ pi ){
|
case 5://Exterior offsets
|
||||||
Polygon_2_with_vector poly=**pi;
|
case 1://Exterior skeleton
|
||||||
draw_in_ipe(poly);
|
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){
|
if (fn==0 || fn==1)
|
||||||
//~ case 0:
|
draw_straight_skeleton(*ss);
|
||||||
//~ CGAL::y_monotone_partition_2(polygon.vertices_begin(),
|
else{
|
||||||
//~ polygon.vertices_end(),
|
boost::tie(ret_val,dist)=
|
||||||
//~ std::back_inserter(partition_polys));
|
request_value_from_user<double>(
|
||||||
//~ break;
|
(boost::format("Offset value (BBox %1%x%2%)") % (bbox.xmax()-bbox.xmin()) % (bbox.ymax()-bbox.ymin())).str()
|
||||||
|
);
|
||||||
//~ case 1:
|
if (ret_val == -1){
|
||||||
//~ CGAL::greene_approx_convex_partition_2(polygon.vertices_begin(),
|
print_error_message("Bad value provided");
|
||||||
//~ polygon.vertices_end(),
|
return;
|
||||||
//~ 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==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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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::Line_2 Line_2;}{The line type.}
|
||||||
\ccTypedef{typedef Kernel::Ray_2 Ray_2;}{The ray type.}
|
\ccTypedef{typedef Kernel::Ray_2 Ray_2;}{The ray type.}
|
||||||
\ccTypedef{typedef Kernel::Triangle_2 Triangle_2;}{The triangle 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.}
|
\ccTypedef{typedef Kernel::Iso_rectangle_2 Iso_rectangle_2;}{A type to represent bounding boxes.}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,8 @@ namespace CGAL{
|
||||||
typedef typename Kernel::Line_2 Line_2;
|
typedef typename Kernel::Line_2 Line_2;
|
||||||
typedef typename Kernel::Iso_rectangle_2 Iso_rectangle_2;
|
typedef typename Kernel::Iso_rectangle_2 Iso_rectangle_2;
|
||||||
typedef typename Kernel::Triangle_2 Triangle_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 typename Kernel::Circle_2 Circle_2;
|
||||||
typedef CGAL::cpp0x::tuple<Circle_2,Point_2,Point_2,CGAL::Sign> Circular_arc_2;
|
typedef CGAL::cpp0x::tuple<Circle_2,Point_2,Point_2,CGAL::Sign> Circular_arc_2;
|
||||||
|
|
@ -614,14 +615,7 @@ public:
|
||||||
|
|
||||||
template<class iterator>
|
template<class iterator>
|
||||||
void
|
void
|
||||||
draw_in_ipe(const iterator begin,const iterator end,bool make_grp=true,bool deselect_all=false,
|
draw_in_ipe(const iterator begin,const iterator end,bool make_grp=true,bool deselect_all=false) const
|
||||||
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
|
|
||||||
{
|
{
|
||||||
for (iterator it=begin;it!=end;++it)
|
for (iterator it=begin;it!=end;++it)
|
||||||
draw_in_ipe(*it);
|
draw_in_ipe(*it);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue