File: poisson_eliminate_example.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 (46 lines) | stat: -rw-r--r-- 1,199 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
#include <vector>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/poisson_eliminate.h>
#include <CGAL/IO/write_points.h>
#include <CGAL/IO/read_points.h>

typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3 Point_3;

void sampling(const std::string& filename, double size_factor = 0.2) {
  if (size_factor >= 1.0) {
    std::cout << "usage poisson_eliminate_example filename size_factor" << std::endl
              << "0 < size_factor < 1" << std::endl;
    return;
  }
  std::vector<Point_3> points;

  if (!CGAL::IO::read_points(
    filename,
    std::back_inserter(points))) {

    std::cerr << "Error: cannot read file!" << std::endl;
    return;
  }

  std::size_t target_size = std::size_t(points.size() * size_factor);
  std::vector<Point_3> output;
  output.reserve(target_size);

  CGAL::poisson_eliminate(points, target_size, std::back_inserter(output));

  CGAL::IO::write_points("out.xyz", output, CGAL::parameters::stream_precision(17));
}


int main(int argc, char* argv[])
{
  if (argc < 2)
    sampling(CGAL::data_file_path("points_3/radar.xyz"));
  else if (argc < 3)
    sampling(argv[1]);
  else if (argc < 4)
    sampling(argv[1], std::atof(argv[2]));

  return 0;
}