27#include <CGAL/Boolean_set_operations_2.h>
32#include <CGAL/Cartesian.h>
33#include <CGAL/Circular_kernel_intersections.h>
34#include <CGAL/Constrained_Delaunay_triangulation_2.h>
35#include <CGAL/Delaunay_mesh_face_base_2.h>
36#include <CGAL/Delaunay_mesh_size_criteria_2.h>
37#include <CGAL/Delaunay_mesher_2.h>
38#include <CGAL/Delaunay_triangulation_2.h>
39#include <CGAL/Exact_predicates_exact_constructions_kernel_with_sqrt.h>
40#include <CGAL/Kernel_traits.h>
41#include <CGAL/Polygon_2.h>
42#include <CGAL/Polygon_with_holes_2.h>
43#include <CGAL/Projection_traits_xy_3.h>
44#include <CGAL/Segment_3.h>
45#include <CGAL/Simple_cartesian.h>
46#include <CGAL/Surface_mesh/Surface_mesh.h>
47#include <CGAL/Tetrahedron_3.h>
48#include <CGAL/Triangle_2.h>
49#include <CGAL/Triangle_3.h>
50#include <CGAL/Triangulation_2.h>
51#include <CGAL/Triangulation_3.h>
52#include <CGAL/Triangulation_face_base_with_id_2.h>
53#include <CGAL/Triangulation_face_base_with_info_2.h>
62 using K = CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt;
63 using K_exact = CGAL::Exact_predicates_exact_constructions_kernel;
93 using Vb = CGAL::Triangulation_vertex_base_2<K>;
94 using Fbb = CGAL::Triangulation_face_base_with_info_2<FaceInfo2, K>;
95 using CFb = CGAL::Constrained_triangulation_face_base_2<K, Fbb>;
96 using Fb = CGAL::Delaunay_mesh_face_base_2<K, CFb>;
97 using Tds = CGAL::Triangulation_data_structure_2<Vb, Fb>;
98 using Itag = CGAL::Exact_predicates_tag;
99 using CDT = CGAL::Constrained_Delaunay_triangulation_2<K, Tds, Itag>;
100 using Criteria = CGAL::Delaunay_mesh_size_criteria_2<CDT>;
104 template <
class T,
class... Types>
108 return std::get_if<T>(v);
111 template <
class T,
class... Types>
115 return boost::get<T>(v);
126 template <
typename TargetVariant>
127 struct Repackage : boost::static_visitor<TargetVariant>
129 template <
typename T>
133 return TargetVariant(t);
143 template <
typename... Types>
144 std::optional<std::variant<Types...>>
145 convert_boost_to_std(
const boost::optional<boost::variant<Types...>> &x)
154 using std_variant = std::variant<Types...>;
155 return boost::apply_visitor(Repackage<std_variant>(), *x);
165 template <
typename... Types>
166 const std::optional<std::variant<Types...>> &
167 convert_boost_to_std(
const std::optional<std::variant<Types...>> &opt)
179 std::list<CDT::Edge> &border)
181 if (start->info().nesting_level != -1)
185 std::list<Face_handle> queue;
186 queue.push_back(start);
187 while (!queue.empty())
191 if (fh->info().nesting_level == -1)
193 fh->info().nesting_level = index;
194 for (
int i = 0; i < 3; i++)
198 if (n->info().nesting_level == -1)
200 if (ct.is_constrained(e))
215 for (CDT::Face_handle f : cdt.all_face_handles())
217 f->info().nesting_level = -1;
219 std::list<CDT::Edge> border;
221 while (!border.empty())
223 CDT::Edge e = border.front();
226 if (n->info().nesting_level == -1)
228 mark_domains(cdt, n, e.first->info().nesting_level + 1, border);
245 std::vector<CGALPoint2>>>
253 std::array<CGALPoint2, 3> pts0, pts1;
255 std::transform(triangle0.begin(),
258 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
260 std::transform(triangle1.begin(),
263 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
267 return convert_boost_to_std(
268 CGAL::intersection(cgal_triangle0, cgal_triangle1));
272 std::optional<std::variant<CGALPoint2, CGALSegment2>>
280 std::array<CGALPoint2, 3> pts0;
281 std::array<CGALPoint2, 2> pts1;
283 std::transform(triangle.begin(),
286 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
288 std::transform(segment.begin(),
291 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
295 return convert_boost_to_std(
296 CGAL::intersection(cgal_segment, cgal_triangle));
302 std::vector<Polygon_with_holes_2>
309 std::array<CGALPoint2, 4> pts0, pts1;
311 std::transform(rectangle0.begin(),
314 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
316 std::transform(rectangle1.begin(),
319 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
321 const CGALPolygon first_poly{pts0.begin(), pts0.end()};
322 const CGALPolygon second_poly{pts1.begin(), pts1.end()};
324 std::vector<Polygon_with_holes_2> poly_list;
325 CGAL::intersection(first_poly,
327 std::back_inserter(poly_list));
333 std::optional<std::variant<CGALPoint3, CGALSegment3>>
338#if DEAL_II_CGAL_VERSION_GTE(5, 5, 0)
343 std::array<CGALPoint3, 4> pts0;
344 std::array<CGALPoint3, 2> pts1;
346 std::transform(tetrahedron.begin(),
349 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3, 3>);
351 std::transform(segment.begin(),
354 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3, 3>);
356 CGALTetra cgal_tetrahedron{pts0[0], pts0[1], pts0[2], pts0[3]};
358 return convert_boost_to_std(
359 CGAL::intersection(cgal_segment, cgal_tetrahedron));
364 "This function requires a version of CGAL greater or equal than 5.5."));
376 std::vector<CGALPoint3>>>
381#if DEAL_II_CGAL_VERSION_GTE(5, 5, 0)
386 std::array<CGALPoint3, 4> pts0;
387 std::array<CGALPoint3, 3> pts1;
389 std::transform(tetrahedron.begin(),
392 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3, 3>);
394 std::transform(triangle.begin(),
397 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3, 3>);
399 CGALTetra cgal_tetrahedron{pts0[0], pts0[1], pts0[2], pts0[3]};
401 return convert_boost_to_std(
402 CGAL::intersection(cgal_triangle, cgal_tetrahedron));
408 "This function requires a version of CGAL greater or equal than 5.5."));
416 std::vector<std::array<Point<2>, 3>>
424 const auto intersection_test =
427 if (!intersection_test.empty())
429 const auto &poly = intersection_test[0].outer_boundary();
430 const unsigned int size_poly = poly.size();
436 {{CGALWrappers::cgal_point_to_dealii_point<2>(poly.vertex(0)),
437 CGALWrappers::cgal_point_to_dealii_point<2>(poly.vertex(1)),
438 CGALWrappers::cgal_point_to_dealii_point<2>(
441 else if (size_poly >= 4)
444 std::vector<std::array<Point<2>, 3>> collection;
447 cdt.insert_constraint(poly.vertices_begin(),
455 if (f->info().in_domain() &&
456 CGAL::to_double(cdt.triangle(f).area()) > tol)
458 collection.push_back(
459 {{CGALWrappers::cgal_point_to_dealii_point<2>(
460 cdt.triangle(f).vertex(0)),
461 CGALWrappers::cgal_point_to_dealii_point<2>(
462 cdt.triangle(f).vertex(1)),
463 CGALWrappers::cgal_point_to_dealii_point<2>(
464 cdt.triangle(f).vertex(2))}});
482 std::vector<std::array<Point<2>, 2>>
490 std::array<CGALPoint2, 4> pts;
492 std::transform(quad.begin(),
495 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
500 CGALWrappers::dealii_point_to_cgal_point<CGALPoint2>(line[0]),
501 CGALWrappers::dealii_point_to_cgal_point<CGALPoint2>(line[1]));
503 cdt.insert_constraint(poly.vertices_begin(), poly.vertices_end(),
true);
504 std::vector<std::array<Point<2>, 2>> vertices;
508 if (f->info().in_domain() &&
509 CGAL::to_double(cdt.triangle(f).area()) > tol &&
510 CGAL::do_intersect(segm, cdt.triangle(f)))
512 const auto intersection =
513 CGAL::intersection(segm, cdt.triangle(f));
514 if (
const CGALSegment2 *s = get_if_<CGALSegment2>(&*intersection))
517 {{CGALWrappers::cgal_point_to_dealii_point<2>((*s)[0]),
518 CGALWrappers::cgal_point_to_dealii_point<2>((*s)[1])}});
527 std::vector<std::array<Point<3>, 2>>
532#if DEAL_II_CGAL_VERSION_GTE(5, 5, 0)
537 std::array<CGALPoint3_exact, 8> pts;
543 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact, 3>);
546 CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact>(line[0]),
547 CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact>(line[1]));
551 std::vector<std::array<Point<3>, 2>> vertices;
553 cgal_triangulation.insert(pts.begin(), pts.end());
554 for (
const auto &c : cgal_triangulation.finite_cell_handles())
556 const auto &cgal_tetrahedron = cgal_triangulation.tetrahedron(c);
557 if (CGAL::do_intersect(cgal_segment, cgal_tetrahedron))
559 const auto intersection =
560 CGAL::intersection(cgal_segment, cgal_tetrahedron);
562 get_if_<CGALSegment3_exact>(&*intersection))
564 if (s->squared_length() > tol * tol)
567 {{CGALWrappers::cgal_point_to_dealii_point<3>(
569 CGALWrappers::cgal_point_to_dealii_point<3>(
580 "This function requires a version of CGAL greater or equal than 5.5."));
588 std::vector<std::array<Point<3>, 3>>
593#if DEAL_II_CGAL_VERSION_GTE(5, 5, 0)
598 std::array<CGALPoint3_exact, 8> pts_hex;
599 std::array<CGALPoint3_exact, 4> pts_quad;
605 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact, 3>);
611 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact, 3>);
614 std::vector<std::array<Point<3>, 3>> vertices;
616 triangulation_hexa.insert(pts_hex.begin(), pts_hex.end());
620 triangulation_quad.insert(pts_quad.begin(), pts_quad.end());
622 for (
const auto &c : triangulation_hexa.finite_cell_handles())
624 const auto &tet = triangulation_hexa.tetrahedron(c);
626 for (
const auto &f : triangulation_quad.finite_facets())
628 if (CGAL::do_intersect(tet, triangulation_quad.triangle(f)))
630 const auto intersection =
631 CGAL::intersection(triangulation_quad.triangle(f), tet);
634 get_if_<CGALTriangle3_exact>(&*intersection))
636 if (CGAL::to_double(t->squared_area()) > tol * tol)
639 {{cgal_point_to_dealii_point<3>((*t)[0]),
640 cgal_point_to_dealii_point<3>((*t)[1]),
641 cgal_point_to_dealii_point<3>((*t)[2])}});
645 if (
const std::vector<CGALPoint3_exact> *vps =
646 get_if_<std::vector<CGALPoint3_exact>>(&*intersection))
649 tria_inter.insert(vps->begin(), vps->end());
651 for (
auto it = tria_inter.finite_facets_begin();
652 it != tria_inter.finite_facets_end();
655 const auto triangle = tria_inter.triangle(*it);
656 if (CGAL::to_double(triangle.squared_area()) >
659 std::array<Point<3>, 3> verts = {
660 {CGALWrappers::cgal_point_to_dealii_point<3>(
662 CGALWrappers::cgal_point_to_dealii_point<3>(
664 CGALWrappers::cgal_point_to_dealii_point<3>(
667 vertices.push_back(verts);
680 "This function requires a version of CGAL greater or equal than 5.5."));
688 std::vector<std::array<Point<3>, 4>>
696 std::array<CGALPoint3_exact, 8> pts_hex0;
697 std::array<CGALPoint3_exact, 8> pts_hex1;
703 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact, 3>);
709 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact, 3>);
713 std::vector<std::array<Point<3>, 4>> vertices;
716 tria0.insert(pts_hex0.begin(), pts_hex0.end());
717 tria1.insert(pts_hex1.begin(), pts_hex1.end());
719 for (
const auto &c0 : tria0.finite_cell_handles())
721 const auto &tet0 = tria1.tetrahedron(c0);
722 const auto &tetg0 = CGAL::make_tetrahedron(tet0.vertex(0),
728 for (
const auto &c1 : tria1.finite_cell_handles())
730 const auto &tet1 = tria1.tetrahedron(c1);
731 const auto &tetg1 = CGAL::make_tetrahedron(tet1.vertex(0),
737 namespace PMP = CGAL::Polygon_mesh_processing;
738 const bool test_intersection =
739 PMP::corefine_and_compute_intersection(surf0, surf1, sm);
740 if (PMP::volume(sm) > tol && test_intersection)
744 triangulation_hexa.insert(sm.points().begin(),
746 for (
const auto &c : triangulation_hexa.finite_cell_handles())
748 const auto &tet = triangulation_hexa.tetrahedron(c);
750 {{CGALWrappers::cgal_point_to_dealii_point<3>(
752 CGALWrappers::cgal_point_to_dealii_point<3>(
754 CGALWrappers::cgal_point_to_dealii_point<3>(
756 CGALWrappers::cgal_point_to_dealii_point<3>(
771 template <
int structdim0,
int structdim1,
int spacedim>
772 std::vector<std::array<Point<spacedim>, structdim1 + 1>>
778 const unsigned int n_vertices0 = vertices0.size();
779 const unsigned int n_vertices1 = vertices1.size();
782 n_vertices0 > 0 || n_vertices1 > 0,
784 "The intersection cannot be computed as at least one of the two cells has no vertices."));
786 if constexpr (structdim0 == 2 && structdim1 == 2 && spacedim == 2)
788 if (n_vertices0 == 4 && n_vertices1 == 4)
795 else if constexpr (structdim0 == 2 && structdim1 == 1 && spacedim == 2)
797 if (n_vertices0 == 4 && n_vertices1 == 2)
804 else if constexpr (structdim0 == 3 && structdim1 == 1 && spacedim == 3)
806 if (n_vertices0 == 8 && n_vertices1 == 2)
813 else if constexpr (structdim0 == 3 && structdim1 == 2 && spacedim == 3)
815 if (n_vertices0 == 8 && n_vertices1 == 4)
822 else if constexpr (structdim0 == 3 && structdim1 == 3 && spacedim == 3)
824 if (n_vertices0 == 8 && n_vertices1 == 8)
841 template <
int structdim0,
int structdim1,
int spacedim>
842 std::vector<std::array<Point<spacedim>, structdim1 + 1>>
851 ReferenceCells::get_hypercube<structdim0>().n_vertices(),
854 ReferenceCells::get_hypercube<structdim1>().n_vertices(),
857 const auto &vertices0 =
858 CGALWrappers::get_vertices_in_cgal_order(cell0, mapping0);
859 const auto &vertices1 =
860 CGALWrappers::get_vertices_in_cgal_order(cell1, mapping1);
862 return compute_intersection_of_cells<structdim0, structdim1, spacedim>(
863 vertices0, vertices1, tol);
873# include "cgal/intersections.inst"
* * Point< dim > operator()(const Point< dim > &p) const *
Abstract base class for mapping classes.
virtual boost::container::small_vector< Point< spacedim >, ReferenceCells::max_n_vertices< dim >() > get_vertices(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
#define DEAL_II_NOT_IMPLEMENTED()
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcMessage(std::string arg1)
std::vector< std::array< Point< 2 >, 2 > > compute_intersection_quad_line(const ArrayView< const Point< 2 > > &quad, const ArrayView< const Point< 2 > > &line, const double tol)
std::vector< std::array< Point< 3 >, 3 > > compute_intersection_hexa_quad(const ArrayView< const Point< 3 > > &hexa, const ArrayView< const Point< 3 > > &quad, const double tol)
void mark_domains(CDT &ct, Face_handle start, int index, std::list< CDT::Edge > &border)
std::optional< std::variant< CGALPoint3, CGALSegment3 > > compute_intersection_tetra_segment(const ArrayView< const Point< 3 > > &tetrahedron, const ArrayView< const Point< 3 > > &segment)
std::vector< Polygon_with_holes_2 > compute_intersection_rect_rect(const ArrayView< const Point< 2 > > &rectangle0, const ArrayView< const Point< 2 > > &rectangle1)
std::vector< std::array< Point< 3 >, 4 > > compute_intersection_hexa_hexa(const ArrayView< const Point< 3 > > &hexa0, const ArrayView< const Point< 3 > > &hexa1, const double tol)
std::vector< std::array< Point< 3 >, 2 > > compute_intersection_hexa_line(const ArrayView< const Point< 3 > > &hexa, const ArrayView< const Point< 3 > > &line, const double tol)
std::optional< std::variant< CGALPoint3, CGALSegment3, CGALTriangle3, std::vector< CGALPoint3 > > > compute_intersection_tetra_triangle(const ArrayView< const Point< 3 > > &tetrahedron, const ArrayView< const Point< 3 > > &triangle)
std::optional< std::variant< CGALPoint2, CGALSegment2 > > compute_intersection_triangle_segment(const ArrayView< const Point< 2 > > &triangle, const ArrayView< const Point< 2 > > &segment)
std::optional< std::variant< CGALPoint2, CGALSegment2, CGALTriangle2, std::vector< CGALPoint2 > > > compute_intersection_triangle_triangle(const ArrayView< const Point< 2 > > &triangle0, const ArrayView< const Point< 2 > > &triangle1)
std::vector< std::array< Point< 2 >, 3 > > compute_intersection_quad_quad(const ArrayView< const Point< 2 > > &quad0, const ArrayView< const Point< 2 > > &quad1, const double tol)
K::Tetrahedron_3 CGALTetra
CGAL::Surface_mesh< K_exact::Point_3 > Surface_mesh
K::Segment_2 CGALSegment2
const T * get_if_(const std::variant< Types... > *v)
CGAL::Exact_predicates_tag Itag
K_exact::Tetrahedron_3 CGALTetra_exact
K_exact::Triangle_3 CGALTriangle3_exact
CDT::Vertex_handle Vertex_handle
K::Triangle_3 CGALTriangle3
K::Segment_3 CGALSegment3
CDT::Face_handle Face_handle
CGAL::Triangulation_3< K_exact > Triangulation3_exact
CGAL::Constrained_Delaunay_triangulation_2< K, Tds, Itag > CDT
std::vector< std::array< Point< spacedim >, structdim1+1 > > compute_intersection_of_cells(const typename Triangulation< structdim0, spacedim >::cell_iterator &cell0, const typename Triangulation< structdim1, spacedim >::cell_iterator &cell1, const Mapping< structdim0, spacedim > &mapping0, const Mapping< structdim1, spacedim > &mapping1, const double tol=1e-9)
CGAL::Delaunay_mesh_size_criteria_2< CDT > Criteria
CGAL::Triangulation_vertex_base_2< K > Vb
CGAL::Polygon_with_holes_2< K > Polygon_with_holes_2
CGAL::Triangulation_data_structure_2< Vb, Fb > Tds
CGAL::Polygon_2< K > CGALPolygon
CGAL::Triangulation_2< K > Triangulation2
CGAL::Exact_predicates_exact_constructions_kernel K_exact
CGAL::Triangulation_3< K > Triangulation3
CGAL::Constrained_triangulation_face_base_2< K, Fbb > CFb
CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt K
K::Triangle_2 CGALTriangle2
CGAL::Delaunay_mesh_face_base_2< K, CFb > Fb
K_exact::Segment_3 CGALSegment3_exact
K_exact::Point_3 CGALPoint3_exact
CGAL::Triangulation_face_base_with_info_2< FaceInfo2, K > Fbb