1 #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
2 
3 #include <CGAL/Polygon_with_holes_2.h>
4 #include <CGAL/create_offset_polygons_from_polygon_with_holes_2.h>
5 #include "dump_to_eps.h"
6 
7 #include <boost/shared_ptr.hpp>
8 
9 #include <cassert>
10 #include <fstream>
11 #include <iostream>
12 #include <string>
13 #include <vector>
14 
15 typedef CGAL::Exact_predicates_inexact_constructions_kernel K ;
16 
17 typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes ;
18 
19 typedef boost::shared_ptr<Polygon_with_holes> Polygon_with_holes_ptr ;
20 
21 typedef std::vector<Polygon_with_holes_ptr> Polygon_with_holes_ptr_vector ;
22 
main(int argc,char * argv[])23 int main( int argc, char* argv[] )
24 {
25   Polygon_with_holes input ;
26 
27   if ( argc > 1 )
28   {
29     std::string name = argv[1] ;
30 
31     std::cout << "Input file: " << name << std::endl ;
32 
33     std::ifstream is(name.c_str()) ;
34     if ( is )
35     {
36       is >> input ;
37 
38       assert(input.outer_boundary().is_counterclockwise_oriented());
39       for(Polygon_with_holes::Hole_const_iterator it = input.holes_begin();
40           it != input.holes_end();
41           ++it){
42         assert(it->is_counterclockwise_oriented());
43       }
44 
45       double lOffset = 0.25 ;
46 
47       if ( argc > 2 )
48         lOffset = std::atof(argv[2]);
49 
50       std::cout << "Offsetting at: " << lOffset << std::endl ;
51 
52       Polygon_with_holes_ptr_vector offset_polygons = CGAL::create_interior_skeleton_and_offset_polygons_with_holes_2(lOffset,input);
53 
54       std::string eps_name ;
55       if ( argc > 3  )
56            eps_name = argv[3];
57       else eps_name = name + ".offset.eps" ;
58 
59       std::ofstream eps(eps_name.c_str()) ;
60       if ( eps )
61       {
62         std::cerr << "Result: " << eps_name << std::endl ;
63         dump_to_eps(input,offset_polygons,eps);
64       }
65       else
66       {
67         std::cerr << "Could not open result file: " << eps_name << std::endl ;
68       }
69     }
70     else
71     {
72       std::cerr << "Could not open input file: " << name << std::endl ;
73     }
74   }
75   else
76   {
77     std::cerr << "Computes the interior offset of a polygon with holes and draws the result in an EPS file." << std::endl
78               << std::endl
79               << "Usage: show_offset_polygon <intput_file> [offset_distance] [output_eps_file]" << std::endl
80               << std::endl
81               << "       intput_file  Text file describing the input polygon with holes." << std::endl
82               << "         (See inputfile_format.txt for details)" << std::endl
83               << "       offset_distance [default=0.25]." << std::endl
84               << "       output_file     [default='innput_file.offset.eps']" << std::endl ;
85   }
86 
87   return 0;
88 }
89