File: star_conflict_zone.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 (62 lines) | stat: -rw-r--r-- 1,875 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
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/draw_triangulation_2.h>
#include <CGAL/spatial_sort.h>
#include <array>
#include <vector>
#include <iostream>

typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
typedef CGAL::Delaunay_triangulation_2<K>  Dt2;
typedef Dt2::Edge Edge;
typedef Dt2::Face_handle Face_handle;
typedef Dt2::Face_circulator Face_circulator;
typedef Dt2::Vertex_handle Vertex_handle;

int main( )
{
  Dt2 dt2;

  dt2.insert(Point_2(0,0));
  dt2.insert(Point_2(10,0));
  dt2.insert(Point_2(0,10));

  std::array<Point_2,3> points = { Point_2(2,2), Point_2(1,0), Point_2(2,2) };

  CGAL::spatial_sort(points.begin(), points.end());

  Face_handle hint;

  std::vector<Face_handle> faces;
  std::vector<Edge> edges;

  assert(dt2.dimension() == 2); // precondition of get_conflicts_and_boundary
  for(const Point_2 p : points){
    faces.clear(); // faster than variables in the scope
    edges.clear();
    dt2.get_conflicts_and_boundary(p,
                                   std::back_inserter(faces),
                                   std::back_inserter(edges),
                                   hint);

    if(faces.empty()){
      std::cout << "point " << p << " already in the triangulation" << std::endl;
    }else{
      // Do something with the faces before the insertion

      Vertex_handle vh = dt2.star_hole(p,
                                       edges.begin(), edges.end(),
                                       faces.begin(), faces.end());
      hint = vh->face(); // we could also take any element of faces

      // Do something with the faces after the insertion
      Face_circulator fc = dt2.incident_faces(vh), done(fc);
      do {
        fc++;
      } while (fc != done);
    }
    draw(dt2);
  }
  return 0;
}