dune-mmesh (unstable)

cutsettriangulation.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_GRID_CUTSETTRIANGULATION_HH
4#define DUNE_MMESH_GRID_CUTSETTRIANGULATION_HH
5
13#include <dune/mmesh/grid/polygoncutting.hh>
14
15namespace Dune {
16
17namespace MMeshImpl {
18
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;
24
25 using EntityImpl = typename Entity::Implementation;
26 using EntityList = std::vector<Entity>;
27 using CachingEntity =
28 MMeshCachingEntity<0, dim, const typename EntityImpl::Grid>;
29
30 public:
31 CutSetTriangulation(const CachingEntity& caching, const Entity& element) {
32 static_assert(dim == 2);
33
34 const auto& cgeo = caching.geometry();
35 const auto& host = element.impl().hostEntity();
36
37 std::array<GlobalCoordinate, 3> c, e;
38
39 for (int i = 0; i < 3; ++i) {
40 c[i] = cgeo.corner(i);
41 // obtain vertices in ccw order
42 e[i] = makeFieldVector(host->vertex(i)->point());
43 }
44
45 // check orientation of caching entity
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]);
48 if (o > 0) // clock wise
49 std::swap(c[1], c[2]);
50
51 using PC = Dune::PolygonCutting<ctype, GlobalCoordinate>;
52 auto points = PC::sutherlandHodgman(c, e);
53
54 if (points.size() < 3) return;
55
56 // we know the intersection polygon of two triangles is convex
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);
61 }
62 }
63
64 const EntityList& triangles() const { return triangles_; }
65
66 EntityList& triangles() { return triangles_; }
67
68 private:
69 EntityList triangles_;
70
71}; // end of CutSetTriangulation
72
73} // namespace MMeshImpl
74
75} // namespace Dune
76
77#endif
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 (Sep 5, 22:35, 2025)