File: snap_polygon_soup.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 (62 lines) | stat: -rw-r--r-- 2,815 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_mesh_processing/repair_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/autorefinement.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
#include <CGAL/IO/polygon_soup_io.h>
#include <CGAL/Real_timer.h>

#include <boost/container/small_vector.hpp>

#include <iostream>

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
namespace PMP = CGAL::Polygon_mesh_processing;

int main(int argc, char** argv)
{
  const std::string filename = argc == 1 ? CGAL::data_file_path("meshes/elephant.off")
                                         : std::string(argv[1]);

  const int grid_size = argc <= 2 ? 23
                                  : std::stoi(std::string(argv[2]));

  const std::string out_file = "rounded_soup.off";

  std::vector<typename Kernel::Point_3> points;
  std::vector<boost::container::small_vector<std::size_t, 3>> triangles;

  std::cout << "Snap rounding on " << filename << "\n";
  if (!CGAL::IO::read_polygon_soup(filename, points, triangles))
  {
    std::cerr << "Cannot read " << filename << "\n";
    return 1;
  }

  PMP::repair_polygon_soup(points, triangles);
  PMP::triangulate_polygons(points, triangles);

  std::cout << "#points = " << points.size() << " and #triangles = " << triangles.size() << std::endl;
  std::cout << "Is 2-manifold: " << PMP::is_polygon_soup_a_polygon_mesh(triangles) << std::endl;

  std::vector<std::pair<std::size_t, std::size_t>> pairs_of_intersecting_triangles;
  PMP::triangle_soup_self_intersections(points, triangles, std::back_inserter(pairs_of_intersecting_triangles));
  std::cout << "Nb of pairs of intersecting triangles: " << pairs_of_intersecting_triangles.size() << std::endl;

  CGAL::Real_timer t;
  t.start();
  bool success=PMP::autorefine_triangle_soup(points, triangles, CGAL::parameters::apply_iterative_snap_rounding(true).erase_all_duplicates(false).concurrency_tag(CGAL::Parallel_if_available_tag()).snap_grid_size(grid_size).number_of_iterations(15));
  t.stop();

  std::cout << "\nOutput:" << std::endl;
  std::cout << "#points = " << points.size() << " and #triangles = " << triangles.size() << " in " << t.time() << " sec." << std::endl;
  if(success)
    std::cout << "Does self-intersect: " << PMP::does_triangle_soup_self_intersect<CGAL::Parallel_if_available_tag>(points, triangles) << std::endl;
  else
    std::cout << "ROUNDING FAILED" << std::endl;

  CGAL::IO::write_polygon_soup(out_file, points, triangles, CGAL::parameters::stream_precision(17));
  std::cout << "Is 2-manifold: " << PMP::orient_polygon_soup(points, triangles) << "\n\n"  << std::endl;
  return 0;
}