| 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
45 #ifndef OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
46 #define OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH
47
48
49 //== INCLUDES =================================================================
50
51 #if !defined(OM_USE_OSG)
52 # define OM_USE_OSG 0
53 #endif
54
55
56 #include <qtimer.h>
57 #include <string>
58 #include <memory>
59
60 //--------------------
61 #include <OpenMesh/Core/IO/MeshIO.hh>
62 //--------------------
63 #if OM_USE_OSG
64 # include <OpenMesh/Tools/Kernel_OSG/TriMesh_OSGArrayKernelT.hh>
65 # define DEFAULT_TRAITS Kernel_OSG::Traits
66 # define TRIMESH_KERNEL Kernel_OSG::TriMesh_OSGArrayKernelT
67 #else
68 //--------------------
69 # include <OpenMesh/Core/Mesh/Traits.hh>
70 # include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
71 # define DEFAULT_TRAITS DefaultTraits
72 # define TRIMESH_KERNEL TriMesh_ArrayKernelT
73 #endif
74
75 #include <OpenMesh/Apps/QtViewer/MeshViewerWidgetT.hh>
76
77 #include <OpenMesh/Tools/Decimater/DecimaterT.hh>
78 #include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
79 #include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
80
81
82 //== CLASS DEFINITION =========================================================
83
84
85 using namespace OpenMesh;
86
87 struct MyTraits : public DEFAULT_TRAITS
88 {
89 VertexAttributes ( Attributes::Normal );
90 FaceAttributes ( Attributes::Normal );
91 };
92
93 typedef TRIMESH_KERNEL<MyTraits> mesh_t;
94 typedef MeshViewerWidgetT<mesh_t> MeshViewerWidgetDecimaterBase;
95
96 //== CLASS DEFINITION =========================================================
97
98
99 class DecimaterViewerWidget : public MeshViewerWidgetDecimaterBase
100 {
101 Q_OBJECT
102
103 public:
104
105 typedef MeshViewerWidgetDecimaterBase inherited_t;
106
107 typedef Decimater::DecimaterT<mesh_t> decimater_t;
108 typedef Decimater::ModQuadricT< mesh_t >::Handle mod_quadric_t;
109 typedef Decimater::ModNormalFlippingT< mesh_t >::Handle mod_nf_t;
110
111 // object types
112 #if (defined(_MSC_VER) && (_MSC_VER >= 1800)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)
113 typedef std::unique_ptr< decimater_t > decimater_o;
114 #else
115 typedef std::auto_ptr< decimater_t > decimater_o;
116 #endif
117
118
119
121 explicit DecimaterViewerWidget(QWidget* _parent=0)
122 : MeshViewerWidgetDecimaterBase(_parent),
123 animate_(false),
124 timer_(0),
125 steps_(1)
126 {
127 timer_ = new QTimer(this);
128
129 connect( timer_, SIGNAL(timeout()), SLOT(animate()) );
130 }
131
132 DecimaterViewerWidget() :
133 animate_(false),
134 timer_(0),
135 steps_(0)
136 {
137 }
138
140 ~DecimaterViewerWidget()
141 {
142 delete timer_;
143 }
144
145 public: // inherited
146
147 bool open_mesh(const char* _filename, OpenMesh::IO::Options _opt) override
148 {
149 bool rc;
150
151 if ( (rc = inherited_t::open_mesh( _filename, _opt )) )
152 {
153 std::cout << "prepare decimater" << std::endl;
154
155 decimater_ = decimater_o ( new decimater_t ( mesh() ) );
156
157 decimater_->add(mod_quadric_);
158 decimater_->module(mod_quadric_).set_binary(false);
159
160 decimater_->add(mod_nf_);
161
162 decimater_->initialize();
163 }
164 return rc;
165 }
166
167 protected slots:
168
169 void animate( void );
170
171 protected:
172
173 virtual void keyPressEvent(QKeyEvent* _event) override;
174
175
176 private:
177
178 bool animate_;
179 QTimer *timer_;
180
181 decimater_o decimater_;
182 mod_quadric_t mod_quadric_;
183 mod_nf_t mod_nf_;
184
185 size_t steps_;
186 };
187
188
189 //=============================================================================
190 #endif // OPENMESHAPPS_DECIMATERVIEWERWIDGET_HH defined
191 //=============================================================================
192
DecimaterViewerWidget
Definition: DecimaterViewerWidget.hh:99
DecimaterViewerWidget::~DecimaterViewerWidget
~DecimaterViewerWidget()
destructor
Definition: DecimaterViewerWidget.hh:140
FaceAttributes
#define FaceAttributes(_i)
Macro for defining the face attributes. See Specifying your MyMesh.
Definition: Traits.hh:88
DecimaterViewerWidget::open_mesh
bool open_mesh(const char *_filename, OpenMesh::IO::Options _opt) override
open mesh
Definition: DecimaterViewerWidget.hh:147
Traits.hh
This file defines the default traits and some convenience macros.
ModNormalFlippingT.hh
DecimaterViewerWidget::DecimaterViewerWidget
DecimaterViewerWidget(QWidget *_parent=0)
default constructor
Definition: DecimaterViewerWidget.hh:121
ModQuadricT.hh
OpenMesh::IO::Options
Set options for reader/writer modules.
Definition: Options.hh:90
MeshViewerWidgetT
Definition: MeshViewerWidgetT.hh:70
DecimaterT.hh
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
OpenMesh::Attributes::Normal
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:82
OpenMesh::TriMesh_ArrayKernelT
Triangle mesh based on the ArrayKernel.
Definition: PolyMesh_ArrayKernelT.hh:73
VertexAttributes
#define VertexAttributes(_i)
Macro for defining the vertex attributes. See Specifying your MyMesh.
Definition: Traits.hh:79