54 #define OPENMESH_LAPLACE_SMOOTHERT_C 72 LaplaceSmootherT<Mesh>::
73 LaplaceSmootherT(Mesh& _mesh)
74 : SmootherT<Mesh>(_mesh)
77 Base::mesh_.add_property(vertex_weights_);
78 Base::mesh_.add_property(edge_weights_);
86 LaplaceSmootherT<Mesh>::
90 Base::mesh_.remove_property(vertex_weights_);
91 Base::mesh_.remove_property(edge_weights_);
100 LaplaceSmootherT<Mesh>::
101 initialize(Component _comp, Continuity _cont)
109 compute_weights(UniformWeighting);
114 compute_weights(CotWeighting);
119 compute_weights(UniformWeighting);
128 template <
class Mesh>
130 LaplaceSmootherT<Mesh>::
131 compute_weights(LaplaceWeighting _weighting)
133 typename Mesh::VertexIter v_it, v_end(Base::mesh_.vertices_end());
134 typename Mesh::EdgeIter e_it, e_end(Base::mesh_.edges_end());
135 typename Mesh::HalfedgeHandle heh0, heh1, heh2;
136 typename Mesh::VertexHandle v0, v1;
138 typename Mesh::Scalar weight, lb(-1.0), ub(1.0);
143 for (v_it=Base::mesh_.vertices_begin(); v_it!=v_end; ++v_it)
144 Base::mesh_.property(vertex_weights_, *v_it) = 0.0;
151 case UniformWeighting:
153 for (e_it=Base::mesh_.edges_begin(); e_it!=e_end; ++e_it)
155 heh0 = Base::mesh_.halfedge_handle(*e_it, 0);
156 heh1 = Base::mesh_.halfedge_handle(*e_it, 1);
157 v0 = Base::mesh_.to_vertex_handle(heh0);
158 v1 = Base::mesh_.to_vertex_handle(heh1);
160 Base::mesh_.property(edge_weights_, *e_it) = 1.0;
161 Base::mesh_.property(vertex_weights_, v0) += 1.0;
162 Base::mesh_.property(vertex_weights_, v1) += 1.0;
172 for (e_it=Base::mesh_.edges_begin(); e_it!=e_end; ++e_it)
174 const typename Mesh::Point *p0, *p1, *p2;
178 heh0 = Base::mesh_.halfedge_handle(*e_it, 0);
179 v0 = Base::mesh_.to_vertex_handle(heh0);
180 p0 = &Base::mesh_.point(v0);
182 heh1 = Base::mesh_.halfedge_handle(*e_it, 1);
183 v1 = Base::mesh_.to_vertex_handle(heh1);
184 p1 = &Base::mesh_.point(v1);
186 heh2 = Base::mesh_.next_halfedge_handle(heh0);
187 p2 = &Base::mesh_.point(Base::mesh_.to_vertex_handle(heh2));
188 d0 = (*p0 - *p2); d0.normalize();
189 d1 = (*p1 - *p2); d1.normalize();
190 weight +=
static_cast<typename Mesh::Scalar
>(1.0) / tan(acos(std::max(lb, std::min(ub,
dot(d0,d1) ))));
192 heh2 = Base::mesh_.next_halfedge_handle(heh1);
193 p2 = &Base::mesh_.point(Base::mesh_.to_vertex_handle(heh2));
194 d0 = (*p0 - *p2); d0.normalize();
195 d1 = (*p1 - *p2); d1.normalize();
196 weight +=
static_cast<typename Mesh::Scalar
>(1.0) / tan(acos(std::max(lb, std::min(ub,
dot(d0,d1) ))));
198 Base::mesh_.property(edge_weights_, *e_it) = weight;
199 Base::mesh_.property(vertex_weights_, v0) += weight;
200 Base::mesh_.property(vertex_weights_, v1) += weight;
210 for (v_it=Base::mesh_.vertices_begin(); v_it!=v_end; ++v_it)
212 weight = Base::mesh_.property(vertex_weights_, *v_it);
214 Base::mesh_.property(vertex_weights_, *v_it) =
static_cast<typename Mesh::Scalar
>(1.0) / weight;
Smooth tangential and normal direction.
Definition: SmootherT.hh:90
Smooth tangential direction.
Definition: SmootherT.hh:88
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:176
Kernel::Normal Normal
Normal type.
Definition: PolyMeshT.hh:114
void initialize(Component _comp, Continuity _cont)
Initialize smoother.
Definition: SmootherT_impl.hh:122
Smooth normal direction.
Definition: SmootherT.hh:89
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59