3#ifndef DUNE_MMESH_GRID_CUTSETTRIANGULATION_HH
4#define DUNE_MMESH_GRID_CUTSETTRIANGULATION_HH
12#include <dune/mmesh/grid/polygoncutting.hh>
21 template<
class Entity>
22 class CutSetTriangulation
24 static constexpr int dim = Entity::dimension;
25 using ctype =
typename Entity::Geometry::ctype;
26 using GlobalCoordinate =
typename Entity::Geometry::GlobalCoordinate;
28 using EntityImpl =
typename Entity::Implementation;
29 using EntityList = std::vector< Entity >;
30 using CachingEntity = MMeshCachingEntity< 0, dim, const typename EntityImpl::Grid >;
33 CutSetTriangulation(
const CachingEntity& caching,
const Entity& element)
35 static_assert( dim == 2 );
37 const auto& cgeo = caching.geometry();
38 const auto& host = element.impl().hostEntity();
40 std::array<GlobalCoordinate, 3> c, e;
42 for (
int i = 0; i < 3; ++i )
44 c[i] = cgeo.corner(i);
46 e[i] = makeFieldVector( host->vertex(i)->point() );
50 int o = (c[1][1]-c[0][1])*(c[2][0]-c[1][0])-(c[1][0]-c[0][0])*(c[2][1]-c[1][1]);
52 std::swap(c[1], c[2]);
54 using PC = Dune::PolygonCutting<ctype, GlobalCoordinate>;
55 auto points = PC::sutherlandHodgman(c, e);
57 if (points.size() < 3)
61 for (std::size_t i = 1; i < points.size()-1; ++i)
63 EntityImpl entity ( &element.impl().grid(), { points[0], points[i], points[i+1] } );
64 if ( entity.geometry().volume() > 1e-8 )
65 triangles_.emplace_back( entity );
69 const EntityList& triangles()
const
74 EntityList& triangles()
80 EntityList triangles_;
Helpers for conversion from CGAL::Point_x to DUNE::FieldVector.