Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
meshviewer.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 <QApplication>
56 #include <QMessageBox>
57 #include <QMainWindow>
58 #include <QMenuBar>
59 #include <QFileDialog>
60 
61 #ifdef ARCH_DARWIN
62 #include <glut.h>
63 #else
64 #include <GL/glut.h>
65 #endif
66 
67 #include "MeshViewerWidget.hh"
68 
69 
70 void create_menu(QMainWindow &w);
71 void usage_and_exit(int xcode);
72 
73 int main(int argc, char **argv)
74 {
75  // OpenGL check
76  QApplication::setColorSpec( QApplication::CustomColor );
77  QApplication app(argc,argv);
78 #if !defined(__APPLE__)
79  glutInit(&argc,argv);
80 #endif
81 
82  if ( !QGLFormat::hasOpenGL() ) {
83  QString msg = "System has no OpenGL support!";
84  QMessageBox::critical( 0, QString("OpenGL"), msg + QString(argv[1]) );
85  return -1;
86  }
87 
88  int c;
90 
91  while ( (c=getopt(argc,argv,"hbs"))!=-1 )
92  {
93  switch(c)
94  {
95  case 'b': opt += OpenMesh::IO::Options::Binary; break;
96  case 'h':
97  usage_and_exit(0);
98  case 's': opt += OpenMesh::IO::Options::Swap; break;
99  default:
100  usage_and_exit(1);
101  }
102  }
103 
104  // enable most options for now
111 
112  // create widget
113  QMainWindow mainWin;
114  MeshViewerWidget w(&mainWin);
115  w.setOptions(opt);
116  mainWin.setCentralWidget(&w);
117 
118  create_menu(mainWin);
119 
120  // static mesh, hence use strips
121  w.enable_strips();
122 
123  mainWin.resize(640, 480);
124  mainWin.show();
125 
126  // load scene if specified on the command line
127  if ( optind < argc )
128  {
129  w.open_mesh_gui(argv[optind]);
130  }
131 
132  if ( ++optind < argc )
133  {
134  w.open_texture_gui(argv[optind]);
135  }
136 
137  return app.exec();
138 }
139 
140 void create_menu(QMainWindow &w)
141 {
142  using namespace Qt;
143  QMenu *fileMenu = w.menuBar()->addMenu(w.tr("&File"));
144 
145  QAction* openAct = new QAction(w.tr("&Open mesh..."), &w);
146  openAct->setShortcut(w.tr("Ctrl+O"));
147  openAct->setStatusTip(w.tr("Open a mesh file"));
148  QObject::connect(openAct, SIGNAL(triggered()), w.centralWidget(), SLOT(query_open_mesh_file()));
149  fileMenu->addAction(openAct);
150 
151  QAction* texAct = new QAction(w.tr("Open &texture..."), &w);
152  texAct->setShortcut(w.tr("Ctrl+T"));
153  texAct->setStatusTip(w.tr("Open a texture file"));
154  QObject::connect(texAct, SIGNAL(triggered()), w.centralWidget(), SLOT(query_open_texture_file()));
155  fileMenu->addAction(texAct);
156 }
157 
158 void usage_and_exit(int xcode)
159 {
160  std::cout << "Usage: meshviewer [-s] [mesh] [texture]\n" << std::endl;
161  std::cout << "Options:\n"
162  << " -b\n"
163  << " Assume input to be binary.\n\n"
164  << " -s\n"
165  << " Reverse byte order, when reading binary files.\n"
166  << std::endl;
167  exit(xcode);
168 }
Has (r) / store (w) vertex normals.
Definition: Options.hh:109
Has (r) / store (w) face normals.
Definition: Options.hh:113
Has (r) / store (w) face colors.
Definition: Options.hh:114
Has (r) / store (w) texture coordinates.
Definition: Options.hh:111
Set options for reader/writer modules.
Definition: Options.hh:95
Has (r) / store (w) face texture coordinates.
Definition: Options.hh:115
Set binary mode for r/w.
Definition: Options.hh:105
Swap byte order in binary mode.
Definition: Options.hh:108
Has (r) / store (w) vertex colors.
Definition: Options.hh:110