#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Polygon_mesh_processing/orientation.h>
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
#include <CGAL/Polygon_mesh_processing/stitch_borders.h>
#include <CGAL/IO/polygon_mesh_io.h>
#include <iostream>
#include <string>
#include <cstdlib>
namespace PMP = CGAL::Polygon_mesh_processing;
void create_mesh_with_cc_to_orient(Mesh& mesh)
{
const std::string filename = CGAL::data_file_path("meshes/elephant.off");
std::vector<Point> points;
std::vector< std::array<std::size_t, 3> > triangles;
triangles.reserve(faces(mesh).size());
points.reserve(3*triangles.size());
for (Mesh::Face_index f : mesh.faces())
{
Mesh::Halfedge_index h = mesh.halfedge(f);
std::size_t s = points.size();
points.push_back(mesh.point(source(h,mesh)));
points.push_back(mesh.point(target(h,mesh)));
points.push_back(mesh.point(target(mesh.next(h),mesh)));
triangles.push_back( {s, s+1, s+2} );
if (std::rand() % 2 == 0)
std::swap(triangles.back()[0], triangles.back()[1]);
}
PMP::polygon_soup_to_polygon_mesh(points, triangles, mesh);
}
int main()
{
Mesh mesh;
create_mesh_with_cc_to_orient(mesh);
auto fbm = mesh.add_property_map<Mesh::Face_index, bool>("fbm", false).first;
bool is_orientable = PMP::compatible_orientations(mesh, fbm);
assert(is_orientable);
std::vector<Mesh::Face_index> faces_to_reverse;
for (Mesh::Face_index f : mesh.faces())
if (get(fbm, f))
faces_to_reverse.push_back(f);
PMP::reverse_face_orientations(faces_to_reverse, mesh);
PMP::stitch_borders(mesh);
return 0;
}
bool is_closed(const FaceGraph &g)
bool read_polygon_mesh(const std::string &fname, Graph &g, const NamedParameters &np=parameters::default_values())
bool write_polygon_mesh(const std::string &fname, Graph &g, const NamedParameters &np=parameters::default_values())