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 /*===========================================================================*\
43  * *
44  * $Revision: 11942 $ *
45  * $Author: kremer $ *
46  * $Date: 2011-07-06 15:10:17 +0200 (Wed, 06 Jul 2011) $ *
47  * *
48 \*===========================================================================*/
49 
50 #ifndef VOLUMEMESHSELECTIONPLUGIN_HH
51 #define VOLUMEMESHSELECTIONPLUGIN_HH
52 
53 #include <QObject>
54 
62 #include <OpenFlipper/BasePlugin/INIInterface.hh>
67 #include <OpenFlipper/INIFile/INIFile.hh>
68 
71 #ifdef ENABLE_OPENVOLUMEMESH_TETRAHEDRAL_SUPPORT
73 #endif
74 
77 {
78  Q_OBJECT
79  Q_INTERFACES(BaseInterface)
80  Q_INTERFACES(KeyInterface)
81  Q_INTERFACES(INIInterface)
82  Q_INTERFACES(BackupInterface)
83  Q_INTERFACES(LoggingInterface)
84  Q_INTERFACES(ScriptInterface)
85  Q_INTERFACES(SelectionInterface)
86 
87 #if QT_VERSION >= 0x050000
88  Q_PLUGIN_METADATA(IID "org.OpenFlipper.Plugins.Plugin-SelectionVolumeMesh")
89 #endif
90 
91 public:
92 
95 
98 
99  friend class SelectVolumeAction;
100 
101 signals:
102 
103  // BaseInterface
104  void updateView();
105  void updatedObject(int, const UpdateType&);
106  void nodeVisibilityChanged(int _identifier);
107  void setSlotDescription(QString _slotName, QString _slotDescription,
108  QStringList _parameters, QStringList _descriptions);
109 
110  // LoggingInterface
111  void log(Logtype _type, QString _message);
112  void log(QString _message);
113 
114  // ScriptInterface
115  void scriptInfo(QString _functionName);
116 
117  // SelectionInterface
118  void addSelectionEnvironment(QString _modeName, QString _description, QString _icon, QString& _handleName);
119  void registerType(QString _handleName, DataType _type);
120  void addPrimitiveType(QString _handleName, QString _name, QString _icon, SelectionInterface::PrimitiveType& _typeHandle);
121  void addSelectionOperations(QString _handleName, QStringList _operationsList, QString _category, SelectionInterface::PrimitiveType _type = 0u);
122 
123  void showToggleSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
124 
125  void showVolumeLassoSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
126  void showFloodFillSelectionMode(QString _handleName, bool _show, SelectionInterface::PrimitiveType _associatedTypes);
127  void addCustomSelectionMode(QString _handleName, QString _modeName, QString _description, QString _icon,
128  SelectionInterface::PrimitiveType _associatedTypes, QString& _customIdentifier);
129 
130  void getActiveDataTypes(SelectionInterface::TypeList& _types);
131  void getActivePrimitiveType(SelectionInterface::PrimitiveType& _type);
132  void targetObjectsOnly(bool& _targetsOnly);
133 
134  void registerKeyShortcut(int _key, Qt::KeyboardModifiers _modifiers = Qt::NoModifier);
135 
136 private slots:
137 
138  // INIInterface
139  void loadIniFile(INIFile& _ini, int _id);
140  void saveIniFile(INIFile& _ini, int _id);
141 
142  // BaseInterface
143  void initializePlugin();
144  void pluginsInitialized();
145  void noguiSupported() {};
146 
147  // SelectionInterface
148  void slotSelectionOperation(QString _operation);
149  void slotToggleSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
150 
151  void slotVolumeLassoSelection(QMouseEvent* _event, SelectionInterface::PrimitiveType _currentType, bool _deselect);
152  void slotFloodFillSelection(QMouseEvent* _event, double _maxAngle, SelectionInterface::PrimitiveType _currentType, bool _deselect);
153  void slotCustomSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, QString _customIdentifier, bool _deselect);
154 
155  void slotLoadSelection(const INIFile& _file);
156  void slotSaveSelection(INIFile& _file);
157 
158  void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers);
159 
160 public slots:
161 
162  // SelectionInterface
163  void loadSelection(int _objId, const QString& _filename);
164 
165 public:
166 
167  // BaseInterface
168  QString name() {
169  return (QString(tr("VolumeMesh Selection")));
170  };
171 
172  QString description() {
173  return (QString(tr("Allows to select VolumeMeshes")));
174  };
175 
176  //===========================================================================
179  //===========================================================================
180 private:
181 
183  void updateSlotDescriptions();
184 
187 public slots:
188 
189  QString version() {
190  return QString("1.0");
191  };
192 
193  //===========================================================================
196  //===========================================================================
197 
199  bool vertexTypeActive();
200 
202  bool edgeTypeActive();
203 
205  bool faceTypeActive();
206 
208  bool cellTypeActive();
209 
210  //===========================================================================
211 
213  void selectAllVertices(int _objectId);
214 
216  void deselectAllVertices(int _objectId);
217 
219  void invertVertexSelection(int _objectId);
220 
222  void selectVertices(int _objectId, const IdList& _ids, bool _deselect = false);
223 
225  IdList getVertexSelection(int _objectId);
226 
228  void deleteSelectedVertices(int _objectId, bool _preserveManifoldness = true);
229 
230  //===========================================================================
231 
233  void selectAllEdges(int _objectId);
234 
236  void deselectAllEdges(int _objectId);
237 
239  void invertEdgeSelection(int _objectId);
240 
242  void selectEdges(int _objectId, const IdList& _ids, bool _deselect = false);
243 
245  IdList getEdgeSelection(int _objectId);
246 
248  void deleteSelectedEdges(int _objectId, bool _preserveManifoldness = true);
249 
250  //===========================================================================
251 
253  void selectAllHalfEdges(int _objectId);
254 
256  void deselectAllHalfEdges(int _objectId);
257 
259  void invertHalfEdgeSelection(int _objectId);
260 
262  void selectHalfEdges(int _objectId, const IdList& _ids, bool _deselect = false);
263 
265  IdList getHalfEdgeSelection(int _objectId);
266 
267  //===========================================================================
268 
270  void selectAllFaces(int _objectId);
271 
273  void deselectAllFaces(int _objectId);
274 
276  void invertFaceSelection(int _objectId);
277 
279  void selectFaces(int _objectId, const IdList& _ids, bool _deselect = false);
280 
282  IdList getFaceSelection(int _objectId);
283 
285  void deleteSelectedFaces(int _objectId, bool _preserveManifoldness = true);
286 
287  //===========================================================================
288 
290  void selectAllHalfFaces(int _objectId);
291 
293  void deselectAllHalfFaces(int _objectId);
294 
296  void invertHalfFaceSelection(int _objectId);
297 
299  void selectHalfFaces(int _objectId, const IdList& _ids, bool _deselect = false);
300 
302  IdList getHalfFaceSelection(int _objectId);
303 
304  //===========================================================================
305 
307  void selectAllCells(int _objectId);
308 
310  void deselectAllCells(int _objectId);
311 
313  void invertCellSelection(int _objectId);
314 
316  void selectCells(int _objectId, const IdList& _ids, bool _deselect = false);
317 
319  IdList getCellSelection(int _objectId);
320 
322  void deleteSelectedCells(int _objectId, bool _preserveManifoldness = true);
323 
326  //===========================================================================
329  //===========================================================================
330 
331 private:
333  template<class MeshT>
334  bool volumeSelection(MeshT* _mesh, ACG::GLState& _state, QRegion *_region,
335  PrimitiveType _primitiveTypes, bool _deselection);
336 
338  template<class MeshT>
339  void floodFillSelection(MeshT* _mesh, uint _fh, double _maxAngle,
340  PrimitiveType _primitiveTypes, bool _deselection);
341 
342  // Get orthogonal orientation of neighboring cell
344  const OpenVolumeMesh::CellHandle& _ch2, unsigned char _firstOrthDirection, const HexahedralMesh* _mesh) const;
345 
346  // Get face shared by two adjacent cells
347  typedef std::pair<OpenVolumeMesh::HalfFaceHandle,OpenVolumeMesh::HalfFaceHandle> HFPair;
348  HFPair getCommonFace(const OpenVolumeMesh::CellHandle& _ch1,
349  const OpenVolumeMesh::CellHandle& _ch2, const HexahedralMesh* _mesh) const;
350 
351 
352  OpenVolumeMesh::StatusAttrib* getStatus(int _objectId);
354 
357 
360 
362  PrimitiveType vertexType_;
363  PrimitiveType edgeType_;
364  PrimitiveType faceType_;
365  PrimitiveType cellType_;
366 
367  PrimitiveType allSupportedTypes_;
369 
371  QVector<QPoint> volumeLassoPoints_;
372 
373  // Store last picked cell for sheet selection
375  unsigned char lastPickedOrientation_;
376  std::map<OpenVolumeMesh::CellHandle, unsigned char> orientationMap_;
377 
380 };
381 
383 class SelectVolumeAction
384 {
385 public:
386  SelectVolumeAction(QRegion&_region, VolumeMeshSelectionPlugin* _plugin,
387  unsigned int _type, bool _deselection, ACG::GLState& _state)
388  : state_(_state)
389  , region_(_region)
390  , plugin_(_plugin)
391  , type_(_type)
392  , deselection_(_deselection)
393  {
394  }
395 
396  void enter(BaseNode* /*_node*/) {}
397  void leave(BaseNode* /*_node*/) {}
398 
399  bool operator()(BaseNode* _node);
400 
401 private:
402  ACG::GLState& state_;
403  QRegion& region_;
404  VolumeMeshSelectionPlugin* plugin_;
405  unsigned int type_;
406  bool deselection_;
407 };
408 //=============================================================================
409 #if defined(INCLUDE_TEMPLATES) && !defined(VOLUMEMESHSELECTIONPLUGINT_CC)
410 #define VOLUMEMESHSELECTIONPLUGINT_TEMPLATES
411 #include "VolumeMeshSelectionPluginT.cc"
412 #endif
413 
414 //=============================================================================
415 #endif // VOLUMEMESHSELECTIONPLUGIN_HH defined
416 //=============================================================================
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
void invertFaceSelection(int _objectId)
Invert face selection.
void invertHalfFaceSelection(int _objectId)
Invert half-face selection.
void deselectAllEdges(int _objectId)
Deselect all edges of a volume mesh.
unsigned char lastPickedOrientation_
Handle to selection environment.
Predefined datatypes.
Definition: DataTypes.hh:96
PrimitiveType faceType_
Handle to selection environment.
void deleteSelectedCells(int _objectId, bool _preserveManifoldness=true)
Delete selected cells from mesh.
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle selection.
Logtype
Log types for Message Window.
unsigned char getOrthogonalOrientationOfNeighborCell(const OpenVolumeMesh::CellHandle &_ch1, const OpenVolumeMesh::CellHandle &_ch2, unsigned char _firstOrthDirection, const HexahedralMesh *_mesh) const
Handle to selection environment.
bool edgeTypeActive()
Is vertex type active? (for use in plugins that need mesh selection)
QString columnSelectionHandle_
Handle to selection environment.
PrimitiveType allSupportedTypes_
Handle to selection environment.
bool faceTypeActive()
Is face type active? (for use in plugins that need mesh selection)
IdList getHalfEdgeSelection(int _objectId)
Get current half-edge selection.
QString name()
Return a name for the plugin.
Keyboard Event Interface.
Definition: KeyInterface.hh:76
void deselectAllCells(int _objectId)
Deselect all cells of a volume mesh.
IdList getHalfFaceSelection(int _objectId)
Get current half-face selection.
void invertVertexSelection(int _objectId)
Invert vertex selection.
void slotFloodFillSelection(QMouseEvent *_event, double _maxAngle, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a flood fill selection.
void selectCells(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific cells of a volume mesh.
QString environmentHandle_
Handle to selection environment.
IdList getCellSelection(int _objectId)
Get current cell selection.
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) ...
void selectAllVertices(int _objectId)
Select all vertices of a volume mesh.
void slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
Traverse the scenegraph and call the selection function for all mesh nodes.
void selectAllEdges(int _objectId)
Select all edges of a volume mesh.
bool cellTypeActive()
Is cell type active? (for use in plugins that need mesh selection)
void slotCustomSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, QString _customIdentifier, bool _deselect)
Called whenever the user performs a custom selection.
Interface for all Plugins which provide scriptable Functions.
Interface class for Plugins which have to store information in ini files.
Definition: INIInterface.hh:81
void selectVertices(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific vertices of a volume mesh.
Interface class from which all plugins have to be created.
void invertEdgeSelection(int _objectId)
Invert edge selection.
QVector< QPoint > volumeLassoPoints_
Keep volume lasso points.
Update type class.
Definition: UpdateType.hh:70
void slotSelectionOperation(QString _operation)
A specific operation is requested.
Interface for all Plugins which do logging to the logging window of the framework.
VolumeMeshSelectionPlugin()
Default constructor.
~VolumeMeshSelectionPlugin()
Default destructor.
void selectAllCells(int _objectId)
Select all cells of a volume mesh.
bool vertexTypeActive()
Is vertex type active? (for use in plugins that need mesh selection)
void deselectAllVertices(int _objectId)
Deselect all vertices of a volume mesh.
OpenVolumeMesh::CellHandle lastPickedCell_
Handle to selection environment.
HFPair getCommonFace(const OpenVolumeMesh::CellHandle &_ch1, const OpenVolumeMesh::CellHandle &_ch2, const HexahedralMesh *_mesh) const
Handle to selection environment.
void selectAllFaces(int _objectId)
Select all faces of a volume mesh.
void selectFaces(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific faces of a volume mesh.
PrimitiveType floodFillSupportedTypes_
Handle to selection environment.
Class for the handling of simple configuration files.
Definition: INIFile.hh:105
OpenVolumeMesh::StatusAttrib * getStatus(int _objectId)
Handle to selection environment.
void selectAllHalfFaces(int _objectId)
Select all half-faces of a volume mesh.
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
Interface for all plugins which want to use selection functions.
PrimitiveType vertexType_
Primitive type handles:
std::vector< int > IdList
Standard Type for id Lists used for scripting.
Definition: DataTypes.hh:192
bool volumeSelection(MeshT *_mesh, ACG::GLState &_state, QRegion *_region, PrimitiveType _primitiveTypes, bool _deselection)
Surface volume selection tool.
IdList getEdgeSelection(int _objectId)
Get current edge selection.
std::map< OpenVolumeMesh::CellHandle, unsigned char > orientationMap_
Handle to selection environment.
void deselectAllHalfEdges(int _objectId)
Deselect all half-edges of a volume mesh.
void selectHalfEdges(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific half-edges of a volume mesh.
IdList getVertexSelection(int _objectId)
Get current vertex selection.
void deleteSelectedVertices(int _objectId, bool _preserveManifoldness=true)
Delete selected vertices from mesh.
void deselectAllFaces(int _objectId)
Deselect all faces of a volume mesh.
QString sheetSelectionHandle_
Handle to selection environment.
void deleteSelectedEdges(int _objectId, bool _preserveManifoldness=true)
Delete selected edges from mesh.
void deleteSelectedFaces(int _objectId, bool _preserveManifoldness=true)
Delete selected faces from mesh.
PrimitiveType edgeType_
Handle to selection environment.
PrimitiveType cellType_
Handle to selection environment.
void selectAllHalfEdges(int _objectId)
Select all half-edges of a volume mesh.
void deselectAllHalfFaces(int _objectId)
Deselect all half-faces of a volume mesh.
void selectEdges(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific edges of a volume mesh.
void selectHalfFaces(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific half-faces of a volume mesh.
void updateSlotDescriptions()
Set slot descriptions for scripting functions.
std::pair< OpenVolumeMesh::HalfFaceHandle, OpenVolumeMesh::HalfFaceHandle > HFPair
Handle to selection environment.
IdList getFaceSelection(int _objectId)
Get current face selection.
Interface class for backup handling.
void invertCellSelection(int _objectId)
Invert cell selection.
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
QString description()
Return a description of what the plugin is doing.
void invertHalfEdgeSelection(int _objectId)
Invert half-edge selection.