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