FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
vertex_set.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
9#include <kernel/shape.hpp>
10#include <kernel/util/tiny_algebra.hpp>
11#include <kernel/adjacency/permutation.hpp>
12
13// includes, system
14#include <vector>
15
16namespace FEAT
17{
18 namespace Geometry
19 {
33 template<
34 int num_coords_,
35 typename Coord_ = Real>
36 struct VertexSet
37 {
38 static_assert(num_coords_ > 0, "invalid num_coords_ parameter");
39
40 public:
42 static constexpr int num_coords = num_coords_;
43
45 typedef Coord_ CoordType;
46
49
50 protected:
52 std::vector<VertexType> _vertices;
53
55 template<int sm_, int sn_, int sv_>
56 static void _aux_rot_mat(
59 {
60 r.set_identity();
61 }
62
63 template<int sm_, int sn_, int sv_>
64 static void _aux_rot_mat(
67 {
68 r.set_rotation_2d(a[0]);
69 }
70
71 template<int sm_, int sn_, int sv_>
72 static void _aux_rot_mat(
75 {
76 r.set_rotation_3d(a[0], a[1], a[2]);
77 }
78
80
82 explicit VertexSet(const std::vector<VertexType>& vtx) :
83 _vertices(vtx)
84 {
85 }
86
87 public:
90 _vertices()
91 {
92 }
93
100 explicit VertexSet(Index num_vertices) :
101 _vertices(std::size_t(num_vertices))
102 {
103 }
104
107 _vertices(std::forward<std::vector<VertexType>>(other._vertices))
108 {
109 }
110
113 {
114 // avoid self-move
115 if(this == &other)
116 return *this;
117 _vertices = std::forward<std::vector<VertexType>>(other._vertices);
118 return *this;
119 }
120
122 virtual ~VertexSet()
123 {
124 }
125
128 {
129 return VertexSet(this->_vertices);
130 }
131
132 template<typename DT2_>
133 std::vector<Tiny::Vector<DT2_,num_coords>> clone_internal_vector() const
134 {
135 std::vector<Tiny::Vector<DT2_,num_coords>> tmp(_vertices.size());
136 for(std::size_t i = 0; i < std::size_t(_vertices.size()); ++i)
137 {
138 for(int j = 0; j < num_coords; ++j)
139 tmp[i][j] = DT2_(_vertices[i][j]);
140 }
141 return tmp;
142 }
143
145 std::size_t bytes() const
146 {
147 return _vertices.size() * sizeof(VertexType);
148 }
149
151 int get_num_coords() const
152 {
153 return num_coords_;
154 }
155
158 {
159 return Index(_vertices.size());
160 }
161
172 {
174 return _vertices[i];
175 }
176
179 {
181 return _vertices[i];
182 }
183
190 {
191 return &_vertices[0];
192 }
193
195 const VertexType* begin() const
196 {
197 return &_vertices[0];
198 }
199
206 {
207 return &_vertices.back() + 1;
208 }
209
211 const VertexType* end() const
212 {
213 return &_vertices.back() + 1;
214 }
215
242 void transform(const VertexType& origin, const VertexType& angles, const VertexType& offset)
243 {
244 // create rotation matrix
246 _aux_rot_mat(rot, angles);
247
248 // transform all vertices
249 for(auto& v : _vertices)
250 {
251 v.set_mat_vec_mult(rot, v - origin) += offset;
252 }
253 }
254
264 void permute(const Adjacency::Permutation& perm, bool invert = false)
265 {
266 if(!perm.empty() && !_vertices.empty())
267 {
268 XASSERT(Index(_vertices.size()) == perm.size());
269 perm.apply(_vertices.data(), invert);
270 }
271 }
272
274 static String name()
275 {
276 return "VertexSet<...>";
277 }
278 }; // class VertexSet<...>
279
280 } // namespace Geometry
281} // namespace FEAT
#define ASSERT(expr)
Debug-Assertion macro definition.
Definition: assertion.hpp:229
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
Index size() const
returns the size of the permutation
bool empty() const
Checks whether the permutation is empty.
void apply(Tx_ *x, bool invert=false) const
Applies In-Situ permutation.
String class implementation.
Definition: string.hpp:47
Tiny Matrix class template.
CUDA_HOST_DEVICE Matrix & set_rotation_3d(T_ yaw, T_ pitch, T_ roll)
Sets this matrix to a 3D yaw-pitch-roll rotation matrix.
CUDA_HOST_DEVICE Matrix & set_rotation_2d(T_ angle)
Sets this matrix to a 2D rotation matrix.
CUDA_HOST_DEVICE Matrix & set_identity()
Sets this matrix to the identity matrix.
Tiny Vector class template.
@ other
generic/other permutation strategy
FEAT namespace.
Definition: adjactor.hpp:12
double Real
Real data type.
std::uint64_t Index
Index data type.
Fixed-Sized Vertex Set class template.
Definition: vertex_set.hpp:37
Index get_num_vertices() const
Returns the number of vertices in the vertex set.
Definition: vertex_set.hpp:157
VertexSet(VertexSet &&other)
move constructor
Definition: vertex_set.hpp:106
static constexpr int num_coords
number of coordinates per vertex
Definition: vertex_set.hpp:42
void permute(const Adjacency::Permutation &perm, bool invert=false)
Applies a permutation onto this vertex set.
Definition: vertex_set.hpp:264
const VertexType & operator[](Index i) const
Returns a reference to a vertex.
Definition: vertex_set.hpp:178
VertexSet(const std::vector< VertexType > &vtx)
internal clone constructor
Definition: vertex_set.hpp:82
Coord_ CoordType
vertex coordinate type
Definition: vertex_set.hpp:45
std::size_t bytes() const
Definition: vertex_set.hpp:145
int get_num_coords() const
Returns the number of coordinates per vertex.
Definition: vertex_set.hpp:151
VertexType & operator[](Index i)
Returns a reference to a vertex.
Definition: vertex_set.hpp:171
const VertexType * end() const
Iterator to the first element.
Definition: vertex_set.hpp:211
const VertexType * begin() const
Iterator to the first element.
Definition: vertex_set.hpp:195
VertexSet()
standard constructor
Definition: vertex_set.hpp:89
VertexSet clone() const
Definition: vertex_set.hpp:127
VertexSet(Index num_vertices)
Constructor.
Definition: vertex_set.hpp:100
std::vector< VertexType > _vertices
vertex vector
Definition: vertex_set.hpp:52
VertexSet & operator=(VertexSet &&other)
move-assignment operator
Definition: vertex_set.hpp:112
VertexType * end()
Iterator past the last element.
Definition: vertex_set.hpp:205
void transform(const VertexType &origin, const VertexType &angles, const VertexType &offset)
Applies a "proper rigid" transformation onto the vertex set.
Definition: vertex_set.hpp:242
VertexType * begin()
Iterator to the first element.
Definition: vertex_set.hpp:189
virtual ~VertexSet()
virtual destructor
Definition: vertex_set.hpp:122
Tiny::Vector< CoordType, num_coords > VertexType
vertex type
Definition: vertex_set.hpp:48
static String name()
Returns the name of the class.
Definition: vertex_set.hpp:274