52 #include <OpenMesh/Core/IO/MeshIO.hh>
53 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
55 #include <OpenMesh/Tools/Utils/getopt.h>
85 std::map< std::string, double > timings;
89 template <
typename Subdiv
ider >
90 bool subdivide(
typename Subdivider::mesh_t& _m,
size_t _n,
97 std::cout <<
"Subdivide " << _n
98 <<
" times with '" << subdivide.name() <<
"'\n";
100 subdivide.attach(_m);
108 std::cout <<
" Done [" << t.
as_string(_fmt) <<
"]\n";
109 timings[subdivide.name()] = t.
seconds();
112 std::cout <<
" Failed!\n";
118 void usage_and_exit(
int _xcode);
122 template <
typename Subdiv
ider >
123 int mainT(
size_t _n,
124 const std::string& _ifname,
125 const std::string& _ofname,
126 const Timer::Format _fmt )
129 std::cout <<
"Read mesh from file " << _ifname << std::endl;
131 typename Subdivider::mesh_t mesh;
134 std::cout <<
" Ok\n";
137 std::cout <<
" Failed!\n";
141 std::cout <<
" #V " << mesh.n_vertices()
142 <<
", #F " << mesh.n_faces()
143 <<
", #E " << mesh.n_edges() << std::endl;
148 if (!subdivide< Subdivider >( mesh, _n, _fmt ))
151 catch(std::bad_alloc& x)
153 std::cerr <<
"Out of memory: " << x.what() << std::endl;
156 catch(std::exception& x)
158 std::cerr << x.what() << std::endl;
163 std::cerr <<
"Unknown exception!\n";
169 std::cout <<
" #V " << mesh.n_vertices()
170 <<
", #F " << mesh.n_faces()
171 <<
", #E " << mesh.n_edges() << std::endl;
173 if ( !_ofname.empty() )
175 std::cout <<
"Write resulting mesh to file " << _ofname <<
"..";
182 std::cerr <<
"Failed! Could not write file!\n";
192 int main(
int argc,
char **argv)
196 bool compare_all =
false;
211 Timer::Format fmt = Timer::Automatic;
213 while ( (c=getopt(argc, argv,
"csSlLbBhf:"))!=-1 )
217 case 'c': compare_all=
true;
break;
218 case 's': st = TypeSqrt3;
break;
219 case 'S': st = TypeCompSqrt3;
break;
220 case 'l': st = TypeLoop;
break;
221 case 'L': st = TypeCompLoop;
break;
222 case 'b': st = TypeLabsikGreiner;
break;
223 case 'B': st = TypeModButterfly;
break;
224 case 'C': st = TypeCatmullClark; std::cerr <<
"Not yet supported, as it needs a poly mesh!";
break;
229 case 'm': fmt = Timer::MSeconds;
break;
230 case 'c': fmt = Timer::HSeconds;
break;
231 case 's': fmt = Timer::Seconds;
break;
233 default: fmt = Timer::Automatic;
break;
237 case 'h': usage_and_exit(0);
239 default: usage_and_exit(1);
248 std::stringstream str; str << argv[optind]; str >> n;
252 ifname = argv[++optind];
255 if ( ++optind < argc )
256 ofname = argv[optind];
263 rc = mainT<Sqrt3> ( n, ifname,
"", fmt );
264 rc += mainT<Loop> ( n, ifname,
"", fmt );
265 rc += mainT<CompositeSqrt3> ( n, ifname,
"", fmt );
266 rc += mainT<CompositeLoop> ( n, ifname,
"", fmt );
267 rc += mainT<InterpolatingSqrt3LG> ( n, ifname,
"", fmt );
268 rc += mainT<ModifiedButterfly> ( n, ifname,
"", fmt );
269 rc += mainT<CatmullClark> ( n, ifname,
"", fmt );
274 std::cout << std::endl;
276 std::map< std::string, double >::iterator it;
278 std::cout <<
"Timings:\n";
279 for(it = timings.begin();it!=timings.end();++it)
280 std::cout << it->first <<
": " << Timer::as_string(it->second)
282 std::cout << std::endl;
283 std::cout <<
"Ratio composite/native algorithm:\n";
284 std::cout <<
"sqrt(3): "
285 << timings[
"Uniform Composite Sqrt3"]/timings[
"Uniform Sqrt3"]
288 << timings[
"Uniform Composite Loop"]/timings[
"Uniform Loop"]
290 <<
"Interpolating sqrt(3) : "
291 << timings[
"Uniform Interpolating Sqrt3"]/timings[
"Uniform Sqrt3"]
298 return mainT<Sqrt3>( n, ifname, ofname, fmt );
300 return mainT<Loop>( n, ifname, ofname, fmt );
302 return mainT<CompositeSqrt3>( n, ifname, ofname, fmt );
304 return mainT<CompositeLoop> ( n, ifname, ofname, fmt );
305 case TypeLabsikGreiner:
306 return mainT<InterpolatingSqrt3LG> ( n, ifname, ofname, fmt );
307 case TypeModButterfly:
308 return mainT<ModifiedButterfly> ( n, ifname, ofname, fmt );
309 case TypeCatmullClark:
310 return mainT<CatmullClark> ( n, ifname, ofname, fmt );
317 void usage_and_exit(
int _xcode)
319 std::cout <<
"Usage: subdivide [Subdivider Type] #Iterations Input [Output].\n";
320 std::cout << std::endl;
321 std::cout <<
"Subdivider Type\n"
324 <<
" -L\tComposite Loop\n"
326 <<
" -S\tComposite Sqrt3\n"
327 <<
" -b\tInterpolating Sqrt3 Labsik-Greiner\n"
328 <<
" -B\tModified Butterfly\n"
bool read_mesh(Mesh &_mesh, const std::string &_filename)
Read a mesh from file _filename.
void stop(void)
Stop measurement.
std::string as_string(Format format=Automatic)
void start(void)
Start measurement.
double seconds(void) const
Returns measured time in seconds, if the timer is in state 'Stopped'.
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.