OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
DecimaterViewerWidget.hh
1 /*===========================================================================*\
2  * *
3  * OpenMesh *
4  * Copyright (C) 2001-2012 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: 736 $ *
38  * $Date: 2012-10-08 09:30:49 +0200 (Mo, 08 Okt 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< mesh_t >::Handle mod_quadric_t;
107  typedef Decimater::ModNormalFlippingT< mesh_t >::Handle mod_nf_t;
108 
109  // object types
110  typedef std::auto_ptr< decimater_t > decimater_o;
111 
113  DecimaterViewerWidget(QWidget* _parent=0)
114  : MeshViewerWidget(_parent), steps_(1)
115  {
116  timer_ = new QTimer(this);
117 
118  connect( timer_, SIGNAL(timeout()), SLOT(animate()) );
119  }
120 
122  animate_(false),
123  timer_(0),
124  steps_(0)
125  {
126  }
127 
130  {
131  delete timer_;
132  }
133 
134 public: // inherited
135 
136  bool open_mesh(const char* _filename, OpenMesh::IO::Options _opt)
137  {
138  bool rc;
139 
140  if ( (rc = inherited_t::open_mesh( _filename, _opt )) )
141  {
142  std::cout << "prepare decimater" << std::endl;
143 
144  // to be compatible with gcc 2.95.3
145  {
146  decimater_o tmp( new decimater_t ( mesh() ) );
147  decimater_ = tmp;
148  }
149 
150  decimater_->add(mod_quadric_);
151  decimater_->module(mod_quadric_).set_binary(false);
152 
153  decimater_->add(mod_nf_);
154 
155  decimater_->initialize();
156  }
157  return rc;
158  }
159 
160 protected slots:
161 
162  void animate( void );
163 
164 protected:
165 
166  virtual void keyPressEvent(QKeyEvent* _event);
167 
168 
169 private:
170 
171  bool animate_;
172  QTimer *timer_;
173 
174  decimater_o decimater_;
175  mod_quadric_t mod_quadric_;
176  mod_nf_t mod_nf_;
177 
178  size_t steps_;
179 };
180 
181 
182 //=============================================================================
183 #endif // OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH defined
184 //=============================================================================
185 

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