33 #ifndef __H__UG__manifold_smoothing__
34 #define __H__UG__manifold_smoothing__
38 #include "../volume_calculation.h"
43 template <
class TIterator,
class AAPosVRT>
45 TIterator vrtsEnd, AAPosVRT& aaPos,
52 bool gotFaces = grid.
num<
Face>() > 0;
55 for(
int iteration = 0; iteration < numIterations; ++iteration){
57 for(TIterator iter = vrtsBegin; iter != vrtsEnd; ++iter){
66 for(
size_t i = 0; i < edges.
size(); ++i){
75 for(
size_t i = 0; i < faces.
size(); ++i){
90 for(
size_t i = 0; i < vols.
size(); ++i){
107 VecAdd(aaPos[vrt], aaPos[vrt], v);
116 template <
class TVrtIter,
class TAAPos3>
121 for(
size_t iteration = 0; iteration < numIterations; ++iteration){
122 for(TVrtIter iter = vrtsBegin; iter != vrtsEnd; ++iter){
130 for(
size_t i = 0; i < faces.
size(); ++i){
138 size_t numConnected = 0;
140 for(
size_t i_face = 0; i_face < faces.
size(); ++i_face){
142 const size_t numVrts = faces[i_face]->num_vertices();
143 for(
size_t i_vrt = 0; i_vrt < numVrts; ++i_vrt){
153 if(numConnected == 0)
174 template <
class TVrtIter,
class TAAPos3>
184 std::vector<vector3*> vrtPos;
185 for(TVrtIter iter = vrtsBegin; iter != vrtsEnd; ++iter){
186 aaInt[*iter] = counter++;
187 vrtPos.push_back(&aaPos[*iter]);
190 std::vector<int> adjVrtInds;
191 std::vector<int> adjVrtOffsets;
192 std::vector<Face*> adjFaces;
193 std::vector<int> adjFaceOffsets;
195 adjVrtInds.reserve(counter * 7);
196 adjVrtOffsets.reserve(counter + 1);
197 vrtPos.reserve(counter);
198 adjFaces.reserve(counter * 7);
199 adjFaceOffsets.reserve(counter + 1);
203 for(TVrtIter iter = vrtsBegin; iter != vrtsEnd; ++iter){
205 adjVrtOffsets.push_back(adjVrtInds.size());
206 adjFaceOffsets.push_back(adjFaces.size());
214 for(
size_t i_face = 0; i_face < faces.
size(); ++i_face){
215 adjFaces.push_back(faces[i_face]);
217 const size_t numVrts = faces[i_face]->num_vertices();
218 for(
size_t i_vrt = 0; i_vrt < numVrts; ++i_vrt){
225 aaInt[v] = (int)vrtPos.size();
226 vrtPos.push_back(&aaPos[v]);
228 adjVrtInds.push_back(aaInt[v]);
235 adjVrtOffsets.push_back(adjVrtInds.size());
236 adjFaceOffsets.push_back(adjFaces.size());
239 std::vector<vector3> offsets(vrtPos.size());
240 std::vector<vector3> newOffsets(vrtPos.size());
242 for(
size_t iteration = 0; iteration < numIterations; ++iteration){
244 for(
size_t i_vrt = 0; i_vrt + 1 < adjVrtOffsets.size(); ++i_vrt){
246 int adjFacesBegin = adjFaceOffsets[i_vrt];
247 int adjFacesEnd = adjFaceOffsets[i_vrt+1];
249 if(adjFacesBegin == adjFacesEnd){
250 offsets[i_vrt] =
vector3(0, 0, 0);
255 for(
int i_adj = adjFacesBegin; i_adj < adjFacesEnd; ++i_adj){
262 int adjVrtsBegin = adjVrtOffsets[i_vrt];
263 int adjVrtsEnd = adjVrtOffsets[i_vrt+1];
265 if(adjVrtsBegin == adjVrtsEnd){
266 offsets[i_vrt] =
vector3(0, 0, 0);
271 for(
int i_adj = adjVrtsBegin; i_adj < adjVrtsEnd; ++i_adj){
272 int adjVrt = adjVrtInds[i_adj];
273 VecAdd(c, c, *vrtPos[adjVrt]);
285 const size_t numOffsetSmoothSteps = 1;
286 for(
size_t i_step = 0; i_step < numOffsetSmoothSteps; ++i_step){
287 for(
size_t i_vrt = 0; i_vrt + 1 < adjVrtOffsets.size(); ++i_vrt){
288 int adjVrtsBegin = adjVrtOffsets[i_vrt];
289 int adjVrtsEnd = adjVrtOffsets[i_vrt+1];
291 if(adjVrtsBegin == adjVrtsEnd)
294 int numAdj = adjVrtsEnd - adjVrtsBegin;
297 VecScale(o, offsets[i_vrt], numAdj);
298 for(
int i_adj = adjVrtsBegin; i_adj < adjVrtsEnd; ++i_adj){
299 int adjVrt = adjVrtInds[i_adj];
300 VecAdd(o, o, offsets[adjVrt]);
305 int adjFacesBegin = adjFaceOffsets[i_vrt];
306 int adjFacesEnd = adjFaceOffsets[i_vrt+1];
308 if(adjFacesBegin == adjFacesEnd){
309 offsets[i_vrt] =
vector3(0, 0, 0);
314 for(
int i_adj = adjFacesBegin; i_adj < adjFacesEnd; ++i_adj){
323 VecSubtract(newOffsets[i_vrt], newOffsets[i_vrt], n);
325 offsets.swap(newOffsets);
329 for(
size_t i_vrt = 0; i_vrt + 1 < adjVrtOffsets.size(); ++i_vrt){
343 template <
class TIterator,
class AAPosVRT>
345 TIterator vrtsEnd, AAPosVRT& aaPos,
349 typedef typename AAPosVRT::ValueType vector_t;
353 for(
int iteration = 0; iteration < numIterations; ++iteration){
355 for(TIterator iter = vrtsBegin; iter != vrtsEnd; ++iter){
358 vector_t vrtPos = aaPos[vrt];
366 for(
size_t i = 0; i < edges.
size(); ++i){
368 if(!cbSmoothVertex(connVrt))
372 number nonSmoothWeight = 1. / std::max<number>(1, numNonSmooth);
374 for(
size_t i = 0; i < edges.
size(); ++i){
377 if(!cbSmoothVertex(connVrt))
384 VecAdd(avDir, avDir, dir);
389 avDir *=
alpha / weight;
390 VecAdd(aaPos[vrt], vrtPos, avDir);
403 template <
class TIterator,
class AAPosVRT>
405 TIterator vrtsEnd, AAPosVRT& aaPos,
409 typedef typename AAPosVRT::ValueType vector_t;
413 for(
int iteration = 0; iteration < numIterations; ++iteration){
415 for(TIterator iter = vrtsBegin; iter != vrtsEnd; ++iter){
418 vector_t vrtPos = aaPos[vrt];
426 for(
size_t i = 0; i < faces.
size(); ++i){
436 if(cbSmoothVertex(v0)){
437 if(cbSmoothVertex(v1))
438 VecScaleAdd(edgeCenter, 0.5, aaPos[v0], 0.5, aaPos[v1]);
440 VecScaleAdd(edgeCenter, 0.75, aaPos[v0], 0.25, aaPos[v1]);
442 else if(cbSmoothVertex(v1))
443 VecScaleAdd(edgeCenter, 0.25, aaPos[v0], 0.75, aaPos[v1]);
445 VecScaleAdd(edgeCenter, 0.5, aaPos[v0], 0.5, aaPos[v1]);
453 VecAdd(avDir, avDir, dir);
458 avDir *=
alpha / weight;
459 VecAdd(aaPos[vrt], vrtPos, avDir);
470 template <
class TIterator,
class AAPosVRT>
472 TIterator vrtsEnd, AAPosVRT& aaPos,
479 typedef typename AAPosVRT::ValueType vector_t;
483 for(
int iteration = 0; iteration < numIterations; ++iteration){
485 for(TIterator iter = vrtsBegin; iter != vrtsEnd; ++iter){
488 vector_t vrtPos = aaPos[vrt];
497 for(
size_t i = 0; i < edges.
size(); ++i){
499 vector_t dir = aaPos[connVrt];
504 if(dot >= dotThreshold){
505 dir *= 0.5 * (dot + 1);
512 avDir *=
alpha / nbrs;
522 template <
class TIterator,
class AAPosVRT>
524 TIterator vrtsEnd, AAPosVRT& aaPos,
531 typedef typename AAPosVRT::ValueType vector_t;
542 for(
int iteration = 0; iteration < numIterations; ++iteration){
544 for(TIterator iter = vrtsBegin; iter != vrtsEnd; ++iter){
547 vector_t vrtPos = aaPos[vrt];
558 for(
size_t i = 0; i < edges.
size(); ++i){
576 VecCross(planeNormal, vrtNorm, upN);
582 for(
size_t i = 0; i < faces.
size(); ++i){
592 if((numInters > 1) &&
598 inters[numInters] = vi;
Base-class for edges.
Definition: grid_base_objects.h:397
virtual Vertex * vertex(size_t index) const
Definition: grid_base_objects.h:366
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
virtual size_t num_vertices() const
Definition: grid_base_objects.h:488
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
void end_marking()
ends a marking sequence. Call this method when you're done with marking.
Definition: grid.cpp:1285
void attach_to_vertices_dv(TAttachment &attachment, const typename TAttachment::ValueType &defaultValue)
Definition: grid.h:754
bool is_marked(GridObject *obj) const
returns true if the object is marked, false if not.
Definition: grid_impl.hpp:843
size_t num() const
Definition: grid_impl.hpp:230
void mark(GridObject *obj)
marks the object. Calls are only valid between calls to Grid::begin_marking and Grid::end_marking.
Definition: grid_impl.hpp:773
void begin_marking()
begin marking.
Definition: grid.cpp:1262
void detach_from_vertices(IAttachment &attachment)
Definition: grid.h:787
GridObject * get_opposing_object(Vertex *vrt, Face *elem)
returns the geometric object on the opposing side of the given vertex regarding the given element.
Definition: grid.cpp:631
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
Vertex *const * ConstVertexArray
Definition: grid_base_objects.h:319
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
bool empty() const
returns true if the associated array is empty
Definition: pointer_const_array_impl.hpp:113
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
bool LiesOnBoundary(Grid &grid, Edge *e)
returns true, if the edge lies on a 2d or 3d boundary
Definition: edge_util.cpp:169
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
bool IsBoundaryEdge2D(Grid &grid, Edge *e)
returns whether an edge lies on the boundary of a 2D grid.
Definition: edge_util.cpp:112
UG_API TAAPosVRT::ValueType CalculateGridObjectCenter(const GridObject *o, TAAPosVRT &aaPosVRT)
calculates the center for arbitrary geometric object
Definition: misc_util_impl.hpp:81
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 CalculateVertexNormal(vector3 &nOut, Grid &grid, Vertex *vrt, TAAPosVRT &aaPos)
calculates the normal of a vertex using associated faces
Definition: vertex_util_impl.hpp:61
Vertex * GetConnectedVertex(Edge *e, Vertex *v)
returns the vertex that is connected to v via e.
Definition: vertex_util.cpp:78
number CalculateVolume(Volume *elem, TAAPos aaPos)
Calculates the volume of the given element.
Definition: volume_calculation_impl.hpp:43
double number
Definition: types.h:124
bool RayPlaneIntersection(vector_t &vOut, number &tOut, const vector_t &rayFrom, const vector_t &rayDir, const vector_t &p, const vector_t &n)
calculates the intersection of the ray rayFrom+t*rayDir and the plane (x-p)*n=0.
Definition: math_util_impl.hpp:360
void ProjectPointToPlane(vector_t &vOut, const vector_t &v, const vector_t &p, const vector_t &n)
projects v onto the plane defined by the point p and the planes normal n.
Definition: math_util_impl.hpp:342
void VecSet(vector_t &vInOut, typename vector_t::value_type s)
Set each vector component to scalar (componentwise)
Definition: math_vector_functions_common_impl.hpp:539
void VecScaleAdd(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1, typename vector_t::value_type s2, const vector_t &v2)
Scales two Vectors, adds them and returns the sum in a third vector.
Definition: math_vector_functions_common_impl.hpp:265
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 VecDistanceSq(const vector_t &v1, const vector_t &v2)
returns the squared distance of two vector_ts.
Definition: math_vector_functions_common_impl.hpp:351
MathVector< 3, number > vector3
a 3d vector
Definition: ugmath_types.h:72
vector_t::value_type VecLengthSq(const vector_t &v)
returns the squared length of v. Faster than VecLength.
Definition: math_vector_functions_common_impl.hpp:324
void VecAdd(vector_t &vOut, const vector_t &v1, const vector_t &v2)
adds two MathVector<N>s and stores the result in a third one
Definition: math_vector_functions_common_impl.hpp:185
void VecScale(vector_t &vOut, const vector_t &v, typename vector_t::value_type s)
scales a MathVector<N>
Definition: math_vector_functions_common_impl.hpp:252
void VecCross(vector_t &vOut, const vector_t &v1, const vector_t &v2)
calculates the cross product of two Vectors of dimension 3. It makes no sense to use VecCross for vec...
Definition: math_vector_functions_common_impl.hpp:437
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
size_t target(SM_edge< typename T::value_type > const &e, ug::BidirectionalMatrix< T > const &m)
Definition: bidirectional_boost.h:100
void TangentialSmooth(Grid &g, TVrtIter vrtsBegin, TVrtIter vrtsEnd, TAAPos3 aaPos, number alpha, size_t numIterations)
Definition: manifold_smoothing.h:175
void SlopeSmooth(Grid &grid, TIterator vrtsBegin, TIterator vrtsEnd, AAPosVRT &aaPos, number alpha, const vector3 &up, int numIterations)
Definition: manifold_smoothing.h:523
const number SMALL
Definition: math_constants.h:41
void WeightedEdgeSmooth(Grid &grid, TIterator vrtsBegin, TIterator vrtsEnd, AAPosVRT &aaPos, number alpha, int numIterations, Grid::vertex_traits::callback cbSmoothVertex)
Definition: manifold_smoothing.h:344
void WeightedNormalSmooth(Grid &grid, TIterator vrtsBegin, TIterator vrtsEnd, AAPosVRT &aaPos, number alpha, number dotThreshold, int numIterations)
Definition: manifold_smoothing.h:471
void TangentialSmoothSimple(Grid &g, TVrtIter vrtsBegin, TVrtIter vrtsEnd, TAAPos3 aaPos, number alpha, size_t numIterations)
Definition: manifold_smoothing.h:117
void WeightedFaceSmooth(Grid &grid, TIterator vrtsBegin, TIterator vrtsEnd, AAPosVRT &aaPos, number alpha, int numIterations, Grid::vertex_traits::callback cbSmoothVertex)
Definition: manifold_smoothing.h:404
void LaplacianSmooth(Grid &grid, TIterator vrtsBegin, TIterator vrtsEnd, AAPosVRT &aaPos, number alpha, int numIterations)
Definition: manifold_smoothing.h:44
boost::function< bool(base_object *)> callback
callback type for the elements base type.
Definition: grid.h:150