50 #include "VolumeMeshSelectionPlugin.hh"
53 #define VERTEX_TYPE "selection_vertex.png"
54 #define EDGE_TYPE "selection_edge.png"
55 #define FACE_TYPE "selection_face.png"
56 #define CELL_TYPE "datacontrol-boundingBox.png"
58 #define COLUMN_SELECTION "column-selection.png"
59 #define SHEET_SELECTION "sheet-selection.png"
64 #define V_SELECT_ALL "Select All Vertices"
65 #define V_DESELECT_ALL "Deselect All Vertices"
66 #define V_INVERT "Invert Vertex Selection"
67 #define V_DELETE "Delete Selected Vertices"
69 #define E_SELECT_ALL "Select All Edges"
70 #define E_DESELECT_ALL "Deselect All Edges"
71 #define E_INVERT "Invert Edge Selection"
72 #define E_DELETE "Delete Selected Edges"
74 #define F_SELECT_ALL "Select All Faces"
75 #define F_DESELECT_ALL "Deselect All Faces"
76 #define F_INVERT "Invert Face Selection"
77 #define F_DELETE "Delete Selected Faces"
79 #define C_SELECT_ALL "Select All Cells"
80 #define C_DESELECT_ALL "Deselect All Cells"
81 #define C_INVERT "Invert Cell Selection"
82 #define C_DELETE "Delete Selected Cells"
86 vertexType_(0), edgeType_(0), allSupportedTypes_(0), lastPickedCell_(
HexahedralMesh::InvalidCellHandle),
87 lastPickedOrientation_(0) {
97 void VolumeMeshSelectionPlugin::initializePlugin() {
105 void VolumeMeshSelectionPlugin::pluginsInitialized() {
109 QString iconPath = OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator();
112 addSelectionEnvironment(
"VolumeMesh Selections",
"Select volume mesh primitives.",
126 emit addCustomSelectionMode(
environmentHandle_,
"Column Selection",
"Select entire column of cells",
130 addCustomSelectionMode(
environmentHandle_,
"Sheet Selection",
"Select entire sheet of cells",
143 QStringList vertexOperations;
144 vertexOperations.append(V_SELECT_ALL);
145 vertexOperations.append(V_DESELECT_ALL);
146 vertexOperations.append(V_INVERT);
147 vertexOperations.append(V_DELETE);
149 QStringList edgeOperations;
150 edgeOperations.append(E_SELECT_ALL);
151 edgeOperations.append(E_DESELECT_ALL);
152 edgeOperations.append(E_INVERT);
153 edgeOperations.append(E_DELETE);
155 QStringList faceOperations;
156 faceOperations.append(F_SELECT_ALL);
157 faceOperations.append(F_DESELECT_ALL);
158 faceOperations.append(F_INVERT);
159 faceOperations.append(F_DELETE);
161 QStringList cellOperations;
162 cellOperations.append(C_SELECT_ALL);
163 cellOperations.append(C_DESELECT_ALL);
164 cellOperations.append(C_INVERT);
165 cellOperations.append(C_DELETE);
180 registerKeyShortcut(Qt::Key_A, Qt::ControlModifier);
183 registerKeyShortcut(Qt::Key_C, Qt::NoModifier);
186 registerKeyShortcut(Qt::Key_I, Qt::NoModifier);
188 emit registerKeyShortcut(Qt::Key_Delete, Qt::NoModifier);
203 SelectionInterface::PrimitiveType t = 0u;
204 emit getActivePrimitiveType(t);
209 SelectionInterface::PrimitiveType t = 0u;
210 emit getActivePrimitiveType(t);
215 SelectionInterface::PrimitiveType t = 0u;
216 emit getActivePrimitiveType(t);
221 SelectionInterface::PrimitiveType t = 0u;
222 emit getActivePrimitiveType(t);
230 SelectionInterface::PrimitiveType type = 0u;
231 emit getActivePrimitiveType(type);
237 bool targetsOnly =
false;
238 emit targetObjectsOnly(targetsOnly);
242 if (_operation == V_SELECT_ALL) {
248 }
else if (_operation == V_DESELECT_ALL) {
254 }
else if (_operation == V_INVERT) {
260 }
else if (_operation == V_DELETE) {
266 }
else if (_operation == E_SELECT_ALL) {
272 }
else if (_operation == E_DESELECT_ALL) {
278 }
else if (_operation == E_INVERT) {
284 }
else if (_operation == E_DELETE) {
290 }
else if (_operation == F_SELECT_ALL) {
296 }
else if (_operation == F_DESELECT_ALL) {
302 }
else if (_operation == F_INVERT) {
308 }
else if (_operation == F_DELETE) {
314 }
else if (_operation == C_SELECT_ALL) {
320 }
else if (_operation == C_DESELECT_ALL) {
326 }
else if (_operation == C_INVERT) {
332 }
else if (_operation == C_DELETE) {
344 SelectionInterface::PrimitiveType _currentType,
bool _deselect) {
351 if(_event->button() != Qt::LeftButton)
354 unsigned int node_idx, target_idx;
362 node_idx, target_idx, &hit_point)
365 if(successfullyPicked) {
369 if(!polyMesh && !hexMesh) {
370 emit log(
LOGERR, tr(
"Neither polyhedral nor hexahedral mesh!"));
390 target_idx, &hit_point)
393 if(successfullyPicked) {
397 if(!polyMesh && !hexMesh) {
398 emit log(
LOGERR, tr(
"Neither polyhedral nor hexahedral mesh!"));
418 target_idx, &hit_point)
421 if(successfullyPicked) {
425 if(!polyMesh && !hexMesh) {
426 emit log(
LOGERR, tr(
"Neither polyhedral nor hexahedral mesh!"));
447 target_idx, &hit_point)
450 if(successfullyPicked) {
454 if(!polyMesh && !hexMesh) {
455 emit log(
LOGERR, tr(
"Neither polyhedral nor hexahedral mesh!"));
477 PrimitiveType _currentType,
bool _deselect)
481 if (_event->type() == QEvent::MouseButtonPress)
486 else if (_event->type() == QEvent::MouseButtonDblClick)
493 QRegion region = QRegion(p);
506 double _maxAngle, PrimitiveType _currentType,
bool _deselect)
512 unsigned int node_idx, target_idx;
517 _event->pos(), node_idx, target_idx, &hit_point))
526 _event->pos(), node_idx, target_idx, &hit_point))
533 target_idx, _maxAngle, _currentType, _deselect);
543 _event->pos(), node_idx, target_idx, &hit_point))
550 target_idx, _maxAngle, _currentType, _deselect);
559 emit log(
LOGERR, tr(
"floodFillSelection: Unsupported dataType"));
571 bool selected =
false;
575 selected = plugin_->
volumeSelection(m, state_, ®ion_, type_, deselection_);
580 selected = plugin_->
volumeSelection(m, state_, ®ion_, type_, deselection_);
593 QString _customIdentifier,
bool _deselect) {
599 if(_event->button() != Qt::LeftButton || _event->type() != QEvent::MouseButtonPress)
611 unsigned int node_idx, target_idx;
613 node_idx, target_idx, &hit_point)
616 if(successfullyPicked) {
620 emit log(
LOGERR,
"Could not get hexahedral mesh object!");
630 (hexMesh->is_boundary(hexMesh->halfface_handle(fh, 0)) ? hexMesh->halfface_handle(fh, 1)
631 : hexMesh->halfface_handle(fh, 0));
633 while(!hexMesh->is_boundary(cif)) {
637 if(status[ch].selected() || _deselect)
638 status[ch].set_selected(
false);
640 status[ch].set_selected(
true);
642 cif = hexMesh->opposite_halfface_handle_in_cell(cif, ch);
643 cif = hexMesh->opposite_halfface_handle(cif);
659 unsigned int node_idx, target_idx;
661 node_idx, target_idx, &hit_point)
664 if(successfullyPicked) {
668 emit log(
LOGERR,
"Could not get hexahedral mesh object!");
678 (hexMesh->is_boundary(hexMesh->halfface_handle(fh, 0)) ? hexMesh->halfface_handle(fh, 1)
679 : hexMesh->halfface_handle(fh, 0));
696 unsigned char secondDir = hexMesh->orientation(pair.first,
lastPickedCell_);
703 std::set<OpenVolumeMesh::CellHandle> unprocessed;
705 std::set<OpenVolumeMesh::CellHandle> processed;
712 while(!unprocessed.empty() ) {
715 unprocessed.erase(cur_c);
716 status[cur_c].set_selected(!status[cur_c].selected());
717 processed.insert(cur_c);
719 std::map<OpenVolumeMesh::CellHandle, unsigned char>::iterator f =
orientationMap_.find(cur_c);
721 emit log(
LOGERR,
"Could not get orientation of current cell in sheet!");
724 unsigned char od = f->second;
727 if(processed.count(*csc_it) > 0)
731 orientationMap_.insert(std::pair<OpenVolumeMesh::CellHandle, unsigned char>(*csc_it, new_o));
732 unprocessed.insert(*csc_it);
748 unsigned char _firstOrthDirection,
758 std::vector<OpenVolumeMesh::HalfEdgeHandle> hes1 = _mesh->halfface(firstOrthHF).halfedges();
759 std::vector<OpenVolumeMesh::HalfEdgeHandle> hes2 = _mesh->halfface(commonHF.first).halfedges();
761 for(std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator he_it1 = hes1.begin(); he_it1 != hes1.end(); ++he_it1) {
762 for(std::vector<OpenVolumeMesh::HalfEdgeHandle>::const_iterator he_it2 = hes2.begin(); he_it2 != hes2.end(); ++he_it2) {
763 if(_mesh->edge_handle(*he_it1) == _mesh->edge_handle(*he_it2)) {
764 sharedHE = _mesh->opposite_halfedge_handle(*he_it2);
767 if(sharedHE != HexahedralMesh::InvalidHalfEdgeHandle)
772 return _mesh->orientation(_mesh->adjacent_halfface_in_cell(commonHF.second, sharedHE), _ch2);
781 std::vector<OpenVolumeMesh::HalfFaceHandle> hfs1 = _mesh->cell(_ch1).halffaces();
782 std::vector<OpenVolumeMesh::HalfFaceHandle> hfs2 = _mesh->cell(_ch2).halffaces();
784 for(std::vector<OpenVolumeMesh::HalfFaceHandle>::const_iterator hf_it1 = hfs1.begin(); hf_it1 != hfs1.end(); ++hf_it1) {
786 for(std::vector<OpenVolumeMesh::HalfFaceHandle>::const_iterator hf_it2 = hfs2.begin(); hf_it2 != hfs2.end(); ++hf_it2) {
788 if(_mesh->face_handle(*hf_it1) == _mesh->face_handle(*hf_it2)) {
789 return HFPair(*hf_it1, *hf_it2);
794 return HFPair(HexahedralMesh::InvalidHalfFaceHandle, HexahedralMesh::InvalidHalfFaceHandle);
799 void VolumeMeshSelectionPlugin::loadSelection(
int _objId,
const QString& _filename) {
815 void VolumeMeshSelectionPlugin::loadIniFile(
INIFile& _ini,
int _id) {
822 emit log(
LOGERR,
"Could not get base object data!");
826 QString section = QString(
"PolyhedralMeshSelection") +
"//" + bod->
name();
831 std::vector<int> ids;
833 _ini.
get_entry(ids, section,
"VertexSelection");
837 _ini.
get_entry(ids, section,
"EdgeSelection");
841 _ini.
get_entry(ids, section,
"HalfEdgeSelection");
845 _ini.
get_entry(ids, section,
"FaceSelection");
849 _ini.
get_entry(ids, section,
"HalfFaceSelection");
853 _ini.
get_entry(ids, section,
"CellSelection");
860 void VolumeMeshSelectionPlugin::saveIniFile(
INIFile& _ini,
int _id) {
867 emit log(
LOGERR,
"Could not get base object data!");
871 QString section = QString(
"PolyhedralMeshSelection") +
"//" + bod->
name();
892 QString section = QString(
"PolyhedralMeshSelection") +
"//" + o_it->name();
897 std::vector<int> ids;
899 _file.
get_entry(ids, section,
"VertexSelection");
903 _file.
get_entry(ids, section,
"EdgeSelection");
907 _file.
get_entry(ids, section,
"HalfEdgeSelection");
911 _file.
get_entry(ids, section,
"FaceSelection");
915 _file.
get_entry(ids, section,
"HalfFaceSelection");
919 _file.
get_entry(ids, section,
"CellSelection");
937 QString section = QString(
"PolyhedralMeshSelection") +
"//" + o_it->name();
953 SelectionInterface::PrimitiveType type = 0u;
955 getActivePrimitiveType(type);
962 bool targetsOnly =
false;
964 targetObjectsOnly(targetsOnly);
968 if(_key == Qt::Key_A && _modifiers == Qt::ControlModifier) {
972 if (o_it->visible()) {
984 }
else if(_key == Qt::Key_C && _modifiers == Qt::NoModifier) {
988 if (o_it->visible()) {
1000 }
else if(_key == Qt::Key_I && _modifiers == Qt::NoModifier) {
1004 if (o_it->visible()) {
1017 }
else if(_key == Qt::Key_Delete && _modifiers == Qt::NoModifier) {
1021 if(o_it->visible()) {
1038 #if QT_VERSION < 0x050000
QString columnSelectionHandle_
Handle to selection environment.
void slotCustomSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, QString _customIdentifier, bool _deselect)
Called whenever the user performs a custom selection.
PrimitiveType allSupportedTypes_
Handle to selection environment.
IdList getCellSelection(int _objectId)
Get current cell selection.
~VolumeMeshSelectionPlugin()
Default destructor.
QString sheetSelectionHandle_
Handle to selection environment.
Viewer::ViewerProperties & viewerProperties(int _id)
Get the viewer properties Use this functions to get basic viewer properties such as backgroundcolor o...
bool cellTypeActive()
Is cell type active? (for use in plugins that need mesh selection)
MeshT * mesh()
return a pointer to the mesh
const QStringList ALL_OBJECTS
Iterable object range.
PrimitiveType edgeType_
Handle to selection environment.
PrimitiveType cellType_
Handle to selection environment.
void slotToggleSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a toggle selection.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
VolumeMeshSelectionPlugin()
Default constructor.
picks faces (should be implemented for all nodes)
pick any of the prior targets (should be implemented for all nodes)
OpenVolumeMesh::CellHandle lastPickedCell_
Handle to selection environment.
#define DATA_POLYHEDRAL_MESH
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void deleteSelectedVertices(int _objectId, bool _preserveManifoldness=true)
Delete selected vertices from mesh.
bool getObject(int _identifier, BSplineCurveObject *&_object)
void deselectAllFaces(int _objectId)
Deselect all faces of a volume mesh.
std::pair< OpenVolumeMesh::HalfFaceHandle, OpenVolumeMesh::HalfFaceHandle > HFPair
Handle to selection environment.
void invertCellSelection(int _objectId)
Invert cell selection.
bool volumeSelection(MeshT *_mesh, int _objectId, ACG::GLState &_state, QRegion *_region, PrimitiveType _primitiveTypes, bool _deselection)
Surface volume selection tool.
bool faceTypeActive()
Is face type active? (for use in plugins that need mesh selection)
void slotLoadSelection(const INIFile &_file)
Load selection for specific objects in the scene.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
bool dataType(DataType _type) const
picks verices (may not be implemented for all nodes)
void slotKeyShortcutEvent(int _key, Qt::KeyboardModifiers _modifiers)
One of the previously registered keys has been pressed.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
const UpdateType UPDATE_SELECTION(UpdateTypeSet(1)<< 4)
Selection updated.
Traverse the scenegraph and call the selection function for all mesh nodes.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
std::map< OpenVolumeMesh::CellHandle, unsigned char > orientationMap_
Handle to selection environment.
PolyhedralMeshObject * polyhedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an PolyhedralMeshObject if possible.
PrimitiveType faceType_
Handle to selection environment.
picks edges (may not be implemented for all nodes)
bool edgeTypeActive()
Is vertex type active? (for use in plugins that need mesh selection)
void selectCells(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific cells of a volume mesh.
void selectHalfEdges(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific half-edges of a volume mesh.
Class for the handling of simple configuration files.
void invertFaceSelection(int _objectId)
Invert face selection.
void selectAllVertices(int _objectId)
Select all vertices of a volume mesh.
HexahedralMeshObject * hexahedralMeshObject(BaseObjectData *_object)
Cast an BaseObject to an HexahedralMeshObject if possible.
bool operator()(BaseNode *_node)
Traverse the scenegraph and call the selection function for all mesh nodes.
void selectHalfFaces(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific half-faces of a volume mesh.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
void invertEdgeSelection(int _objectId)
Invert edge selection.
PrimitiveType vertexType_
Primitive type handles:
void deleteSelectedEdges(int _objectId, bool _preserveManifoldness=true)
Delete selected edges from mesh.
const StatusAttrib & status() const
return a pointer to the mesh
ACG::SceneGraph::BaseNode * getRootNode()
Get the root node for data objects.
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.
IdList getVertexSelection(int _objectId)
Get current vertex selection.
bool vertexTypeActive()
Is vertex type active? (for use in plugins that need mesh selection)
void set_updateGL(bool _b)
should GL matrices be updated after each matrix operation
void selectEdges(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific edges of a volume mesh.
void deselectAllVertices(int _objectId)
Deselect all vertices of a volume mesh.
void selectVertices(int _objectId, const IdList &_ids, bool _deselect=false)
Select specific vertices of a volume mesh.
IdList getHalfFaceSelection(int _objectId)
Get current half-face selection.
void deleteSelectedCells(int _objectId, bool _preserveManifoldness=true)
Delete selected cells from mesh.
QVector< QPoint > volumeLassoPoints_
Keep volume lasso points.
picks faces (may not be implemented for all nodes)
void slotVolumeLassoSelection(QMouseEvent *_event, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a volume lasso selection.
void slotSelectionOperation(QString _operation)
A specific operation is requested.
IdList getHalfEdgeSelection(int _objectId)
Get current half-edge selection.
void selectAllEdges(int _objectId)
Select all edges of a volume 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) ...
void selectAllCells(int _objectId)
Select all cells of a volume mesh.
bool scenegraphPick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
Execute picking operation on scenegraph.
unsigned char lastPickedOrientation_
Handle to selection environment.
void updateSlotDescriptions()
Set slot descriptions for scripting functions.
#define DATA_HEXAHEDRAL_MESH
QStringList IteratorRestriction
Iterable object range.
IdList getEdgeSelection(int _objectId)
Get current edge selection.
void deleteSelectedFaces(int _objectId, bool _preserveManifoldness=true)
Delete selected faces from mesh.
void invertVertexSelection(int _objectId)
Invert vertex selection.
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
HFPair getCommonFace(const OpenVolumeMesh::CellHandle &_ch1, const OpenVolumeMesh::CellHandle &_ch2, const HexahedralMesh *_mesh) const
Handle to selection environment.
QString environmentHandle_
Handle to selection environment.
PrimitiveType floodFillSupportedTypes_
Handle to selection environment.
ACG::GLState & glState()
Get the glState of the Viewer.
void traverse(BaseNode *_node, Action &_action)
bool getPickedObject(const unsigned int _node_idx, BaseObjectData *&_object)
Get the picked mesh.
void deselectAllCells(int _objectId)
Deselect all cells of a volume mesh.
IdList getFaceSelection(int _objectId)
Get current face selection.
HexahedralMesh * hexahedralMesh(BaseObjectData *_object)
Get an HexahedralMesh from an object.
void deselectAllEdges(int _objectId)
Deselect all edges of a volume mesh.
void slotSaveSelection(INIFile &_file)
Save selection for all objects in the scene.
bool updateGL() const
should GL matrices be updated after each matrix operation
PolyhedralMesh * polyhedralMesh(BaseObjectData *_object)
Get an PolyhedralMesh from an object.
unsigned char getOrthogonalOrientationOfNeighborCell(const OpenVolumeMesh::CellHandle &_ch1, const OpenVolumeMesh::CellHandle &_ch2, unsigned char _firstOrthDirection, const HexahedralMesh *_mesh) const
Handle to selection environment.
void slotFloodFillSelection(QMouseEvent *_event, double _maxAngle, SelectionInterface::PrimitiveType _currentType, bool _deselect)
Called whenever the user performs a flood fill selection.