3#ifndef DUNE_MMESH_CGAL_TRIANGULATIONWRAPPER_HH
4#define DUNE_MMESH_CGAL_TRIANGULATIONWRAPPER_HH
9#include <dune/grid/common/exceptions.hh>
14template <
class Coordinate>
17 Plane(
const Coordinate& a,
const Coordinate& b) {
20 std::swap(n_[0], n_[1]);
27 template <
class Vertex>
28 Plane(
const Vertex& a,
const Vertex& b)
29 : Plane(makeFieldVector(a->point()), makeFieldVector(b->point())) {}
31 auto signedDistance(
const Coordinate& x)
const {
return n_ * (x - p_); }
33 template <
class Vertex>
34 auto signedDistance(
const Vertex& vh)
const {
35 return signedDistance(makeFieldVector(vh->point()));
44class TriangulationWrapper<2> :
public MMeshDefaults::Triangulation<2>::type {
46 using BaseType =
typename MMeshDefaults::Triangulation<2>::type;
48 using CellHandle =
typename BaseType::Face_handle;
49 using FacetHandle = std::pair<typename BaseType::Face_handle, int>;
50 using VertexHandle =
typename BaseType::Vertex_handle;
52 using Vertex_pair = std::pair<VertexHandle, VertexHandle>;
53 using Vertex_pair_Facet_map = std::map<Vertex_pair, FacetHandle>;
54 using Vertex_handle_unique_hash_map = std::map<VertexHandle, VertexHandle>;
57 template <
class VertexHandle,
class Elements>
58 void removeAndGiveNewElements(
const VertexHandle& vh, Elements& elements) {
59 std::list<FacetHandle> hole;
60 this->make_hole(vh, hole);
61 this->fill_hole_delaunay(hole, std::back_inserter(elements));
62 this->delete_vertex(vh);
65 template <
class VertexHandle,
class Elements>
66 void remeshHoleConstrained(
const VertexHandle& vh,
67 std::list<FacetHandle>& hole, Elements& elements,
68 const std::vector<VertexHandle> constraint) {
69 assert(constraint.size() == 2);
71 std::list<FacetHandle> hole1;
72 std::list<FacetHandle> hole2;
74 Plane<FieldVector<double, 2> > plane(constraint[0], constraint[1]);
79 auto helperface = create_face();
80 FacetHandle helperfacet(helperface, 0);
83 for (
const FacetHandle& facet : hole) {
84 const auto& vh = facet.first->vertex((facet.second + 1) % 3);
86 if (vh == constraint[0] || vh == constraint[1]) {
87 const auto& vh2 = facet.first->vertex((facet.second + 2) % 3);
88 if (plane.signedDistance(vh2) > 0) {
89 hole1.push_back(facet);
91 hole1.push_back(helperfacet);
93 hole2.push_back(facet);
95 hole2.push_back(helperfacet);
98 if (plane.signedDistance(vh) > 0)
99 hole1.push_back(facet);
101 hole2.push_back(facet);
106 helperface->set_vertices(VertexHandle(), right, left);
107 this->fill_hole(vh, hole1, std::back_inserter(elements));
110 helperface->set_vertices(VertexHandle(), left, right);
111 this->fill_hole(vh, hole2, std::back_inserter(elements));
116 for (
auto f : elements)
117 for (
int i = 0; i < 3; ++i)
118 if (f->neighbor(i) == helperface) {
119 if (f1 == Face_handle()) {
123 f->set_neighbor(i, f1);
124 f1->set_neighbor(i1, f);
127 delete_face(helperface);
132 DUNE_THROW(GridError,
"Could not remesh hole with interface.");
136 Vertex_pair make_vertex_pair(FacetHandle f)
const {
138 vp.first = f.first->vertex((f.second + 1) % 3);
139 vp.second = f.first->vertex((f.second + 2) % 3);
141 if (vp.first > vp.second) std::swap(vp.first, vp.second);
149class TriangulationWrapper<3> :
public MMeshDefaults::Triangulation<3>::type {
151 using BaseType =
typename MMeshDefaults::Triangulation<3>::type;
154 template <
class VertexHandle,
class Elements>
155 void removeAndGiveNewElements(
const VertexHandle& v, Elements fit) {
156 DUNE_THROW(GridError,
"Removal is not supported in 3D!");
164 using BaseType =
typename MMeshDefaults::Delaunay<dim>::type;
DelaunayTriangulationWrapper.
Definition: triangulationwrapper.hh:162
TriangulationWrapper<2>
Definition: triangulationwrapper.hh:44
TriangulationWrapper<3>
Definition: triangulationwrapper.hh:149
Helpers for conversion from CGAL::Point_x to DUNE::FieldVector.