File: face_selection_borders_regularization_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 (53 lines) | stat: -rw-r--r-- 1,484 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
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/selection.h>
#include <CGAL/boost/graph/IO/OFF.h>
#include <CGAL/Random.h>
#include <fstream>
#include <iostream>

using Kernel = CGAL::Simple_cartesian<double>;
using Mesh = CGAL::Surface_mesh<Kernel::Point_3>;
using Face_index = Mesh::Face_index;

int main(int argc, char** argv)
{
  std::ifstream in((argc>1) ? argv[1] : CGAL::data_file_path("meshes/blobby.off"));

  if(!in)
  {
    std::cerr << "Error: could not read input file" << std::endl;
    return EXIT_FAILURE;
  }

  Mesh mesh;
  CGAL::IO::read_OFF (in, mesh);

  std::unordered_map<Face_index, bool> is_selected_map;

  // randomly select 1/3 of faces
  std::size_t nb_selected_before = 0;
  CGAL::Random rand;
  for (Face_index fi : faces(mesh))
  {
    bool selected = (rand.get_double() < 1. / 3.);
    is_selected_map[fi] = selected;
    if (selected)
      nb_selected_before ++;
  }

  std::cerr << nb_selected_before << " selected before regularization" << std::endl;

  CGAL::regularize_face_selection_borders (mesh,
                                           boost::make_assoc_property_map(is_selected_map),
                                           0.5); // using weight = 0.5

  std::size_t nb_selected_after = 0;
  for (const auto& sel : is_selected_map)
    if (sel.second)
      ++ nb_selected_after;

  std::cerr << nb_selected_after << " selected after regularization" << std::endl;

  return EXIT_SUCCESS;
}