PropertyVisPlugin.hh 11.9 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
4
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
37
38
39
40
41
42
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen       *
*                           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/>.                                       *
*                                                                            *
\*===========================================================================*/

/*===========================================================================*\
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
\*===========================================================================*/

Jan Möbius's avatar
 
Jan Möbius committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//=============================================================================
//
//  CLASS PropertyVisPlugin
//
//=============================================================================


#ifndef PROPERTYVISPLUGIN_HH
#define PROPERTYVISPLUGIN_HH


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

#include <QObject>
#include <QMenuBar>
#include <QSpinBox>
#include <QFile>
#include <QTextStream>
#include <vector>

#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/BasePlugin/BaseInterface.hh>
#include <OpenFlipper/BasePlugin/ToolboxInterface.hh>
#include <OpenFlipper/BasePlugin/KeyInterface.hh>
#include <OpenFlipper/BasePlugin/MouseInterface.hh>
#include <OpenFlipper/BasePlugin/PickingInterface.hh>
#include <OpenFlipper/BasePlugin/ScriptInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
Jan Möbius's avatar
Jan Möbius committed
71
#include <OpenFlipper/BasePlugin/INIInterface.hh>
Jan Möbius's avatar
 
Jan Möbius committed
72
73
74

#include <ACG/QtWidgets/QtExaminerViewer.hh>

Jan Möbius's avatar
Jan Möbius committed
75
76
77
78
79
80
81
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>

#ifdef ENABLE_SKELETON_SUPPORT
  #include <ObjectTypes/Skeleton/BaseSkin.hh>
#endif

Jan Möbius's avatar
 
Jan Möbius committed
82
#include "PropertyVisToolbar.hh"
Jan Möbius's avatar
Jan Möbius committed
83
#include "PropertyNameListModel.hh"
Jan Möbius's avatar
 
Jan Möbius committed
84
85
#include "ObjectListItemModel.hh"

Jan Möbius's avatar
Jan Möbius committed
86
87
#include <ACG/Scenegraph/LineNode.hh>
#include <ACG/Utils/ColorGenerator.hh>
Jan Möbius's avatar
 
Jan Möbius committed
88

89
90
#include <stdexcept>

Jan Möbius's avatar
 
Jan Möbius committed
91
92
//== CLASS DEFINITION =========================================================

Jan Möbius's avatar
Jan Möbius committed
93
94
95
96
97
98
class VizException : public std::logic_error {
    public:
        VizException(const std::string &msg) : std::logic_error(msg) {}
};

class PropertyVisPlugin : public QObject, BaseInterface, ToolboxInterface, KeyInterface, ScriptInterface, MouseInterface, PickingInterface, LoggingInterface, INIInterface
Jan Möbius's avatar
 
Jan Möbius committed
99
100
101
102
103
104
105
106
107
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(ToolboxInterface)
  Q_INTERFACES(KeyInterface)
  Q_INTERFACES(ScriptInterface)
  Q_INTERFACES(MouseInterface)
  Q_INTERFACES(PickingInterface)
  Q_INTERFACES(LoggingInterface)
Jan Möbius's avatar
Jan Möbius committed
108
  Q_INTERFACES(INIInterface)
Jan Möbius's avatar
 
Jan Möbius committed
109
110
111
112
113
114
115
116
117

signals:
  void updateView();
  void updatedObject(int, const UpdateType&);

  void log(Logtype, QString);
  void log(QString);
  
  // ToolboxInterface
118
  void addToolbox( QString  _name  , QWidget* _widget ,QIcon* _icon);
Jan Möbius's avatar
 
Jan Möbius committed
119
120
121
122
123

  //PickingInterface
  void addHiddenPickMode( const std::string& _mode );
  

Jan Möbius's avatar
Jan Möbius committed
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
public slots:

  // load and save properties in text format
  void loadSelectedProperty( );
  void saveSelectedProperty( );

  // script functions to change selection
  void selectObjectByID  ( int _id);
  void selectObjectByName( QString _name );
  void selectElementType ( QString _etype);
  void selectDataType    ( QString _dtype);

  // properties of selected mesh for scripting
  int n_vertices();
  int n_edges();
  int n_faces();
  int n_halfedges();
  
  // File Handling
  QString getLoadFilename();
  QString getSaveFilename();
  void    openFile(QString _filename);
  void    closeFile();
  bool    eofFile();

  // Readers
  double       readDouble();
  int          readInteger();
  unsigned int readUnsignedInteger();
  QString      readString();

  // Writers
  void writeDouble(double _d);
  void writeUnsignedInteger(unsigned int _i);
  void writeInteger(int _i);
  void writeString(QString _s);

  // access of selected property (_vector_idx is only used if a vector property is selected)
  void   setCurrentProp( int _element_idx, double _val, int _vector_idx = 0);
  double getCurrentProp( int _element_idx,              int _vector_idx = 0);

private:
		  
  // Property Handling
  template <typename PropertyType>
  void setVProp(QString _property, int _vidx, PropertyType _val);

  void setVPropV3D(QString _property, int _vidx, int _vector_idx, double _val);

  template <typename PropertyType>
  void setEProp  (QString _property, int _eidx, PropertyType _val);
  void setEPropV3D(QString _property, int _eidx, int _vector_idx, double _val);

  template <typename PropertyType>
  void setFProp  (QString _property, int _fidx, PropertyType _val);
  void setFPropV3D(QString _property, int _fidx, int _vector_idx, double _val);

  template <typename PropertyType>
  void setHProp  (QString _property, int _hidx, PropertyType _val);
  void setHPropV3D(QString _property, int _hidx, int _vector_idx, double _val);

Jan Möbius's avatar
 
Jan Möbius committed
185
186
187
188
189
190
private slots:

  // BaseInterface
  void slotObjectUpdated( int _identifier, const UpdateType& _type );
  void slotAllCleared();
  
Jan Möbius's avatar
Jan Möbius committed
191
192
  void slotCreateProperty();
  
Jan Möbius's avatar
 
Jan Möbius committed
193
194
195
196
  // initialization functions
  void initializePlugin();
  void pluginsInitialized();

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

Jan Möbius's avatar
 
Jan Möbius committed
198
199
200
  // toolbox slots
  void slotMeshChanged(int _index = -1);
  void slotVisualize();
Jan Möbius's avatar
Jan Möbius committed
201
202
203
204
205

  //INIInterface
  void loadIniFileOptions( INIFile& _ini);
  void saveIniFileOptions( INIFile& _ini);
  void saveOnExit( INIFile& _ini );
Jan Möbius's avatar
 
Jan Möbius committed
206
207
208
209
210
211
212
213
214
215
216
  
  // MouseInterface
  void slotMouseEvent( QMouseEvent* _event );
  
  //PickingInterface
  void slotPickModeChanged( const std::string& _mode);
  
  void updateGUI();

  void propertySelectionChanged();

Jan Möbius's avatar
Jan Möbius committed
217
  /// Does exactly what the name suggests.
Jan Möbius's avatar
 
Jan Möbius committed
218
219
  void slotDuplicateProperty();

Jan Möbius's avatar
Jan Möbius committed
220
  /// Does exactly what the name suggests.
Jan Möbius's avatar
 
Jan Möbius committed
221
222
223
224
225
  void slotRemoveProperty();

public :

  PropertyVisPlugin();
Jan Möbius's avatar
Jan Möbius committed
226
  ~PropertyVisPlugin() {};
Jan Möbius's avatar
 
Jan Möbius committed
227
228


Jan Möbius's avatar
Jan Möbius committed
229
230
  QString name() { return (QString("Property Visualization")); };
  QString description( ) { return (QString("Computes the PropertyVis of the the active Mesh")); }; 
Jan Möbius's avatar
 
Jan Möbius committed
231
232
233


private :
Jan Möbius's avatar
Jan Möbius committed
234
235
236
237
238
239
240
  bool pickModeActive_;
  
  ACG::Vec3d hit_point_;
  
  std::string lastPickMode_;
  Viewer::ActionMode lastActionMode_;
  
Jan Möbius's avatar
 
Jan Möbius committed
241
242
243
  // Widget for Toolbox
  PropertyVisToolbar* tool_;

Jan Möbius's avatar
Jan Möbius committed
244
245
246
247
248
249
250
251
252
253
254
  // Line Node
  std::vector<ACG::SceneGraph::LineNode*> lineNodes_;

  // Converts a qcolor to a mesh color
  OpenMesh::Vec4f convertColor(const QColor _icon);

private slots:
  
  void pickValue();
  
//templates
Jan Möbius's avatar
 
Jan Möbius committed
255
256
private:

Jan Möbius's avatar
Jan Möbius committed
257
258
259
260
261
262
263
264
265
  template< class MeshT >
  void visualizeVector( MeshT*   _mesh, const PropertyNameListModel::PROP_INFO &currentProp);

  //compute the point for visualization
  template< class MeshT >
  typename MeshT::Point halfedge_point(const typename MeshT::HalfedgeHandle _heh, const MeshT *_mesh);

  template< class MeshT >
  void visualizeVector_asStroke( MeshT*   _mesh, const PropertyNameListModel::PROP_INFO &currentProp);
266

Jan Möbius's avatar
Jan Möbius committed
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
  template< class MeshT >
  void visualizeVector_asColor( MeshT*   _mesh, const PropertyNameListModel::PROP_INFO &currentProp);

  template< class MeshT >
  void visualizeVector_onEdges( MeshT*   _mesh, const PropertyNameListModel::PROP_INFO &currentProp);

  template< class MeshT >
  void visualizeDouble( MeshT*   _mesh, const PropertyNameListModel::PROP_INFO &currentProp);
  
  template< class MeshT >
  void visualizeUnsignedInteger( MeshT*   _mesh, const PropertyNameListModel::PROP_INFO &currentProp);

  template< class MeshT >
  void visualizeInteger( MeshT*   _mesh, const PropertyNameListModel::PROP_INFO &currentProp);
  
  template< class MeshT >
  void visualizeBool( MeshT*   _mesh, const PropertyNameListModel::PROP_INFO &currentProp);
  
  template< class MeshT >
  void visualizeSkinWeights( MeshT*   _mesh, int _boneId, const PropertyNameListModel::PROP_INFO &currentProp);

  template< class MeshT >
  void updatePropertyList(MeshT* _mesh);
  
  template< class MeshT >
  void getPropertyValue( MeshT* _mesh, int _id, unsigned int _face, ACG::Vec3d& _hitPoint );
  
  /// Get closest vertex index
  template< class MeshT >
  int getClosestVertex(MeshT* _mesh, int _face_idx);
  
  /// Get closest edge index
  template< class MeshT >
  int getClosestEdge(MeshT* _mesh, int _face_idx);

  /// Get closest halfedge index
  template< class MeshT >
  int getClosestHalfEdge(MeshT* _mesh, int _face_idx);


  template< class MeshT >
  void addNewProperty(MeshT* _mesh);

  /// Does exactly what the name suggests.
  template<typename MeshT>
  void visualizeProperty(MeshT *mesh, const PropertyNameListModel::PROP_INFO &currentProp);

  /// Does exactly what the name suggests.
  template<typename MeshT>
  void duplicateProperty(MeshT *mesh, const PropertyNameListModel::PROP_INFO &currentProp);

  /// Does exactly what the name suggests.
  template<typename MeshT>
  void removeProperty(MeshT *mesh, const PropertyNameListModel::PROP_INFO &currentProp);

  /// Does exactly what the name suggests.
  template<typename MeshT, float (*ScalarFn)(const typename MeshT::Point &, const typename MeshT::Point &)>
  void visualizeVectorFieldDifference(MeshT *mesh, const PropertyNameListModel::PROP_INFO &p1,
                                      const PropertyNameListModel::PROP_INFO &p2);

  BaseObjectData* getSelectedObject();
Jan Möbius's avatar
 
Jan Möbius committed
328
329

private:
330

Jan Möbius's avatar
Jan Möbius committed
331
332
333
334
335
336
337
338
  // file for reading
  QFile        file_;
  QTextStream* file_stream_;

  // Color Generator
  ACG::ColorGenerator colorGenerator_;
  PropertyNameListModel propertyNameListModel_;
  ObjectListItemModel objectListItemModel_;
Jan Möbius's avatar
 
Jan Möbius committed
339
340
341
342
343
344
345
346
347
348
};

#if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYVISPLUGIN_CC)
#define PROPERTYVISPLUGIN_TEMPLATES
#include "PropertyVisPluginT.cc"
#endif
//=============================================================================
#endif // PROPERTYVISPLUGIN_HH defined
//=============================================================================