Loading [MathJax]/extensions/tex2jax.js

dune-mmesh (1.4)

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{
14
15 template< class Coordinate >
16 class Plane
17 {
18 public:
19 Plane( const Coordinate& a, const Coordinate& b )
20 {
21 n_ = a;
22 n_ -= b;
23 std::swap( n_[0], n_[1] );
24 n_[0] *= -1.0;
25 n_ /= n_.two_norm();
26
27 p_ = a;
28 }
29
30 template< class Vertex >
31 Plane( const Vertex& a, const Vertex& b )
32 : Plane( makeFieldVector( a->point() ), makeFieldVector( b->point() ) )
33 {}
34
35 auto signedDistance( const Coordinate& x ) const
36 {
37 return n_ * (x - p_);
38 }
39
40 template< class Vertex >
41 auto signedDistance( const Vertex& vh ) const
42 {
43 return signedDistance( makeFieldVector( vh->point() ) );
44 }
45
46 private:
47 Coordinate p_, n_;
48 };
49
51 template<>
52 class TriangulationWrapper<2> :
53 public MMeshDefaults::Triangulation<2>::type
54 {
56 using BaseType = typename MMeshDefaults::Triangulation<2>::type;
57
58 using CellHandle = typename BaseType::Face_handle;
59 using FacetHandle = std::pair<typename BaseType::Face_handle, int>;
60 using VertexHandle = typename BaseType::Vertex_handle;
61
62 using Vertex_pair = std::pair< VertexHandle, VertexHandle >;
63 using Vertex_pair_Facet_map = std::map< Vertex_pair, FacetHandle >;
64 using Vertex_handle_unique_hash_map = std::map< VertexHandle, VertexHandle >;
65
66 public:
67 template< class VertexHandle, class Elements >
68 void removeAndGiveNewElements (const VertexHandle& vh, Elements& elements)
69 {
70 std::list<FacetHandle> hole;
71 this->make_hole(vh, hole);
72 this->fill_hole_delaunay(hole, std::back_inserter(elements));
73 this->delete_vertex(vh);
74 }
75
76 template< class VertexHandle, class Elements >
77 void remeshHoleConstrained(const VertexHandle& vh, std::list<FacetHandle>& hole, Elements& elements, const std::vector<VertexHandle> constraint)
78 {
79 assert( constraint.size() == 2 );
80
81 std::list<FacetHandle> hole1;
82 std::list<FacetHandle> hole2;
83
84 Plane< FieldVector<double, 2> > plane ( constraint[0], constraint[1] );
85
86 VertexHandle right;
87 VertexHandle left;
88
89 auto helperface = create_face();
90 FacetHandle helperfacet (helperface, 0);
91
92 // collect facets corresponding to their side of the constraint
93 for( const FacetHandle& facet : hole )
94 {
95 const auto& vh = facet.first->vertex( (facet.second+1)%3 );
96
97 if ( vh == constraint[0] || vh == constraint[1] )
98 {
99 const auto& vh2 = facet.first->vertex( (facet.second+2)%3 );
100 if ( plane.signedDistance( vh2 ) > 0 )
101 {
102 hole1.push_back( facet );
103 left = vh;
104 hole1.push_back( helperfacet );
105 }
106 else
107 {
108 hole2.push_back( facet );
109 right = vh;
110 hole2.push_back( helperfacet );
111 }
112 }
113 else
114 {
115 if ( plane.signedDistance( vh ) > 0 )
116 hole1.push_back( facet );
117 else
118 hole2.push_back( facet );
119 }
120 }
121
122 // fill hole1
123 helperface->set_vertices( VertexHandle(), right, left );
124 this->fill_hole(vh, hole1, std::back_inserter(elements));
125
126 // fill hole2
127 helperface->set_vertices( VertexHandle(), left, right );
128 this->fill_hole(vh, hole2, std::back_inserter(elements));
129
130 // glue the facets at helperface together
131 Face_handle f1; int i1;
132 for ( auto f : elements )
133 for ( int i = 0; i < 3; ++i )
134 if (f->neighbor(i) == helperface)
135 {
136 if (f1 == Face_handle())
137 {
138 f1 = f;
139 i1 = i;
140 }
141 else
142 {
143 f->set_neighbor(i, f1);
144 f1->set_neighbor(i1, f);
145
146 delete_vertex(vh);
147 delete_face(helperface);
148 return;
149 }
150 }
151
152 DUNE_THROW( GridError, "Could not remesh hole with interface." );
153 }
154
155 private:
156 Vertex_pair make_vertex_pair ( FacetHandle f ) const
157 {
158 Vertex_pair vp;
159 vp.first = f.first->vertex( (f.second+1)%3 );
160 vp.second = f.first->vertex( (f.second+2)%3 );
161
162 if ( vp.first > vp.second )
163 std::swap( vp.first, vp.second );
164
165 return vp;
166 }
167 };
168
169
171 template<>
172 class TriangulationWrapper<3> :
173 public MMeshDefaults::Triangulation<3>::type
174 {
176 using BaseType = typename MMeshDefaults::Triangulation<3>::type;
177
178 public:
179 template< class VertexHandle, class Elements >
180 void removeAndGiveNewElements (const VertexHandle& v, Elements fit)
181 {
182 DUNE_THROW( GridError, "Removal is not supported in 3D!" );
183 }
184 }; // end of TriangulationWrapper<3>
185
186
188 template<int dim>
190 public MMeshDefaults::Delaunay<dim>::type
191 {
193 using BaseType = typename MMeshDefaults::Delaunay<dim>::type;
194 };
195
196} // namespace Dune
197
198#endif
DelaunayTriangulationWrapper.
Definition: triangulationwrapper.hh:191
TriangulationWrapper<2>
Definition: triangulationwrapper.hh:54
TriangulationWrapper<3>
Definition: triangulationwrapper.hh:174
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 (Apr 6, 22:49, 2025)