3#ifndef DUNE_MMESH_GRID_CUTSETTRIANGULATION_HH
4#define DUNE_MMESH_GRID_CUTSETTRIANGULATION_HH
13#include <dune/mmesh/grid/polygoncutting.hh>
19template <
class Entity>
20class CutSetTriangulation {
21 static constexpr int dim = Entity::dimension;
22 using ctype =
typename Entity::Geometry::ctype;
23 using GlobalCoordinate =
typename Entity::Geometry::GlobalCoordinate;
25 using EntityImpl =
typename Entity::Implementation;
26 using EntityList = std::vector<Entity>;
28 MMeshCachingEntity<0, dim, const typename EntityImpl::Grid>;
31 CutSetTriangulation(
const CachingEntity& caching,
const Entity& element) {
32 static_assert(dim == 2);
34 const auto& cgeo = caching.geometry();
35 const auto& host = element.impl().hostEntity();
37 std::array<GlobalCoordinate, 3> c, e;
39 for (
int i = 0; i < 3; ++i) {
40 c[i] = cgeo.corner(i);
42 e[i] = makeFieldVector(host->vertex(i)->point());
46 int o = (c[1][1] - c[0][1]) * (c[2][0] - c[1][0]) -
47 (c[1][0] - c[0][0]) * (c[2][1] - c[1][1]);
49 std::swap(c[1], c[2]);
51 using PC = Dune::PolygonCutting<ctype, GlobalCoordinate>;
52 auto points = PC::sutherlandHodgman(c, e);
54 if (points.size() < 3)
return;
57 for (std::size_t i = 1; i < points.size() - 1; ++i) {
58 EntityImpl entity(&element.impl().grid(),
59 {points[0], points[i], points[i + 1]});
60 if (entity.geometry().volume() > 1e-8) triangles_.emplace_back(entity);
64 const EntityList& triangles()
const {
return triangles_; }
66 EntityList& triangles() {
return triangles_; }
69 EntityList triangles_;
Helpers for conversion from CGAL::Point_x to DUNE::FieldVector.