File: edges_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 (56 lines) | stat: -rw-r--r-- 1,725 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
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/vcm_estimate_edges.h>
#include <CGAL/property_map.h>
#include <CGAL/IO/read_points.h>

#include <utility> // defines std::pair
#include <vector>
#include <fstream>

// Types
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point;
typedef Kernel::Vector_3 Vector;

// Point with normal vector stored in a std::pair.
typedef std::pair<Point, Vector> PointVectorPair;
typedef std::vector<PointVectorPair> PointList;

typedef std::array<double,6> Covariance;

int main (int , char**)
{
  // Reads a polygon mesh file in points[].
  std::list<PointVectorPair> points;
  if(!CGAL::IO::read_points(CGAL::data_file_path("meshes/fandisk_large.off"),
                            std::back_inserter(points),
                            CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>())))
  {
    std::cerr << "Error: cannot read file data/fandisk_large.off" << std::endl;
    return EXIT_FAILURE;
  }

  // Estimates covariance matrices per points.
  double R = 0.2,
         r = 0.1;
  std::vector<Covariance> cov;
  CGAL::First_of_pair_property_map<PointVectorPair> point_map;

  CGAL::compute_vcm(points, cov, R, r,
                    CGAL::parameters::point_map (point_map).geom_traits (Kernel()));

  // Find the points on the edges.
  // Note that this step is not expensive and can be done several time to get better results
  double threshold = 0.16;
  std::ofstream output("points_on_edges.xyz");
  int i = 0;
  for(const PointVectorPair& p : points)
  {
    if(CGAL::vcm_is_on_feature_edge(cov[i], threshold))
      output << p.first << "\n";
    ++i;
  }

  return 0;
}