DecimaterPlugin.hh 10.2 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
Jan Möbius's avatar
Jan Möbius committed
4
*      Copyright (C) 2001-2014 by Computer Graphics Group, RWTH Aachen       *
Jan Möbius's avatar
 
Jan Möbius committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
\*===========================================================================*/

/*===========================================================================*\
*                                                                            *
Jan Möbius's avatar
Jan Möbius committed
37
38
39
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
Jan Möbius's avatar
 
Jan Möbius committed
40
41
42
*                                                                            *
\*===========================================================================*/

Jan Möbius's avatar
Jan Möbius committed
43
44
45
46
47
#ifndef DECIMATERPLUGIN_HH
#define DECIMATERPLUGIN_HH

//== INCLUDES =================================================================

Jan Möbius's avatar
 
Jan Möbius committed
48
49
50
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/BackupInterface.hh>
Jan Möbius's avatar
Jan Möbius committed
51
52
53
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/RPCInterface.hh>
54
#include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
55
#include <OpenFlipper/BasePlugin/ProcessInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
56
57
58
59
60

#include <OpenFlipper/common/Types.hh>

#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>

Jan Möbius's avatar
Jan Möbius committed
61
62
#include "DecimaterInfo.hh"

Jan Möbius's avatar
 
Jan Möbius committed
63
64
#include "DecimaterToolbarWidget.hh"

65
66
#include "DecimateThread.hh"

Jan Möbius's avatar
 
Jan Möbius committed
67
#include <OpenMesh/Tools/Decimater/DecimaterT.hh>
68
69
#include <OpenMesh/Tools/Decimater/McDecimaterT.hh>
#include <OpenMesh/Tools/Decimater/MixedDecimaterT.hh>
Jan Möbius's avatar
 
Jan Möbius committed
70
71
72
73
74
#include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
#include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
#include <OpenMesh/Tools/Decimater/ModHausdorffT.hh>
#include <OpenMesh/Tools/Decimater/ModNormalDeviationT.hh>
#include <OpenMesh/Tools/Decimater/ModEdgeLengthT.hh>
75
#include <OpenMesh/Tools/Decimater/ModAspectRatioT.hh>
Jan Möbius's avatar
Jan Möbius committed
76
77
#include <OpenMesh/Tools/Decimater/ModRoundnessT.hh>
#include <OpenMesh/Tools/Decimater/ModIndependentSetsT.hh>
Jan Möbius's avatar
 
Jan Möbius committed
78

Jan Möbius's avatar
Jan Möbius committed
79
80
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>

81
82
83
#include <ACG/Utils/SmartPointer.hh>
#include <vector>

84
85
86
87
#include <QObject>
#include <QMenuBar>
#include <QTimer>

Jan Möbius's avatar
 
Jan Möbius committed
88
89
90

//== CLASS DEFINITION =========================================================

Jan Möbius's avatar
Jan Möbius committed
91
92
/** Plugin for Decimater Support
 */
93
class DecimaterPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingInterface, ScriptInterface, BackupInterface, RPCInterface, LoadSaveInterface, ProcessInterface
Jan Möbius's avatar
Jan Möbius committed
94
95
96
97
98
99
100
101
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(ToolboxInterface)
  Q_INTERFACES(BackupInterface)
  Q_INTERFACES(LoggingInterface)
  Q_INTERFACES(ScriptInterface)
  Q_INTERFACES(RPCInterface)
102
  Q_INTERFACES(LoadSaveInterface)
103
  Q_INTERFACES(ProcessInterface)
Jan Möbius's avatar
 
Jan Möbius committed
104

Matthias Möller's avatar
Matthias Möller committed
105
#if QT_VERSION >= 0x050000
Jan Möbius's avatar
Jan Möbius committed
106
  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Decimater")
Matthias Möller's avatar
Matthias Möller committed
107
#endif
Jan Möbius's avatar
 
Jan Möbius committed
108
109
110
111
signals:

  // BaseInterface
  void updateView();
112
  void updatedObject(int _id, const UpdateType& _type);
Jan Möbius's avatar
Jan Möbius committed
113
114
  void setSlotDescription(QString     _slotName,   QString     _slotDescription,
                          QStringList _parameters, QStringList _descriptions);
Jan Möbius's avatar
 
Jan Möbius committed
115
116
117
118
119

  // LoggingInterface
  void log(Logtype _type, QString _message);
  void log(QString _message);

Jan Möbius's avatar
Jan Möbius committed
120
121
122
  // RPC Interface
  void pluginExists( QString _pluginName , bool& _exists  ) ;
  void functionExists( QString _pluginName , QString _functionName , bool& _exists  );
123

Jan Möbius's avatar
 
Jan Möbius committed
124
125
  // ToolboxInterface
  void addToolbox( QString _name  , QWidget* _widget, QIcon* _icon );
126

Jan Möbius's avatar
Jan Möbius committed
127
128
  // ScriptInterface
  void scriptInfo( QString _functionName );
129

Jan Möbius's avatar
 
Jan Möbius committed
130
  // BackupInterface
Jan Möbius's avatar
Jan Möbius committed
131
  void createBackup( int _id , QString _name, UpdateType _type = UPDATE_ALL );
Jan Möbius's avatar
 
Jan Möbius committed
132

133
134
135
136
137
138
139
140
141
142
143
  // ProcessInterface
  void startJob( QString _jobId, QString _description , int _min , int _max , bool _blocking  = false);
  void cancelJob(QString _jobId );
  void finishJob(QString _jobId );
  void setJobState(QString, int);
  void setJobName(QString _jobId, QString _name );
  void setJobDescription(QString _jobId, QString _text );

  //self defined signals
  void jobCanceled(QString _jobId);

Jan Möbius's avatar
Jan Möbius committed
144
145
146
147
private slots:
    // BaseInterface
    void initializePlugin();
    void pluginsInitialized();
148

149
    void slotObjectUpdated( int _identifier , const UpdateType& _type ); // BaseInterface
Jan Möbius's avatar
Jan Möbius committed
150
    void slotObjectSelectionChanged( int _identifier ); // BaseInterface
Jan Möbius's avatar
 
Jan Möbius committed
151

152
153
    void objectDeleted(int _id); //LoadSaveInterface

154
155
    void slotAboutToRestore(int _id); //BackupInterface

156
157
158
    // Tell system that this plugin runs without ui
    void noguiSupported( ) {} ;

159
160
161
    // ProcessInterface
    void canceledJob (QString _job );

Jan Möbius's avatar
Jan Möbius committed
162
163
164
public :

  /// Default constructor
165
  DecimaterPlugin();
Jan Möbius's avatar
Jan Möbius committed
166
167

  /// Default destructor
Jan Möbius's avatar
 
Jan Möbius committed
168
169
  ~DecimaterPlugin() {};

Jan Möbius's avatar
Jan Möbius committed
170
171
  /// Name of the Plugin
  QString name(){ return (QString("Decimater")); };
Jan Möbius's avatar
 
Jan Möbius committed
172

Jan Möbius's avatar
Jan Möbius committed
173
174
175
  /// Description of the Plugin
  QString description() { return (QString(tr("Mesh Decimation ..."))); };

Jan Möbius's avatar
 
Jan Möbius committed
176

177
178
179
180
181
private :
  typedef DecimateThread::BaseDecimaterType             BaseDecimaterType;
  typedef DecimateThread::DecimaterType                 DecimaterType;
  typedef DecimateThread::McDecimaterType               McDecimaterType;
  typedef DecimateThread::MixedDecimaterType            MixedDecimaterType;
182

183
184
185
186
187
188
189
190
  typedef OpenMesh::Decimater::ModAspectRatioT< TriMesh >::Handle     ModAspectRatioH;
  typedef OpenMesh::Decimater::ModEdgeLengthT< TriMesh >::Handle      ModEdgeLengthH;
  typedef OpenMesh::Decimater::ModHausdorffT< TriMesh >::Handle       ModHausdorffH;
  typedef OpenMesh::Decimater::ModIndependentSetsT< TriMesh >::Handle ModIndependentH;
  typedef OpenMesh::Decimater::ModNormalDeviationT< TriMesh >::Handle ModNormalDeviationH;
  typedef OpenMesh::Decimater::ModNormalFlippingT< TriMesh >::Handle  ModNormalFlippingH;
  typedef OpenMesh::Decimater::ModQuadricT< TriMesh >::Handle         ModQuadricH;
  typedef OpenMesh::Decimater::ModRoundnessT< TriMesh >::Handle       ModRoundnessH;
191
192
193
194
195

  /// Widget for Toolbox
  DecimaterToolbarWidget* tool_;

  //saves the decimater and the object id
Matthias Möller's avatar
Matthias Möller committed
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  struct DecimaterInit
  {
    ptr::shared_ptr<BaseDecimaterType> decimater;
    int objId;
    ModAspectRatioH     hModAspectRatio;
    ModEdgeLengthH      hModEdgeLength;
    ModHausdorffH       hModHausdorff;
    ModIndependentH     hModIndependent;
    ModNormalDeviationH hModNormalDeviation;
    ModNormalFlippingH  hModNormalFlipping;
    ModQuadricH         hModQuadric;
    ModRoundnessH       hModRoundness;
  };
  std::vector< ptr::shared_ptr<DecimaterInit> > decimater_objects_;
210
211
  QIcon* toolIcon_;

212
213
  int runningJobs_;

214
private slots:
Jan Möbius's avatar
 
Jan Möbius committed
215
216
217

  /// decimating called from button in toolbox
  void slot_decimate();
218
  void slot_decimate_finished(QString _jobId); //postprocess after threads finished
Jan Möbius's avatar
 
Jan Möbius committed
219

220
221
  /// init called from button in toolbox
  void slot_initialize();
222
  void slot_initialize_object(int obj_id, bool clear = false);
223

224
private slots:
Jan Möbius's avatar
Jan Möbius committed
225
  /// roundness slider - spinbox sync
226
227
228
229
  void slotUpdateRoundness(int    _value);
  void slotUpdateRoundness(double _value);
  void slotUpdateAspectRatio(int _value);
  void slotUpdateAspectRatio(double _value);
Jan Möbius's avatar
Jan Möbius committed
230
231

  /// slider / spinbox updates
232
233
234
235
236
  void slotUpdateDistance ();
  void slotUpdateNormalDev ();
  void slotUpdateVertices ();
  void slotUpdateTriangles ();
  void slotUpdateEdgeLength ();
Jan Möbius's avatar
 
Jan Möbius committed
237

Jan Möbius's avatar
Jan Möbius committed
238
239
  /// update number of vertices information
  void slotUpdateNumVertices();
240
  void slotUpdateNumTriangles();
Jan Möbius's avatar
 
Jan Möbius committed
241

242
243
  void slotMixedCounterValueChanged(double);
  void slotMixedSliderValueChanged(int);
Matthias Möller's avatar
Matthias Möller committed
244
  void slotDisableDecimation();
245

246
247
248
private:
  void initialize_object(BaseObjectData *obj);

Jan Möbius's avatar
Jan Möbius committed
249
250
251
252
//===========================================================================
/** @name Scripting Functions
  * @{ */
//===========================================================================
Jan Möbius's avatar
 
Jan Möbius committed
253

Jan Möbius's avatar
Jan Möbius committed
254
public slots:
Jan Möbius's avatar
Jan Möbius committed
255
256
257

  /** \brief decimate an object
   *
Jan Möbius's avatar
Jan Möbius committed
258
   * @param _objID       Id of the object that should be decimated
Jan Möbius's avatar
Jan Möbius committed
259
260
261
   * @param _constraints List of constraints for the decimater
   *
   */
Jan Möbius's avatar
Jan Möbius committed
262
  void decimate(int _objID, QVariantMap _constraints);
Jan Möbius's avatar
 
Jan Möbius committed
263

Jan Möbius's avatar
Jan Möbius committed
264
265
  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
266
public slots:
Jan Möbius's avatar
Jan Möbius committed
267
268
   QString version() { return QString("1.0"); };

Jan Möbius's avatar
 
Jan Möbius committed
269
270
};

271

Jan Möbius's avatar
Jan Möbius committed
272
#endif //DECIMATERPLUGIN_HH