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