Developer Documentation
VolumeMeshSelectionPlugin.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 #ifndef VOLUMEMESHSELECTIONPLUGIN_HH
43 #define VOLUMEMESHSELECTIONPLUGIN_HH
44 
45 #include <QObject>
46 
54 #include <OpenFlipper/BasePlugin/INIInterface.hh>
59 #include <OpenFlipper/INIFile/INIFile.hh>
60 
63 #ifdef ENABLE_TETRAHEDRALMESH_SUPPORT
65 #endif
66 
67 class ParameterWidget;
68 
71 {
72  Q_OBJECT
73  Q_INTERFACES(BaseInterface)
74  Q_INTERFACES(KeyInterface)
75  Q_INTERFACES(INIInterface)
76  Q_INTERFACES(BackupInterface)
77  Q_INTERFACES(LoggingInterface)
78  Q_INTERFACES(ScriptInterface)
79  Q_INTERFACES(SelectionInterface)
80 
81  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-SelectionVolumeMesh")
82 
83 public:
84 
87 
90 
91  friend class SelectVolumeAction;
92 
94  void set_max_angle(const double _a);
96  double get_max_angle();
97 
98 signals:
99 
100  // BaseInterface
101  void updateView();
102  void updatedObject(int, const UpdateType&);
103  void nodeVisibilityChanged(int _identifier);
104  void setSlotDescription(QString _slotName, QString _slotDescription,
105  QStringList _parameters, QStringList _descriptions);
106 
107  // LoggingInterface
108  void log(Logtype _type, QString _message);
109  void log(QString _message);
110 
111  // ScriptInterface
112  void scriptInfo(QString _functionName);
113 
114  // SelectionInterface
115  void addSelectionEnvironment(QString _modeName, QString _description, QString _icon, QString& _handleName);
116  void registerType(QString _handleName, DataType _type);
117  void addPrimitiveType(QString _handleName, QString _name, QString _icon, SelectionInterface::PrimitiveType& _typeHandle);
118  void addSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type = 0u);
119  void addSelectionParameters(QString _handleName, QWidget* _widget, QString _category, SelectionInterface::PrimitiveType _type = 0u);
120 
121  void showToggleSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
122 
123  void showVolumeLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
124  void showFloodFillSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
125  void addCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QString _icon,
126  SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier);
127 
128  void getActiveDataTypes(SelectionInterface::TypeList& _types);
129  void getActivePrimitiveType(SelectionInterface::PrimitiveType& _type);
130  void targetObjectsOnly(bool& _targetsOnly);
131 
132  void registerKeyShortcut(int _key, Qt::KeyboardModifiers _modifiers = Qt::NoModifier);
133 
134 private slots:
135 
136  // INIInterface
137  void loadIniFile(INIFile& _ini, int _id);
138  void saveIniFile(INIFile& _ini, int _id);
139 
140  // BaseInterface
141  void initializePlugin();
142  void pluginsInitialized();
143  void noguiSupported() {};
144 
145  // SelectionInterface
146  void slotSelectionOperation(QString _operation);
147  void slotToggleSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
148 
149  void slotVolumeLassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
150  void slotFloodFillSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
151  void slotCustomSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, QString _customIdentifier, bool _deselect);
152 
153  void slotLoadSelection(const INIFile& _file);
154  void slotSaveSelection(INIFile& _file);
155 
156  void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers);
157 
158 public slots:
159 
160  // SelectionInterface
161  void loadSelection(int _objId, const QString& _filename);
162 
163 public:
164 
165  // BaseInterface
166  QString name() {
167  return (QString(tr("VolumeMesh Selection")));
168  };
169 
170  QString description() {
171  return (QString(tr("Allows to select VolumeMeshes")));
172  };
173 
174  //===========================================================================
177  //===========================================================================
178 private:
179 
181  void updateSlotDescriptions();
182 
185 public slots:
186 
187  QString version() {
188  return QString("1.0");
189  };
190 
191  //===========================================================================
194  //===========================================================================
195 
197  bool vertexTypeActive();
198 
200  bool edgeTypeActive();
201 
203  bool faceTypeActive();
204 
206  bool cellTypeActive();
207 
208  //===========================================================================
209 
211  void selectAllVertices(int _objectId);
212 
214  void deselectAllVertices(int _objectId);
215 
217  void invertVertexSelection(int _objectId);
218 
220  void selectVertices(int _objectId, const IdList& _ids, bool _deselect = false);
221 
223  IdList getVertexSelection(int _objectId);
224 
226  void deleteSelectedVertices(int _objectId, bool _preserveManifoldness = true);
227 
228  //===========================================================================
229 
231  void selectAllEdges(int _objectId);
232 
234  void deselectAllEdges(int _objectId);
235 
237  void invertEdgeSelection(int _objectId);
238 
240  void selectEdges(int _objectId, const IdList& _ids, bool _deselect = false);
241 
243  IdList getEdgeSelection(int _objectId);
244 
246  void deleteSelectedEdges(int _objectId, bool _preserveManifoldness = true);
247 
248  //===========================================================================
249 
251  void selectAllHalfEdges(int _objectId);
252 
254  void deselectAllHalfEdges(int _objectId);
255 
257  void invertHalfEdgeSelection(int _objectId);
258 
260  void selectHalfEdges(int _objectId, const IdList& _ids, bool _deselect = false);
261 
263  IdList getHalfEdgeSelection(int _objectId);
264 
265  //===========================================================================
266 
268  void selectAllFaces(int _objectId);
269 
271  void deselectAllFaces(int _objectId);
272 
274  void invertFaceSelection(int _objectId);
275 
277  void selectFaces(int _objectId, const IdList& _ids, bool _deselect = false);
278 
280  IdList getFaceSelection(int _objectId);
281 
283  void deleteSelectedFaces(int _objectId, bool _preserveManifoldness = true);
284 
285  //===========================================================================
286 
288  void selectAllHalfFaces(int _objectId);
289 
291  void deselectAllHalfFaces(int _objectId);
292 
294  void invertHalfFaceSelection(int _objectId);
295 
297  void selectHalfFaces(int _objectId, const IdList& _ids, bool _deselect = false);
298 
300  IdList getHalfFaceSelection(int _objectId);
301 
302  //===========================================================================
303 
305  void selectAllCells(int _objectId);
306 
308  void deselectAllCells(int _objectId);
309 
311  void invertCellSelection(int _objectId);
312 
314  void selectCells(int _objectId, const IdList& _ids, bool _deselect = false);
315 
317  IdList getCellSelection(int _objectId);
318 
320  void deleteSelectedCells(int _objectId, bool _preserveManifoldness = true);
321 
324  //===========================================================================
327  //===========================================================================
328 
329 private:
331  template<class MeshT>
332  bool volumeSelection(MeshT* _mesh, ACG::GLState& _state, QRegion *_region,
333  PrimitiveType _primitiveTypes, bool _deselection);
334 
336  template<class MeshT>
337  void floodFillSelection(MeshT* _mesh, uint _fh, double _maxAngle,
338  PrimitiveType _primitiveTypes, bool _deselection);
339 
340  // Get orthogonal orientation of neighboring cell
342  const OpenVolumeMesh::CellHandle& _ch2, unsigned char _firstOrthDirection, const HexahedralMesh* _mesh) const;
343 
344  // Get face shared by two adjacent cells
345  typedef std::pair<OpenVolumeMesh::HalfFaceHandle,OpenVolumeMesh::HalfFaceHandle> HFPair;
346  HFPair getCommonFace(const OpenVolumeMesh::CellHandle& _ch1,
347  const OpenVolumeMesh::CellHandle& _ch2, const HexahedralMesh* _mesh) const;
348 
349 
350  OpenVolumeMesh::StatusAttrib* getStatus(int _objectId);
352 
355 
358 
360  PrimitiveType vertexType_;
361  PrimitiveType edgeType_;
362  PrimitiveType faceType_;
363  PrimitiveType cellType_;
364 
365  PrimitiveType allSupportedTypes_;
367 
369 
370  double max_angle_;
371 
373  QVector<QPoint> volumeLassoPoints_;
374 
375  // Store last picked cell for sheet selection
377  unsigned char lastPickedOrientation_;
378  std::map<OpenVolumeMesh::CellHandle, unsigned char> orientationMap_;
379 
382 };
383 
385 class SelectVolumeAction
386 {
387 public:
388  SelectVolumeAction(QRegion&_region, VolumeMeshSelectionPlugin* _plugin,
389  unsigned int _type, bool _deselection, ACG::GLState& _state)
390  : state_(_state)
391  , region_(_region)
392  , plugin_(_plugin)
393  , type_(_type)
394  , deselection_(_deselection)
395  {
396  }
397 
398  void enter(BaseNode* /*_node*/) {}
399  void leave(BaseNode* /*_node*/) {}
400 
401  bool operator()(BaseNode* _node);
402 
403 private:
404  ACG::GLState& state_;
405  QRegion& region_;
406  VolumeMeshSelectionPlugin* plugin_;
407  unsigned int type_;
408  bool deselection_;
409 };
410 //=============================================================================
411 #if defined(INCLUDE_TEMPLATES) && !defined(VOLUMEMESHSELECTIONPLUGINT_CC)
412 #define VOLUMEMESHSELECTIONPLUGINT_TEMPLATES
413 #include "VolumeMeshSelectionPluginT_impl.hh"
414 #endif
415 
416 //=============================================================================
417 #endif // VOLUMEMESHSELECTIONPLUGIN_HH defined
418 //=============================================================================
OpenVolumeMesh::CellHandle lastPickedCell_
Handle to selection environment.
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
void selectFaces(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific faces of a volume mesh.
void selectAllCells(int _objectId)
Select all cells of a volume mesh.
~VolumeMeshSelectionPlugin()
Default destructor.
unsigned char getOrthogonalOrientationOfNeighborCell(const OpenVolumeMesh::CellHandle &_ch1, const OpenVolumeMesh::CellHandle &_ch2, unsigned char _firstOrthDirection, const HexahedralMesh *_mesh) const
Handle to selection environment.
void selectAllHalfEdges(int _objectId)
Select all half-edges of a volume mesh.
void deselectAllEdges(int _objectId)
Deselect all edges of a volume mesh.
void selectHalfEdges(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific half-edges of a volume mesh.
void selectCells(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific cells of a volume mesh.
QString environmentHandle_
Handle to selection environment.
void deleteSelectedEdges(int _objectId, bool _preserveManifoldness=true)
Delete selected edges from mesh.
void selectAllVertices(int _objectId)
Select all vertices of a volume mesh.
void selectEdges(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific edges of a volume mesh.
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
void slotFloodFillSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a flood fill selection.
void slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
OpenVolumeMesh::StatusAttrib * getStatus(int _objectId)
Handle to selection environment.
double max_angle_
Handle to selection environment.
Logtype
Log types for Message Window.
bool edgeTypeActive()
Is vertex type active? (for use in plugins that need mesh selection)
PrimitiveType allSupportedTypes_
Handle to selection environment.
IdList getCellSelection(int _objectId)
Get current cell selection.
Predefined datatypes.
Definition: DataTypes.hh:83
Interface for all Plugins which do logging to the logging window of the framework.
bool faceTypeActive()
Is face type active? (for use in plugins that need mesh selection)
void deleteSelectedFaces(int _objectId, bool _preserveManifoldness=true)
Delete selected faces from mesh.
IdList getHalfFaceSelection(int _objectId)
Get current half-face selection.
void deselectAllVertices(int _objectId)
Deselect all vertices of a volume mesh.
HFPair getCommonFace(const OpenVolumeMesh::CellHandle &_ch1, const OpenVolumeMesh::CellHandle &_ch2, const HexahedralMesh *_mesh) const
Handle to selection environment.
QString name()
Return a name for the plugin.
void selectHalfFaces(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific half-faces of a volume mesh.
IdList getEdgeSelection(int _objectId)
Get current edge selection.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:181
bool volumeSelection(MeshT *_mesh, ACG::GLState &_state, QRegion *_region, PrimitiveType _primitiveTypes, bool _deselection)
Surface volume selection tool.
void deleteSelectedVertices(int _objectId, bool _preserveManifoldness=true)
Delete selected vertices from mesh.
void floodFillSelection(MeshT *_mesh, uint _fh, double _maxAngle, PrimitiveType _primitiveTypes, bool _deselection)
Select all entities that are connected (and do not exceed the maximum dihedral angle) ...
bool vertexTypeActive()
Is vertex type active? (for use in plugins that need mesh selection)
void invertHalfEdgeSelection(int _objectId)
Invert half-edge selection.
void selectAllFaces(int _objectId)
Select all faces of a volume mesh.
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
void selectAllHalfFaces(int _objectId)
Select all half-faces of a volume mesh.
QVector< QPoint > volumeLassoPoints_
Keep volume lasso points.
bool cellTypeActive()
Is cell type active? (for use in plugins that need mesh selection)
PrimitiveType faceType_
Handle to selection environment.
void deselectAllFaces(int _objectId)
Deselect all faces of a volume mesh.
PrimitiveType cellType_
Handle to selection environment.
PrimitiveType edgeType_
Handle to selection environment.
QString columnSelectionHandle_
Handle to selection environment.
PrimitiveType vertexType_
Primitive type handles:
Interface for all plugins which want to use selection functions.
void deselectAllCells(int _objectId)
Deselect all cells of a volume mesh.
void deleteSelectedCells(int _objectId, bool _preserveManifoldness=true)
Delete selected cells from mesh.
Update type class.
Definition: UpdateType.hh:59
void invertEdgeSelection(int _objectId)
Invert edge selection.
void invertCellSelection(int _objectId)
Invert cell selection.
IdList getFaceSelection(int _objectId)
Get current face selection.
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle selection.
void slotSelectionOperation(QString _operation)
A specific operation is requested.
unsigned char lastPickedOrientation_
Handle to selection environment.
Keyboard Event Interface.
Definition: KeyInterface.hh:59
Interface class for Plugins which have to store information in ini files.
Definition: INIInterface.hh:60
void deselectAllHalfFaces(int _objectId)
Deselect all half-faces of a volume mesh.
void selectAllEdges(int _objectId)
Select all edges of a volume mesh.
std::map< OpenVolumeMesh::CellHandle, unsigned char > orientationMap_
Handle to selection environment.
Class for the handling of simple configuration files.
Definition: INIFile.hh:99
ParameterWidget * parameterWidget_
Handle to selection environment.
IdList getVertexSelection(int _objectId)
Get current vertex selection.
void deselectAllHalfEdges(int _objectId)
Deselect all half-edges of a volume mesh.
void selectVertices(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific vertices of a volume mesh.
std::pair< OpenVolumeMesh::HalfFaceHandle, OpenVolumeMesh::HalfFaceHandle > HFPair
Handle to selection environment.
Interface for all Plugins which provide scriptable Functions.
void set_max_angle(const double _a)
set max angle for flood fill selection
QString description()
Return a description of what the plugin is doing.
void invertFaceSelection(int _objectId)
Invert face selection.
void slotCustomSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, QString _customIdentifier, bool _deselect)
Called whenever the user performs a custom selection.
double get_max_angle()
get max angle for flood fill selection
VolumeMeshSelectionPlugin()
Default constructor.
void invertVertexSelection(int _objectId)
Invert vertex selection.
QString sheetSelectionHandle_
Handle to selection environment.
void updateSlotDescriptions()
Set slot descriptions for scripting functions.
IdList getHalfEdgeSelection(int _objectId)
Get current half-edge selection.
PrimitiveType floodFillSupportedTypes_
Handle to selection environment.
Interface class from which all plugins have to be created.
Interface class for backup handling.
Traverse the scenegraph and call the selection function for all mesh nodes.
void invertHalfFaceSelection(int _objectId)
Invert half-face selection.