33 #ifndef __H__UG_simplify_polychain
34 #define __H__UG_simplify_polychain
53 template <
class TEdgeIter,
class TAAPos>
55 number curvatureThreshold, TAAPos aaPos)
58 typedef typename TAAPos::ValueType vector_t;
64 vector<Vertex*> candidates;
66 for(TEdgeIter eiter = edgesBegin; eiter != edgesEnd; ++eiter){
69 for(
int i = 0; i < 2; ++i){
72 candidates.push_back(e->
vertex(i));
79 vrts.reserve(candidates.size());
80 vector<number> curvatures;
81 curvatures.reserve(candidates.size());
82 vector<size_t> indices;
83 indices.reserve(candidates.size());
88 while(!candidates.empty()){
93 for(
size_t icandidate = 0; icandidate < candidates.size(); ++icandidate){
94 Vertex* vrt = candidates[icandidate];
98 for(assIter.
reinit(grid, vrt); assIter.
valid(); ++assIter){
109 if(angle <= curvatureThresholdRad){
111 curvatures.push_back(angle);
122 for(
size_t i = 0; i < vrts.size(); ++i)
123 indices.push_back(i);
128 sort(indices.begin(), indices.end(), cmp);
134 for(
size_t ivrt = 0; ivrt < vrts.size(); ++ivrt){
135 Vertex* vrt = vrts[indices[ivrt]];
142 Edge* cedge[2] = {NULL, NULL};
143 Vertex* cvrt[2] = {NULL, NULL};
144 for(assIter.
reinit(grid, vrt); assIter.
valid(); ++assIter){
156 UG_LOG(
"ALGORITHM ERROR in SimplifyPolylines: two connected vertices "
157 "should always be found for a marked candidate... "
158 "ignoring vertex.\n");
168 for(
size_t i = 0; i < 2; ++i){
171 candidates.push_back(cvrt[i]);
181 template <
class TEdgeIter,
class TAAPos>
183 number curvatureThreshold,
186 int smoothingIterations)
190 TAAPos aaSmoothPos(grid, aSmoothPos);
193 aaSmoothPos[*iter] = aaPos[*iter];
196 smoothingAlpha, smoothingIterations);
Iterator that allows to traverse associated elements of a given element.
Definition: associated_elements_iterator.h:51
bool valid() const
Definition: associated_elements_iterator.h:94
void reinit(Grid &grid, TElem *elem)
Definition: associated_elements_iterator.h:73
A generic specialization of IAttachment.
Definition: attachment_pipe.h:263
Can be used to store information about an edge and to construct an edge.
Definition: grid_base_objects.h:464
Base-class for edges.
Definition: grid_base_objects.h:397
virtual Vertex * vertex(size_t index) const
Definition: grid_base_objects.h:366
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 unmark(GridObject *obj)
unmarks the object. Calls are only valid between calls to Grid::begin_marking and Grid::end_marking.
Definition: grid_impl.hpp:808
bool is_marked(GridObject *obj) const
returns true if the object is marked, false if not.
Definition: grid_impl.hpp:843
Edge * get_edge(Vertex *v1, Vertex *v2)
returns the edge between v1 and v2, if it exists. Returns NULL if not.
Definition: grid.cpp:1069
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 erase(GridObject *geomObj)
Definition: grid.cpp:459
void begin_marking()
begin marking.
Definition: grid.cpp:1262
void detach_from_vertices(IAttachment &attachment)
Definition: grid.h:787
geometry_traits< TGeomObj >::iterator begin()
Definition: grid_impl.hpp:164
void attach_to_vertices(IAttachment &attachment, bool passOnValues)
Definition: grid.h:728
geometry_traits< TGeomObj >::iterator create(GridObject *pParent=NULL)
create a custom element.
Definition: grid_impl.hpp:69
geometry_traits< TGeomObj >::iterator end()
Definition: grid_impl.hpp:175
Element callback that returns true, if an element is marked.
Definition: basic_callbacks.h:71
Edges connect two vertices.
Definition: grid_objects_1d.h:66
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Vertex * GetConnectedVertex(Edge *e, Vertex *v)
returns the vertex that is connected to v via e.
Definition: vertex_util.cpp:78
#define UG_LOG(msg)
Definition: log.h:367
double number
Definition: types.h:124
TNumber deg_to_rad(TNumber deg)
Definition: math_util_impl.hpp:49
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 VecAngle(const vector_t &v1, const vector_t &v2)
returns the angle between two vectors in radiants
Definition: math_vector_functions_common_impl.hpp:401
Definition: smart_pointer.h:814
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
void SimplifyPolylines(Grid &grid, TEdgeIter edgesBegin, TEdgeIter edgesEnd, number curvatureThreshold, TAAPos aaPos)
Definition: simplify_polychain.h:54
void SimplifySmoothedPolylines(Grid &grid, TEdgeIter edgesBegin, TEdgeIter edgesEnd, number curvatureThreshold, TAAPos aaPos, number smoothingAlpha, int smoothingIterations)
Definition: simplify_polychain.h:182
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
Definition: simplify_polychain.h:45
IndCmp(const std::vector< number > &vals)
Definition: simplify_polychain.h:46
bool operator()(size_t i1, size_t i2)
Definition: simplify_polychain.h:47
const std::vector< number > & m_vals
Definition: simplify_polychain.h:50