OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MeshViewerWidget.hh
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
5 * www.openmesh.org *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of OpenMesh. *
9 * *
10 * OpenMesh is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenMesh is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenMesh. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34
35 /*===========================================================================*\
36 * *
37 * $Revision: 736 $ *
38 * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08. Okt 2012) $ *
39 * *
40 \*===========================================================================*/
41
42 #ifndef OPENMESHAPPS_VIEWERWIDGET_HH
43 #define OPENMESHAPPS_VIEWERWIDGET_HH
44
45 //== INCLUDES =================================================================
46
47 #include <QWidget>
48 #include <QString>
49 #include <QMessageBox>
50 #include <QFileDialog>
51 #include <OpenMesh/Tools/Utils/getopt.h>
52 #include <OpenMesh/Tools/Utils/Timer.hh>
53 #include <OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh>
54 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
55
56
57 //== CLASS DEFINITION =========================================================
58
59 using namespace OpenMesh;
60 using namespace OpenMesh::Attributes;
61
62 struct MyTraits : public OpenMesh::DefaultTraits
63 {
64 HalfedgeAttributes(OpenMesh::Attributes::PrevHalfedge);
65 };
66
67 typedef OpenMesh::TriMesh_ArrayKernelT<MyTraits> MyMesh;
68
69
70
71 //== CLASS DEFINITION =========================================================
72
73 class MeshViewerWidget : public MeshViewerWidgetT<MyMesh>
74 {
75 Q_OBJECT
76 public:
78 MeshViewerWidget(QWidget* parent=0) : MeshViewerWidgetT<MyMesh>(parent)
79 {}
80 OpenMesh::IO::Options& options() { return _options; }
81 const OpenMesh::IO::Options& options() const { return _options; }
82 void setOptions(const OpenMesh::IO::Options& opts) { _options = opts; }
83
84 void open_mesh_gui(QString fname)
85 {
86 OpenMesh::Utils::Timer t;
87 t.start();
88 if ( fname.isEmpty() || !open_mesh(fname.toLocal8Bit(), _options) )
89 {
90 QString msg = "Cannot read mesh from file:\n '";
91 msg += fname;
92 msg += "'";
93 QMessageBox::critical( NULL, windowTitle(), msg);
94 }
95 t.stop();
96 std::cout << "Loaded mesh in ~" << t.as_string() << std::endl;
97 }
98 void open_texture_gui(QString fname)
99 {
100 if ( fname.isEmpty() || !open_texture( fname.toLocal8Bit() ) )
101 {
102 QString msg = "Cannot load texture image from file:\n '";
103 msg += fname;
104 msg += "'\n\nPossible reasons:\n";
105 msg += "- Mesh file didn't provide texture coordinates\n";
106 msg += "- Texture file does not exist\n";
107 msg += "- Texture file is not accessible.\n";
108 QMessageBox::warning( NULL, windowTitle(), msg );
109 }
110 }
111
112 public slots:
113 void query_open_mesh_file() {
114 QString fileName = QFileDialog::getOpenFileName(this,
115 tr("Open mesh file"),
116 tr(""),
117 tr("OBJ Files (*.obj);;"
118 "OFF Files (*.off);;"
119 "STL Files (*.stl);;"
120 "All Files (*)"));
121 if (!fileName.isEmpty())
122 open_mesh_gui(fileName);
123 }
124 void query_open_texture_file() {
125 QString fileName = QFileDialog::getOpenFileName(this,
126 tr("Open texture file"),
127 tr(""),
128 tr("PNG Files (*.png);;"
129 "BMP Files (*.bmp);;"
130 "GIF Files (*.gif);;"
131 "JPEG Files (*.jpg);;"
132 "TIFF Files (*.tif);;"
133 "All Files (*)"));
134 if (!fileName.isEmpty())
135 open_texture_gui(fileName);
136 }
137 private:
138 OpenMesh::IO::Options _options;
139 };
140
141
142 #endif