OpenMesh
OpenMesh/Apps/QtViewer/MeshViewerWidget.hh
00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                               OpenMesh                                    *
00004  *      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openmesh.org                                *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------* 
00008  *  This file is part of OpenMesh.                                           *
00009  *                                                                           *
00010  *  OpenMesh is free software: you can redistribute it and/or modify         * 
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenMesh is distributed in the hope that it will be useful,              *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenMesh.  If not,                                    *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/ 
00034 
00035 /*===========================================================================*\
00036  *                                                                           *             
00037  *   $Revision: 362 $                                                         *
00038  *   $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00042 #ifndef OPENMESHAPPS_VIEWERWIDGET_HH
00043 #define OPENMESHAPPS_VIEWERWIDGET_HH
00044 
00045 //== INCLUDES =================================================================
00046 
00047 #include <QWidget>
00048 #include <QString>
00049 #include <QMessageBox>
00050 #include <QFileDialog>
00051 #include <OpenMesh/Tools/Utils/getopt.h>
00052 #include <OpenMesh/Tools/Utils/Timer.hh>
00053 #include <OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh>
00054 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
00055 
00056 
00057 //== CLASS DEFINITION =========================================================
00058 
00059 using namespace OpenMesh;  
00060 using namespace OpenMesh::Attributes;
00061 
00062 struct MyTraits : public OpenMesh::DefaultTraits
00063 {
00064   HalfedgeAttributes(OpenMesh::Attributes::PrevHalfedge);
00065 };
00066 
00067 typedef OpenMesh::TriMesh_ArrayKernelT<MyTraits>  MyMesh;
00068 
00069 
00070 
00071 //== CLASS DEFINITION =========================================================
00072 
00073 class MeshViewerWidget : public MeshViewerWidgetT<MyMesh>
00074 {
00075     Q_OBJECT
00076 public:
00078     MeshViewerWidget(QWidget* parent=0) : MeshViewerWidgetT<MyMesh>(parent)
00079     {}
00080     OpenMesh::IO::Options& options() { return _options; }
00081     const OpenMesh::IO::Options& options() const { return _options; }
00082     void setOptions(const OpenMesh::IO::Options& opts) { _options = opts; }
00083 
00084     void open_mesh_gui(QString fname)
00085     {
00086         OpenMesh::Utils::Timer t;
00087         t.start();
00088         if ( fname.isEmpty() || !open_mesh(fname.toLocal8Bit(), _options) )
00089         {
00090             QString msg = "Cannot read mesh from file:\n '";
00091             msg += fname;
00092             msg += "'";
00093             QMessageBox::critical( NULL, windowTitle(), msg);
00094         }
00095         t.stop();
00096         std::cout << "Loaded mesh in ~" << t.as_string() << std::endl;
00097     }
00098     void open_texture_gui(QString fname)
00099     {
00100         if ( fname.isEmpty() || !open_texture( fname.toLocal8Bit() ) )
00101         {
00102             QString msg = "Cannot load texture image from file:\n '";
00103             msg += fname;
00104             msg += "'\n\nPossible reasons:\n";
00105             msg += "- Mesh file didn't provide texture coordinates\n";
00106             msg += "- Texture file does not exist\n";
00107             msg += "- Texture file is not accessible.\n";
00108             QMessageBox::warning( NULL, windowTitle(), msg );
00109         }
00110     }
00111 
00112 public slots:
00113     void query_open_mesh_file() {
00114         QString fileName = QFileDialog::getOpenFileName(this,
00115             tr("Open mesh file"),
00116             tr(""),
00117             tr("OBJ Files (*.obj);;"
00118             "OFF Files (*.off);;"
00119             "STL Files (*.stl);;"
00120             "All Files (*)"));
00121         if (!fileName.isEmpty())
00122             open_mesh_gui(fileName);
00123     }
00124     void query_open_texture_file() {
00125         QString fileName = QFileDialog::getOpenFileName(this,
00126             tr("Open texture file"),
00127             tr(""),
00128             tr("PNG Files (*.png);;"
00129             "BMP Files (*.bmp);;"
00130             "GIF Files (*.gif);;"
00131             "JPEG Files (*.jpg);;"
00132             "TIFF Files (*.tif);;"
00133             "All Files (*)"));
00134         if (!fileName.isEmpty())
00135             open_texture_gui(fileName);
00136     }
00137 private:
00138     OpenMesh::IO::Options _options;
00139 };
00140 
00141 
00142 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines