File: segment_soup_to_polylines.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 (58 lines) | stat: -rw-r--r-- 2,045 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
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Constrained_triangulation_plus_2.h>

typedef CGAL::Exact_predicates_exact_constructions_kernel                 K;
typedef CGAL::Constrained_Delaunay_triangulation_2<K>                     CDT;
typedef CGAL::Constrained_triangulation_plus_2<CDT>                       CDTP;

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

int main()
{
  CDTP cdtp;

  // First polyline
  cdtp.insert_constraint(Point(0,0), Point(1,1));
  cdtp.insert_constraint(Point(1,1), Point(2,2));
  cdtp.insert_constraint(Point(2,2), Point(3,3));

  // Second polyline that cuts the first one in 2
  cdtp.insert_constraint(Point(1,1), Point(1,2));
  cdtp.insert_constraint(Point(1,2), Point(1,3));

  // Third polyline
  cdtp.insert_constraint(Point(10,10), Point(20,20));
  cdtp.insert_constraint(Point(20,20), Point(30,30));

  // Fourth polyline
  cdtp.insert_constraint(Point(100,100), Point(200,200));

  // Segment soup of 8 segments as input
  std::cout << "Input CDT+ has " << cdtp.number_of_constraints()
            << " constraints/subconstraints" << std::endl;

  std::cout << "Splitting subconstraints graph into constraints" << std::endl;
  cdtp.split_subconstraint_graph_into_constraints();

  // 5 polylines as output
  std::cout << "Output CDT+ has " << cdtp.number_of_constraints() << " constraints:" << std::endl;

  for (CDTP::Constraint_id cid : cdtp.constraints())
  {
    std::cout << " *";
    for (CDTP::Vertex_handle vh : cdtp.vertices_in_constraint(cid))
      std::cout << " (" << vh->point() << ")";
    std::cout << std::endl;
  }

  if(cdtp.number_of_constraints() != 5)
  {
    std::cerr << "Error: expected 5 constraints/subconstraints" << std::endl;
    return EXIT_FAILURE;
  }

  return EXIT_SUCCESS;
}