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 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $Date$ *
46 * *
47 \*===========================================================================*/
48
49
50 #include <iostream>
51 #include <OpenMesh/Core/IO/MeshIO.hh> // include before kernel type!
52 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
53 #include <OpenMesh/Tools/Utils/Timer.hh>
54 #include <OpenMesh/Tools/Smoother/JacobiLaplaceSmootherT.hh>
55 #include <OpenMesh/Tools/Utils/getopt.h>
56
57
58 using namespace OpenMesh;
59 using namespace Smoother;
60
61
62 struct MyTraits : public OpenMesh::DefaultTraits
63 {
64 #if 1
65 typedef OpenMesh::Vec3f Point;
66 typedef OpenMesh::Vec3f Normal;
67 #else
68 typedef OpenMesh::Vec3d Point;
69 typedef OpenMesh::Vec3d Normal;
70 #endif
71 };
72
73 typedef OpenMesh::TriMesh_ArrayKernelT<MyTraits> MyMesh;
74
75
76 //-----------------------------------------------------------------------------
77
78 void usage_and_exit(int _xcode)
79 {
80 std::cout << std::endl;
81 std::cout << "Usage: smooth [Options] <iterations> <input mesh> <output mesh>\n";
82 std::cout << std::endl;
83 std::cout << "Options \n"
84 << std::endl
85 << " -c <0|1> \t continuity (C0,C1). Default: C1\n"
86 << " -t \t\t smooth tangential direction. Default: Enabled\n"
87 << " -n \t\t smooth normal direction. Default: Enabled\n"
88 << std::endl;
89 exit(_xcode);
90 }
91
92
93 //-----------------------------------------------------------------------------
94
95
96 int main(int argc, char **argv)
97 {
98 int c;
99
100 MyMesh mesh;
101 OpenMesh::Utils::Timer t;
102 std::string ifname;
103 std::string ofname;
104
105 SmootherT<MyMesh>::Continuity
106 continuity = SmootherT<MyMesh>::C1;
107
108 SmootherT<MyMesh>::Component
109 component = SmootherT<MyMesh>::Tangential_and_Normal;
110
111 int iterations;
112
113 // ---------------------------------------- evaluate command line
114
115 while ( (c=getopt(argc, argv, "tnc:h"))!=-1 )
116 {
117 switch(c)
118 {
119 case 'c': {
120 switch(*optarg)
121 {
122 case '0' : continuity = SmootherT<MyMesh>::C0; break;
123 case '1' : continuity = SmootherT<MyMesh>::C1; break;
124 }
125 break;
126 }
127 case 't':
128 component = component==SmootherT<MyMesh>::Normal
129 ? SmootherT<MyMesh>::Tangential_and_Normal
130 : SmootherT<MyMesh>::Tangential;
131 break;
132
133 case 'n':
134 component = component==SmootherT<MyMesh>::Tangential
135 ? SmootherT<MyMesh>::Tangential_and_Normal
136 : SmootherT<MyMesh>::Normal;
137 break;
138
139 case 'h': usage_and_exit(0);
140 case '?':
141 default: usage_and_exit(1);
142 }
143 }
144
145 if (argc-optind < 3)
146 usage_and_exit(1);
147
148
149 // # iterations
150 {
151 std::stringstream str; str << argv[optind]; str >> iterations;
152 }
153
154
155 // input file
156 ifname = argv[++optind];
157
158
159 // output file
160 ofname = argv[++optind];
161
162
163 OpenMesh::IO::Options opt;
164
165 // ---------------------------------------- read mesh
166
167 omout() << "read mesh..." << std::flush;
168 t.start();
169 OpenMesh::IO::read_mesh(mesh, ifname, opt);
170 t.stop();
171 omout() << "done (" << t.as_string() << ")\n";
172
173 omout() << " #V " << mesh.n_vertices() << std::endl;
174
175 // ---------------------------------------- smooth
176
177 JacobiLaplaceSmootherT<MyMesh> smoother(mesh);
178 smoother.initialize(component,continuity);
179
180 omout() << "smoothing..." << std::flush;
181
182 t.start();
183 smoother.smooth(iterations);
184 t.stop();
185
186 omout() << "done (";
187 omout() << t.seconds() << "s ~ ";
188 omout() << t.as_string() << ", "
189 << (iterations*mesh.n_vertices())/t.seconds() << " Vertices/s)\n";
190
191 // ---------------------------------------- write mesh
192
193 omout() << "write mesh..." << std::flush;
194 t.start();
195 OpenMesh::IO::write_mesh(mesh, ofname, opt);
196 t.stop();
197 omout() << "done (" << t.as_string() << ")\n";
198
199 return 0;
200 }
OpenMesh::IO::read_mesh
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
Definition: MeshIO.hh:104
OpenMesh::Utils::Timer::stop
void stop(void)
Stop measurement.
OpenMesh
Definition: MeshItems.hh:64
OpenMesh::TriMesh_ArrayKernelT
Definition: TriMesh_ArrayKernelT.hh:98
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:95
OpenMesh::Utils::Timer::as_string
std::string as_string(Format format=Automatic)
Timer.hh
OpenMesh::Smoother::JacobiLaplaceSmootherT
Definition: JacobiLaplaceSmootherT.hh:80
OpenMesh::VectorT< float, 3 >
OpenMesh::Utils::Timer::start
void start(void)
Start measurement.
OpenMesh::Smoother::SmootherT
Definition: SmootherT.hh:81
OpenMesh::Attributes::Normal
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
OpenMesh::Utils::Timer::seconds
double seconds(void) const
Returns measured time in seconds, if the timer is in state 'Stopped'.
JacobiLaplaceSmootherT.hh
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::Utils::Timer
Definition: Timer.hh:87