PropertyVisPlugin.hh 8.1 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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//=============================================================================
//
//  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>
#include <OpenFlipper/BasePlugin/INIInterface.hh>

#include <ACG/QtWidgets/QtExaminerViewer.hh>

#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include <ObjectTypes/Skeleton/BaseSkin.hh>

#include "PropertyVisToolbar.hh"
#include "PropertyNameListModel.hh"
#include "ObjectListItemModel.hh"

#include <ACG/Scenegraph/LineNode.hh>
#include <ACG/Utils/ColorGenerator.hh>

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


class PropertyVisPlugin : public QObject, BaseInterface, ToolboxInterface, KeyInterface, ScriptInterface, MouseInterface, PickingInterface, LoggingInterface, INIInterface
{
  Q_OBJECT
  Q_INTERFACES(BaseInterface)
  Q_INTERFACES(ToolboxInterface)
  Q_INTERFACES(KeyInterface)
  Q_INTERFACES(ScriptInterface)
  Q_INTERFACES(MouseInterface)
  Q_INTERFACES(PickingInterface)
  Q_INTERFACES(LoggingInterface)
  Q_INTERFACES(INIInterface)

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

  void log(Logtype, QString);
  void log(QString);
  
  // ToolboxInterface
  void addToolbox( QString _name  , QWidget* _widget ); 

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

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);

private slots:

  // BaseInterface
  void slotObjectUpdated( int _identifier, const UpdateType& _type );
  void slotAllCleared();
  
  void slotCreateProperty();
  
  // initialization functions
  void initializePlugin();
  void pluginsInitialized();


  // toolbox slots
  void slotMeshChanged(int _index = -1);
  void slotVisualize();

  //INIInterface
  void loadIniFileOptions( INIFile& _ini);
  void saveIniFileOptions( INIFile& _ini);
  void saveOnExit( INIFile& _ini );
  
  // MouseInterface
  void slotMouseEvent( QMouseEvent* _event );
  
  //PickingInterface
  void slotPickModeChanged( const std::string& _mode);
  
  void updateGUI();

  void propertySelectionChanged();

  /// Does exactly what the name suggests.
  void slotDuplicateProperty();

  /// Does exactly what the name suggests.
  void slotRemoveProperty();

public :

  PropertyVisPlugin();
  ~PropertyVisPlugin() {};


  QString name() { return (QString("Property Visualization")); };
  QString description( ) { return (QString("Computes the PropertyVis of the the active Mesh")); }; 


private :
  bool pickModeActive_;
  
  ACG::Vec3d hit_point_;
  
  std::string lastPickMode_;
  Viewer::ActionMode lastActionMode_;
  
  // Widget for Toolbox
  PropertyVisToolbar* tool_;

  // 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
private:

  template< class MeshT >
  void visualizeVector( 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();

private:

  // file for reading
  QFile        file_;
  QTextStream* file_stream_;

  // Color Generator
  ACG::ColorGenerator colorGenerator_;
  PropertyNameListModel propertyNameListModel_;
  ObjectListItemModel objectListItemModel_;
};

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