dune-mmesh 1.4.1-git
Loading...
Searching...
No Matches
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
14
15namespace Dune {
16
17namespace MMeshImpl {
18
19template <class Entity>
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;
27 using CachingEntity =
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
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
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.
size_type dim() const
static FieldVector< typename Kernel::RT, 2 > makeFieldVector(const CGAL::Point_2< Kernel > &p)
Helper function to create DUNE::FieldVector from CGAL::Point_2.
Definition pointfieldvector.hh:20
const EntityType & entity() const
Implementation & impl()
Definition grid/connectedcomponent.hh:19
Definition cutsettriangulation.hh:20
CutSetTriangulation(const CachingEntity &caching, const Entity &element)
Definition cutsettriangulation.hh:31
EntityList & triangles()
Definition cutsettriangulation.hh:66
const EntityList & triangles() const
Definition cutsettriangulation.hh:64
Definition polygoncutting.hh:9
T emplace_back(T... args)
T swap(T... args)