Skip to content

Instantly share code, notes, and snippets.

@afabri
Created March 7, 2025 10:52
Show Gist options
  • Save afabri/ae295da18bbdfe3a81b44786d5fa9cd0 to your computer and use it in GitHub Desktop.
Save afabri/ae295da18bbdfe3a81b44786d5fa9cd0 to your computer and use it in GitHub Desktop.
issue 8773
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Mesh_triangulation_3.h>
#include <CGAL/Mesh_complex_3_in_triangulation_3.h>
#include <CGAL/Mesh_criteria_3.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/boost/graph/helpers.h>
#include <CGAL/Polyhedral_mesh_domain_3.h>
#include <CGAL/make_mesh_3.h>
#include <CGAL/IO/output_to_vtu.h>
#include <CGAL/IO/File_binary_mesh_3.h>
// Domain
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Surface_mesh<K::Point_3> Polyhedron;
typedef CGAL::Polyhedral_mesh_domain_3<Polyhedron, K> Mesh_domain;
typedef CGAL::Sequential_tag Concurrency_tag;
// Triangulation
typedef CGAL::Mesh_triangulation_3<Mesh_domain,CGAL::Default,Concurrency_tag>::type Tr;
typedef CGAL::Mesh_complex_3_in_triangulation_3<Tr> C3t3;
// Criteria
typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;
namespace params = CGAL::parameters;
int main(int argc, char*argv[])
{
const std::string fname = (argc>1)?argv[1]:CGAL::data_file_path("meshes/sphere.off");
// Create input polyhedron
Polyhedron polyhedron;
std::ifstream input(fname);
input >> polyhedron;
// Create domain
Mesh_domain domain(polyhedron);
// Mesh criteria (no cell_size set)
Mesh_criteria criteria(params::facet_angle(25).facet_size(0.15).facet_distance(0.1).
cell_radius_edge_ratio(3));
// Mesh generation
C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, params::no_perturb().no_exude());
// Output
{
std::ofstream out("ascii.vtu");
CGAL::IO::output_to_vtu(out, c3t3, CGAL::IO::ASCII);
}
{
std::ofstream out("binary.vtu", std::ios::binary);
CGAL::IO::output_to_vtu(out, c3t3, CGAL::IO::BINARY);
}
{
std::ofstream out("mesh.binary", std::ios::binary);
CGAL::IO::save_binary_file(out, c3t3);
out.close();
C3t3 bis;
std::ifstream in("mesh.binary", std::ios::binary);
bool b = CGAL::IO::load_binary_file(in, bis);
std::ofstream outbis("bis.vtu");
CGAL::IO::output_to_vtu(outbis, bis, CGAL::IO::ASCII);
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment