00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00046
00047
00048
00049
00050
00051
00052 #define OPENMESH_LAPLACE_SMOOTHERT_C
00053
00054
00055
00056 #include <OpenMesh/Tools/Smoother/LaplaceSmootherT.hh>
00057
00058
00059
00060
00061
00062 namespace OpenMesh {
00063 namespace Smoother {
00064
00065
00066
00067
00068
00069 template <class Mesh>
00070 LaplaceSmootherT<Mesh>::
00071 LaplaceSmootherT(Mesh& _mesh)
00072 : SmootherT<Mesh>(_mesh)
00073 {
00074
00075 Base::mesh_.add_property(vertex_weights_);
00076 Base::mesh_.add_property(edge_weights_);
00077 }
00078
00079
00080
00081
00082
00083 template <class Mesh>
00084 LaplaceSmootherT<Mesh>::
00085 ~LaplaceSmootherT()
00086 {
00087
00088 Base::mesh_.remove_property(vertex_weights_);
00089 Base::mesh_.remove_property(edge_weights_);
00090 }
00091
00092
00093
00094
00095
00096 template <class Mesh>
00097 void
00098 LaplaceSmootherT<Mesh>::
00099 initialize(Component _comp, Continuity _cont)
00100 {
00101 SmootherT<Mesh>::initialize(_comp, _cont);
00102
00103
00104 switch (_comp)
00105 {
00106 case Base::Tangential:
00107 compute_weights(UniformWeighting);
00108 break;
00109
00110
00111 case Base::Normal:
00112 compute_weights(CotWeighting);
00113 break;
00114
00115
00116 case Base::Tangential_and_Normal:
00117 compute_weights(UniformWeighting);
00118 break;
00119 }
00120 }
00121
00122
00123
00124
00125
00126 template <class Mesh>
00127 void
00128 LaplaceSmootherT<Mesh>::
00129 compute_weights(LaplaceWeighting _weighting)
00130 {
00131 typename Mesh::VertexIter v_it, v_end(Base::mesh_.vertices_end());
00132 typename Mesh::EdgeIter e_it, e_end(Base::mesh_.edges_end());
00133 typename Mesh::HalfedgeHandle heh0, heh1, heh2;
00134 typename Mesh::VertexHandle v0, v1;
00135 const typename Mesh::Point *p0, *p1, *p2;
00136 typename Mesh::Normal d0, d1;
00137 typename Mesh::Scalar weight, lb(-1.0), ub(1.0);
00138
00139
00140
00141
00142 for (v_it=Base::mesh_.vertices_begin(); v_it!=v_end; ++v_it)
00143 Base::mesh_.property(vertex_weights_, v_it) = 0.0;
00144
00145
00146
00147 switch (_weighting)
00148 {
00149
00150 case UniformWeighting:
00151 {
00152 for (e_it=Base::mesh_.edges_begin(); e_it!=e_end; ++e_it)
00153 {
00154 heh0 = Base::mesh_.halfedge_handle(e_it.handle(), 0);
00155 heh1 = Base::mesh_.halfedge_handle(e_it.handle(), 1);
00156 v0 = Base::mesh_.to_vertex_handle(heh0);
00157 v1 = Base::mesh_.to_vertex_handle(heh1);
00158
00159 Base::mesh_.property(edge_weights_, e_it) = 1.0;
00160 Base::mesh_.property(vertex_weights_, v0) += 1.0;
00161 Base::mesh_.property(vertex_weights_, v1) += 1.0;
00162 }
00163
00164 break;
00165 }
00166
00167
00168
00169 case CotWeighting:
00170 {
00171 for (e_it=Base::mesh_.edges_begin(); e_it!=e_end; ++e_it)
00172 {
00173 weight = 0.0;
00174
00175 heh0 = Base::mesh_.halfedge_handle(e_it.handle(), 0);
00176 v0 = Base::mesh_.to_vertex_handle(heh0);
00177 p0 = &Base::mesh_.point(v0);
00178
00179 heh1 = Base::mesh_.halfedge_handle(e_it.handle(), 1);
00180 v1 = Base::mesh_.to_vertex_handle(heh1);
00181 p1 = &Base::mesh_.point(v1);
00182
00183 heh2 = Base::mesh_.next_halfedge_handle(heh0);
00184 p2 = &Base::mesh_.point(Base::mesh_.to_vertex_handle(heh2));
00185 d0 = (*p0 - *p2); d0.normalize();
00186 d1 = (*p1 - *p2); d1.normalize();
00187 weight += 1.0 / tan(acos(std::max(lb, std::min(ub, dot(d0,d1) ))));
00188
00189 heh2 = Base::mesh_.next_halfedge_handle(heh1);
00190 p2 = &Base::mesh_.point(Base::mesh_.to_vertex_handle(heh2));
00191 d0 = (*p0 - *p2); d0.normalize();
00192 d1 = (*p1 - *p2); d1.normalize();
00193 weight += 1.0 / tan(acos(std::max(lb, std::min(ub, dot(d0,d1) ))));
00194
00195 Base::mesh_.property(edge_weights_, e_it) = weight;
00196 Base::mesh_.property(vertex_weights_, v0) += weight;
00197 Base::mesh_.property(vertex_weights_, v1) += weight;
00198 }
00199 break;
00200 }
00201 }
00202
00203
00204
00205
00206
00207 for (v_it=Base::mesh_.vertices_begin(); v_it!=v_end; ++v_it)
00208 {
00209 weight = Base::mesh_.property(vertex_weights_, v_it);
00210 if (weight)
00211 Base::mesh_.property(vertex_weights_, v_it) = 1.0 / weight;
00212 }
00213 }
00214
00215
00216
00217
00218 }
00219 }
00220