Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (unstable)

triangulationwrapper.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_MMESH_CGAL_TRIANGULATIONWRAPPER_HH
4#define DUNE_MMESH_CGAL_TRIANGULATIONWRAPPER_HH
5
9#include <dune/grid/common/exceptions.hh>
11
12namespace Dune {
13
14template <class Coordinate>
15class Plane {
16 public:
17 Plane(const Coordinate& a, const Coordinate& b) {
18 n_ = a;
19 n_ -= b;
20 std::swap(n_[0], n_[1]);
21 n_[0] *= -1.0;
22 n_ /= n_.two_norm();
23
24 p_ = a;
25 }
26
27 template <class Vertex>
28 Plane(const Vertex& a, const Vertex& b)
29 : Plane(makeFieldVector(a->point()), makeFieldVector(b->point())) {}
30
31 auto signedDistance(const Coordinate& x) const { return n_ * (x - p_); }
32
33 template <class Vertex>
34 auto signedDistance(const Vertex& vh) const {
35 return signedDistance(makeFieldVector(vh->point()));
36 }
37
38 private:
39 Coordinate p_, n_;
40};
41
43template <>
44class TriangulationWrapper<2> : public MMeshDefaults::Triangulation<2>::type {
46 using BaseType = typename MMeshDefaults::Triangulation<2>::type;
47
48 using CellHandle = typename BaseType::Face_handle;
49 using FacetHandle = std::pair<typename BaseType::Face_handle, int>;
50 using VertexHandle = typename BaseType::Vertex_handle;
51
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>;
55
56 public:
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);
63 }
64
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);
70
71 std::list<FacetHandle> hole1;
72 std::list<FacetHandle> hole2;
73
74 Plane<FieldVector<double, 2> > plane(constraint[0], constraint[1]);
75
76 VertexHandle right;
77 VertexHandle left;
78
79 auto helperface = create_face();
80 FacetHandle helperfacet(helperface, 0);
81
82 // collect facets corresponding to their side of the constraint
83 for (const FacetHandle& facet : hole) {
84 const auto& vh = facet.first->vertex((facet.second + 1) % 3);
85
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);
90 left = vh;
91 hole1.push_back(helperfacet);
92 } else {
93 hole2.push_back(facet);
94 right = vh;
95 hole2.push_back(helperfacet);
96 }
97 } else {
98 if (plane.signedDistance(vh) > 0)
99 hole1.push_back(facet);
100 else
101 hole2.push_back(facet);
102 }
103 }
104
105 // fill hole1
106 helperface->set_vertices(VertexHandle(), right, left);
107 this->fill_hole(vh, hole1, std::back_inserter(elements));
108
109 // fill hole2
110 helperface->set_vertices(VertexHandle(), left, right);
111 this->fill_hole(vh, hole2, std::back_inserter(elements));
112
113 // glue the facets at helperface together
114 Face_handle f1;
115 int i1;
116 for (auto f : elements)
117 for (int i = 0; i < 3; ++i)
118 if (f->neighbor(i) == helperface) {
119 if (f1 == Face_handle()) {
120 f1 = f;
121 i1 = i;
122 } else {
123 f->set_neighbor(i, f1);
124 f1->set_neighbor(i1, f);
125
126 delete_vertex(vh);
127 delete_face(helperface);
128 return;
129 }
130 }
131
132 DUNE_THROW(GridError, "Could not remesh hole with interface.");
133 }
134
135 private:
136 Vertex_pair make_vertex_pair(FacetHandle f) const {
137 Vertex_pair vp;
138 vp.first = f.first->vertex((f.second + 1) % 3);
139 vp.second = f.first->vertex((f.second + 2) % 3);
140
141 if (vp.first > vp.second) std::swap(vp.first, vp.second);
142
143 return vp;
144 }
145};
146
148template <>
149class TriangulationWrapper<3> : public MMeshDefaults::Triangulation<3>::type {
151 using BaseType = typename MMeshDefaults::Triangulation<3>::type;
152
153 public:
154 template <class VertexHandle, class Elements>
155 void removeAndGiveNewElements(const VertexHandle& v, Elements fit) {
156 DUNE_THROW(GridError, "Removal is not supported in 3D!");
157 }
158}; // end of TriangulationWrapper<3>
159
161template <int dim>
162class DelaunayTriangulationWrapper : public MMeshDefaults::Delaunay<dim>::type {
164 using BaseType = typename MMeshDefaults::Delaunay<dim>::type;
165};
166
167} // namespace Dune
168
169#endif
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.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Mar 17, 23:30, 2025)