Created
January 10, 2019 06:14
-
-
Save sloriot/f9f929ce2e30b59f1b63a3cf3780159e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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/refine_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; | |
#ifdef CGAL_CONCURRENT_MESH_3 | |
typedef CGAL::Parallel_tag Concurrency_tag; | |
#else | |
typedef CGAL::Sequential_tag Concurrency_tag; | |
#endif | |
// 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; | |
// To avoid verbose function and named parameters call | |
using namespace CGAL::parameters; | |
typedef CGAL::Triangulation_3<K> Triangulation; | |
struct Vertex_converter | |
{ | |
Triangulation::Vertex operator()(const C3t3::Triangulation::Vertex& src) const { | |
return Triangulation::Vertex(src.point().point()); | |
} | |
void operator()(const C3t3::Triangulation::Vertex&,Triangulation::Vertex&) const {} | |
}; | |
struct Cell_converter | |
{ | |
Triangulation::Cell operator()(const C3t3::Triangulation::Cell&) const { | |
return Triangulation::Cell(); | |
} | |
void operator()(const C3t3::Triangulation::Cell&,Triangulation::Cell&) const {} | |
}; | |
int main(int argc, char*argv[]) | |
{ | |
const char* fname = (argc>1)?argv[1]:"elephant.off"; | |
// Create input polyhedron | |
Polyhedron polyhedron; | |
std::ifstream input(fname); | |
input >> polyhedron; | |
if(input.fail()){ | |
std::cerr << "Error: Cannot read file " << fname << std::endl; | |
return EXIT_FAILURE; | |
} | |
input.close(); | |
if (!CGAL::is_triangle_mesh(polyhedron)){ | |
std::cerr << "Input geometry is not triangulated." << std::endl; | |
return EXIT_FAILURE; | |
} | |
// Create domain | |
Mesh_domain domain(polyhedron); | |
// Mesh criteria (no cell_size set) | |
Mesh_criteria criteria(facet_angle=25, facet_size=0.15, facet_distance=0.008, | |
cell_radius_edge_ratio=3); | |
// Mesh generation | |
C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, no_perturb(), no_exude()); | |
std::ofstream("triangulation.txt") << c3t3.triangulation(); | |
std::ofstream("c3t3.txt") << c3t3; | |
std::ofstream medit_file("out_1.mesh"); | |
c3t3.output_to_medit(medit_file); | |
medit_file.close(); | |
Triangulation t; | |
t.tds().copy_tds(c3t3.triangulation().tds(), c3t3.triangulation().infinite_vertex(), | |
Vertex_converter(), | |
Cell_converter()); | |
assert(t.is_valid()); | |
std::cout << t.number_of_vertices() << "\n"; | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment