OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
DecimaterViewerWidget.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2011 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: 487 $ *
38  * $Date: 2012-01-12 13:09:36 +0100 (Do, 12 Jan 2012) $ *
39  * *
40 \*===========================================================================*/
41 
42 
43 #ifndef OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
44 #define OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
45 
46 
47 //== INCLUDES =================================================================
48 
49 #if !defined(OM_USE_OSG)
50 # define OM_USE_OSG 0
51 #endif
52 
53 
54 #include <qtimer.h>
55 #include <string>
56 #include <memory>
57 
58 //--------------------
59 #include <OpenMesh/Core/IO/MeshIO.hh>
60 //--------------------
61 #if OM_USE_OSG
62 # include <OpenMesh/Tools/Kernel_OSG/TriMesh_OSGArrayKernelT.hh>
63 # define DEFAULT_TRAITS Kernel_OSG::Traits
64 # define TRIMESH_KERNEL Kernel_OSG::TriMesh_OSGArrayKernelT
65 #else
66 //--------------------
68 # include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
69 # define DEFAULT_TRAITS DefaultTraits
70 # define TRIMESH_KERNEL TriMesh_ArrayKernelT
71 #endif
72 
73 #include <OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh>
74 
78 
79 
80 //== CLASS DEFINITION =========================================================
81 
82 
83 using namespace OpenMesh;
84 
85 struct MyTraits : public DEFAULT_TRAITS
86 {
89 };
90 
91 typedef TRIMESH_KERNEL<MyTraits> mesh_t;
93 
94 //== CLASS DEFINITION =========================================================
95 
96 
98 {
99  Q_OBJECT
100 
101 public:
102 
104 
105  typedef Decimater::DecimaterT<mesh_t> decimater_t;
106  typedef Decimater::ModQuadricT< decimater_t > mod_quadric_t;
107  typedef Decimater::ModNormalFlippingT< decimater_t > mod_nf_t;
108 
109  // object types
110  typedef std::auto_ptr< decimater_t > decimater_o;
111  typedef std::auto_ptr< mod_quadric_t > mod_quadric_o;
112  typedef std::auto_ptr< mod_nf_t > mod_nf_o;
113 
115  DecimaterViewerWidget(QWidget* _parent=0)
116  : MeshViewerWidget(_parent), steps_(1)
117  {
118  timer_ = new QTimer(this);
119 
120  connect( timer_, SIGNAL(timeout()), SLOT(animate()) );
121  }
122 
124  animate_(false),
125  timer_(0),
126  steps_(0)
127  {
128  }
129 
132  {
133  delete timer_;
134  }
135 
136 public: // inherited
137 
138  bool open_mesh(const char* _filename, OpenMesh::IO::Options _opt)
139  {
140  bool rc;
141 
142  if ( (rc = inherited_t::open_mesh( _filename, _opt )) )
143  {
144  std::cout << "prepare decimater" << std::endl;
145 
146  // to be compatible with gcc 2.95.3
147  {
148  decimater_o tmp( new decimater_t ( mesh() ) );
149  decimater_ = tmp;
150  }
151  {
152  mod_quadric_o tmp( new mod_quadric_t( *decimater_ ) );
153  mod_quadric_ = tmp;
154  }
155  {
156  mod_nf_o tmp( new mod_nf_t ( *decimater_ ) );
157  mod_nf_ = tmp;
158  }
159 
160  decimater_->initialize();
161  }
162  return rc;
163  }
164 
165 protected slots:
166 
167  void animate( void );
168 
169 protected:
170 
171  virtual void keyPressEvent(QKeyEvent* _event);
172 
173 
174 private:
175 
176  bool animate_;
177  QTimer *timer_;
178 
179  decimater_o decimater_;
180  mod_quadric_o mod_quadric_;
181  mod_nf_o mod_nf_;
182 
183  size_t steps_;
184 };
185 
186 
187 //=============================================================================
188 #endif // OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH defined
189 //=============================================================================
190 

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