File: segment_cell_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 (107 lines) | stat: -rw-r--r-- 3,217 bytes parent folder | download | duplicates (2)
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
99
100
101
102
103
104
105
106
107

#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_points.h>
#include <CGAL/Random.h>


// 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::Cell_handle                          Cell_handle;
typedef DT::Segment_cell_iterator                Segment_cell_iterator;

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;
  if (!CGAL::IO::read_points(fname, std::back_inserter(points)))
  {
    std::cerr << "Error: cannot read file " << fname << std::endl;
    return EXIT_FAILURE;
  }

  //bbox
  auto xmin = points[0].x();
  auto xmax = points[0].x();
  auto ymin = points[0].y();
  auto ymax = points[0].y();
  auto zmin = points[0].z();
  auto zmax = points[0].z();

  for(const Point_3& p : points)
  {
    xmin = (std::min)(xmin, p.x());
    ymin = (std::min)(ymin, p.y());
    zmin = (std::min)(zmin, p.z());
    xmax = (std::max)(xmax, p.x());
    ymax = (std::max)(ymax, p.y());
    zmax = (std::max)(zmax, p.z());
  }

  // 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;

  ////////////////////////////////////////////////////////////
  // Construct a traverser and use begin/end iterators
  ////////////////////////////////////////////////////////////
  Point_3 p1(rng.get_double(xmin, xmax),
             rng.get_double(ymin, ymax),
             rng.get_double(zmin, zmax));
  Point_3 p2(rng.get_double(xmin, xmax),
             rng.get_double(ymin, ymax),
             rng.get_double(zmin, zmax));

  Segment_cell_iterator ct = dt.segment_traverser_cells_begin(p1, p2);
  Segment_cell_iterator ctend = dt.segment_traverser_cells_end();

  // Count the number of finite cells traversed.
  unsigned int inf = 0, fin = 0;
  for( ; ct != ctend; ++ct )
  {
    if( dt.is_infinite(ct) )
      ++inf;
    else
      ++fin;
  }

  std::cout << "While traversing from " << p1 << " to " << p2 << std::endl;
  std::cout << inf << " infinite and "
            << fin << " finite cells were visited." << std::endl;
  std::cout << std::endl << std::endl;

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

  // Count the number of finite cells traversed.
  inf = 0, fin = 0;
  for (const Cell_handle ch : dt.segment_traverser_cell_handles(p1, p2))
  {
    if (dt.is_infinite(ch))
      ++inf;
    else
      ++fin;
  }

  std::cout << "While traversing from " << p1 << " to " << p2 << std::endl;
  std::cout << inf << " infinite and "
            << fin << " finite cells were visited." << std::endl;
  std::cout << std::endl << std::endl;

  return 0;
}