File: partition.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 (113 lines) | stat: -rw-r--r-- 3,076 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
// Copyright (c) 2005-2009  INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s)     : Sebastien Loriot, Sylvain Pion

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/partition_2.h>
#include <CGAL/CGAL_Ipelet_base.h>


namespace CGAL_convex_part{

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;

const std::string Slab[] = {
  "Y monotone partition", "Greene's approx Convex Partition","Approx Convex Partition","Optimal Convex Partition", "Help"
};

const std::string Hmsg[] = {
  "Y monotonic decomposition of a polygon",
  "Approximation of convex decomposition of a polygon using Greene's algorithm",
  "Approximation of convex decomposition of a polygon using Hertel and Mehlhorn's algorithm",
  "Optimal convex decomposition of a polygon"
};

class ConvexpartitionIpelet
  : public CGAL::Ipelet_base<Kernel,5>{
public:
  ConvexpartitionIpelet()
    :CGAL::Ipelet_base<Kernel,5>("Polygon Partition",Slab,Hmsg){}
  void protected_run(int);
};


void ConvexpartitionIpelet::protected_run(int fn)
{

  if (fn==4) {
    show_help();
    return;
  }

  std::list<Polygon_2> pol_list;
  read_active_objects( CGAL::dispatch_or_drop_output<Polygon_2>( std::back_inserter(pol_list) ) );



  if (pol_list.size ()==0){
    print_error_message("No polygon selected");
    return;
  }

  for (std::list<Polygon_2>::iterator itp=pol_list.begin();itp!=pol_list.end();++itp){
    //~ Polygon_2 polygon=*itp;
    //~ std::list<Polygon_2> partition_polys;
    CGAL::Polygon_2<Kernel,std::list<Kernel::Point_2> > polygon(itp->vertices_begin(),itp->vertices_end());
    std::list<CGAL::Polygon_2<Kernel,std::list<Kernel::Point_2> > > partition_polys;

    if (!polygon.is_simple()){
      print_error_message("Polygon must be simple");
      continue;
    }

    if (polygon.orientation()!=CGAL::COUNTERCLOCKWISE)
      polygon.reverse_orientation();

    switch(fn){
    case 0:
    CGAL::y_monotone_partition_2(polygon.vertices_begin(),
                                  polygon.vertices_end(),
                                  std::back_inserter(partition_polys));
    break;

    case 1:
    CGAL::greene_approx_convex_partition_2(polygon.vertices_begin(),
                                  polygon.vertices_end(),
                                  std::back_inserter(partition_polys));
    break;

    case 2:
    CGAL::approx_convex_partition_2(polygon.vertices_begin(),
                                  polygon.vertices_end(),
                                  std::back_inserter(partition_polys));
    break;

    case 3:
    CGAL::optimal_convex_partition_2(polygon.vertices_begin(),
                                  polygon.vertices_end(),
                                  std::back_inserter(partition_polys));
    break;
    }

    draw_in_ipe(partition_polys.begin(),partition_polys.end());
  }
}

}







CGAL_IPELET(CGAL_convex_part::ConvexpartitionIpelet)