OpenMesh
MeshViewerWidget.hh
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 #ifndef OPENMESHAPPS_VIEWERWIDGET_HH
50 #define OPENMESHAPPS_VIEWERWIDGET_HH
51 
52 //== INCLUDES =================================================================
53 
54 #include <QWidget>
55 #include <QString>
56 #include <QMessageBox>
57 #include <QFileDialog>
58 #include <OpenMesh/Tools/Utils/getopt.h>
60 #include <OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh>
61 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
62 
63 
64 //== CLASS DEFINITION =========================================================
65 
66 using namespace OpenMesh;
67 using namespace OpenMesh::Attributes;
68 
69 struct MyTraits : public OpenMesh::DefaultTraits
70 {
72 };
73 
75 
76 
77 
78 //== CLASS DEFINITION =========================================================
79 
80 class MeshViewerWidget : public MeshViewerWidgetT<MyMesh>
81 {
82  Q_OBJECT
83 public:
85  explicit MeshViewerWidget(QWidget* parent=0) : MeshViewerWidgetT<MyMesh>(parent)
86  {}
87  OpenMesh::IO::Options& options() { return _options; }
88  const OpenMesh::IO::Options& options() const { return _options; }
89  void setOptions(const OpenMesh::IO::Options& opts) { _options = opts; }
90 
91  void open_mesh_gui(QString fname)
92  {
94  t.start();
95  if ( fname.isEmpty() || !open_mesh(fname.toLocal8Bit(), _options) )
96  {
97  QString msg = "Cannot read mesh from file:\n '";
98  msg += fname;
99  msg += "'";
100  QMessageBox::critical( NULL, windowTitle(), msg);
101  }
102  t.stop();
103  std::cout << "Loaded mesh in ~" << t.as_string() << std::endl;
104  }
105  void open_texture_gui(QString fname)
106  {
107  if ( fname.isEmpty() || !open_texture( fname.toLocal8Bit() ) )
108  {
109  QString msg = "Cannot load texture image from file:\n '";
110  msg += fname;
111  msg += "'\n\nPossible reasons:\n";
112  msg += "- Mesh file didn't provide texture coordinates\n";
113  msg += "- Texture file does not exist\n";
114  msg += "- Texture file is not accessible.\n";
115  QMessageBox::warning( NULL, windowTitle(), msg );
116  }
117  }
118 
119 public slots:
120  void query_open_mesh_file() {
121  QString fileName = QFileDialog::getOpenFileName(this,
122  tr("Open mesh file"),
123  tr(""),
124  tr("OBJ Files (*.obj);;"
125  "OFF Files (*.off);;"
126  "STL Files (*.stl);;"
127  "All Files (*)"));
128  if (!fileName.isEmpty())
129  open_mesh_gui(fileName);
130  }
131  void query_open_texture_file() {
132  QString fileName = QFileDialog::getOpenFileName(this,
133  tr("Open texture file"),
134  tr(""),
135  tr("PNG Files (*.png);;"
136  "BMP Files (*.bmp);;"
137  "GIF Files (*.gif);;"
138  "JPEG Files (*.jpg);;"
139  "TIFF Files (*.tif);;"
140  "All Files (*)"));
141  if (!fileName.isEmpty())
142  open_texture_gui(fileName);
143  }
144 private:
145  OpenMesh::IO::Options _options;
146 };
147 
148 
149 #endif
MeshViewerWidget(QWidget *parent=0)
default constructor
Definition: MeshViewerWidget.hh:85
#define HalfedgeAttributes(_i)
Macro for defining the halfedge attributes. See Specifying your MyMesh.
Definition: Traits.hh:87
void stop(void)
Stop measurement.
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
void start(void)
Start measurement.
Definition: MeshViewerWidgetT.hh:76
Triangle mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:78
A timer class.
Definition: MeshViewerWidget.hh:80
Set options for reader/writer modules.
Definition: Options.hh:95
Polygonal mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:99
This namespace holds per item attributes like normal/color.
Base class for all traits.
Definition: Traits.hh:126
std::string as_string(Format format=Automatic)
Returns the measured time as a string.
Timer class.
Definition: Timer.hh:87
Add storage for previous halfedge (halfedges). The bit is set by default in the DefaultTraits.
Definition: Attributes.hh:89

Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .