File: nef_2_polylines.cpp

package info (click to toggle)
cgal 3.6.1-2
  • links: PTS
  • area: non-free
  • in suites: squeeze
  • size: 62,184 kB
  • ctags: 95,782
  • sloc: cpp: 453,758; ansic: 96,821; sh: 226; makefile: 120; xml: 2
file content (84 lines) | stat: -rw-r--r-- 3,098 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <CGAL/Gmpq.h>
#include <CGAL/Lazy_exact_nt.h>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Bounded_kernel.h>
#include <CGAL/Nef_polyhedron_2.h>


typedef CGAL::Lazy_exact_nt<CGAL::Gmpq> FT;
typedef CGAL::Simple_cartesian<FT> Kernel;
typedef CGAL::Bounded_kernel<Kernel> Extended_kernel;
typedef CGAL::Nef_polyhedron_2<Extended_kernel> Nef_polyhedron;
typedef Nef_polyhedron::Point Point;

typedef Nef_polyhedron::Explorer Explorer;
typedef Explorer::Face_const_iterator Face_const_iterator;
typedef Explorer::Hole_const_iterator Hole_const_iterator;
typedef Explorer::Halfedge_around_face_const_circulator Halfedge_around_face_const_circulator;
typedef Explorer::Vertex_const_handle Vertex_const_handle;

int main()
{
  Point r1[3] = { Point(20,15), Point(25,5), Point(30,15) };
  //Point s1[3] = { Point(40,15), Point(40,5) };
  Point t1[3] = { Point(20,10), Point(30,10), Point(25, 15) };

  std::list<std::pair<Point*,Point*> > polylines;
  polylines.push_back(std::make_pair(r1+0, r1+3));
  //polylines.push_back(std::make_pair(s1+0, s1+2));
  polylines.push_back(std::make_pair(t1+0, t1+3));


   Nef_polyhedron RST(polylines.begin(), polylines.end(), Nef_polyhedron::POLYLINES);

   std::cout << RST << std::endl;

    Explorer explorer = RST.explorer();


    // The first face is the infinite one. It has no outer face cycle but only holes

    Face_const_iterator fit = explorer.faces_begin();
    std::cout << "explorer.mark(explorer.faces_begin()) "  << ((explorer.mark(fit))? "is part of polygon" :  "is not part of polygon") << std::endl;
    for(Hole_const_iterator hit = explorer.holes_begin(fit); hit != explorer.holes_end(fit); hit++){
	std::cout << " A hole" << std::endl;
	Halfedge_around_face_const_circulator hafc(hit), done(hit);
	do{
	  Vertex_const_handle vh = explorer.target(hafc);
	  std::cout << explorer.point(vh) << " [" << explorer.point(vh).x().exact() << " | " << explorer.point(vh).y().exact() << "],  " ;
	  hafc++;
	}while(hafc != done);
	std::cout << std::endl;
      }


    // The other faces have outer face cycles, and they may have holes
    for( fit++;
	fit != explorer.faces_end();
	fit++){

      Halfedge_around_face_const_circulator hafc = explorer.face_cycle(fit), done(hafc);
      std::cout << "face: " << ((explorer.mark(fit))? "is part of polygon" :  "is not part of polygon") << std::endl;
      do{
	Vertex_const_handle vh = explorer.target(hafc);
	  std::cout << explorer.point(vh) << " [" << explorer.point(vh).x().exact() << " | " << explorer.point(vh).y().exact() << "],  " ;
	  hafc++;
      }while(hafc != done);
      std::cout << std::endl;

      for(Hole_const_iterator hit = explorer.holes_begin(fit); hit != explorer.holes_end(fit); hit++){
	std::cout << " A hole" << std::endl;
	Halfedge_around_face_const_circulator hafc(hit), done(hit);
	do{
	  Vertex_const_handle vh = explorer.target(hafc);
	  std::cout << explorer.point(vh) << " [" << explorer.point(vh).x().exact() << " | " << explorer.point(vh).y().exact() << "],  " ;
	  hafc++;
	}while(hafc != done);
	std::cout << std::endl;
      }

    }


  return 0;
}