Developer Documentation

decimaterviewer.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 #ifdef _MSC_VER
45 # pragma warning(disable: 4267 4311)
46 #endif
47
48 #include <iostream>
49 #include <fstream>
50 #include <OpenMesh/Tools/Utils/getopt.h>
51 #include <qapplication.h>
52 #include <qmessagebox.h>
53
54 #include "DecimaterViewerWidget.hh"
55
56 void usage_and_exit(int xcode);
57
58
59 int main(int argc, char **argv)
60 {
61 #if defined(OM_USE_OSG) && OM_USE_OSG
62 osg::osgInit(argc, argv);
63 #endif
64
65 // OpenGL check
66 QApplication::setColorSpec( QApplication::CustomColor );
67 QApplication app(argc,argv);
68
69 if ( !QGLFormat::hasOpenGL() ) {
70 QString msg = "System has no OpenGL support!";
71 QMessageBox::critical( NULL, "OpenGL", msg + argv[1] );
72 return -1;
73 }
74
75
76 int c;
77 OpenMesh::IO::Options opt;
78
79 while ( (c=getopt(argc,argv,"s"))!=-1 )
80 {
81 switch(c)
82 {
83 case 's': opt += OpenMesh::IO::Options::Swap; break;
84 case 'h':
85 usage_and_exit(0);
86 break;
87 default:
88 usage_and_exit(1);
89 }
90 }
91 // create widget
92 DecimaterViewerWidget w(0);
93 // app.setMainWidget(&w);
94
95 w.resize(400, 400);
96 w.show();
97
98 // load scene
99 if ( optind < argc )
100 {
101 if ( ! w.open_mesh(argv[optind], opt) )
102 {
103 QString msg = "Cannot read mesh from file:\n '";
104 msg += argv[optind];
105 msg += "'";
106 QMessageBox::critical( NULL, w.windowTitle(), msg );
107 return 1;
108 }
109 }
110
111 if ( ++optind < argc )
112 {
113 if ( ! w.open_texture( argv[optind] ) )
114 {
115 QString msg = "Cannot load texture image from file:\n '";
116 msg += argv[optind];
117 msg += "'\n\nPossible reasons:\n";
118 msg += "- Mesh file didn't provide texture coordinates\n";
119 msg += "- Texture file does not exist\n";
120 msg += "- Texture file is not accessible.\n";
121 QMessageBox::warning( NULL, w.windowTitle(), msg );
122 }
123 }
124
125 return app.exec();
126 }
127
128 void usage_and_exit(int xcode)
129 {
130 std::cout << "Usage: DecimaterGui [-s] [mesh] [texture]\n" << std::endl;
131 std::cout << "Options:\n"
132 << " -s\n"
133 << " Reverse byte order, when reading binary files.\n"
134 << " Press 'h' when the application is running for more options.\n"
135 << std::endl;
136 exit(xcode);
137 }
DecimaterViewerWidget
Definition: DecimaterViewerWidget.hh:99
OpenMesh::IO::Options::Swap
Swap byte order in binary mode.
Definition: Options.hh:103
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:90