OpenMesh: OpenMesh/Apps/Decimating/DecimaterViewerWidget.hh Source File

| OpenMesh

DecimaterViewerWidget.hh
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42 /*===========================================================================*\
43 * *
44 * $Revision$ *
45 * $Date$ *
46 * *
47 \*===========================================================================*/
48
49
50 #ifndef OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
51 #define OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
52
53
54 //== INCLUDES =================================================================
55
56 #if !defined(OM_USE_OSG)
57 # define OM_USE_OSG 0
58 #endif
59
60
61 #include <qtimer.h>
62 #include <string>
63 #include <memory>
64
65 //--------------------
66 #include <OpenMesh/Core/IO/MeshIO.hh>
67 //--------------------
68 #if OM_USE_OSG
69 # include <OpenMesh/Tools/Kernel_OSG/TriMesh_OSGArrayKernelT.hh>
70 # define DEFAULT_TRAITS Kernel_OSG::Traits
71 # define TRIMESH_KERNEL Kernel_OSG::TriMesh_OSGArrayKernelT
72 #else
73 //--------------------
74 # include <OpenMesh/Core/Mesh/Traits.hh>
75 # include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
76 # define DEFAULT_TRAITS DefaultTraits
77 # define TRIMESH_KERNEL TriMesh_ArrayKernelT
78 #endif
79
80 #include <OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh>
81
82 #include <OpenMesh/Tools/Decimater/DecimaterT.hh>
83 #include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
84 #include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
85
86
87 //== CLASS DEFINITION =========================================================
88
89
90 using namespace OpenMesh;
91
92 struct MyTraits : public DEFAULT_TRAITS
93 {
94 VertexAttributes ( Attributes::Normal );
95 FaceAttributes ( Attributes::Normal );
96 };
97
98 typedef TRIMESH_KERNEL<MyTraits> mesh_t;
99 typedef MeshViewerWidgetT<mesh_t> MeshViewerWidget;
100
101 //== CLASS DEFINITION =========================================================
102
103
104 class DecimaterViewerWidget : public MeshViewerWidget
105 {
106 Q_OBJECT
107
108 public:
109
110 typedef MeshViewerWidget inherited_t;
111
112 typedef Decimater::DecimaterT<mesh_t> decimater_t;
113 typedef Decimater::ModQuadricT< mesh_t >::Handle mod_quadric_t;
114 typedef Decimater::ModNormalFlippingT< mesh_t >::Handle mod_nf_t;
115
116 // object types
117 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
118 typedef std::unique_ptr< decimater_t > decimater_o;
119 #else
120 typedef std::auto_ptr< decimater_t > decimater_o;
121 #endif
122
123
124
126 explicit DecimaterViewerWidget(QWidget* _parent=0)
127 : MeshViewerWidget(_parent),
128 animate_(false),
129 timer_(0),
130 steps_(1)
131 {
132 timer_ = new QTimer(this);
133
134 connect( timer_, SIGNAL(timeout()), SLOT(animate()) );
135 }
136
137 DecimaterViewerWidget() :
138 animate_(false),
139 timer_(0),
140 steps_(0)
141 {
142 }
143
145 ~DecimaterViewerWidget()
146 {
147 delete timer_;
148 }
149
150 public: // inherited
151
152 bool open_mesh(const char* _filename, OpenMesh::IO::Options _opt)
153 {
154 bool rc;
155
156 if ( (rc = inherited_t::open_mesh( _filename, _opt )) )
157 {
158 std::cout << "prepare decimater" << std::endl;
159
160 decimater_ = decimater_o ( new decimater_t ( mesh() ) );
161
162 decimater_->add(mod_quadric_);
163 decimater_->module(mod_quadric_).set_binary(false);
164
165 decimater_->add(mod_nf_);
166
167 decimater_->initialize();
168 }
169 return rc;
170 }
171
172 protected slots:
173
174 void animate( void );
175
176 protected:
177
178 virtual void keyPressEvent(QKeyEvent* _event);
179
180
181 private:
182
183 bool animate_;
184 QTimer *timer_;
185
186 decimater_o decimater_;
187 mod_quadric_t mod_quadric_;
188 mod_nf_t mod_nf_;
189
190 size_t steps_;
191 };
192
193
194 //=============================================================================
195 #endif // OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH defined
196 //=============================================================================
197
MeshViewerWidgetT
Definition: MeshViewerWidgetT.hh:76
DecimaterViewerWidget::DecimaterViewerWidget
DecimaterViewerWidget(QWidget *_parent=0)
default constructor
Definition: DecimaterViewerWidget.hh:126
VertexAttributes
#define VertexAttributes(_i)
Macro for defining the vertex attributes. See Specifying your MyMesh.
Definition: Traits.hh:84
DecimaterT.hh
FaceAttributes
#define FaceAttributes(_i)
Macro for defining the face attributes. See Specifying your MyMesh.
Definition: Traits.hh:93
DecimaterViewerWidget::open_mesh
bool open_mesh(const char *_filename, OpenMesh::IO::Options _opt)
open mesh
Definition: DecimaterViewerWidget.hh:152
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
DecimaterViewerWidget::~DecimaterViewerWidget
~DecimaterViewerWidget()
destructor
Definition: DecimaterViewerWidget.hh:145
ModQuadricT.hh
OpenMesh::Attributes::Normal
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
OpenMesh::TriMesh_ArrayKernelT
Triangle mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:78
ModNormalFlippingT.hh
MeshViewerWidget
Definition: MeshViewerWidget.hh:80
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:95
DecimaterViewerWidget
Definition: DecimaterViewerWidget.hh:104
Traits.hh
This file defines the default traits and some convenience macros.