OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DecimaterViewerWidget.hh
1 /*===========================================================================*\
2 * *
3 * OpenMesh *
4 * Copyright (C) 2001-2014 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: 990 $ *
38 * $Date: 2014-02-05 10:01:07 +0100 (Mi, 05. Feb 2014) $ *
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 //--------------------
67 # include <OpenMesh/Core/Mesh/Traits.hh>
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
75 #include <OpenMesh/Tools/Decimater/DecimaterT.hh>
76 #include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
77 #include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
78
79
80 //== CLASS DEFINITION =========================================================
81
82
83 using namespace OpenMesh;
84
85 struct MyTraits : public DEFAULT_TRAITS
86 {
87 VertexAttributes ( Attributes::Normal );
88 FaceAttributes ( Attributes::Normal );
89 };
90
91 typedef TRIMESH_KERNEL<MyTraits> mesh_t;
92 typedef MeshViewerWidgetT<mesh_t> MeshViewerWidget;
93
94 //== CLASS DEFINITION =========================================================
95
96
97 class DecimaterViewerWidget : public MeshViewerWidget
98 {
99 Q_OBJECT
100
101 public:
102
103 typedef MeshViewerWidget inherited_t;
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),
115 animate_(false),
116 timer_(0),
117 steps_(1)
118 {
119 timer_ = new QTimer(this);
120
121 connect( timer_, SIGNAL(timeout()), SLOT(animate()) );
122 }
123
124 DecimaterViewerWidget() :
125 animate_(false),
126 timer_(0),
127 steps_(0)
128 {
129 }
130
132 ~DecimaterViewerWidget()
133 {
134 delete timer_;
135 }
136
137 public: // inherited
138
139 bool open_mesh(const char* _filename, OpenMesh::IO::Options _opt)
140 {
141 bool rc;
142
143 if ( (rc = inherited_t::open_mesh( _filename, _opt )) )
144 {
145 std::cout << "prepare decimater" << std::endl;
146
147 decimater_ = decimater_o ( new decimater_t ( mesh() ) );
148
149 decimater_->add(mod_quadric_);
150 decimater_->module(mod_quadric_).set_binary(false);
151
152 decimater_->add(mod_nf_);
153
154 decimater_->initialize();
155 }
156 return rc;
157 }
158
159 protected slots:
160
161 void animate( void );
162
163 protected:
164
165 virtual void keyPressEvent(QKeyEvent* _event);
166
167
168 private:
169
170 bool animate_;
171 QTimer *timer_;
172
173 decimater_o decimater_;
174 mod_quadric_t mod_quadric_;
175 mod_nf_t mod_nf_;
176
177 size_t steps_;
178 };
179
180
181 //=============================================================================
182 #endif // OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH defined
183 //=============================================================================
184
FaceAttributes
#define FaceAttributes(_i)
Macro for defining the face attributes. See Specifying your MyMesh.
Definition: Traits.hh:86
DecimaterViewerWidget::DecimaterViewerWidget
DecimaterViewerWidget(QWidget *_parent=0)
default constructor
Definition: DecimaterViewerWidget.hh:113
DecimaterViewerWidget::open_mesh
bool open_mesh(const char *_filename, OpenMesh::IO::Options _opt)
open mesh
Definition: DecimaterViewerWidget.hh:139
Traits.hh
This file defines the default traits and some convenience macros.
ModQuadricT.hh
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:88
DecimaterViewerWidget::~DecimaterViewerWidget
~DecimaterViewerWidget()
destructor
Definition: DecimaterViewerWidget.hh:132
OpenMesh::Attributes::Normal
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:80
MeshViewerWidgetT
Definition: MeshViewerWidgetT.hh:69
OpenMesh::TriMesh_ArrayKernelT
Triangle mesh based on the ArrayKernel.
Definition: TriMesh_ArrayKernelT.hh:91
DecimaterT.hh
VertexAttributes
#define VertexAttributes(_i)
Macro for defining the vertex attributes. See Specifying your MyMesh.
Definition: Traits.hh:77
ModNormalFlippingT.hh
MeshViewerWidget
Definition: MeshViewerWidget.hh:73
DecimaterViewerWidget
Definition: DecimaterViewerWidget.hh:97