16#ifndef dealii_cgal_utilities_h
17#define dealii_cgal_utilities_h
25#ifdef DEAL_II_WITH_CGAL
30# include <boost/hana.hpp>
32# include <CGAL/Cartesian.h>
33# include <CGAL/Complex_2_in_triangulation_3.h>
34# include <CGAL/Exact_predicates_exact_constructions_kernel.h>
35# include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
36# include <CGAL/Kernel_traits.h>
37# include <CGAL/Mesh_complex_3_in_triangulation_3.h>
38# include <CGAL/Mesh_criteria_3.h>
39# include <CGAL/Mesh_triangulation_3.h>
40# include <CGAL/Polygon_mesh_processing/corefinement.h>
41# include <CGAL/Polygon_mesh_processing/measure.h>
42# include <CGAL/Polygon_mesh_processing/remesh.h>
43# include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
44# include <CGAL/Polyhedral_mesh_domain_with_features_3.h>
45# include <CGAL/Simple_cartesian.h>
46# include <CGAL/Surface_mesh.h>
47# include <CGAL/Triangulation_3.h>
48# include <CGAL/boost/graph/copy_face_graph.h>
49# include <CGAL/boost/graph/selection.h>
50# include <CGAL/convex_hull_3.h>
51# include <CGAL/make_mesh_3.h>
52# include <CGAL/make_surface_mesh.h>
57# include <type_traits>
76# ifdef CGAL_CONCURRENT_MESH_3
137 template <
typename C3t3>
140 CGAL::Surface_mesh<typename C3t3::Point::Point> &surface_mesh,
187 template <
typename CGALPo
intType>
190 const CGAL::Surface_mesh<CGALPointType> &surface_mesh_1,
191 const CGAL::Surface_mesh<CGALPointType> &surface_mesh_2,
193 CGAL::Surface_mesh<CGALPointType> & output_surface_mesh);
206 template <
typename CGALTriangulationType>
209 const unsigned int degree);
226 template <
int dim0,
int dim1,
int spacedim>
229 const typename ::Triangulation<dim0, spacedim>::cell_iterator &cell0,
230 const typename ::Triangulation<dim1, spacedim>::cell_iterator &cell1,
231 const unsigned int degree,
234 (::ReferenceCells::get_hypercube<dim0>()
235 .
template get_default_linear_mapping<dim0, spacedim>()),
237 (::ReferenceCells::get_hypercube<dim1>()
238 .
template get_default_linear_mapping<dim1, spacedim>()));
255 template <
int dim0,
int dim1,
int spacedim>
258 const typename ::Triangulation<dim0, spacedim>::cell_iterator &cell0,
259 const typename ::Triangulation<dim1, spacedim>::cell_iterator &cell1,
260 const unsigned int degree,
292 template <
typename CGALPo
intType>
302 template <
typename C3t3>
305 CGAL::Surface_mesh<typename C3t3::Point::Point> &surface_mesh,
307 const AdditionalData<3> & data)
309 using CGALPointType =
typename C3t3::Point::Point;
310 Assert(CGAL::is_closed(surface_mesh),
311 ExcMessage(
"The surface mesh must be closed."));
313 using K =
typename CGAL::Kernel_traits<CGALPointType>::Kernel;
314 using Mesh_domain = CGAL::Polyhedral_mesh_domain_with_features_3<
316 CGAL::Surface_mesh<CGALPointType>>;
317 using Tr =
typename CGAL::
318 Mesh_triangulation_3<Mesh_domain, CGAL::Default, ConcurrencyTag>::type;
319 using Mesh_criteria = CGAL::Mesh_criteria_3<Tr>;
321 CGAL::Polygon_mesh_processing::triangulate_faces(surface_mesh);
322 Mesh_domain domain(surface_mesh);
323 domain.detect_features();
324 Mesh_criteria criteria(CGAL::parameters::facet_size = data.facet_size,
325 CGAL::parameters::facet_angle = data.facet_angle,
326 CGAL::parameters::facet_distance =
328 CGAL::parameters::cell_radius_edge_ratio =
329 data.cell_radius_edge_ratio,
330 CGAL::parameters::cell_size = data.cell_size);
334 CGAL::parameters::no_perturb(),
335 CGAL::parameters::no_exude());
340 template <
typename CGALPo
intType>
343 const CGAL::Surface_mesh<CGALPointType> &surface_mesh_1,
344 const CGAL::Surface_mesh<CGALPointType> &surface_mesh_2,
346 CGAL::Surface_mesh<CGALPointType> & output_surface_mesh)
348 Assert(output_surface_mesh.is_empty(),
350 "output_surface_mesh must be empty upon calling this function"));
351 Assert(CGAL::is_closed(surface_mesh_1),
353 "The input surface_mesh_1 must be a closed surface mesh."));
354 Assert(CGAL::is_closed(surface_mesh_2),
356 "The input surface_mesh_2 must be a closed surface mesh."));
357 Assert(CGAL::is_triangle_mesh(surface_mesh_1),
358 ExcMessage(
"The first CGAL mesh must be triangulated."));
359 Assert(CGAL::is_triangle_mesh(surface_mesh_2),
360 ExcMessage(
"The second CGAL mesh must be triangulated."));
363 auto surf_1 = surface_mesh_1;
364 auto surf_2 = surface_mesh_2;
365 namespace PMP = CGAL::Polygon_mesh_processing;
366 switch (boolean_operation)
369 res = PMP::corefine_and_compute_union(surf_1,
371 output_surface_mesh);
374 res = PMP::corefine_and_compute_intersection(surf_1,
376 output_surface_mesh);
379 res = PMP::corefine_and_compute_difference(surf_1,
381 output_surface_mesh);
384 PMP::corefine(surf_1,
386 output_surface_mesh = std::move(surf_1);
390 output_surface_mesh.clear();
395 ExcMessage(
"The boolean operation was not successfully computed."));
400 template <
typename CGALTriangulationType>
403 const unsigned int degree)
406 Assert(CGALTriangulationType::Point::Ambient_dimension::value == 3,
409 ExcMessage(
"The degree of the Quadrature formula is not positive."));
411 constexpr int spacedim =
412 CGALTriangulationType::Point::Ambient_dimension::value;
414 std::vector<::Point<spacedim>> pts;
415 std::vector<double> wts;
416 std::array<::Point<spacedim>, spacedim + 1>
vertices;
418 const auto is_c3t3 = boost::hana::is_valid(
419 [](
auto &&obj) ->
decltype(obj.cells_in_complex_begin()) {});
421 const auto is_tria3 = boost::hana::is_valid(
422 [](
auto &&obj) ->
decltype(obj.finite_cell_handles()) {});
424 if constexpr (
decltype(is_c3t3(
tria)){})
426 for (
auto iter =
tria.cells_in_complex_begin();
427 iter !=
tria.cells_in_complex_end();
430 for (
unsigned int i = 0; i < (spacedim + 1); ++i)
432 vertices[i] = cgal_point_to_dealii_point<spacedim>(
433 iter->vertex(i)->point());
436 auto local_quad = quad.compute_affine_transformation(
vertices);
437 std::transform(local_quad.get_points().begin(),
438 local_quad.get_points().end(),
439 std::back_inserter(pts),
440 [&pts](
const auto &p) { return p; });
441 std::transform(local_quad.get_weights().begin(),
442 local_quad.get_weights().end(),
443 std::back_inserter(wts),
444 [&wts](
const double w) { return w; });
447 else if constexpr (
decltype(is_tria3(
tria)){})
449 for (
const auto &f :
tria.finite_cell_handles())
451 for (
unsigned int i = 0; i < (spacedim + 1); ++i)
454 cgal_point_to_dealii_point<spacedim>(f->vertex(i)->point());
457 auto local_quad = quad.compute_affine_transformation(
vertices);
458 std::transform(local_quad.get_points().begin(),
459 local_quad.get_points().end(),
460 std::back_inserter(pts),
461 [&pts](
const auto &p) { return p; });
462 std::transform(local_quad.get_weights().begin(),
463 local_quad.get_weights().end(),
464 std::back_inserter(wts),
465 [&wts](
const double w) { return w; });
477 template <
int dim0,
int dim1,
int spacedim>
480 const typename ::Triangulation<dim0, spacedim>::cell_iterator &cell0,
481 const typename ::Triangulation<dim1, spacedim>::cell_iterator &cell1,
482 const unsigned int degree,
487 Assert(dim0 == 3 && dim1 == 3 && spacedim == 3,
503 cell0, cell1, degree, mapping0, mapping1);
507 using K = CGAL::Exact_predicates_inexact_constructions_kernel;
508 using CGALPoint = CGAL::Point_3<K>;
509 CGAL::Surface_mesh<CGALPoint> surface_1, surface_2, out_surface;
513 CGAL::Polygon_mesh_processing::triangulate_faces(surface_1);
514 CGAL::Polygon_mesh_processing::triangulate_faces(surface_2);
515 Assert(CGAL::is_triangle_mesh(surface_1),
516 ExcMessage(
"The surface must be a triangle mesh."));
519 using Mesh_domain = CGAL::Polyhedral_mesh_domain_with_features_3<
521 CGAL::Surface_mesh<CGALPoint>>;
522 using Tr =
typename CGAL::Mesh_triangulation_3<Mesh_domain,
525 using Mesh_criteria = CGAL::Mesh_criteria_3<Tr>;
526 using C3t3 = CGAL::Mesh_complex_3_in_triangulation_3<Tr>;
535 template <
int dim0,
int dim1,
int spacedim>
538 const typename ::Triangulation<dim0, spacedim>::cell_iterator &cell0,
539 const typename ::Triangulation<dim1, spacedim>::cell_iterator &cell1,
540 const unsigned int degree,
544 Assert(dim0 == 3 && dim1 == 3 && spacedim == 3,
546 using K = CGAL::Exact_predicates_inexact_constructions_kernel;
547 using CGALPoint = CGAL::Point_3<K>;
548 using CGALTriangulation = CGAL::Triangulation_3<K>;
550 CGAL::Surface_mesh<CGALPoint> surface_1, surface_2, out_surface;
554 CGAL::Polygon_mesh_processing::triangulate_faces(surface_1);
555 CGAL::Polygon_mesh_processing::triangulate_faces(surface_2);
561 CGAL::Surface_mesh<CGALPoint> dummy;
562 CGALTriangulation tr;
563 CGAL::convex_hull_3(out_surface.points().begin(),
564 out_surface.points().end(),
566 tr.insert(dummy.points().begin(), dummy.points().end());
572 template <
typename CGALPo
intType>
575 const AdditionalData<3> & data)
577 using K = CGAL::Exact_predicates_inexact_constructions_kernel;
578 using Mesh_domain = CGAL::Polyhedral_mesh_domain_with_features_3<K>;
580 using Polyhedron = CGAL::Mesh_polyhedron_3<K>::type;
582 using Tr = CGAL::Mesh_triangulation_3<Mesh_domain>::type;
584 CGAL::Mesh_complex_3_in_triangulation_3<Tr,
585 Mesh_domain::Corner_index,
586 Mesh_domain::Curve_index>;
588 using Mesh_criteria = CGAL::Mesh_criteria_3<Tr>;
591 CGAL::copy_face_graph(cgal_mesh, poly);
594 std::vector<Polyhedron *> poly_ptrs_vector(1, &poly);
598 Mesh_domain domain(poly_ptrs_vector.begin(), poly_ptrs_vector.end());
600 domain.detect_features();
603 const double default_value_edge_size = std::numeric_limits<double>::max();
604 if (data.edge_size > 0 &&
605 std::abs(data.edge_size - default_value_edge_size) > 1e-12)
607 Mesh_criteria criteria(CGAL::parameters::edge_size = data.edge_size,
608 CGAL::parameters::facet_size = data.facet_size,
609 CGAL::parameters::facet_angle = data.facet_angle,
610 CGAL::parameters::facet_distance =
612 CGAL::parameters::cell_radius_edge_ratio =
613 data.cell_radius_edge_ratio,
614 CGAL::parameters::cell_size = data.cell_size);
616 C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain,
618 CGAL::parameters::no_perturb(),
619 CGAL::parameters::no_exude());
621 CGAL::facets_in_complex_3_to_triangle_mesh(c3t3, cgal_mesh);
623 else if (
std::abs(data.edge_size - default_value_edge_size) <= 1e-12)
625 Mesh_criteria criteria(CGAL::parameters::facet_size = data.facet_size,
626 CGAL::parameters::facet_angle = data.facet_angle,
627 CGAL::parameters::facet_distance =
629 CGAL::parameters::cell_radius_edge_ratio =
630 data.cell_radius_edge_ratio,
631 CGAL::parameters::cell_size = data.cell_size);
633 C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain,
635 CGAL::parameters::no_perturb(),
636 CGAL::parameters::no_exude());
638 CGAL::facets_in_complex_3_to_triangle_mesh(c3t3, cgal_mesh);
Abstract base class for mapping classes.
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
void remesh_surface(CGAL::Surface_mesh< CGALPointType > &surface_mesh, const AdditionalData< 3 > &data=AdditionalData< 3 >{})
::Quadrature< CGALTriangulationType::Point::Ambient_dimension::value > compute_quadrature(const CGALTriangulationType &tria, const unsigned int degree)
::Quadrature< spacedim > compute_quadrature_on_boolean_operation(const typename ::Triangulation< dim0, spacedim >::cell_iterator &cell0, const typename ::Triangulation< dim1, spacedim >::cell_iterator &cell1, const unsigned int degree, const BooleanOperation &bool_op, const Mapping< dim0, spacedim > &mapping0=(::ReferenceCells::get_hypercube< dim0 >() .template get_default_linear_mapping< dim0, spacedim >()), const Mapping< dim1, spacedim > &mapping1=(::ReferenceCells::get_hypercube< dim1 >() .template get_default_linear_mapping< dim1, spacedim >()))
CGAL::Sequential_tag ConcurrencyTag
void cgal_surface_mesh_to_cgal_triangulation(CGAL::Surface_mesh< typename C3t3::Point::Point > &surface_mesh, C3t3 &triangulation, const AdditionalData< 3 > &data=AdditionalData< 3 >{})
void dealii_cell_to_cgal_surface_mesh(const typename ::Triangulation< dim, spacedim >::cell_iterator &cell, const ::Mapping< dim, spacedim > &mapping, CGAL::Surface_mesh< CGALPointType > &mesh)
void compute_boolean_operation(const CGAL::Surface_mesh< CGALPointType > &surface_mesh_1, const CGAL::Surface_mesh< CGALPointType > &surface_mesh_2, const BooleanOperation &boolean_operation, CGAL::Surface_mesh< CGALPointType > &output_surface_mesh)
::Quadrature< spacedim > compute_quadrature_on_intersection(const typename ::Triangulation< dim0, spacedim >::cell_iterator &cell0, const typename ::Triangulation< dim1, spacedim >::cell_iterator &cell1, const unsigned int degree, const Mapping< dim0, spacedim > &mapping0, const Mapping< dim1, spacedim > &mapping1)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
const ::Triangulation< dim, spacedim > & tria