dune-mmesh (1.4)

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
12#include <dune/mmesh/grid/polygoncutting.hh>
14
15namespace Dune
16{
17
18 namespace MMeshImpl
19 {
20
21 template<class Entity>
22 class CutSetTriangulation
23 {
24 static constexpr int dim = Entity::dimension;
25 using ctype = typename Entity::Geometry::ctype;
26 using GlobalCoordinate = typename Entity::Geometry::GlobalCoordinate;
27
28 using EntityImpl = typename Entity::Implementation;
29 using EntityList = std::vector< Entity >;
30 using CachingEntity = MMeshCachingEntity< 0, dim, const typename EntityImpl::Grid >;
31
32 public:
33 CutSetTriangulation(const CachingEntity& caching, const Entity& element)
34 {
35 static_assert( dim == 2 );
36
37 const auto& cgeo = caching.geometry();
38 const auto& host = element.impl().hostEntity();
39
40 std::array<GlobalCoordinate, 3> c, e;
41
42 for ( int i = 0; i < 3; ++i )
43 {
44 c[i] = cgeo.corner(i);
45 // obtain vertices in ccw order
46 e[i] = makeFieldVector( host->vertex(i)->point() );
47 }
48
49 // check orientation of caching entity
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]);
51 if (o > 0) // clock wise
52 std::swap(c[1], c[2]);
53
54 using PC = Dune::PolygonCutting<ctype, GlobalCoordinate>;
55 auto points = PC::sutherlandHodgman(c, e);
56
57 if (points.size() < 3)
58 return;
59
60 // we know the intersection polygon of two triangles is convex
61 for (std::size_t i = 1; i < points.size()-1; ++i)
62 {
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 );
66 }
67 }
68
69 const EntityList& triangles() const
70 {
71 return triangles_;
72 }
73
74 EntityList& triangles()
75 {
76 return triangles_;
77 }
78
79 private:
80 EntityList triangles_;
81
82 }; // end of CutSetTriangulation
83
84 } // namespace MMeshImpl
85
86} // namespace Dune
87
88#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 (Apr 6, 22:49, 2025)