Developer Documentation
Loading...
Searching...
No Matches
decimaterviewer.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
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#include <QOpenGLContext>
54
55#include "DecimaterViewerWidget.hh"
56
57void usage_and_exit(int xcode);
58
59
60int main(int argc, char **argv)
61{
62#if defined(OM_USE_OSG) && OM_USE_OSG
63 osg::osgInit(argc, argv);
64#endif
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, "OpenGL", msg + argv[1] );
76 return -1;
77 }
78
79
80 int c;
82
83 while ( (c=getopt(argc,argv,"s"))!=-1 )
84 {
85 switch(c)
86 {
87 case 's': opt += OpenMesh::IO::Options::Swap; break;
88 case 'h':
89 usage_and_exit(0);
90 break;
91 default:
92 usage_and_exit(1);
93 }
94 }
95 // create widget
97// app.setMainWidget(&w);
98
99 w.resize(400, 400);
100 w.show();
101
102 // load scene
103 if ( optind < argc )
104 {
105 if ( ! w.open_mesh(argv[optind], opt) )
106 {
107 QString msg = "Cannot read mesh from file:\n '";
108 msg += argv[optind];
109 msg += "'";
110 QMessageBox::critical( nullptr, w.windowTitle(), msg );
111 return 1;
112 }
113 }
114
115 if ( ++optind < argc )
116 {
117 if ( ! w.open_texture( argv[optind] ) )
118 {
119 QString msg = "Cannot load texture image from file:\n '";
120 msg += argv[optind];
121 msg += "'\n\nPossible reasons:\n";
122 msg += "- Mesh file didn't provide texture coordinates\n";
123 msg += "- Texture file does not exist\n";
124 msg += "- Texture file is not accessible.\n";
125 QMessageBox::warning( nullptr, w.windowTitle(), msg );
126 }
127 }
128
129 return app.exec();
130}
131
132void usage_and_exit(int xcode)
133{
134 std::cout << "Usage: DecimaterGui [-s] [mesh] [texture]\n" << std::endl;
135 std::cout << "Options:\n"
136 << " -s\n"
137 << " Reverse byte order, when reading binary files.\n"
138 << " Press 'h' when the application is running for more options.\n"
139 << std::endl;
140 exit(xcode);
141}
Set options for reader/writer modules.
Definition Options.hh:92
@ Swap
Swap byte order in binary mode.
Definition Options.hh:104