Created
January 27, 2016 12:00
-
-
Save afabri/32a7b4082208bd53b78d to your computer and use it in GitHub Desktop.
Distinguish inner and boundary vertices of a Mesh_complex_3_in_triangulation_3
This file contains hidden or 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/Labeled_image_mesh_domain_3.h> | |
#include <CGAL/make_mesh_3.h> | |
#include <CGAL/Image_3.h> | |
// Domain | |
typedef CGAL::Exact_predicates_inexact_constructions_kernel K; | |
typedef CGAL::Labeled_image_mesh_domain_3<CGAL::Image_3,K> Mesh_domain; | |
// Triangulation | |
#ifdef CGAL_CONCURRENT_MESH_3 | |
typedef CGAL::Mesh_triangulation_3< | |
Mesh_domain, | |
CGAL::Kernel_traits<Mesh_domain>::Kernel, // Same as sequential | |
CGAL::Parallel_tag // Tag to activate parallelism | |
>::type Tr; | |
#else | |
typedef CGAL::Mesh_triangulation_3<Mesh_domain>::type Tr; | |
#endif | |
typedef CGAL::Mesh_complex_3_in_triangulation_3<Tr> C3t3; | |
// Mesh Criteria | |
typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria; | |
// To avoid verbose function and named parameters call | |
using namespace CGAL::parameters; | |
int main() | |
{ | |
// Domain | |
CGAL::Image_3 image; | |
image.read("data/liver.inr"); | |
Mesh_domain domain(image); | |
// Mesh criteria | |
Mesh_criteria criteria(facet_angle=30, facet_distance=1.2); | |
// Mesh generation and optimization in one call | |
C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, | |
no_perturb(), no_exude()); | |
// Output | |
std::ofstream medit_file("out.mesh"); | |
c3t3.output_to_medit(medit_file); | |
std::set<Tr::Vertex_handle> boundary_vertices, inner_vertices; | |
// A facet is in the complex if it has different indices to its two sides | |
// or if its adjacent or opposite cell is not in the complex | |
for(C3t3::Facets_in_complex_iterator fit = c3t3.facets_in_complex_begin(), end = c3t3.facets_in_complex_end(); fit != end; ++fit){ | |
Tr::Cell_handle ch = fit->first; | |
int i = fit->second; | |
Tr::Cell_handle nh = ch->neighbor(i); | |
if(c3t3.is_in_complex(ch) != c3t3.is_in_complex(nh)){ | |
boundary_vertices.insert(ch->vertex((i+1)% 4)); | |
boundary_vertices.insert(ch->vertex((i+2)% 4)); | |
boundary_vertices.insert(ch->vertex((i+3)% 4)); | |
} | |
} | |
std::cout << boundary_vertices.size() << " boundary vertices"<< std::endl; | |
// A vertex is inside if it is vertex on a cell but not on the boundary | |
for (C3t3::Cells_in_complex_iterator cit = c3t3.cells_in_complex_begin(), end = c3t3.cells_in_complex_end(); cit != end; ++cit){ | |
for(int i=0; i < 4; i++){ | |
if(boundary_vertices.find(cit->vertex(i)) == boundary_vertices.end()){ | |
inner_vertices.insert(cit->vertex(i)); | |
} | |
} | |
} | |
std::cout << inner_vertices.size() << " inner vertices"<< std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment