| 1 |
// ------------------------------------------------------------------------ |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
// Copyright (C) 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_polygon_h |
| 16 |
#define dealii_cgal_polygon_h |
| 17 |
|
| 18 |
#include <deal.II/base/config.h> |
| 19 |
|
| 20 |
#ifdef DEAL_II_WITH_CGAL |
| 21 |
# include <deal.II/cgal/point_conversion.h> |
| 22 |
# include <deal.II/cgal/utilities.h> |
| 23 |
|
| 24 |
# include <CGAL/version.h> |
| 25 |
# if CGAL_VERSION_MAJOR >= 6 |
| 26 |
# include <CGAL/Installation/internal/disable_deprecation_warnings_and_errors.h> |
| 27 |
# endif |
| 28 |
# include <CGAL/Polygon_2.h> |
| 29 |
# include <CGAL/Polygon_with_holes_2.h> |
| 30 |
|
| 31 |
|
| 32 |
DEAL_II_NAMESPACE_OPEN |
| 33 |
|
| 34 |
namespace CGALWrappers |
| 35 |
{ |
| 36 |
/** |
| 37 |
* Build a CGAL::Polygon_2 from a deal.II cell. |
| 38 |
* |
| 39 |
* The class Polygon_2 is a wrapper around a container of points that can |
| 40 |
* be used to represent polygons. |
| 41 |
* The points are added in counterclockwise order to a Polygon_2 |
| 42 |
* |
| 43 |
* More information on this class is available at |
| 44 |
* https://doc.cgal.org/latest/Polygon/index.html |
| 45 |
* |
| 46 |
* The functions are for 2D triangulations in 2D space. |
| 47 |
* Projecting 3D points is possible with CGAL but not implemented. |
| 48 |
* |
| 49 |
* The generated boundary representation can be used to perform |
| 50 |
* regularized boolean set-operations. |
| 51 |
* |
| 52 |
* @param[in] cell The input deal.II cell iterator |
| 53 |
* @param[in] mapping The mapping used to map the vertices of the cell |
| 54 |
*/ |
| 55 |
template <typename KernelType> |
| 56 |
CGAL::Polygon_2<KernelType> |
| 57 |
dealii_cell_to_cgal_polygon( |
| 58 |
const typename Triangulation<2, 2>::cell_iterator &cell, |
| 59 |
const Mapping<2, 2> &mapping); |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
/** |
| 64 |
* Convert a deal.II triangulation to a CGAL::Polygon_2. |
| 65 |
* |
| 66 |
* Triangulations that have holes are not supported. |
| 67 |
* |
| 68 |
* @param[in] tria The input deal.II triangulation |
| 69 |
* @param[in] mapping The mapping used to map the vertices of cells |
| 70 |
*/ |
| 71 |
template <typename KernelType> |
| 72 |
CGAL::Polygon_with_holes_2<KernelType> |
| 73 |
dealii_tria_to_cgal_polygon(const Triangulation<2, 2> &tria, |
| 74 |
const Mapping<2, 2> &mapping); |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
/** |
| 79 |
* Constructs a Polygon_with_holes_2 from the input Polygon_2. |
| 80 |
* Further polygons for holes are optional. |
| 81 |
* |
| 82 |
* Polygon_with_holes_2 has function .outer_boundary() as well as |
| 83 |
* .holes() or .holes_begin() and .holes_end() |
| 84 |
* |
| 85 |
* @param[in] boundary_outside Polygon for the outer boundary |
| 86 |
* @param[in] boundary_holes Polygons for the holes |
| 87 |
*/ |
| 88 |
template <typename KernelType> |
| 89 |
CGAL::Polygon_with_holes_2<KernelType> |
| 90 |
polygon_to_polygon_with_holes( |
| 91 |
const CGAL::Polygon_2<KernelType> &boundary_outside, |
| 92 |
const std::vector<CGAL::Polygon_2<KernelType>> &boundary_holes = {}); |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
/** |
| 97 |
* Perform a Regularized Boolean set-operation on two CGAL::Polygon_2. |
| 98 |
* |
| 99 |
* More information on this class is available at |
| 100 |
* https://doc.cgal.org/latest/Boolean_set_operations_2/index.html |
| 101 |
* |
| 102 |
* The output is generally a vector of CGAL::Polygon_2_with_holes. |
| 103 |
* |
| 104 |
* For the union operation the vector will always have length one. |
| 105 |
* |
| 106 |
* For the difference operation the second polygon is subtracted |
| 107 |
* from the first one. |
| 108 |
* |
| 109 |
* Corefinement is not supported as boolean operation. |
| 110 |
* |
| 111 |
* @param[in] polygon_1 The first input CGAL::Polygon_2 |
| 112 |
* @param[in] polygon_2 The second input CGAL::Polygon_2 |
| 113 |
* @param[in] boolean_operation The input BooleanOperation |
| 114 |
*/ |
| 115 |
template <typename KernelType> |
| 116 |
std::vector<CGAL::Polygon_with_holes_2<KernelType>> |
| 117 |
compute_boolean_operation( |
| 118 |
const CGAL::Polygon_with_holes_2<KernelType> &polygon_1, |
| 119 |
const CGAL::Polygon_with_holes_2<KernelType> &polygon_2, |
| 120 |
const BooleanOperation &boolean_operation); |
| 121 |
} // namespace CGALWrappers |
| 122 |
|
| 123 |
DEAL_II_NAMESPACE_CLOSE |
| 124 |
|
| 125 |
#else |
| 126 |
|
| 127 |
// Make sure the scripts that create the C++20 module input files have |
| 128 |
// something to latch on if the preprocessor #ifdef above would |
| 129 |
// otherwise lead to an empty content of the file. |
| 130 |
DEAL_II_NAMESPACE_OPEN |
| 131 |
DEAL_II_NAMESPACE_CLOSE |
| 132 |
|
| 133 |
#endif |
| 134 |
#endif |