Developer Documentation

DecimaterPlugin.hh
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
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 #pragma once
43
44 //== INCLUDES =================================================================
45
46 #include <OpenFlipper/BasePlugin/BaseInterface.hh>
47 #include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
48 #include <OpenFlipper/BasePlugin/BackupInterface.hh>
49 #include <OpenFlipper/BasePlugin/LoggingInterface.hh>
50 #include <OpenFlipper/BasePlugin/ScriptInterface.hh>
51 #include <OpenFlipper/BasePlugin/RPCInterface.hh>
52 #include <OpenFlipper/BasePlugin/LoadSaveInterface.hh>
53 #include <OpenFlipper/BasePlugin/ProcessInterface.hh>
54 #include <OpenFlipper/BasePlugin/PythonInterface.hh>
55
56 #include <OpenFlipper/common/Types.hh>
57
58 #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
59
60 #include "DecimaterInfo.hh"
61
62 #include "DecimaterToolbarWidget.hh"
63
64 #include "DecimateThread.hh"
65
66 #include <OpenMesh/Tools/Decimater/DecimaterT.hh>
67 #include <OpenMesh/Tools/Decimater/McDecimaterT.hh>
68 #include <OpenMesh/Tools/Decimater/MixedDecimaterT.hh>
69 #include <OpenMesh/Tools/Decimater/ModQuadricT.hh>
70 #include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
71 #include <OpenMesh/Tools/Decimater/ModHausdorffT.hh>
72 #include <OpenMesh/Tools/Decimater/ModNormalDeviationT.hh>
73 #include <OpenMesh/Tools/Decimater/ModEdgeLengthT.hh>
74 #include <OpenMesh/Tools/Decimater/ModAspectRatioT.hh>
75 #include <OpenMesh/Tools/Decimater/ModRoundnessT.hh>
76 #include <OpenMesh/Tools/Decimater/ModIndependentSetsT.hh>
77
78 #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
79
80 #include <ACG/Utils/SmartPointer.hh>
81 #include <vector>
82
83 #include <QObject>
84 #include <QMenuBar>
85 #include <QTimer>
86
87
88 //== CLASS DEFINITION =========================================================
89
92 class DecimaterPlugin : public QObject, BaseInterface, ToolboxInterface, LoggingInterface, ScriptInterface, BackupInterface, RPCInterface, LoadSaveInterface, ProcessInterface, PythonInterface
93 {
94 Q_OBJECT
95 Q_INTERFACES(BaseInterface)
96 Q_INTERFACES(ToolboxInterface)
97 Q_INTERFACES(BackupInterface)
98 Q_INTERFACES(LoggingInterface)
99 Q_INTERFACES(ScriptInterface)
100 Q_INTERFACES(RPCInterface)
101 Q_INTERFACES(LoadSaveInterface)
102 Q_INTERFACES(ProcessInterface)
103 Q_INTERFACES(PythonInterface)
104
105
106 Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-Decimater")
107 signals:
108
109 // BaseInterface
110 void updateView();
111 void updatedObject(int _id, const UpdateType& _type);
112 void setSlotDescription(QString _slotName, QString _slotDescription,
113 QStringList _parameters, QStringList _descriptions);
114
115 // LoggingInterface
116 void log(Logtype _type, QString _message);
117 void log(QString _message);
118
119 // RPC Interface
120 void pluginExists( QString _pluginName , bool& _exists ) ;
121 void functionExists( QString _pluginName , QString _functionName , bool& _exists );
122
123 // ToolboxInterface
124 void addToolbox( QString _name , QWidget* _widget, QIcon* _icon );
125
126 // ScriptInterface
127 void scriptInfo( QString _functionName );
128
129 // BackupInterface
130 void createBackup( int _id , QString _name, UpdateType _type = UPDATE_ALL );
131
132 // ProcessInterface
133 void startJob( QString _jobId, QString _description , int _min , int _max , bool _blocking = false);
134 void cancelJob(QString _jobId );
135 void finishJob(QString _jobId );
136 void setJobState(QString, int);
137 void setJobName(QString _jobId, QString _name );
138 void setJobDescription(QString _jobId, QString _text );
139
140 //self defined signals
141 void jobCanceled(QString _jobId);
142
143 private slots:
144 // BaseInterface
145 void initializePlugin();
146 void pluginsInitialized();
147
148 void slotObjectUpdated( int _identifier , const UpdateType& _type ); // BaseInterface
149 void slotObjectSelectionChanged( int _identifier ); // BaseInterface
150
151 void objectDeleted(int _id); //LoadSaveInterface
152
153 void slotAboutToRestore(int _id); //BackupInterface
154
155 // Tell system that this plugin runs without ui
156 void noguiSupported( ) {} ;
157
158 // ProcessInterface
159 void canceledJob (QString _job );
160
161 public :
162
164 DecimaterPlugin();
165
167 ~DecimaterPlugin() {};
168
170 QString name(){ return (QString("Decimater")); };
171
173 QString description() { return (QString(tr("Mesh Decimation ..."))); };
174
175
176 private :
177 typedef DecimateThread::BaseDecimaterType BaseDecimaterType;
178 typedef DecimateThread::DecimaterType DecimaterType;
179 typedef DecimateThread::McDecimaterType McDecimaterType;
180 typedef DecimateThread::MixedDecimaterType MixedDecimaterType;
181
182 typedef OpenMesh::Decimater::ModAspectRatioT< TriMesh >::Handle ModAspectRatioH;
183 typedef OpenMesh::Decimater::ModEdgeLengthT< TriMesh >::Handle ModEdgeLengthH;
184 typedef OpenMesh::Decimater::ModHausdorffT< TriMesh >::Handle ModHausdorffH;
185 typedef OpenMesh::Decimater::ModIndependentSetsT< TriMesh >::Handle ModIndependentH;
186 typedef OpenMesh::Decimater::ModNormalDeviationT< TriMesh >::Handle ModNormalDeviationH;
187 typedef OpenMesh::Decimater::ModNormalFlippingT< TriMesh >::Handle ModNormalFlippingH;
188 typedef OpenMesh::Decimater::ModQuadricT< TriMesh >::Handle ModQuadricH;
189 typedef OpenMesh::Decimater::ModRoundnessT< TriMesh >::Handle ModRoundnessH;
190
192 DecimaterToolbarWidget* tool_;
193
194 //saves the decimater and the object id
195 struct DecimaterInit
196 {
197 ptr::shared_ptr<BaseDecimaterType> decimater;
198 int objId;
199 ModAspectRatioH hModAspectRatio;
200 ModEdgeLengthH hModEdgeLength;
201 ModHausdorffH hModHausdorff;
202 ModIndependentH hModIndependent;
203 ModNormalDeviationH hModNormalDeviation;
204 ModNormalFlippingH hModNormalFlipping;
205 ModQuadricH hModQuadric;
206 ModRoundnessH hModRoundness;
207 };
208 std::vector< ptr::shared_ptr<DecimaterInit> > decimater_objects_;
209 QIcon* toolIcon_;
210
211 int runningJobs_;
212
213 private slots:
214
216 void slot_decimate();
217 void slot_decimate_finished(QString _jobId); //postprocess after threads finished
218
220 void slot_initialize();
221 void slot_initialize_object(int obj_id, bool clear = false);
222
223 private slots:
225 void slotUpdateRoundness(int _value);
226 void slotUpdateRoundness(double _value);
227 void slotUpdateAspectRatio(int _value);
228 void slotUpdateAspectRatio(double _value);
229
231 void slotUpdateDistance ();
232 void slotUpdateNormalDev ();
233 void slotUpdateVertices ();
234 void slotUpdateTriangles ();
235 void slotUpdateEdgeLength ();
236
238 void slotUpdateNumVertices();
239 void slotUpdateNumTriangles();
240
241 void slotMixedCounterValueChanged(double);
242 void slotMixedSliderValueChanged(int);
243 void slotDisableDecimation();
244
245 private:
246 void initialize_object(BaseObjectData *obj);
247
248 //===========================================================================
251 //===========================================================================
252
253 public slots:
254
261 void decimate(int _objID, QVariantMap _constraints);
262
272 void decimate(int _objID, QString _constraints);
273
274 public slots:
275 QString version() { return QString("1.0"); };
276
277 };
OpenMesh::Decimater::ModHausdorffT
Use Hausdorff distance to control decimation.
Definition: ModHausdorffT.hh:79
ModNormalFlippingT.hh
UpdateType
Update type class.
Definition: UpdateType.hh:60
DecimaterPlugin::DecimaterPlugin
DecimaterPlugin()
Default constructor.
Definition: DecimaterPlugin.cc:60
RPCInterface
Interface to call functions across plugins.
Definition: RPCInterface.hh:61
ModHausdorffT.hh
UPDATE_ALL
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
TriangleMesh.hh
ProcessInterface
Interface class for Thread handling.
Definition: ProcessInterface.hh:60
DecimaterPlugin::DecimaterInit
Definition: DecimaterPlugin.hh:195
Logtype
Logtype
Log types for Message Window.
Definition: LoggingInterface.hh:92
DecimaterPlugin::name
QString name()
Name of the Plugin.
Definition: DecimaterPlugin.hh:170
LoadSaveInterface
Interface for all plugins which want to Load or Save files and create Objects.
Definition: LoadSaveInterface.hh:59
ScriptInterface
Interface for all Plugins which provide scriptable Functions.
Definition: ScriptInterface.hh:58
LoggingInterface.hh
DecimaterPlugin::decimate
void decimate(int _objID, QVariantMap _constraints)
decimate an object
Definition: DecimaterPlugin.cc:559
ModEdgeLengthT.hh
ModAspectRatioT.hh
DecimaterPlugin::canceledJob
void canceledJob(QString _job)
A job has been canceled.
Definition: DecimaterPlugin.cc:484
DecimaterPlugin::slotUpdateNumTriangles
void slotUpdateNumTriangles()
gets and sets the current maximum number of triangles
Definition: DecimaterPlugin.cc:945
LoggingInterface
Interface for all Plugins which do logging to the logging window of the framework.
Definition: LoggingInterface.hh:112
DecimaterPlugin
Definition: DecimaterPlugin.hh:92
DecimaterPlugin::slotUpdateAspectRatio
void slotUpdateAspectRatio(int _value)
sync between values of aspect ratio slider and spinbox in the toolbox
Definition: DecimaterPlugin.cc:218
BaseInterface.hh
ModRoundnessT.hh
DecimaterToolbarWidget
Definition: DecimaterToolbarWidget.hh:48
DecimaterPlugin::slot_decimate
void slot_decimate()
decimating called from button in toolbox
Definition: DecimaterPlugin.cc:417
DecimaterPlugin::description
QString description()
Description of the Plugin.
Definition: DecimaterPlugin.hh:173
ToolboxInterface
Plugins can add its own toolbox to the main widget&#39;s toolbox area by using this interface.
Definition: ToolboxInterface.hh:68
LoadSaveInterface.hh
OpenMesh::Decimater::ModNormalDeviationT
Use Normal deviation to control decimation.
Definition: ModNormalDeviationT.hh:88
OpenMesh::Decimater::ModEdgeLengthT
Use edge length to control decimation.
Definition: ModEdgeLengthT.hh:75
DecimaterPlugin::~DecimaterPlugin
~DecimaterPlugin()
Default destructor.
Definition: DecimaterPlugin.hh:167
DecimaterPlugin::tool_
DecimaterToolbarWidget * tool_
Widget for Toolbox.
Definition: DecimaterPlugin.hh:192
BaseInterface
Interface class from which all plugins have to be created.
Definition: BaseInterface.hh:65
ToolboxInterface.hh
MixedDecimaterT.hh
DecimaterT.hh
OpenMesh::Decimater::ModRoundnessT
Use Roundness of triangles to control decimation.
Definition: ModRoundnessT.hh:86
BackupInterface.hh
PythonInterface.hh
DecimaterPlugin::slotUpdateRoundness
void slotUpdateRoundness(int _value)
roundness slider - spinbox sync
Definition: DecimaterPlugin.cc:182
Types.hh
ProcessInterface.hh
DecimaterPlugin::slotUpdateNumVertices
void slotUpdateNumVertices()
update number of vertices information
Definition: DecimaterPlugin.cc:893
DecimaterPlugin::pluginsInitialized
void pluginsInitialized()
Initialization of the plugin when it is loaded by the core.
Definition: DecimaterPlugin.cc:153
OpenMesh::Decimater::ModAspectRatioT
Use aspect ratio to control decimation.
Definition: ModAspectRatioT.hh:81
ModQuadricT.hh
DecimaterPlugin::slotUpdateDistance
void slotUpdateDistance()
slider / spinbox updates
Definition: DecimaterPlugin.cc:1055
ModNormalDeviationT.hh
DecimaterPlugin::slot_initialize
void slot_initialize()
init called from button in toolbox
Definition: DecimaterPlugin.cc:242
BaseObjectData
Definition: BaseObjectData.hh:102
OpenMesh::Decimater::ModIndependentSetsT
Definition: ModIndependentSetsT.hh:69
BackupInterface
Interface class for backup handling.
Definition: BackupInterface.hh:59
RPCInterface.hh
PythonInterface
Interface class for exporting functions to python.
Definition: PythonInterface.hh:58
McDecimaterT.hh
OpenMesh::Decimater::ModQuadricT
Mesh decimation module computing collapse priority based on error quadrics.
Definition: ModQuadricT.hh:75
ScriptInterface.hh
OpenMesh::Decimater::ModNormalFlippingT
Definition: ModNormalFlippingT.hh:80