CGAL 6.0 - CGAL and the Boost Graph Library
Loading...
Searching...
No Matches
BGL_graphcut/face_selection_borders_regularization_example.cpp
#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 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;
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;
}
void regularize_face_selection_borders(TriangleMesh &mesh, IsSelectedMap is_selected, double weight, const NamedParameters &np=parameters::default_values())
regularizes a selection in order to minimize the length of the border of the selection.
Definition: selection.h:503
bool read_OFF(std::istream &is, PointRange &points, PolygonRange &polygons, const NamedParameters &np=parameters::default_values())