| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 2022 - 2025 by the deal.II authors |
| 5 |
// |
| 6 |
// This file is part of the deal.II library. |
| 7 |
// |
| 8 |
// Part of the source code is dual licensed under Apache-2.0 WITH |
| 9 |
// LLVM-exception OR LGPL-2.1-or-later. Detailed license information |
| 10 |
// governing the source code and code contributions can be found in |
| 11 |
// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. |
| 12 |
// |
| 13 |
// ------------------------------------------------------------------------ |
| 14 |
|
| 15 |
#ifndef dealii_cgal_surface_mesh_h |
| 16 |
#define dealii_cgal_surface_mesh_h |
| 17 |
|
| 18 |
#include <deal.II/base/config.h> |
| 19 |
|
| 20 |
#include <deal.II/fe/mapping.h> |
| 21 |
|
| 22 |
#include <deal.II/grid/tria.h> |
| 23 |
|
| 24 |
|
| 25 |
#ifdef DEAL_II_WITH_CGAL |
| 26 |
# include <deal.II/cgal/point_conversion.h> |
| 27 |
|
| 28 |
# include <CGAL/version.h> |
| 29 |
# if CGAL_VERSION_MAJOR >= 6 |
| 30 |
# include <CGAL/Installation/internal/disable_deprecation_warnings_and_errors.h> |
| 31 |
# endif |
| 32 |
# include <CGAL/Polygon_mesh_processing/stitch_borders.h> |
| 33 |
# include <CGAL/Surface_mesh.h> |
| 34 |
|
| 35 |
|
| 36 |
DEAL_II_NAMESPACE_OPEN |
| 37 |
|
| 38 |
namespace CGALWrappers |
| 39 |
{ |
| 40 |
/** |
| 41 |
* Build a CGAL::Surface_mesh from a deal.II cell. |
| 42 |
* |
| 43 |
* The class Surface_mesh implements a halfedge data structure and can be used |
| 44 |
* to represent polyhedral surfaces. It is an edge-centered data structure |
| 45 |
* capable of maintaining incidence information of vertices, edges, and faces. |
| 46 |
* Each edge is represented by two halfedges with opposite orientation. The |
| 47 |
* orientation of a face is chosen so that the halfedges around a face are |
| 48 |
* oriented counterclockwise. |
| 49 |
* |
| 50 |
* More information on this class is available at |
| 51 |
* https://doc.cgal.org/latest/Surface_mesh/index.html |
| 52 |
* |
| 53 |
* The function will throw an exception in dimension one. In dimension two, it |
| 54 |
* generates a surface mesh of the quadrilateral cell or of the triangle cell, |
| 55 |
* while in dimension three it will generate the surface mesh of the cell, |
| 56 |
* i.e., a polyhedral mesh containing the faces of the input cell. |
| 57 |
* |
| 58 |
* The generated mesh is useful when performing geometric operations using |
| 59 |
* CGAL::Polygon_mesh_processing, i.e., to compute boolean operations on |
| 60 |
* cells, splitting, cutting, slicing, etc. |
| 61 |
* |
| 62 |
* For examples on how to use the resulting CGAL::Surface_mesh see |
| 63 |
* https://doc.cgal.org/latest/Polygon_mesh_processing/ |
| 64 |
* |
| 65 |
* @param[in] cell The input deal.II cell iterator |
| 66 |
* @param[in] mapping The mapping used to map the vertices of the cell |
| 67 |
* @param[out] mesh The output CGAL::Surface_mesh |
| 68 |
*/ |
| 69 |
template <typename CGALPointType, int dim, int spacedim> |
| 70 |
void |
| 71 |
dealii_cell_to_cgal_surface_mesh( |
| 72 |
const typename dealii::Triangulation<dim, spacedim>::cell_iterator &cell, |
| 73 |
const dealii::Mapping<dim, spacedim> &mapping, |
| 74 |
CGAL::Surface_mesh<CGALPointType> &mesh); |
| 75 |
|
| 76 |
/** |
| 77 |
* Convert a deal.II triangulation to a CGAL::Surface_mesh. The output depends |
| 78 |
* on the intrinsic dimension of the input deal.II triangulation. |
| 79 |
* |
| 80 |
* In 2d, i.e. with a |
| 81 |
* Triangulation<2> or a Triangulation<2,3>, the output is the |
| 82 |
* CGAL::Surface_mesh describing the whole triangulation. |
| 83 |
* |
| 84 |
* In 3d, the boundary the of the deal.II Triangulation is converted to |
| 85 |
* a CGAL::Surface_mesh by looping over all the boundary faces. |
| 86 |
* |
| 87 |
* @param[in] triangulation The input deal.II triangulation. |
| 88 |
* @param[out] mesh The output CGAL::Surface_mesh. |
| 89 |
*/ |
| 90 |
template <typename CGALPointType, int dim, int spacedim> |
| 91 |
void |
| 92 |
dealii_tria_to_cgal_surface_mesh( |
| 93 |
const dealii::Triangulation<dim, spacedim> &triangulation, |
| 94 |
CGAL::Surface_mesh<CGALPointType> &mesh); |
| 95 |
} // namespace CGALWrappers |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
DEAL_II_NAMESPACE_CLOSE |
| 100 |
|
| 101 |
#else |
| 102 |
|
| 103 |
// Make sure the scripts that create the C++20 module input files have |
| 104 |
// something to latch on if the preprocessor #ifdef above would |
| 105 |
// otherwise lead to an empty content of the file. |
| 106 |
DEAL_II_NAMESPACE_OPEN |
| 107 |
DEAL_II_NAMESPACE_CLOSE |
| 108 |
|
| 109 |
#endif |
| 110 |
#endif |