OpenMesh
OpenMesh/Apps/ProgViewer/ProgViewerWidget.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 
00043 #ifndef OPENMESHAPPS_PROGVIEWERWIDGET_HH
00044 #define OPENMESHAPPS_PROGVIEWERWIDGET_HH
00045 
00046 
00047 //== INCLUDES =================================================================
00048 
00049 #include <QTimer>
00050 #include <OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh>
00051 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
00052 #include <OpenMesh/Core/Mesh/Attributes.hh>
00053 #include <string>
00054 
00055 
00056 
00057 //== CLASS DEFINITION =========================================================
00058 
00059 
00060 using namespace OpenMesh;
00061 using namespace OpenMesh::Attributes;
00062 
00063 
00064 struct MyTraits : public OpenMesh::DefaultTraits
00065 {
00066   VertexAttributes  ( OpenMesh::Attributes::Normal       |
00067                       OpenMesh::Attributes::Status       );
00068   EdgeAttributes    ( OpenMesh::Attributes::Status       );
00069   HalfedgeAttributes( OpenMesh::Attributes::PrevHalfedge );
00070   FaceAttributes    ( OpenMesh::Attributes::Normal       |
00071                       OpenMesh::Attributes::Status       );  
00072 };
00073 
00074   
00075 typedef OpenMesh::TriMesh_ArrayKernelT<MyTraits>  MyMesh;
00076 typedef MeshViewerWidgetT<MyMesh>                 MeshViewerWidget;
00077 
00078 
00079 //== CLASS DEFINITION =========================================================
00080 
00081               
00082 
00083 class ProgViewerWidget : public MeshViewerWidget
00084 {
00085   Q_OBJECT
00086    
00087 public:
00088 
00089   typedef MeshViewerWidget Base;
00090   typedef ProgViewerWidget This;
00091 
00092 
00093 public:   
00095   ProgViewerWidget(QWidget* _parent=0)
00096     : MeshViewerWidget(_parent)
00097   {
00098     timer_ = new QTimer(this);
00099 
00100     connect( timer_, SIGNAL(timeout()), SLOT(animate()) );
00101   }
00102 
00104   ~ProgViewerWidget()
00105   {
00106     delete timer_;
00107   }
00108 
00110   void open_prog_mesh(const char* _filename);
00111 
00112 protected slots:
00113 
00114 void animate( void );
00115    
00116 private:
00117 
00118   QTimer *timer_;
00119    
00120   struct PMInfo 
00121   {
00122     MyMesh::Point        p0;
00123     MyMesh::VertexHandle v0, v1, vl, vr;
00124   };
00125   typedef std::vector<PMInfo>          PMInfoContainer;
00126   typedef PMInfoContainer::iterator    PMInfoIter;
00127 
00129   void refine(unsigned int _n);
00130 
00132   void coarsen(unsigned int _n);
00133 
00134   virtual void keyPressEvent(QKeyEvent* _event);
00135 
00136   // mesh data
00137   bool              animateRefinement_;
00138   PMInfoContainer   pminfos_;
00139   PMInfoIter        pmiter_;
00140   size_t            n_base_vertices_, n_base_faces_, n_detail_vertices_;
00141   size_t            n_max_vertices_;
00142 };
00143 
00144 
00145 //=============================================================================
00146 #endif // OPENMESHAPPS_PROGVIEWERWIDGET_HH defined
00147 //=============================================================================
00148