Developer Documentation

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
smooth.cc
1 #include <iostream>
2 #include <vector>
3 // -------------------- OpenMesh
4 #include <OpenMesh/Core/IO/MeshIO.hh>
5 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
6 #include <OpenMesh/Core/Mesh/Traits.hh>
7
8 struct MyTraits : public OpenMesh::DefaultTraits
9 {
10 // store barycenter of neighbors in this member
11 VertexTraits
12 {
13 private:
14 Point cog_;
15 public:
16
17 VertexT() : cog_( Point(0.0f, 0.0f, 0.0f ) ) { }
18
19 const Point& cog() const { return cog_; }
20 void set_cog(const Point& _p) { cog_ = _p; }
21 };
22 };
23
24 typedef OpenMesh::TriMesh_ArrayKernelT<MyTraits> MyMesh;
25 typedef OpenMesh::TriMesh_ArrayKernelT<> MyMesh2;
26
27 // ---------------------------------------------------------------------------
28 #define SIZEOF( entity,b ) \
29 std::cout << _prefix << "size of " << #entity << ": " \
30 << sizeof( entity ) << std::endl; \
31 b += sizeof( entity )
32
33 template <typename Mesh>
34 void print_size(const std::string& _prefix = "")
35 {
36 size_t total=0;
37 SIZEOF(typename Mesh::Vertex, total);
38 SIZEOF(typename Mesh::Halfedge, total);
39 SIZEOF(typename Mesh::Edge, total);
40 SIZEOF(typename Mesh::Face, total);
41 std::cout << _prefix << "total: " << total << std::endl;
42 }
43
44 #undef SIZEOF
45 // ---------------------------------------------------------------------------
46
47
48 int main(int argc, char **argv)
49 {
50 MyMesh mesh;
51
52 // check command line options
53 if (argc < 4 || argc > 5)
54 {
55 std::cerr << "Usage: " << argv[0] << " [-s] #iterations infile outfile\n";
56 exit(1);
57 }
58
59 int idx=2;
60
61 // display size of entities of the enhanced and the default mesh type
62 // when commandline option '-s' has been used.
63 if (argc == 5)
64 {
65 if (std::string("-s")==argv[idx-1])
66 {
67 std::cout << "Enhanced mesh size statistics\n";
68 print_size<MyMesh>(" ");
69
70 std::cout << "Default mesh size statistics\n";
71 print_size<MyMesh2>(" ");
72 }
73 // else ignore!
74 ++idx;
75 }
76
77
78 // read mesh from stdin
79 std::cout<< " Input mesh: " << argv[idx] << std::endl;
80 if ( ! OpenMesh::IO::read_mesh(mesh, argv[idx]) )
81 {
82 std::cerr << "Error: Cannot read mesh from " << argv[idx] << std::endl;
83 return 0;
84 }
85
86
87
88 // smoothing mesh argv[1] times
89 MyMesh::VertexIter v_it, v_end(mesh.vertices_end());
90 MyMesh::VertexVertexIter vv_it;
91 MyMesh::Point cog;
92 MyMesh::Scalar valence;
93 unsigned int i, N(atoi(argv[idx-1]));
94
95 std::cout<< "Smooth mesh " << N << " times\n";
96
97 for (i=0; i < N; ++i)
98 {
99 for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
100 {
101 cog[0] = cog[1] = cog[2] = valence = 0.0;
102
103 for (vv_it=mesh.vv_iter(*v_it); vv_it.is_valid(); ++vv_it)
104 {
105 cog += mesh.point( *vv_it );
106 ++valence;
107 }
108
109 mesh.data(*v_it).set_cog(cog / valence);
110 }
111
112 for (v_it=mesh.vertices_begin(); v_it!=v_end; ++v_it)
113 if (!mesh.is_boundary(*v_it))
114 mesh.set_point( *v_it, mesh.data(*v_it).cog());
115 }
116
117
118 // write mesh to stdout
119 std::cout<< "Output mesh: " << argv[idx+1] << std::endl;
120
121 if ( ! OpenMesh::IO::write_mesh(mesh, argv[idx+1]) )
122 {
123 std::cerr << "Error: cannot write mesh to " << argv[idx+1] << std::endl;
124 return 0;
125 }
126 return 1;
127 }
OpenMesh::IO::read_mesh
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:104
OpenMesh::PolyMeshT::VertexVertexIter
Kernel::VertexVertexIter VertexVertexIter
Circulator.
Definition: PolyMeshT.hh:165
OpenMesh::PolyMeshT::Face
Kernel::Face Face
Face type.
Definition: PolyMeshT.hh:133
OpenMesh::PolyMeshT::Vertex
Kernel::Vertex Vertex
Vertex type.
Definition: PolyMeshT.hh:127
OpenMesh::PolyMeshT::Point
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115
OpenMesh::TriMesh_ArrayKernelT
Definition: TriMesh_ArrayKernelT.hh:98
Traits.hh
OpenMesh::PolyMeshT::Edge
Kernel::Edge Edge
Edge type.
Definition: PolyMeshT.hh:131
OpenMesh::PolyMeshT::Scalar
Kernel::Scalar Scalar
Scalar type.
Definition: PolyMeshT.hh:113
MyTraits
Definition: mymesh.cc:5
OpenMesh::IO::write_mesh
bool write_mesh(const Mesh &_mesh, const std::string &_filename, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to the file _filename.
Definition: MeshIO.hh:199
OpenMesh::DefaultTraits
Definition: Traits.hh:126
OpenMesh::PolyMeshT::Halfedge
Kernel::Halfedge Halfedge
Halfedge type.
Definition: PolyMeshT.hh:129