mirror of https://github.com/CGAL/cgal
Weighted straight skeleton API update
This commit is contained in:
parent
9ee39b4642
commit
dafa6c5e7c
|
|
@ -3247,11 +3247,13 @@ Straight_skeleton_2/doc_tex/Straight_skeleton_2_ref/Straight_skeleton_converter_
|
|||
Straight_skeleton_2/doc_tex/Straight_skeleton_2_ref/Straight_skeleton_face_base_2.tex -text
|
||||
Straight_skeleton_2/doc_tex/Straight_skeleton_2_ref/Straight_skeleton_items_converter_2.tex -text
|
||||
Straight_skeleton_2/examples/Straight_skeleton_2/Create_offset_polygons_2.cpp -text
|
||||
Straight_skeleton_2/examples/Straight_skeleton_2/Create_partial_straight_skeleton_2.cpp -text
|
||||
Straight_skeleton_2/examples/Straight_skeleton_2/Create_skeleton_and_offset_polygons_2.cpp -text
|
||||
Straight_skeleton_2/examples/Straight_skeleton_2/Create_skeleton_and_offset_polygons_from_polygon_with_holes_2.cpp -text
|
||||
Straight_skeleton_2/examples/Straight_skeleton_2/Create_skeleton_and_offset_polygons_with_holes_2.cpp -text
|
||||
Straight_skeleton_2/examples/Straight_skeleton_2/Create_straight_skeleton_2.cpp -text
|
||||
Straight_skeleton_2/examples/Straight_skeleton_2/Create_straight_skeleton_from_polygon_with_holes_2.cpp -text
|
||||
Straight_skeleton_2/examples/Straight_skeleton_2/Create_weighted_straight_skeleton_2.cpp -text
|
||||
Straight_skeleton_2/examples/Straight_skeleton_2/print.h -text
|
||||
Straight_skeleton_2/examples/Straight_skeleton_2/sample_1.dat -text
|
||||
Straight_skeleton_2/examples/Straight_skeleton_2/sample_2.dat -text
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
#include<boost/shared_ptr.hpp>
|
||||
|
||||
#include<CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include<CGAL/Polygon_2.h>
|
||||
#include<CGAL/create_straight_skeleton_from_polygon_with_holes_2.h>
|
||||
|
||||
#include "dump_to_eps.h"
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K ;
|
||||
|
||||
typedef K::Point_2 Point ;
|
||||
typedef CGAL::Polygon_2<K> Polygon ;
|
||||
typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes ;
|
||||
typedef CGAL::Straight_skeleton_2<K> Ss ;
|
||||
|
||||
|
||||
typedef boost::shared_ptr<Ss> SsPtr ;
|
||||
|
||||
int main()
|
||||
{
|
||||
Polygon_with_holes input ;
|
||||
|
||||
std::ifstream is("bee.poly") ;
|
||||
is >> input ;
|
||||
|
||||
SsPtr ss = CGAL::create_partial_interior_straight_skeleton_2(input,2.5);
|
||||
|
||||
dump_to_eps(input,*ss,"partial_skeleton.eps");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
#include<CGAL/Polygon_2.h>
|
||||
#include<CGAL/create_straight_skeleton_2.h>
|
||||
|
||||
#include "print.h"
|
||||
#include "dump_to_eps.h"
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K ;
|
||||
|
||||
|
|
@ -32,9 +32,9 @@ int main()
|
|||
|
||||
// Or you can pass the polygon directly, as below.
|
||||
SsPtr oss = CGAL::create_exterior_straight_skeleton_2(poly);
|
||||
|
||||
print_straight_skeleton(*iss);
|
||||
print_straight_skeleton(*oss);
|
||||
|
||||
dump_to_eps(poly,*iss,"interior_skeleton.eps");
|
||||
dump_to_eps(poly,*oss,"exterior_skeleton.eps");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,41 @@
|
|||
#include<boost/shared_ptr.hpp>
|
||||
|
||||
#include<CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include<CGAL/Polygon_2.h>
|
||||
#include<CGAL/create_straight_skeleton_2.h>
|
||||
|
||||
#include "dump_to_eps.h"
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K ;
|
||||
|
||||
typedef K::Point_2 Point ;
|
||||
typedef CGAL::Polygon_2<K> Polygon ;
|
||||
typedef CGAL::Straight_skeleton_2<K> Ss ;
|
||||
|
||||
typedef boost::shared_ptr<Ss> SsPtr ;
|
||||
|
||||
int main()
|
||||
{
|
||||
Polygon poly ;
|
||||
|
||||
poly.push_back( Point(-1,-1) ) ;
|
||||
poly.push_back( Point(0,-12) ) ;
|
||||
poly.push_back( Point(1,-1) ) ;
|
||||
poly.push_back( Point(12,0) ) ;
|
||||
poly.push_back( Point(1,1) ) ;
|
||||
poly.push_back( Point(0,12) ) ;
|
||||
poly.push_back( Point(-1,1) ) ;
|
||||
poly.push_back( Point(-12,0) ) ;
|
||||
|
||||
SsPtr ss0 = CGAL::create_straight_skeleton_2(poly, -1.5);
|
||||
|
||||
dump_to_eps(poly,*ss0,"uniform_weights_skeleton.eps");
|
||||
|
||||
double weights[] = { -1.0, -1.0, -1.5, -1.0, -0.5, 1.0, 1.5, -1.0 } ;
|
||||
|
||||
SsPtr ss1 = CGAL::create_straight_skeleton_2(poly.vertices_begin(), poly.vertices_end(), weights, weights+8);
|
||||
|
||||
dump_to_eps(poly,*ss1,"mixed_weights_skeleton.eps");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,37 +1,38 @@
|
|||
#include <fstream>
|
||||
#include <CGAL/Polygon_2.h>
|
||||
#include <CGAL/Polygon_with_holes_2.h>
|
||||
|
||||
namespace CGAL
|
||||
{
|
||||
|
||||
template<class Poly> Bbox_2 bbox_2 ( Poly const& aPoly ) { return bbox_2(aPoly.begin(), aPoly.end()); }
|
||||
|
||||
template<class K> Bbox_2 bbox_2 ( Polygon_2<K> const& aPoly ) { return bbox_2(aPoly.vertices_begin(), aPoly.vertices_end()); }
|
||||
|
||||
template<class K>
|
||||
Bbox_2 bbox_2 ( Polygon_with_holes_2<K> const& aPolyWH )
|
||||
{
|
||||
Bbox_2 rBbox = bbox_2(aPolyWH.outer_boundary().vertices_begin(), aPolyWH.outer_boundary().vertices_end());
|
||||
Bbox_2 rBbox = bbox_2(aPolyWH.outer_boundary());
|
||||
|
||||
for ( typename Polygon_with_holes_2<K>::Hole_const_iterator hit = aPolyWH.holes_begin()
|
||||
; hit != aPolyWH.holes_end()
|
||||
; ++ hit
|
||||
)
|
||||
rBbox = rBbox + bbox_2(hit->vertices_begin(), hit->vertices_end());
|
||||
rBbox = rBbox + bbox_2(*hit);
|
||||
|
||||
return rBbox ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<class K>
|
||||
void dump_to_eps( CGAL::Polygon_2<K> const& aPoly, char const* aType, double aScale, std::ostream& rOut )
|
||||
template<class InputIterator>
|
||||
void dump_to_eps( InputIterator aBegin, InputIterator aEnd, char const* aType, double aScale, std::ostream& rOut )
|
||||
{
|
||||
typedef typename CGAL::Polygon_2<K>::const_iterator vertex_const_iterator ;
|
||||
|
||||
vertex_const_iterator begin = aPoly.vertices_begin() ;
|
||||
vertex_const_iterator end = aPoly.vertices_end () ;
|
||||
vertex_const_iterator last = end - 1 ;
|
||||
InputIterator lLast = aEnd - 1 ;
|
||||
|
||||
for( vertex_const_iterator curr = begin ; curr != end ; ++ curr )
|
||||
for( InputIterator curr = aBegin ; curr != aEnd ; ++ curr )
|
||||
{
|
||||
vertex_const_iterator next = curr == last ? begin : curr + 1 ;
|
||||
InputIterator next = curr == lLast ? aBegin : curr + 1 ;
|
||||
|
||||
rOut << aType << std::endl
|
||||
<< aScale * curr->x()
|
||||
|
|
@ -45,6 +46,18 @@ void dump_to_eps( CGAL::Polygon_2<K> const& aPoly, char const* aType, double aSc
|
|||
}
|
||||
}
|
||||
|
||||
template<class Poly>
|
||||
void dump_to_eps( Poly const& aPoly, char const* aType, double aScale, std::ostream& rOut )
|
||||
{
|
||||
dump_to_eps(aPoly.begin(), aPoly.end(), aType, aScale, rOut);
|
||||
}
|
||||
|
||||
template<class K>
|
||||
void dump_to_eps( CGAL::Polygon_2<K> const& aPoly, char const* aType, double aScale, std::ostream& rOut )
|
||||
{
|
||||
dump_to_eps(aPoly.vertices_begin(), aPoly.vertices_end(), aType, aScale, rOut);
|
||||
}
|
||||
|
||||
template<class K>
|
||||
void dump_to_eps( CGAL::Polygon_with_holes_2<K> const& aPWH, char const* aType, double aScale, std::ostream& rOut )
|
||||
{
|
||||
|
|
@ -82,17 +95,17 @@ void dump_to_eps( CGAL::Straight_skeleton_2<K> const& aSkeleton, char const* aTy
|
|||
}
|
||||
}
|
||||
|
||||
template<class K>
|
||||
void dump_to_eps ( CGAL::Polygon_with_holes_2<K> const& aInput
|
||||
, std::vector< boost::shared_ptr< CGAL::Polygon_with_holes_2<K> > > const& aOutput
|
||||
, std::ostream& rOut
|
||||
template<class Poly>
|
||||
void dump_to_eps ( Poly const& aInput
|
||||
, std::vector< boost::shared_ptr<Poly> > const& aOutput
|
||||
, std::ostream& rOut
|
||||
)
|
||||
{
|
||||
typedef std::vector< boost::shared_ptr< CGAL::Polygon_with_holes_2<K> > > PolyWH_vector ;
|
||||
typedef std::vector< boost::shared_ptr<Poly> > Poly_vector ;
|
||||
|
||||
CGAL::Bbox_2 lBbox = CGAL::bbox_2(aInput);
|
||||
|
||||
for( typename PolyWH_vector::const_iterator it = aOutput.begin() ; it != aOutput.end(); ++ it )
|
||||
for( typename Poly_vector::const_iterator it = aOutput.begin() ; it != aOutput.end(); ++ it )
|
||||
lBbox = lBbox + CGAL::bbox_2(**it);
|
||||
|
||||
double lScale = 1000 / (lBbox.xmax() - lBbox.xmin()) ;
|
||||
|
|
@ -122,15 +135,15 @@ void dump_to_eps ( CGAL::Polygon_with_holes_2<K> const&
|
|||
|
||||
dump_to_eps(aInput,"input",lScale,rOut);
|
||||
|
||||
for( typename PolyWH_vector::const_iterator it = aOutput.begin() ; it != aOutput.end(); ++ it )
|
||||
for( typename Poly_vector::const_iterator it = aOutput.begin() ; it != aOutput.end(); ++ it )
|
||||
dump_to_eps(**it,"output",lScale,rOut);
|
||||
|
||||
rOut << "grestore\nshowpage" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
template<class K>
|
||||
void dump_to_eps ( CGAL::Polygon_with_holes_2<K> const& aInput
|
||||
template<class Input, class K>
|
||||
void dump_to_eps ( Input const& aInput
|
||||
, CGAL::Straight_skeleton_2<K> const& aSkeleton
|
||||
, std::ostream& rOut
|
||||
)
|
||||
|
|
@ -169,3 +182,39 @@ void dump_to_eps ( CGAL::Polygon_with_holes_2<K> const& aInput
|
|||
rOut << "grestore\nshowpage" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
template<class Input, class K>
|
||||
void dump_to_eps ( Input const& aInput
|
||||
, CGAL::Straight_skeleton_2<K> const& aSkeleton
|
||||
, std::string aFilename
|
||||
)
|
||||
{
|
||||
std::ofstream eps(aFilename.c_str()) ;
|
||||
if ( eps )
|
||||
{
|
||||
std::cerr << "Result: " << aFilename << std::endl ;
|
||||
dump_to_eps(aInput,aSkeleton,eps);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Could not open result file: " << aFilename << std::endl ;
|
||||
}
|
||||
}
|
||||
|
||||
template<class Input, class Output>
|
||||
void dump_to_eps ( Input const& aInput
|
||||
, Output const& aOutput
|
||||
, std::string aFilename
|
||||
)
|
||||
{
|
||||
std::ofstream eps(aFilename.c_str()) ;
|
||||
if ( eps )
|
||||
{
|
||||
std::cerr << "Result: " << aFilename << std::endl ;
|
||||
dump_to_eps(aInput,aOutput,eps);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Could not open result file: " << aFilename << std::endl ;
|
||||
}
|
||||
}
|
||||
|
|
@ -78,11 +78,11 @@ create_straight_skeleton_2 ( PointIterator aOuterContour_VerticesBe
|
|||
|
||||
SsBuilder ssb(aMaxTime) ;
|
||||
|
||||
ssb.enter_contour( aOuterContour_VerticesBegin, aOuterContour_VerticesEnd, aOuterContour_WeightsBegin, aOuterContour_WeightsEnd, false, Point_converter ) ;
|
||||
ssb.enter_contour( aOuterContour_VerticesBegin, aOuterContour_VerticesEnd, aOuterContour_WeightsBegin, aOuterContour_WeightsEnd, true, Point_converter ) ;
|
||||
|
||||
WeightSequenceIterator whi = aHolesWeightBegin ;
|
||||
for ( HoleIterator hi = aHolesBegin ; hi != aHolesEnd ; ++ hi, ++ whi )
|
||||
ssb.enter_contour( CGAL_SS_i::vertices_begin(*hi), CGAL_SS_i::vertices_end(*hi), whi->begin(), whi->end(), false, Point_converter ) ;
|
||||
ssb.enter_contour( CGAL_SS_i::vertices_begin(*hi), CGAL_SS_i::vertices_end(*hi), whi->begin(), whi->end(), true, Point_converter ) ;
|
||||
|
||||
return ssb.construct_skeleton();
|
||||
}
|
||||
|
|
@ -139,10 +139,10 @@ create_straight_skeleton_2 ( PointIterator aOuterContour_VerticesBe
|
|||
|
||||
SsBuilder ssb(aMaxTime) ;
|
||||
|
||||
ssb.enter_contour( aOuterContour_VerticesBegin, aOuterContour_VerticesEnd, aWeight, false, Point_converter ) ;
|
||||
ssb.enter_contour( aOuterContour_VerticesBegin, aOuterContour_VerticesEnd, aWeight, true, Point_converter ) ;
|
||||
|
||||
for ( HoleIterator hi = aHolesBegin ; hi != aHolesEnd ; ++ hi )
|
||||
ssb.enter_contour( CGAL_SS_i::vertices_begin(*hi), CGAL_SS_i::vertices_end(*hi), aWeight, false, Point_converter ) ;
|
||||
ssb.enter_contour( CGAL_SS_i::vertices_begin(*hi), CGAL_SS_i::vertices_end(*hi), aWeight, true, Point_converter ) ;
|
||||
|
||||
return ssb.construct_skeleton();
|
||||
}
|
||||
|
|
@ -153,8 +153,8 @@ create_straight_skeleton_2 ( PointIterator aOuterContour_Vertic
|
|||
, PointIterator aOuterContour_VerticesEnd
|
||||
, HoleIterator aHolesBegin
|
||||
, HoleIterator aHolesEnd
|
||||
, double aWeight = 1.0
|
||||
, boost::optional<double> const& aMaxTime = boost::optional<double>()
|
||||
, double aWeight
|
||||
, boost::optional<double> const& aMaxTime
|
||||
)
|
||||
{
|
||||
return create_straight_skeleton_2(aOuterContour_VerticesBegin
|
||||
|
|
|
|||
|
|
@ -24,19 +24,62 @@
|
|||
|
||||
CGAL_BEGIN_NAMESPACE
|
||||
|
||||
template<class K>
|
||||
|
||||
template<class K, class NT>
|
||||
boost::shared_ptr< Straight_skeleton_2<K> >
|
||||
inline
|
||||
create_interior_straight_skeleton_2 ( Polygon_with_holes_2<K> const& aPolyWithHoles )
|
||||
create_straight_skeleton_2 ( Polygon_with_holes_2<K> const& aPolyWithHoles, NT aWeight, boost::optional<NT> const& aMaxTime, K const& k )
|
||||
{
|
||||
return create_interior_straight_skeleton_2(aPolyWithHoles.outer_boundary().vertices_begin()
|
||||
,aPolyWithHoles.outer_boundary().vertices_end ()
|
||||
,aPolyWithHoles.holes_begin ()
|
||||
,aPolyWithHoles.holes_end ()
|
||||
,K()
|
||||
);
|
||||
return create_straight_skeleton_2( aPolyWithHoles.outer_boundary().vertices_begin()
|
||||
, aPolyWithHoles.outer_boundary().vertices_end ()
|
||||
, aPolyWithHoles.holes_begin ()
|
||||
, aPolyWithHoles.holes_end ()
|
||||
, aWeight
|
||||
, aMaxTime
|
||||
, k
|
||||
);
|
||||
}
|
||||
|
||||
boost::shared_ptr< Straight_skeleton_2<Exact_predicates_inexact_constructions_kernel> >
|
||||
inline
|
||||
create_straight_skeleton_2 ( Polygon_with_holes_2<Exact_predicates_inexact_constructions_kernel> const& aPolyWithHoles
|
||||
, double aWeight
|
||||
, boost::optional<double> const& aMaxTime
|
||||
)
|
||||
{
|
||||
return create_straight_skeleton_2(aPolyWithHoles, aWeight, aMaxTime, Exact_predicates_inexact_constructions_kernel() );
|
||||
}
|
||||
|
||||
boost::shared_ptr< Straight_skeleton_2<Exact_predicates_inexact_constructions_kernel> >
|
||||
inline
|
||||
create_partial_interior_straight_skeleton_2 ( Polygon_with_holes_2<Exact_predicates_inexact_constructions_kernel> const& aPolyWithHoles, boost::optional<double> const& aMaxTime )
|
||||
{
|
||||
return create_straight_skeleton_2(aPolyWithHoles, 1.0, aMaxTime, Exact_predicates_inexact_constructions_kernel() );
|
||||
}
|
||||
|
||||
boost::shared_ptr< Straight_skeleton_2<Exact_predicates_inexact_constructions_kernel> >
|
||||
inline
|
||||
create_interior_straight_skeleton_2 ( Polygon_with_holes_2<Exact_predicates_inexact_constructions_kernel> const& aPolyWithHoles )
|
||||
{
|
||||
return create_straight_skeleton_2(aPolyWithHoles, 1.0, boost::optional<double> (), Exact_predicates_inexact_constructions_kernel() );
|
||||
}
|
||||
|
||||
boost::shared_ptr< Straight_skeleton_2<Exact_predicates_inexact_constructions_kernel> >
|
||||
inline
|
||||
create_partial_exterior_straight_skeleton_2 ( Polygon_with_holes_2<Exact_predicates_inexact_constructions_kernel> const& aPolyWithHoles, boost::optional<double> const& aMaxTime )
|
||||
{
|
||||
return create_straight_skeleton_2(aPolyWithHoles, -1.0, aMaxTime, Exact_predicates_inexact_constructions_kernel() );
|
||||
}
|
||||
|
||||
boost::shared_ptr< Straight_skeleton_2<Exact_predicates_inexact_constructions_kernel> >
|
||||
inline
|
||||
create_exterior_straight_skeleton_2 ( Polygon_with_holes_2<Exact_predicates_inexact_constructions_kernel> const& aPolyWithHoles )
|
||||
{
|
||||
return create_straight_skeleton_2(aPolyWithHoles, -1.0, boost::optional<double> (), Exact_predicates_inexact_constructions_kernel() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
CGAL_END_NAMESPACE
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue