19#ifdef DEAL_II_WITH_CGAL
21# include <CGAL/Exact_predicates_exact_constructions_kernel.h>
22# include <CGAL/Simple_cartesian.h>
23# include <CGAL/Surface_mesh/Surface_mesh.h>
30 template <
typename dealiiFace,
typename CGAL_Mesh>
33 const dealiiFace &face,
34 const std::map<unsigned int, typename CGAL_Mesh::Vertex_index> &deal2cgal,
36 const bool clockwise_ordering =
true)
38 const auto reference_cell_type = face->reference_cell();
39 std::vector<typename CGAL_Mesh::Vertex_index> indices;
43 mesh.add_edge(deal2cgal.at(face->vertex_index(0)),
44 deal2cgal.at(face->vertex_index(1)));
46 if (clockwise_ordering)
47 std::reverse(indices.begin(), indices.end());
51 indices = {deal2cgal.at(face->vertex_index(0)),
52 deal2cgal.at(face->vertex_index(1)),
53 deal2cgal.at(face->vertex_index(2))};
55 if (clockwise_ordering)
56 std::reverse(indices.begin(), indices.end());
61 if (clockwise_ordering)
63 indices = {deal2cgal.at(face->vertex_index(0)),
64 deal2cgal.at(face->vertex_index(2)),
65 deal2cgal.at(face->vertex_index(3)),
66 deal2cgal.at(face->vertex_index(1))};
70 indices = {deal2cgal.at(face->vertex_index(0)),
71 deal2cgal.at(face->vertex_index(1)),
72 deal2cgal.at(face->vertex_index(3)),
73 deal2cgal.at(face->vertex_index(2))};
79 [[maybe_unused]]
const auto new_face = mesh.add_face(indices);
80 Assert(new_face != mesh.null_face(),
82 "CGAL encountered a orientation problem that it "
83 "was not able to solve."));
88 template <
typename dealiiFace,
typename CGAL_Mesh>
91 const dealiiFace &cell,
92 std::map<unsigned int, typename CGAL_Mesh::Vertex_index> &deal2cgal,
95 for (
const auto i : cell->vertex_indices())
97 if (deal2cgal.find(cell->vertex_index(i)) == deal2cgal.end())
99 deal2cgal[cell->vertex_index(i)] =
100 mesh.add_vertex(CGALWrappers::dealii_point_to_cgal_point<
101 typename CGAL_Mesh::Point>(cell->vertex(i)));
113 template <
typename CGALPo
intType,
int dim,
int spacedim>
117 const Mapping<dim, spacedim> &
mapping,
118 CGAL::Surface_mesh<CGALPointType> &mesh)
121 using Mesh = CGAL::Surface_mesh<CGALPointType>;
123 std::map<unsigned int, typename Mesh::Vertex_index> deal2cgal;
129 CGALWrappers::dealii_point_to_cgal_point<CGALPointType>(vertices[i]));
134 add_facet(cell, deal2cgal, mesh);
154 bool face_is_clockwise_oriented =
159 face_is_clockwise_oriented = !face_is_clockwise_oriented;
160 add_facet(cell->
face(f), deal2cgal, mesh, face_is_clockwise_oriented);
166 template <
typename CGALPo
intType,
int dim,
int spacedim>
169 const ::Triangulation<dim, spacedim> &tria,
170 CGAL::Surface_mesh<CGALPointType> &mesh)
172 Assert(tria.n_cells() > 0,
174 "Triangulation cannot be empty upon calling this function."));
177 "The surface mesh must be empty upon calling this function."));
180 using Mesh = CGAL::Surface_mesh<CGALPointType>;
181 using Vertex_index =
typename Mesh::Vertex_index;
183 std::map<unsigned int, Vertex_index> deal2cgal;
184 if constexpr (dim == 2)
186 for (
const auto &cell : tria.active_cell_iterators())
188 map_vertices(cell, deal2cgal, mesh);
189 add_facet(cell, deal2cgal, mesh);
192 else if constexpr (dim == 3 && spacedim == 3)
194 for (
const auto &cell : tria.active_cell_iterators())
198 if (cell->
face(f)->at_boundary())
200 map_vertices(cell->
face(f), deal2cgal, mesh);
201 add_facet(cell->
face(f),
222# include "cgal/surface_mesh.inst"
TriaIterator< TriaAccessor< dim - 1, dim, spacedim > > face(const unsigned int i) const
virtual boost::container::small_vector< Point< spacedim >, ReferenceCells::max_n_vertices< dim >() > get_vertices(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const
std_cxx20::ranges::iota_view< unsigned int, unsigned int > vertex_indices() const
unsigned int n_vertices() const
std_cxx20::ranges::iota_view< unsigned int, unsigned int > face_indices() const
unsigned int vertex_index(const unsigned int i) const
ReferenceCell reference_cell() const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_ASSERT_UNREACHABLE()
static ::ExceptionBase & ExcImpossibleInDimSpacedim(int arg1, int arg2)
#define Assert(cond, exc)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
TriaIterator< CellAccessor< dim, spacedim > > cell_iterator
bool face_orientation(const unsigned int face) const
MappingQ< dim, spacedim > StaticMappingQ1< dim, spacedim >::mapping
void dealii_tria_to_cgal_surface_mesh(const ::Triangulation< dim, spacedim > &triangulation, CGAL::Surface_mesh< CGALPointType > &mesh)
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)
constexpr ReferenceCell Triangle
constexpr ReferenceCell Hexahedron
constexpr ReferenceCell Quadrilateral
constexpr ReferenceCell Line