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