#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_2_algorithms.h>
#include <CGAL/Straight_skeleton_builder_2.h>
#include <CGAL/Polygon_offset_builder_2.h>
#include <CGAL/compute_outer_frame_margin.h>
#include "print.h"
#include <boost/shared_ptr.hpp>
#include <vector>
#include <cassert>
typedef boost::shared_ptr<Contour> ContourPtr;
typedef std::vector<ContourPtr> ContourSequence ;
typedef Ss::Halfedge_iterator Halfedge_iterator;
typedef Ss::Halfedge_handle Halfedge_handle;
typedef Ss::Vertex_handle Vertex_handle;
int main()
{
Point_2 pts[] = { Point_2(-1,-1)
, Point_2(0,-12)
, Point_2(1,-1)
, Point_2(12,0)
, Point_2(1,1)
, Point_2(0,12)
, Point_2(-1,1)
, Point_2(-12,0)
} ;
std::vector<Point_2> star(pts,pts+8);
double offset = 3 ;
if ( margin )
{
double fxmin = bbox.
xmin() - *margin ;
double fxmax = bbox.
xmax() + *margin ;
double fymin = bbox.
ymin() - *margin ;
double fymax = bbox.
ymax() + *margin ;
Point_2 frame[4]= { Point_2(fxmin,fymin)
, Point_2(fxmax,fymin)
, Point_2(fxmax,fymax)
, Point_2(fxmin,fymax)
} ;
SsBuilder ssb ;
ssb.enter_contour(frame,frame+4);
ssb.enter_contour(star.rbegin(),star.rend());
boost::shared_ptr<Ss> ss = ssb.construct_skeleton();
if ( ss )
{
print_straight_skeleton(*ss);
ContourSequence offset_contours ;
OffsetBuilder ob(*ss);
ob.construct_offset_contours(offset, std::back_inserter(offset_contours));
ContourSequence::iterator f = offset_contours.end();
double lLargestArea = 0.0 ;
for (ContourSequence::iterator i = offset_contours.begin(); i != offset_contours.end(); ++ i )
{
double lArea = CGAL_NTS
abs( (*i)->area() ) ;
if ( lArea > lLargestArea )
{
f = i ;
lLargestArea = lArea ;
}
}
offset_contours.erase(f);
print_polygons(offset_contours);
}
}
return 0;
}