File: svdlinf.cpp

package info (click to toggle)
cgal 6.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (127 lines) | stat: -rw-r--r-- 3,347 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef CGAL_SDG_VERBOSE
#define CGAL_SDG_DEBUG(a)
#else
#define CGAL_SDG_DEBUG(a) { a }
#endif

// Kernels
//#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
//#include <CGAL/Cartesian.h>

#include <CGAL/CGAL_Ipelet_base.h>
#include <CGAL/Segment_Delaunay_graph_Linf_2.h>
#include <CGAL/Segment_Delaunay_graph_Linf_traits_2.h>

namespace CGAL_svdlinf {

//typedef CGAL::Cartesian<double>                               Kernel;
  typedef CGAL::Exact_predicates_exact_constructions_kernel     Kernel;
//typedef CGAL::Exact_predicates_inexact_constructions_kernel   Kernel;
  typedef CGAL::Segment_Delaunay_graph_Linf_traits_2<Kernel>    Gt;
  typedef CGAL::Segment_Delaunay_graph_Linf_2<Gt>               SDG2;

  const unsigned int num_entries = 3;

  const std::string sublabel[] = {
    "Segment VD Linf general",
    "Segment skeleton Linf general",
    "Help"
  };

  const std::string helpmsg[] = {
    "Draw the L_inf Voronoi diagram of segments in Linf",
    "Draw the L_inf Voronoi skeleton of segments in Linf",
  };

  class svdlinfIpelet
    : public CGAL::Ipelet_base<Kernel,num_entries> {
      public:
        svdlinfIpelet()
          :CGAL::Ipelet_base<Kernel,num_entries>
             ("SVDLinf",sublabel,helpmsg){}
        void protected_run(int);

    };
  // --------------------------------------------------------------------

  void svdlinfIpelet::protected_run(int fn)
  {
    SDG2   svd;

    if (fn == (num_entries-1)) {
      show_help();
      return;
    }

    std::list<Point_2> pt_list;
    std::list<Segment_2> sg_list;

    Iso_rectangle_2 bbox;

    // grab input

    bbox =
      read_active_objects(
          CGAL::dispatch_or_drop_output
          <Point_2,Polygon_2,Segment_2>(
          std::back_inserter(pt_list),
          segment_grabber(std::back_inserter(sg_list)),
          std::back_inserter(sg_list)
          )
          );

    // check input

    if (pt_list.empty() and sg_list.empty()) {
      print_error_message(("Nothing selected"));
      return;
    }

    if ( (fn == 2) or (fn == 3) ) {
      // check that segments are all axis-parallel
      for (std::list<Segment_2>::iterator
          sit  = sg_list.begin();
          sit != sg_list.end();
          ++sit)
      {
        if (not (sit->is_horizontal() or sit->is_vertical())) {
          print_error_message(("Non axis-parallel segment"));
          return;
        }
      }
    }


    Kernel::FT incr_len = 75;
    // slightly increase the size of the bbox
    bbox = Iso_rectangle_2(
      (bbox.min)()+Kernel::Vector_2(-incr_len,-incr_len),
      (bbox.max)()+Kernel::Vector_2(incr_len,incr_len));

    for (std::list<Segment_2>::iterator
         sit  = sg_list.begin();
         sit != sg_list.end();
         ++sit)
    {
      CGAL_SDG_DEBUG( std::cout << "IPELET: inserting segment "
          << *sit << std::endl ; );
      svd.insert(sit->point(0),sit->point(1));
    }

    CGAL_SDG_DEBUG( std::cout << "IPELET: inserting points"
        << std::endl ; );

    svd.insert(pt_list.begin(),pt_list.end());

    if ( fn == 0 ) {
      draw_dual_in_ipe(svd, bbox);
    } else if ( fn == 1 ) {
      draw_skeleton_in_ipe(svd, bbox);
    }

  } // end of void svdlinfIpelet::protected_run(int fn)

}

CGAL_IPELET(CGAL_svdlinf::svdlinfIpelet)