File: segment_simplex_traverser_3.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 (98 lines) | stat: -rw-r--r-- 3,579 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>

#include <assert.h>
#include <iostream>
#include <fstream>
#include <string>

#include <CGAL/IO/read_xyz_points.h>
#include <CGAL/Random.h>

#define CGAL_TRIANGULATION_3_VERBOSE_TRAVERSER_EXAMPLE

// Define the kernel.
typedef CGAL::Exact_predicates_inexact_constructions_kernel     Kernel;
typedef Kernel::Point_3                                         Point_3;

// Define the structure.
typedef CGAL::Delaunay_triangulation_3<Kernel>                               DT;
typedef DT::Segment_simplex_iterator                   Segment_simplex_iterator;
typedef CGAL::Triangulation_simplex_3<DT::Triangulation_data_structure> Simplex;

int main(int argc, char* argv[])
{
  const std::string fname = (argc>1) ? argv[1] : CGAL::data_file_path("points_3/blobby.xyz");

  std::vector<Point_3> points;
  std::ifstream stream(fname);
  if (!stream ||
      !CGAL::IO::read_XYZ(stream, std::back_inserter(points)))
  {
    std::cerr << "Error: cannot read file " << fname << std::endl;
    return EXIT_FAILURE;
  }

  // Construct the Delaunay triangulation.
  DT dt( points.begin(), points.end() );
  assert( dt.is_valid() );

  CGAL::Random rng;
  std::cout << "Random seed is " << CGAL::get_default_random().get_seed() << std::endl;

  unsigned int nb_cells = 0, nb_facets = 0, nb_edges = 0, nb_vertex = 0;

  ////////////////////////////////////////////////////////////
  // Construct a traverser and use begin/end iterators
  ////////////////////////////////////////////////////////////
  Point_3 p1(rng.get_double(-0.48, 0.31),
             rng.get_double(-0.22, 0.22),
             rng.get_double(-0.19, 0.19));
  Point_3 p2(rng.get_double(-0.48, 0.31),
             rng.get_double(-0.22, 0.22),
             rng.get_double(-0.19, 0.19));

  Segment_simplex_iterator st = dt.segment_traverser_simplices_begin(p1, p2);
  Segment_simplex_iterator stend = dt.segment_traverser_simplices_end();

  for (; st != stend; ++st)
  {
    if (st->dimension() == 3)          ++nb_cells;
    else if (st->dimension() == 2)     ++nb_facets;
    else if (st->dimension() == 1)     ++nb_edges;
    else if (st->dimension() == 0)     ++nb_vertex;
  }

#ifdef CGAL_TRIANGULATION_3_VERBOSE_TRAVERSER_EXAMPLE
  std::cout << "While traversing from " << p1 << " to " << p2 << std::endl;
  std::cout << "\tcells    : " << nb_cells << std::endl;
  std::cout << "\tfacets   : " << nb_facets << std::endl;
  std::cout << "\tedges    : " << nb_edges << std::endl;
  std::cout << "\tvertices : " << nb_vertex << std::endl;
  std::cout << std::endl << std::endl;
#endif

  ////////////////////////////////////////////////////////////
  // Construct a traverser and use range-iterator
  ////////////////////////////////////////////////////////////

  nb_cells = 0, nb_facets = 0, nb_edges = 0, nb_vertex = 0;
  for (const Simplex& s : dt.segment_traverser_simplices(p1, p2))
  {
    if (s.dimension() == 3)          ++nb_cells;
    else if (s.dimension() == 2)     ++nb_facets;
    else if (s.dimension() == 1)     ++nb_edges;
    else if (s.dimension() == 0)     ++nb_vertex;
  }

#ifdef CGAL_TRIANGULATION_3_VERBOSE_TRAVERSER_EXAMPLE
  std::cout << "While traversing from " << p1 << " to " << p2 << std::endl;
  std::cout << "\tcells    : " << nb_cells << std::endl;
  std::cout << "\tfacets   : " << nb_facets << std::endl;
  std::cout << "\tedges    : " << nb_edges << std::endl;
  std::cout << "\tvertices : " << nb_vertex << std::endl;
  std::cout << std::endl << std::endl;
#endif

  return 0;
}