ug4
vertex_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__LIB_GRID__VERTEX_UTIL__
34 #define __H__LIB_GRID__VERTEX_UTIL__
35 
36 #include <vector>
37 #include "lib_grid/grid/grid.h"
42 #include "common/math/ugmath.h"
43 
44 namespace ug
45 {
56 // GetVertexIndex
58 
61 UG_API int GetVertexIndex(EdgeVertices* e, Vertex* v);
62 
64 // GetVertexIndex
66 
69 UG_API int GetVertexIndex(FaceVertices* f, Vertex* v);
70 
72 // GetVertexIndex
74 
77 UG_API int GetVertexIndex(VolumeVertices* vol, Vertex* v);
78 
80 // GetConnectedVertex
82 
85 UG_API Vertex* GetConnectedVertex(Edge* e, Vertex* v);
86 
88 // GetConnectedVertex
90 UG_API Vertex* GetConnectedVertex(EdgeVertices* e, Face* f);
91 
93 // GetConnectedVertexIndex
95 UG_API int GetConnectedVertexIndex(Face* f, const EdgeDescriptor& ed);
96 UG_API int GetConnectedVertexIndex(Face* f, const EdgeVertices* e);
97 
100 
101 UG_API Edge* GetConnectedEdge(Grid& g, Vertex* vrt, Face* tri);
102 
103 
106 UG_API Vertex* GetSharedVertex(IVertexGroup* vrts0, IVertexGroup* vrts1);
107 
110 
111 size_t GetSharedVertices(
112  std::vector<Vertex*>& vrtsOut,
113  IVertexGroup* vrts0,
114  IVertexGroup* vrts1);
115 
118 size_t NumSharedVertices(IVertexGroup* vrts0, IVertexGroup* vrts1);
119 
122 UG_API
123 int NumAssociatedEdges(Grid& grid, Vertex* v);
124 
127 UG_API
128 int NumAssociatedFaces(Grid& grid, Vertex* v);
129 
131 // CollectSurfaceNeighborsSorted
133 
140 UG_API
141 bool CollectSurfaceNeighborsSorted(std::vector<Vertex*>& vNeighborsOut,
142  Grid& grid, Vertex* v);
143 
146 template <class TAAPos>
147 UG_API
148 number VertexDistanceSq(Vertex* v0, Vertex* v1, TAAPos& aaPos);
149 
152 template <class TAAPos>
153 UG_API
154 number VertexDistance(Vertex* v0, Vertex* v1, TAAPos& aaPos);
155 
157 // FindVertexByCoordiante
159 
162 UG_API
163 Vertex* FindVertexByCoordiante(vector3& coord, VertexIterator iterBegin,
164  VertexIterator iterEnd,
165  Grid::VertexAttachmentAccessor<APosition>& aaPos);
166 
168 
169 template <size_t dim>
170 int FindVertexByCoordinate(const MathVector<dim>& coord, size_t ncoords, const MathVector<dim> vCoords[]);
171 
174 
178 template <class TAAPosVRT>
179 UG_API
180 void CalculateVertexNormal(vector3& nOut, Grid& grid, Vertex* vrt,
181  TAAPosVRT& aaPos);
182 
185 
197 template <class TAAPosVRT>
198 UG_API
199 void CalculateBoundaryVertexNormal2D(typename TAAPosVRT::ValueType& nOut,
200  Grid& grid, Vertex* vrt,
201  TAAPosVRT& aaPos);
202 
205 
215 template <class TAAPosVRT>
216 UG_API
217 void CalculateBoundaryVertexNormal3D(vector3& nOut, Grid& grid, Vertex* vrt,
218  TAAPosVRT& aaPos);
219 
221 // CalculateVertexNormals
223 
228 UG_API
229 bool CalculateVertexNormals(Grid& grid, APosition& aPos, ANormal& aNorm);
230 
231 UG_API
232 bool CalculateVertexNormals(Grid& grid,
233  Grid::AttachmentAccessor<Vertex, APosition>& aaPos,
234  Grid::AttachmentAccessor<Vertex, ANormal>& aaNorm);
235 
239 // CalculateBoundingBox
241 
242 template <class TVrtIter, class TAPosition>
243 UG_API
244 void
245 CalculateBoundingBox(typename TAPosition::ValueType& vMinOut,
246  typename TAPosition::ValueType& vMaxOut,
247  TVrtIter vrtsBegin, TVrtIter vrtsEnd,
248  Grid::AttachmentAccessor<Vertex, TAPosition>& aaPos);
249 
251 // CalculateCenter
253 
256 template <class TVrtIter, class TAPosition>
257 UG_API
258 typename TAPosition::ValueType
259 CalculateCenter(TVrtIter vrtsBegin, TVrtIter vrtsEnd,
260  Grid::AttachmentAccessor<Vertex, TAPosition>& aaPos);
261 
263 // CalculateBarycenter
265 template <class TVrtIter, class TAPosition>
266 UG_API
267 typename TAPosition::ValueType
268 CalculateBarycenter(TVrtIter vrtsBegin, TVrtIter vrtsEnd,
269  Grid::VertexAttachmentAccessor<TAPosition>& aaPos);
270 
272 // MergeVertices
274 
279 UG_API
280 void MergeVertices(Grid& grid, Vertex* v1, Vertex* v2);
281 
284 
286 template <class TVrtIterator>
287 UG_API
288 Vertex* MergeMultipleVertices(Grid& grid, TVrtIterator vrtsBegin,
289  TVrtIterator vrtsEnd);
290 
292 // RemoveDoubles
294 
302 template <int dim, class TVrtIterator>
303 UG_API
304 void RemoveDoubles(Grid& grid, const TVrtIterator& iterBegin,
305  const TVrtIterator& iterEnd, Attachment<MathVector<dim> >& aPos,
306  number threshold);
307 
308 template <int dim, class TVrtIterator, class TAAPos>
309 UG_API
310 void RemoveDoubles(Grid& grid, const TVrtIterator& iterBegin,
311  const TVrtIterator& iterEnd,
312  TAAPos aaPos,
313  number threshold);
318 
322 UG_API
323 bool IsBoundaryVertex1D(Grid& grid, Vertex* v,
324  Grid::edge_traits::callback cbConsiderEdge = ConsiderAll());
325 
328 
333 UG_API bool IsBoundaryVertex2D(Grid& grid, Vertex* v);
334 
337 
342 UG_API bool IsBoundaryVertex3D(Grid& grid, Vertex* v);
343 
346 UG_API bool LiesOnBoundary(Grid& grid, Vertex* v);
347 
349 // IsRegularSurfaceVertex
351 
357 UG_API bool IsRegularSurfaceVertex(Grid& grid, Vertex* v);
358 
360 
366 UG_API
367 void MarkFixedCreaseVertices(Grid& grid, SubsetHandler& sh,
368  int creaseSI, int fixedSI);
369 
372 
375 template<class TVertexPositionAttachmentAccessor>
376 UG_API
377 inline
378 typename TVertexPositionAttachmentAccessor::ValueType
379 CalculateCenter(const Vertex* v, TVertexPositionAttachmentAccessor& aaPosVRT);
380 
381 template<class TAAPosVRT, class TAAWeightVRT>
382 UG_API
383 typename TAAPosVRT::ValueType
384 CalculateCenter(const Vertex* v, TAAPosVRT& aaPos, TAAWeightVRT& aaWeight);
390 template<class TAAPos> inline
391 UG_API
392 void TransformVertex(Vertex* vrt, matrix33& m, TAAPos& aaPos);
393 
396 template<class TIterator, class TAAPos> inline
397 UG_API
398 void TransformVertices(TIterator vrtsBegin, TIterator vrtsEnd,
399  matrix33& m, TAAPos& aaPos);
400 
403 template<class TIterator, class TAAPos> inline
404 void MoveVertices(TIterator vrtsBegin, TIterator vrtsEnd, TAAPos aaPos,
405  const typename TAAPos::ValueType& offset);
406 
409 
413 template <class vector_t, class TAAPos>
414 UG_API bool
415 ContainsPoint(const Vertex* v, const vector_t& p, TAAPos aaPos);
416 
418 
419 }// end of namespace
420 
422 // include implementation
423 #include "vertex_util_impl.hpp"
424 
425 #endif
bool LiesOnBoundary(Grid &grid, Edge *e)
returns true, if the edge lies on a 2d or 3d boundary
Definition: edge_util.cpp:169
int NumAssociatedFaces(Grid &grid, Edge *e)
returns the number of associated faces of the given edge
Definition: edge_util.cpp:247
UG_API bool ContainsPoint(const EdgeVertices *e, const vector_t &p, TAAPos aaPos)
Returns true if the given point lies on the given edge.
Definition: edge_util_impl.hpp:513
UG_API size_t NumSharedVertices(Grid &grid, TElemPtr1 elem1, TElemPtr2 elem2)
returns the number of vertices that are shared by two objects
Definition: misc_util_impl.hpp:200
UG_API void TransformVertices(TIterator vrtsBegin, TIterator vrtsEnd, matrix33 &m, TAAPos &aaPos)
transforms all given vertices by a given matrix
Definition: vertex_util_impl.hpp:383
bool IsRegularSurfaceVertex(Grid &grid, Vertex *v)
returns true if the vertex lies inside a regular surface
Definition: vertex_util.cpp:601
Vertex * GetSharedVertex(IVertexGroup *vrts0, IVertexGroup *vrts1)
returns the first vertex of vrts0 that is also contained in vrts1 (or NULL if no such vertex exists)
Definition: vertex_util.cpp:134
UG_API void RemoveDoubles(Grid &grid, const TVrtIterator &iterBegin, const TVrtIterator &iterEnd, Attachment< MathVector< dim > > &aPos, number threshold)
merges all vertices that are closer to each other than the specified threshold.
Definition: vertex_util_impl.hpp:255
UG_API number VertexDistance(Vertex *v0, Vertex *v1, TAAPos &aaPos)
Returns the distance between two vertices.
Definition: vertex_util_impl.hpp:54
bool IsBoundaryVertex2D(Grid &grid, Vertex *v)
returns whether a vertex lies on the boundary of a 2D grid.
Definition: vertex_util.cpp:531
bool IsBoundaryVertex1D(Grid &grid, Vertex *v, Grid::edge_traits::callback cbConsiderEdge)
returns whether a vertex lies on the boundary of a polygonal chain.
Definition: vertex_util.cpp:504
int NumAssociatedEdges(Grid &grid, Vertex *v)
returns the number of associated edges of the given vertex
Definition: vertex_util.cpp:200
Edge * GetConnectedEdge(Grid &g, Vertex *vrt, Face *tri)
returns the edge in the triangle tri, which does not contain vrt.
Definition: vertex_util.cpp:121
UG_API void CalculateBoundaryVertexNormal3D(vector3 &nOut, Grid &grid, Vertex *vrt, TAAPosVRT &aaPos)
calculates the normal of a boundary vertex using associated volumes
Definition: vertex_util_impl.hpp:120
bool CollectSurfaceNeighborsSorted(std::vector< Vertex * > &vNeighborsOut, Grid &grid, Vertex *v)
Collects neighbor-vertices in either clockwise or counter clockwise order.
Definition: vertex_util.cpp:217
UG_API Vertex * MergeMultipleVertices(Grid &grid, TVrtIterator vrtsBegin, TVrtIterator vrtsEnd)
Merges all vertices between the given iterators into a single vertex.
Definition: vertex_util_impl.hpp:235
void MoveVertices(TIterator vrtsBegin, TIterator vrtsEnd, TAAPos aaPos, const typename TAAPos::ValueType &offset)
moves vertices by the specified offset
Definition: vertex_util_impl.hpp:392
void MergeVertices(Grid &grid, Vertex *v1, Vertex *v2)
merges two vertices and restructures the adjacent elements.
Definition: vertex_util.cpp:395
size_t GetSharedVertices(std::vector< Vertex * > &vrtsOut, IVertexGroup *vrts0, IVertexGroup *vrts1)
fills a vector with the vertices that are both contained in vrts0 and vrts1.
Definition: vertex_util.cpp:154
bool IsBoundaryVertex3D(Grid &grid, Vertex *v)
returns true if a vertex lies on the boundary of a 3D grid.
Definition: vertex_util.cpp:558
UG_API void CalculateVertexNormal(vector3 &nOut, Grid &grid, Vertex *vrt, TAAPosVRT &aaPos)
calculates the normal of a vertex using associated faces
Definition: vertex_util_impl.hpp:61
UG_API void TransformVertex(Vertex *vrt, matrix33 &m, TAAPos &aaPos)
transforms a vertex by a given matrix
Definition: vertex_util_impl.hpp:374
int GetConnectedVertexIndex(Face *f, const EdgeDescriptor &ed)
returns the index of the first vertex that is contained in the specified face and is not contained in...
Definition: vertex_util.cpp:101
int GetVertexIndex(EdgeVertices *e, Vertex *v)
returns the index at which vertex v is found in the given edge
Definition: vertex_util.cpp:44
UG_API TAPosition::ValueType CalculateBarycenter(TVrtIter vrtsBegin, TVrtIter vrtsEnd, Grid::VertexAttachmentAccessor< TAPosition > &aaPos)
calculates the barycenter of a set of vertices
Definition: vertex_util_impl.hpp:216
UG_API number VertexDistanceSq(Vertex *v0, Vertex *v1, TAAPos &aaPos)
Returns the squared distance between two vertices.
Definition: vertex_util_impl.hpp:47
bool CalculateVertexNormals(Grid &grid, Grid::AttachmentAccessor< Vertex, APosition > &aaPos, Grid::AttachmentAccessor< Vertex, ANormal > &aaNorm)
calculates the normals of all vertices in grid and stores them in aNorm.
Definition: vertex_util.cpp:345
int FindVertexByCoordinate(const MathVector< dim > &coord, size_t ncoords, const MathVector< dim > vCoords[])
returns (non-unique?) index of closest vertex
Definition: vertex_util_impl.hpp:413
UG_API void CalculateBoundaryVertexNormal2D(typename TAAPosVRT::ValueType &nOut, Grid &grid, Vertex *vrt, TAAPosVRT &aaPos)
calculates the normal of a boundary vertex using associated faces
Definition: vertex_util_impl.hpp:81
Vertex * GetConnectedVertex(Edge *e, Vertex *v)
returns the vertex that is connected to v via e.
Definition: vertex_util.cpp:78
Vertex * FindVertexByCoordiante(vector3 &coord, VertexIterator iterBegin, VertexIterator iterEnd, Grid::VertexAttachmentAccessor< APosition > &aaPos)
returns the vertex that is the closest to the given coordinate
Definition: vertex_util.cpp:317
void MarkFixedCreaseVertices(Grid &grid, SubsetHandler &sh, int creaseSI, int fixedSI)
Definition: vertex_util.cpp:615
#define UG_API
Definition: ug_config.h:65
double number
Definition: types.h:124
void CalculateCenter(vector_t &centerOut, const vector_t *pointSet, size_t numPoints)
calculates the center of a point-set
Definition: math_util_impl.hpp:98
MathVector< 3, number > vector3
a 3d vector
Definition: ugmath_types.h:72
MathMatrix< 3, 3, number > matrix33
a 3x3 matrix
Definition: ugmath_types.h:81
the ug namespace
ElementStorage< Vertex >::SectionContainer::iterator VertexIterator
This Iterator will be used as base-class for iterators of specialized geometric objects.
Definition: grid_base_object_traits.h:73
GridSubsetHandler SubsetHandler
Definition: subset_handler_grid.h:376
AABox< typename TAAPos::ValueType > CalculateBoundingBox(Vertex *e, TAAPos aaPos)
calculates the smallest axis aligned box that contains the given vertex
Definition: bounding_box_util.h:43
APosition3 APosition
Definition: common_attachments.h:76
ANormal3 ANormal
Definition: common_attachments.h:77
boost::function< bool(base_object *)> callback
callback type for the elements base type.
Definition: grid.h:150