File: Show_offset_polygon.cpp

package info (click to toggle)
cgal 4.5-2
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 69,700 kB
  • ctags: 118,537
  • sloc: cpp: 571,870; ansic: 110,997; sh: 725; python: 92; makefile: 87
file content (82 lines) | stat: -rw-r--r-- 2,389 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<vector>
#include<iterator>
#include<iostream>
#include<iomanip>
#include<string>
#include <fstream>

#include<boost/shared_ptr.hpp>

#include<CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include<CGAL/Polygon_with_holes_2.h>
#include<CGAL/create_offset_polygons_from_polygon_with_holes_2.h>

#include "dump_to_eps.h"

typedef CGAL::Exact_predicates_inexact_constructions_kernel K ;

typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes ;

typedef boost::shared_ptr<Polygon_with_holes> Polygon_with_holes_ptr ;

typedef std::vector<Polygon_with_holes_ptr> Polygon_with_holes_ptr_vector ;

int main( int argc, char* argv[] )
{
  Polygon_with_holes input ;
  
  if ( argc > 1 )
  {
    std::string name = argv[1] ;
  
    std::cout << "Input file: " << name << std::endl ;
      
    std::ifstream is(name.c_str()) ;
    if ( is )
    {
      is >> input ;
      
      double lOffset = 0.25 ;
      
      if ( argc > 2 )
        lOffset = std::atof(argv[2]);
      
      std::cout << "Offsetting at: " << lOffset << std::endl ;

      Polygon_with_holes_ptr_vector offset_polygons = CGAL::create_interior_skeleton_and_offset_polygons_with_holes_2(lOffset,input);

      std::string eps_name ;
      if ( argc > 3  )
           eps_name = argv[3];
      else eps_name = name + ".offset.eps" ;
      
      std::ofstream eps(eps_name.c_str()) ;
      if ( eps )  
      {
        std::cerr << "Result: " << eps_name << std::endl ;
        dump_to_eps(input,offset_polygons,eps);
      }
      else
      {
        std::cerr << "Could not open result file: " << eps_name << std::endl ;
      }  
    }  
    else
    {
      std::cerr << "Could not open input file: " << name << std::endl ;
    }  
  }
  else
  {
    std::cerr << "Computes the interior offset of a polygon with holes and draws the result in an EPS file." << std::endl 
              << std::endl 
              << "Usage: show_offset_polygon <intput_file> [offset_distance] [output_eps_file]" << std::endl 
              << std::endl 
              << "       intput_file  Text file describing the input polygon with holes." << std::endl
              << "         (See inputfile_format.txt for details)" << std::endl
              << "       offset_distance [default=0.25]." << std::endl 
              << "       output_file     [default='innput_file.offset.eps']" << std::endl ; 
  }

  return 0;
}