54 #define OPENMESH_SMOOTHERT_C 58 #include <OpenMesh/Core/Utils/vector_cast.hh> 78 mesh_.request_vertex_status();
79 mesh_.request_face_normals();
80 mesh_.request_vertex_normals();
83 mesh_.add_property(original_positions_);
84 mesh_.add_property(original_normals_);
85 mesh_.add_property(new_positions_);
86 mesh_.add_property(is_active_);
90 component_ = Tangential_and_Normal;
104 mesh_.release_vertex_status();
105 mesh_.release_face_normals();
106 mesh_.release_vertex_normals();
109 mesh_.remove_property(original_positions_);
110 mesh_.remove_property(original_normals_);
111 mesh_.remove_property(new_positions_);
112 mesh_.remove_property(is_active_);
119 template <
class Mesh>
124 typename Mesh::VertexIter v_it, v_end(mesh_.vertices_end());
138 for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
140 mesh_.property(original_positions_, *v_it) = mesh_.point(*v_it);
141 mesh_.property(original_normals_, *v_it) = mesh_.normal(*v_it);
149 template <
class Mesh>
154 typename Mesh::VertexIter v_it, v_end(mesh_.vertices_end());
158 bool nothing_selected(
true);
159 for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
160 if (mesh_.status(*v_it).selected())
161 { nothing_selected =
false;
break; }
165 for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
167 bool active = ((nothing_selected || mesh_.status(*v_it).selected())
168 && !mesh_.is_boundary(*v_it)
169 && !mesh_.status(*v_it).locked());
171 if ( skip_features_ ) {
173 active = active && !mesh_.status(*v_it).feature();
176 for ( ; voh_it.is_valid() ; ++voh_it ) {
179 if ( mesh_.status(mesh_.edge_handle(*voh_it)).feature() )
182 typename Mesh::FaceHandle fh1 = mesh_.face_handle(*voh_it );
183 typename Mesh::FaceHandle fh2 = mesh_.face_handle(mesh_.opposite_halfedge_handle(*voh_it ) );
186 if ( fh1.is_valid() && mesh_.status( fh1 ).feature() )
188 if ( fh2.is_valid() && mesh_.status( fh2 ).feature() )
194 mesh_.property(is_active_, *v_it) = active;
199 if (continuity_ == C1)
201 typename Mesh::VVIter vv_it;
203 for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
204 if (mesh_.is_boundary(*v_it))
205 for (vv_it=mesh_.vv_iter(*v_it); vv_it.is_valid(); ++vv_it)
206 mesh_.property(is_active_, *vv_it) =
false;
211 if (continuity_ == C2)
213 typename Mesh::VVIter vv_it;
215 for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
217 mesh_.status(*v_it).set_tagged(
false);
218 mesh_.status(*v_it).set_tagged2(
false);
221 for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
222 if (mesh_.is_boundary(*v_it))
223 for (vv_it=mesh_.vv_iter(*v_it); vv_it.is_valid(); ++vv_it)
224 mesh_.status(*v_it).set_tagged(
true);
226 for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
227 if (mesh_.status(*v_it).tagged())
228 for (vv_it=mesh_.vv_iter(*v_it); vv_it.is_valid(); ++vv_it)
229 mesh_.status(*v_it).set_tagged2(
true);
231 for (v_it=mesh_.vertices_begin(); v_it!=v_end; ++v_it)
233 if (mesh_.status(*v_it).tagged2())
234 mesh_.property(is_active_, *vv_it) =
false;
235 mesh_.status(*v_it).set_tagged(
false);
236 mesh_.status(*v_it).set_tagged2(
false);
245 template <
class Mesh>
250 if (!mesh_.vertices_empty())
252 typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
253 v_end(mesh_.vertices_end());
257 Point bb_min, bb_max;
258 bb_min = bb_max = mesh_.point(*v_it);
259 for (++v_it; v_it!=v_end; ++v_it)
261 minimize(bb_min, mesh_.point(*v_it));
262 maximize(bb_max, mesh_.point(*v_it));
267 set_absolute_local_error(norm(_err * (bb_max-bb_min)));
275 template <
class Mesh>
287 template <
class Mesh>
299 template <
class Mesh>
305 set_active_vertices();
310 compute_new_positions();
312 if (component_ == Tangential)
313 project_to_tangent_plane();
315 else if (tolerance_ >= 0.0)
326 template <
class Mesh>
334 compute_new_positions_C0();
338 compute_new_positions_C1();
350 template <
class Mesh>
355 typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
356 v_end(mesh_.vertices_end());
362 for (; v_it != v_end; ++v_it)
364 if (is_active(*v_it))
366 translation = new_position(*v_it)-orig_position(*v_it);
367 normal = orig_normal(*v_it);
368 normal *= dot(translation, normal);
369 translation -= normal;
371 set_new_position(*v_it, translation);
380 template <
class Mesh>
385 typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
386 v_end(mesh_.vertices_end());
392 for (; v_it != v_end; ++v_it)
394 if (is_active(*v_it))
396 translation = new_position(*v_it) - orig_position(*v_it);
398 s = fabs(dot(translation, orig_normal(*v_it)));
402 translation *= (tolerance_ / s);
403 translation +=
vector_cast<NormalType>(orig_position(*v_it));
404 set_new_position(*v_it, translation);
414 template <
class Mesh>
419 typename Mesh::VertexIter v_it(mesh_.vertices_begin()),
420 v_end(mesh_.vertices_end());
422 for (; v_it != v_end; ++v_it)
423 if (is_active(*v_it))
424 mesh_.set_point(*v_it, mesh_.property(new_positions_, *v_it));
void vector_cast(const src_t &_src, dst_t &_dst, GenProg::Int2Type< n >)
Cast vector type to another vector type by copying the vector elements.
Kernel::Normal Normal
Normal type.
SmootherT(Mesh &_mesh)
constructor & destructor
Kernel::VertexOHalfedgeIter VertexOHalfedgeIter
Circulator.
void update_vertex_normals()
Update normal vectors for all vertices.
Kernel::Scalar Scalar
Scalar type.
void update_face_normals()
Update normal vectors for all faces.