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 //--------------------
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 
85 
86 
87 //== CLASS DEFINITION =========================================================
88 
89 
90 using namespace OpenMesh;
91 
92 struct MyTraits : public DEFAULT_TRAITS
93 {
96 };
97 
98 typedef TRIMESH_KERNEL<MyTraits> mesh_t;
100 
101 //== CLASS DEFINITION =========================================================
102 
103 
105 {
106  Q_OBJECT
107 
108 public:
109 
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 >= 1900)) || __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  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 
138  animate_(false),
139  timer_(0),
140  steps_(0)
141  {
142  }
143 
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 
~DecimaterViewerWidget()
destructor
Definition: DecimaterViewerWidget.hh:145
Definition: MeshViewerWidget.hh:80
This file defines the default traits and some convenience macros.
Set options for reader/writer modules.
Definition: Options.hh:95
Definition: MeshViewerWidgetT.hh:76
#define VertexAttributes(_i)
Macro for defining the vertex attributes. See Specifying your MyMesh.
Definition: Traits.hh:84
Triangle mesh based on the ArrayKernel.
Definition: TriMesh_ArrayKernelT.hh:98
#define FaceAttributes(_i)
Macro for defining the face attributes. See Specifying your MyMesh.
Definition: Traits.hh:93
bool open_mesh(const char *_filename, OpenMesh::IO::Options _opt)
open mesh
Definition: DecimaterViewerWidget.hh:152
DecimaterViewerWidget(QWidget *_parent=0)
default constructor
Definition: DecimaterViewerWidget.hh:126
Add normals to mesh item (vertices/faces)
Definition: Attributes.hh:87
Definition: DecimaterViewerWidget.hh:104
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64

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