CGAL 6.2 - Tetrahedral Remeshing
Loading...
Searching...
No Matches
Tetrahedral_remeshing/mesh_and_remesh_one_subdomain.cpp
#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/Mesh_domain_with_polyline_features_3.h>
#include <CGAL/Labeled_mesh_domain_3.h>
#include <CGAL/Image_3.h>
#include <CGAL/Mesh_3/Detect_features_in_image.h>
#include <CGAL/make_mesh_3.h>
#include <CGAL/tetrahedral_remeshing.h>
#include <CGAL/property_map.h>
#include <unordered_set>
#include <iostream>
using Image_domain = CGAL::Labeled_mesh_domain_3<K>;
#ifdef CGAL_CONCURRENT_MESH_3
using Concurrency_tag = CGAL::Parallel_tag;
#else
using Concurrency_tag = CGAL::Sequential_tag;
#endif
// Triangulation
// Criteria
using Mesh_criteria = CGAL::Mesh_criteria_3<Tr>;
// Triangulation for Remeshing
// Constraints for protecting 1D-features
using Vertex_handle = Triangulation_3::Vertex_handle;
using Vertex_pair = std::pair<Vertex_handle, Vertex_handle>;
using Constraints_set = std::unordered_set<Vertex_pair, boost::hash<Vertex_pair>>;
using Constraints_pmap = CGAL::Boolean_property_map<Constraints_set>;
template <typename Tr>
struct Cells_of_subdomain_pmap
{
using Subdomain_index
= typename Tr::Triangulation_data_structure::Cell::Subdomain_index;
const Subdomain_index m_subdomain;
public:
using key_type = typename Tr::Cell_handle;
using value_type = bool;
using reference = bool;
using category = boost::read_write_property_map_tag;
friend value_type get(const Cells_of_subdomain_pmap& map, const key_type& c) {
return (map.m_subdomain == c->subdomain_index());
}
friend void put(Cells_of_subdomain_pmap&, const key_type&, const value_type) {
; // nothing to do : subdomain indices are updated in remeshing
}
};
// To avoid verbose function and named parameters call
namespace params = CGAL::parameters;
int main(int argc, char* argv[])
{
const std::string fname = (argc>1) ? argv[1] : CGAL::data_file_path("images/420.inr");
if(!image.read(fname)){
std::cerr << "Error: Cannot read file " << fname << std::endl;
return EXIT_FAILURE;
}
Mesh_domain domain
= Mesh_domain::create_labeled_image_mesh_domain(image,
params::features_detector = CGAL::Mesh_3::Detect_features_in_image());
const CGAL::Bbox_3 bbox = domain.bbox();
double diag = CGAL::sqrt(CGAL::square(bbox.xmax() - bbox.xmin()) +
CGAL::square(bbox.ymax() - bbox.ymin()) +
CGAL::square(bbox.zmax() - bbox.zmin()));
double sizing_default = diag * 0.05;
Mesh_criteria criteria(params::edge_size = sizing_default,
params::facet_size = sizing_default,
params::facet_distance = sizing_default / 10
);
C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria,
params::no_exude().no_perturb());
// Output
std::ofstream out0("out_meshed.mesh");
CGAL::IO::write_MEDIT(out0, c3t3.triangulation());
out0.close();
Constraints_set constraints;
Constraints_pmap constraints_pmap(constraints);
Triangulation_3 tr = CGAL::convert_to_triangulation_3(std::move(c3t3),
params::edge_is_constrained_map(constraints_pmap));
const double remeshing_target_size = sizing_default * 0.5;
std::cout << "Remeshing with target edge length: " << remeshing_target_size << std::endl;
CGAL::tetrahedral_isotropic_remeshing(tr, remeshing_target_size,
params::cell_is_selected_map(Cells_of_subdomain_pmap<Triangulation_3>{4})
.number_of_iterations(5)
.edge_is_constrained_map(constraints_pmap)
.remesh_boundaries(false));
// Output
std::ofstream out("out_remeshed.mesh");
out.close();
return EXIT_SUCCESS;
}
double ymin() const
double xmax() const
double zmin() const
double zmax() const
double ymax() const
double xmin() const
bool read(const char *file)
NT square(const NT &x)
NT sqrt(const NT &x)
unspecified_type no_perturb()
void write_MEDIT(std::ostream &os, const T3 &t3, const NamedParameters &np=parameters::default_values())
void tetrahedral_isotropic_remeshing(CGAL::Triangulation_3< Traits, TDS, SLDS > &tr, const SizingFunction &sizing, const NamedParameters &np=parameters::default_values())
remeshes a tetrahedral mesh.
Definition: tetrahedral_remeshing.h:187
CGAL::Triangulation_3< typename Tr::Geom_traits, typename Tr::Triangulation_data_structure > convert_to_triangulation_3(CGAL::Mesh_complex_3_in_triangulation_3< Tr, CornerIndex, CurveIndex > c3t3, const NamedParameters &np=parameters::default_values())
converts the triangulation contained in the input to a Triangulation_3.
Definition: tetrahedral_remeshing.h:357
std::string data_file_path(const std::string &filename)