3#ifndef DUNE_MMESH_CGAL_TRIANGULATIONWRAPPER_HH
4#define DUNE_MMESH_CGAL_TRIANGULATIONWRAPPER_HH
9#include <dune/grid/common/exceptions.hh>
15 template<
class Coordinate >
19 Plane(
const Coordinate& a,
const Coordinate& b )
23 std::swap( n_[0], n_[1] );
30 template<
class Vertex >
31 Plane(
const Vertex& a,
const Vertex& b )
32 : Plane( makeFieldVector( a->point() ), makeFieldVector( b->point() ) )
35 auto signedDistance(
const Coordinate& x )
const
40 template<
class Vertex >
41 auto signedDistance(
const Vertex& vh )
const
43 return signedDistance( makeFieldVector( vh->point() ) );
52 class TriangulationWrapper<2> :
53 public MMeshDefaults::Triangulation<2>::type
56 using BaseType =
typename MMeshDefaults::Triangulation<2>::type;
58 using CellHandle =
typename BaseType::Face_handle;
59 using FacetHandle = std::pair<typename BaseType::Face_handle, int>;
60 using VertexHandle =
typename BaseType::Vertex_handle;
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 >;
67 template<
class VertexHandle,
class Elements >
68 void removeAndGiveNewElements (
const VertexHandle& vh, Elements& elements)
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);
76 template<
class VertexHandle,
class Elements >
77 void remeshHoleConstrained(
const VertexHandle& vh, std::list<FacetHandle>& hole, Elements& elements,
const std::vector<VertexHandle> constraint)
79 assert( constraint.size() == 2 );
81 std::list<FacetHandle> hole1;
82 std::list<FacetHandle> hole2;
84 Plane< FieldVector<double, 2> > plane ( constraint[0], constraint[1] );
89 auto helperface = create_face();
90 FacetHandle helperfacet (helperface, 0);
93 for(
const FacetHandle& facet : hole )
95 const auto& vh = facet.first->vertex( (facet.second+1)%3 );
97 if ( vh == constraint[0] || vh == constraint[1] )
99 const auto& vh2 = facet.first->vertex( (facet.second+2)%3 );
100 if ( plane.signedDistance( vh2 ) > 0 )
102 hole1.push_back( facet );
104 hole1.push_back( helperfacet );
108 hole2.push_back( facet );
110 hole2.push_back( helperfacet );
115 if ( plane.signedDistance( vh ) > 0 )
116 hole1.push_back( facet );
118 hole2.push_back( facet );
123 helperface->set_vertices( VertexHandle(), right, left );
124 this->fill_hole(vh, hole1, std::back_inserter(elements));
127 helperface->set_vertices( VertexHandle(), left, right );
128 this->fill_hole(vh, hole2, std::back_inserter(elements));
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)
136 if (f1 == Face_handle())
143 f->set_neighbor(i, f1);
144 f1->set_neighbor(i1, f);
147 delete_face(helperface);
152 DUNE_THROW( GridError,
"Could not remesh hole with interface." );
156 Vertex_pair make_vertex_pair ( FacetHandle f )
const
159 vp.first = f.first->vertex( (f.second+1)%3 );
160 vp.second = f.first->vertex( (f.second+2)%3 );
162 if ( vp.first > vp.second )
163 std::swap( vp.first, vp.second );
172 class TriangulationWrapper<3> :
173 public MMeshDefaults::Triangulation<3>::type
176 using BaseType =
typename MMeshDefaults::Triangulation<3>::type;
179 template<
class VertexHandle,
class Elements >
180 void removeAndGiveNewElements (
const VertexHandle& v, Elements fit)
182 DUNE_THROW( GridError,
"Removal is not supported in 3D!" );
190 public MMeshDefaults::Delaunay<dim>::type
193 using BaseType =
typename MMeshDefaults::Delaunay<dim>::type;
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.