ug4
mark_util_impl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-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__UG_mark_util_impl
34 #define __H__UG_mark_util_impl
35 
37 namespace ug{
38 
39 template <class TEdgeIterator>
41  TEdgeIterator edgesBegin, TEdgeIterator edgesEnd,
42  int subsetIndex, number angle,
43  APosition& aPos,
44  ANormal* paFaceNormal)
45 {
46 
47 // get the position accessor
48  if(!grid.has_vertex_attachment(aPos))
49  return;
50 
52 
53 // we'll store face normals in those vectors:
54  vector3 n[2];
55 
56 // associated faces are stored in this array
57  Face* f[2];
58 
59 // all dot-products between normals lower than minDot mark a crease.
60  number minDot = cos(angle * 3.14159265 / 180.f);
61 
62 // iterate through the edges
63  for(TEdgeIterator iter = edgesBegin; iter != edgesEnd; ++iter)
64  {
65  Edge* e = *iter;
66  // get the associated faces
67  // all edges that do not have exactly 2 associated edges
68  // are regarded as seam-edges
69  if(GetAssociatedFaces(f, grid, e, 2) == 2){
70  // get the normals of the associated faces
71  CalculateNormal(n[0], f[0], aaPos);
72  CalculateNormal(n[1], f[1], aaPos);
73  // if the dot-product is lower than minDot, then the edge is a crease edge.
74  if(VecDot(n[0], n[1]) < minDot)
75  sh.assign_subset(e, subsetIndex);
76  }
77  else{
78  sh.assign_subset(e, subsetIndex);
79  }
80  }
81 }
82 
83 template <class TVertexIterator, class TAPosition>
85  TVertexIterator vrtsBegin, TVertexIterator vrtsEnd,
86  Grid::edge_traits::callback cbPathEdge,
87  int subsetIndex, number angle,
88  TAPosition& aPos)
89 {
90  typedef typename TAPosition::ValueType vector_t;
91 
92  if(!grid.has_vertex_attachment(aPos))
93  return;
94 
96 
98  vector_t dir[2];
99  Edge* pathEdge[2];
100 
101  number dotThreshold = cos(deg_to_rad(angle));
102 
103  for(TVertexIterator iter = vrtsBegin; iter != vrtsEnd; ++iter){
104  Vertex* vrt = *iter;
105  grid.associated_elements(edges, vrt);
106  int numPathEdges = 0;
107 
108  for(size_t i = 0; i < edges.size(); ++i){
109  Edge* e = edges[i];
110  if(cbPathEdge(e)){
111  if(numPathEdges < 2)
112  pathEdge[numPathEdges] = e;
113  ++numPathEdges;
114  }
115  }
116 
117  if(numPathEdges == 2){
118  for(size_t i = 0; i < 2; ++i){
119  Vertex* cv = GetConnectedVertex(pathEdge[i], vrt);
120  VecSubtract(dir[i], aaPos[cv], aaPos[vrt]);
121  VecNormalize(dir[i], dir[i]);
122  }
123 
124  dir[1] *= -1;
125  if(VecDot(dir[0], dir[1]) < dotThreshold)
126  sh.assign_subset(vrt, subsetIndex);
127  }
128  else if(numPathEdges > 0){
129  sh.assign_subset(vrt, subsetIndex);
130  }
131  }
132 }
133 
134 }// end of namespace
135 
136 #endif //__H__mark_util_impl
A generic specialization of IAttachment.
Definition: attachment_pipe.h:263
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
bool has_vertex_attachment(IAttachment &attachment)
Definition: grid.h:798
void associated_elements(traits< Vertex >::secure_container &elemsOut, TElem *e)
Puts all elements of type TAss which are contained in 'e' or which contain 'e' into elemsOut.
Definition: grid_impl.hpp:466
Definition: subset_handler_interface.h:223
void assign_subset(TIterator iterBegin, TIterator iterEnd, int subsetIndex)
Definition: subset_handler_interface_impl.hpp:170
Container which holds an array of pointers.
Definition: pointer_const_array.h:84
size_t size() const
returns the size of the associated array.
Definition: pointer_const_array_impl.hpp:106
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
int CalculateNormal(vector3 &vNormOut, Grid &grid, Edge *e, Grid::AttachmentAccessor< Vertex, APosition > &aaPos, Grid::AttachmentAccessor< Face, ANormal > *paaNormFACE)
Calculates the normal of the given edge.
Definition: edge_util.cpp:314
int GetAssociatedFaces(Face **facesOut, Grid &grid, Edge *e, int maxNumFaces)
writes associated faces of e to facesOut.
Definition: edge_util.cpp:186
Vertex * GetConnectedVertex(Edge *e, Vertex *v)
returns the vertex that is connected to v via e.
Definition: vertex_util.cpp:78
double number
Definition: types.h:124
TNumber deg_to_rad(TNumber deg)
Definition: math_util_impl.hpp:49
void VecNormalize(vector_t &vOut, const vector_t &v)
scales a vector_t to unit length
Definition: math_vector_functions_common_impl.hpp:501
void VecSubtract(vector_t &vOut, const vector_t &v1, const vector_t &v2)
subtracts v2 from v1 and stores the result in a vOut
Definition: math_vector_functions_common_impl.hpp:226
vector_t::value_type VecDot(const vector_t &v1, const vector_t &v2)
returns the dot-product of two vector_ts
Definition: math_vector_functions_common_impl.hpp:385
the ug namespace
UG_API void MarkCorners(Grid &grid, ISubsetHandler &sh, TVertexIterator vrtsBegin, TVertexIterator vrtsEnd, Grid::edge_traits::callback cbPathEdge, int subsetIndex, number angle, TAPosition &aPos)
Definition: mark_util_impl.h:84
UG_API void MarkCreaseEdges(Grid &grid, ISubsetHandler &sh, TEdgeIterator edgesBegin, TEdgeIterator edgesEnd, int subsetIndex, number angle, APosition &aPos=aPosition, ANormal *paFaceNormal=NULL)
Definition: mark_util_impl.h:40
boost::function< bool(base_object *)> callback
callback type for the elements base type.
Definition: grid.h:150