OpenMesh
OpenMesh/Apps/Decimating/DecimaterViewerWidget.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: 487 $                                                         *
00038  *   $Date: 2012-01-12 13:09:36 +0100 (Do, 12 Jan 2012) $                   *
00039  *                                                                           *
00040 \*===========================================================================*/
00041 
00042 
00043 #ifndef OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
00044 #define OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
00045 
00046 
00047 //== INCLUDES =================================================================
00048 
00049 #if !defined(OM_USE_OSG)
00050 #  define OM_USE_OSG 0
00051 #endif
00052 
00053 
00054 #include <qtimer.h>
00055 #include <string>
00056 #include <memory>
00057 
00058 //--------------------
00059 #include <OpenMesh/Core/IO/MeshIO.hh>
00060 //--------------------
00061 #if OM_USE_OSG
00062 #  include <OpenMesh/Tools/Kernel_OSG/TriMesh_OSGArrayKernelT.hh>
00063 #  define DEFAULT_TRAITS Kernel_OSG::Traits
00064 #  define TRIMESH_KERNEL Kernel_OSG::TriMesh_OSGArrayKernelT
00065 #else
00066 //--------------------
00067 #  include <OpenMesh/Core/Mesh/Traits.hh>
00068 #  include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
00069 #  define DEFAULT_TRAITS DefaultTraits
00070 #  define TRIMESH_KERNEL TriMesh_ArrayKernelT
00071 #endif
00072 
00073 #include <OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh>
00074 
00075 #include <OpenMesh/Tools/Decimater/DecimaterT.hh>
00076 #include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
00077 #include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
00078 
00079 
00080 //== CLASS DEFINITION =========================================================
00081 
00082 
00083 using namespace OpenMesh;
00084 
00085 struct MyTraits : public DEFAULT_TRAITS
00086 {
00087   VertexAttributes  ( Attributes::Normal       );
00088   FaceAttributes    ( Attributes::Normal       );  
00089 };
00090 
00091 typedef TRIMESH_KERNEL<MyTraits>                     mesh_t;
00092 typedef MeshViewerWidgetT<mesh_t>                    MeshViewerWidget;
00093 
00094 //== CLASS DEFINITION =========================================================
00095 
00096 
00097 class DecimaterViewerWidget : public MeshViewerWidget
00098 {
00099   Q_OBJECT
00100    
00101 public:
00102   
00103   typedef MeshViewerWidget inherited_t;
00104 
00105   typedef Decimater::DecimaterT<mesh_t>                decimater_t;  
00106   typedef Decimater::ModQuadricT< decimater_t >        mod_quadric_t;
00107   typedef Decimater::ModNormalFlippingT< decimater_t > mod_nf_t;
00108 
00109   // object types
00110   typedef std::auto_ptr< decimater_t   >   decimater_o;
00111   typedef std::auto_ptr< mod_quadric_t >   mod_quadric_o;
00112   typedef std::auto_ptr< mod_nf_t      >   mod_nf_o;
00113 
00115   DecimaterViewerWidget(QWidget* _parent=0)
00116     : MeshViewerWidget(_parent), steps_(1)
00117   {
00118     timer_ = new QTimer(this);
00119     
00120     connect( timer_, SIGNAL(timeout()), SLOT(animate()) );
00121   }
00122   
00123   DecimaterViewerWidget() :
00124           animate_(false),
00125           timer_(0),
00126           steps_(0)
00127   {
00128   }
00129 
00131   ~DecimaterViewerWidget()
00132   {
00133     delete timer_;
00134   }
00135 
00136 public: // inherited
00137 
00138   bool open_mesh(const char* _filename, OpenMesh::IO::Options _opt)
00139   {
00140     bool rc;
00141 
00142     if ( (rc = inherited_t::open_mesh( _filename, _opt )) )
00143     {
00144       std::cout << "prepare decimater" << std::endl;
00145 
00146       // to be compatible with gcc 2.95.3
00147       {
00148         decimater_o  tmp( new decimater_t  ( mesh() ) );
00149         decimater_ = tmp;
00150       }
00151       {
00152         mod_quadric_o  tmp( new mod_quadric_t( *decimater_ ) );
00153         mod_quadric_ = tmp;
00154       }
00155       {
00156         mod_nf_o       tmp( new mod_nf_t     ( *decimater_ ) );
00157         mod_nf_      = tmp;
00158       }
00159 
00160       decimater_->initialize();
00161     }
00162     return rc;
00163   }
00164   
00165 protected slots:
00166 
00167   void animate( void );
00168 
00169 protected:   
00170 
00171   virtual void keyPressEvent(QKeyEvent* _event);  
00172 
00173 
00174 private:
00175   
00176   bool              animate_;
00177   QTimer           *timer_;
00178 
00179   decimater_o       decimater_;  
00180   mod_quadric_o     mod_quadric_;
00181   mod_nf_o          mod_nf_;
00182 
00183   size_t            steps_;
00184 };
00185 
00186 
00187 //=============================================================================
00188 #endif // OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH defined
00189 //=============================================================================
00190 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines