File: polylines_triangulation.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (75 lines) | stat: -rw-r--r-- 2,279 bytes parent folder | download
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
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Constrained_triangulation_plus_2.h>

#include <vector>

typedef CGAL::Exact_predicates_exact_constructions_kernel                 K;
typedef CGAL::Polygon_2<K>                                                Polygon_2;
typedef CGAL::Exact_intersections_tag                                     Itag;
typedef CGAL::Constrained_Delaunay_triangulation_2<K,CGAL::Default, Itag> CDT;
typedef CGAL::Constrained_triangulation_plus_2<CDT>                       CDTP;

typedef CDTP::Point                                                       Point;
typedef CDTP::Constraint_id                                               Cid;
typedef CDTP::Vertex_handle                                               Vertex_handle;

void
print(const CDTP& cdtp, Cid cid)
{
  std::cout << "Polyline constraint:" << std::endl;
  for(Vertex_handle vh : cdtp.vertices_in_constraint(cid)){
    std::cout << vh->point() << std::endl;
  }
}


void
contexts(const CDTP& cdtp)
{
  for(const auto& sc_and_contexts : cdtp.subconstraints_and_contexts()) {
    const auto& [subconstraint, contexts_list_ptr] = sc_and_contexts;
    Vertex_handle vp = subconstraint.first, vq = subconstraint.second;

    if(cdtp.number_of_enclosing_constraints(vp, vq) == 2){
      std::cout << "subconstraint " << vp->point() << " " << vq->point()
                << " is on constraints starting at:\n";
      for(const CDTP::Context& c : *contexts_list_ptr) {
        std::cout << (*(c.vertices_begin()))->point() << std::endl;
      }
    }
  }
}

int
main( )
{
  CDTP cdtp;

  cdtp.insert_constraint(Point(0,0), Point(1,1));

  std::vector<Point> points;
  points.push_back(Point(1,1));
  points.push_back(Point(5,2));
  points.push_back(Point(6,0));
  points.push_back(Point(3,0));
  Cid id1 = cdtp.insert_constraint(points.begin(), points.end());

  print(cdtp, id1);

  Polygon_2 poly;
  poly.push_back(Point(2,3));
  poly.push_back(Point(4,0));
  poly.push_back(Point(5,0));
  poly.push_back(Point(6,2));

  Cid id2 = cdtp.insert_constraint(poly.vertices_begin(), poly.vertices_end(), true);

  print(cdtp, id1);
  print(cdtp, id2);

  contexts(cdtp);

  return 0;
}