OMToolkit 1.0 The polygonal mesh processing tool.

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OMSmoother.h
Go to the documentation of this file.
1 #ifndef _OMSMOOTHER_H_
2 #define _OMSMOOTHER_H_
3
4 #include <OMToolkit\OMTypes.h>
5 #include <OMToolkit\OMGaussFunc.h>
6 #include <OpenMesh\Tools\Smoother\JacobiLaplaceSmootherT.hh>
7 namespace OMToolkit {
8
9 class OMSmoother
10 {
11 public:
12 typedef Types::ModuleMeshd MeshT;
13 typedef MeshT::Point PointT;
14 typedef MeshT::Normal NormalT;
15 typedef MeshT::Scalar ScalarT;
16 typedef MeshT::VertexHandle VertexH;
17
18 OMSmoother(MeshT *mesh, OpenMesh::VPropHandleT<NormalT> &curvVectorHandle, OpenMesh::VPropHandleT<ScalarT> &curvHandle, ScalarT gaussF);
19 ~OMSmoother();
20
21 void smooth(int n, ScalarT alpha);
22
23 private:
24
25 void computeWeightsAround(VertexH vertex);
26 OpenMesh::VPropHandleT<PointT> original_positions;
27 OpenMesh::VPropHandleT<NormalT> original_normals;
28 OpenMesh::VPropHandleT<ScalarT> weight;
29 OpenMesh::VPropHandleT<NormalT> weight_direction;
30 OMGaussFunction<ScalarT> *gaussFunc;
31 MeshT *m_mesh;
32 };
33
34
35
36 typedef Types::ModuleMeshd MeshT;
37
38 class smoother2 : public OpenMesh::Smoother::JacobiLaplaceSmootherT<MeshT>
39 {
40 public:
41
42
43 smoother2(MeshT *mesh) : OpenMesh::Smoother::JacobiLaplaceSmootherT<Types::ModuleMeshd>::JacobiLaplaceSmootherT(*mesh)
44 {
45
46 }
47 typedef SmootherT<MeshT> Base;
48 enum LaplaceWeighting {jedna};
49 void compute_weights(LaplaceWeighting _weighting)
50 {
51 MeshT::VertexIter v_it, v_end(Base::mesh_.vertices_end());
52 MeshT::EdgeIter e_it, e_end(Base::mesh_.edges_end());
53 MeshT::HalfedgeHandle heh0, heh1, heh2;
54 MeshT::VertexHandle v0, v1;
55 //const MeshT::Point *p0, *p1, *p2;
56 MeshT::Normal d0, d1;
57 MeshT::Scalar weight, lb(-1.0), ub(1.0);
58
59
60
61 OpenMesh::VPropHandleT<float> vertex_weights_;
62 Base::mesh_.add_property(vertex_weights_);
63
64 OpenMesh::EPropHandleT<float> edge_weights_;
65 Base::mesh_.add_property(edge_weights_);
66 // init vertex weights
67 for (v_it=Base::mesh_.vertices_begin(); v_it!=v_end; ++v_it)
68 Base::mesh_.property(vertex_weights_, v_it) = 0.0;
69
70
71 // Uniform weighting
72
73 for (e_it=Base::mesh_.edges_begin(); e_it!=e_end; ++e_it)
74 {
75 heh0 = Base::mesh_.halfedge_handle(e_it.handle(), 0);
76 heh1 = Base::mesh_.halfedge_handle(e_it.handle(), 1);
77 v0 = Base::mesh_.to_vertex_handle(heh0);
78 v1 = Base::mesh_.to_vertex_handle(heh1);
79
80 Base::mesh_.property(edge_weights_, e_it) = 1.0;
81 Base::mesh_.property(vertex_weights_, v0) += 1.0;
82 Base::mesh_.property(vertex_weights_, v1) += 1.0;
83 }
84
85
86
87
88 // // Cotangent weighting
89 // case CotWeighting:
90 // {
91 // for (e_it=Base::mesh_.edges_begin(); e_it!=e_end; ++e_it)
92 // {
93 //weight = 0.0;
94
95 //heh0 = Base::mesh_.halfedge_handle(e_it.handle(), 0);
96 //v0 = Base::mesh_.to_vertex_handle(heh0);
97 //p0 = &Base::mesh_.point(v0);
98
99 //heh1 = Base::mesh_.halfedge_handle(e_it.handle(), 1);
100 //v1 = Base::mesh_.to_vertex_handle(heh1);
101 //p1 = &Base::mesh_.point(v1);
102
103 //heh2 = Base::mesh_.next_halfedge_handle(heh0);
104 //p2 = &Base::mesh_.point(Base::mesh_.to_vertex_handle(heh2));
105 //d0 = (*p0 - *p2); d0.normalize();
106 //d1 = (*p1 - *p2); d1.normalize();
107 //weight += 1.0 / tan(acos(std::max(lb, std::min(ub, dot(d0,d1) ))));
108
109 //heh2 = Base::mesh_.next_halfedge_handle(heh1);
110 //p2 = &Base::mesh_.point(Base::mesh_.to_vertex_handle(heh2));
111 //d0 = (*p0 - *p2); d0.normalize();
112 //d1 = (*p1 - *p2); d1.normalize();
113 //weight += 1.0 / tan(acos(std::max(lb, std::min(ub, dot(d0,d1) ))));
114
115 //Base::mesh_.property(edge_weights_, e_it) = weight;
116 //Base::mesh_.property(vertex_weights_, v0) += weight;
117 //Base::mesh_.property(vertex_weights_, v1) += weight;
118 // }
119 // break;
120 // }
121
122
123
124 // invert vertex weights:
125 // before: sum of edge weights
126 // after: one over sum of edge weights
127 for (v_it=Base::mesh_.vertices_begin(); v_it!=v_end; ++v_it)
128 {
129 weight = Base::mesh_.property(vertex_weights_, v_it);
130 if (weight)
131 Base::mesh_.property(vertex_weights_, v_it) = 1.0 / weight;
132 }
133 }
134 };
135
136
137 } // namespace
138 #endif