File: Show_straight_skeleton.cpp

package info (click to toggle)
cgal 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (107 lines) | stat: -rw-r--r-- 3,170 bytes parent folder | download | duplicates (3)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <vector>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cassert>

#include <CGAL/draw_straight_skeleton_2.h>

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_with_holes_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_2 ;
typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes ;
typedef CGAL::Straight_skeleton_2<K>  Straight_skeleton ;

typedef std::shared_ptr<Straight_skeleton> Straight_skeleton_ptr ;

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 ;

      assert(input.outer_boundary().is_counterclockwise_oriented());
      for(Polygon_with_holes::Hole_const_iterator it = input.holes_begin();
          it != input.holes_end();
          ++it){
        assert(it->is_clockwise_oriented());
      }

      //check the validity of the input and fix orientation
      if (!input.outer_boundary().is_simple())
      {
        std::cerr << "ERROR: outer boundary is not simple.";
        return 1;
      }
      int k=0;
      for (Polygon_with_holes::Hole_iterator it = input.holes_begin();
                                             it!=input.holes_end(); ++it, ++k)
      {
        if (!it->is_simple())
        {
          std::cerr << "ERROR: hole "<< k << " is not simple.\n";
          return 1;
        }
      }

      Straight_skeleton_ptr ss = CGAL::create_interior_straight_skeleton_2(input);
      if ( ss )
      {
        std::string eps_name ;
        if ( argc > 2  )
             eps_name = argv[2];
        else eps_name = name + ".skeleton.eps" ;

        std::ofstream eps(eps_name.c_str()) ;
        if ( eps )
        {
          std::cerr << "Result: " << eps_name << std::endl ;
          dump_to_eps(input,*ss,eps);
        }
        else
        {
          std::cerr << "Could not open result file: " << eps_name << std::endl ;
        }
      }
      else
      {
        std::cerr << "ERROR creating interior straight skeleton" << std::endl ;
      }
    }
    else
    {
      std::cerr << "Could not open input file: " << name << std::endl ;
    }
  }
  else
  {
    std::cerr << "Computes the straight skeleton in the interior of a polygon with holes and draws it in an EPS file." << std::endl
              << std::endl
              << "Usage: show_straight_skeleton <input_file> [output_eps_file]" << std::endl
              << std::endl
              << "       input_file  Text file describing the input polygon with holes." << std::endl
              << "         (See input_file_format.txt for details" << std::endl
              << "         or use input_file_example.txt)" << std::endl
              << "       output_file     [default='input_file.skeleton.eps']" << std::endl ;
  }

  return 0;
}