diff --git a/Gui/DataView/CMakeLists.txt b/Gui/DataView/CMakeLists.txt index 0e2f4e04e9c6dfac8f20b43d67ae133d2b2b2a8a..7d4f36cd852ff4947c3996ddfc1ed4c689316cfc 100644 --- a/Gui/DataView/CMakeLists.txt +++ b/Gui/DataView/CMakeLists.txt @@ -6,6 +6,7 @@ set( SOURCES ConditionWriterDialog.cpp DirectConditionGenerator.cpp ElementTreeModel.cpp + ElementTreeView.cpp FEMConditionSetupDialog.cpp GeoMapper.cpp GEOModels.cpp @@ -45,6 +46,7 @@ set( MOC_HEADERS CondFromRasterDialog.h ConditionWriterDialog.h ElementTreeModel.h + ElementTreeView.h FEMConditionSetupDialog.h GEOModels.h GeoTabWidget.h diff --git a/Gui/DataView/ElementTreeModel.cpp b/Gui/DataView/ElementTreeModel.cpp index d0f3e9cc2e12a9452e9ae8c38df3f36d82c7c73b..1173148cdcc8011e0f755abec04bc6dd2966ac47 100644 --- a/Gui/DataView/ElementTreeModel.cpp +++ b/Gui/DataView/ElementTreeModel.cpp @@ -19,66 +19,76 @@ #include "Node.h" #include "Elements/Element.h" +#include "VtkMeshSource.h" + /** * Constructor. */ ElementTreeModel::ElementTreeModel( QObject* parent ) - : TreeModel(parent) + : TreeModel(parent), _mesh_source(nullptr) { QList<QVariant> rootData; delete _rootItem; rootData << "Name" << "Type" << "" << ""; - _rootItem = new TreeItem(rootData, NULL); + _rootItem = new TreeItem(rootData, nullptr); } ElementTreeModel::~ElementTreeModel() { } -void ElementTreeModel::setElement(const MeshLib::Mesh* grid, const size_t elem_index) +void ElementTreeModel::setElement(vtkUnstructuredGridAlgorithm const*const grid, const unsigned elem_index) { + this->_mesh_source = grid; this->clearView(); - const MeshLib::Element* elem = grid->getElement(elem_index); - QList<QVariant> elemData; - elemData << "Element " + QString::number(elem_index) << "" << "" << ""; - TreeItem* elemItem = new TreeItem(elemData, _rootItem); - _rootItem->appendChild(elemItem); + VtkMeshSource const*const source = dynamic_cast<VtkMeshSource const*const>(grid); - QList<QVariant> typeData; - typeData << "Element Type: " << QString::fromStdString(MshElemType2String(elem->getGeomType())); - TreeItem* typeItem = new TreeItem(typeData, elemItem); - elemItem->appendChild(typeItem); + if (source) + { + const MeshLib::Mesh* mesh = source->GetMesh(); + const MeshLib::Element* elem = mesh->getElement(elem_index); - QList<QVariant> materialData; - materialData << "MaterialID: " << QString::number(elem->getValue()); - TreeItem* matItem = new TreeItem(materialData, elemItem); - elemItem->appendChild(matItem); + QList<QVariant> elemData; + elemData << "Element " + QString::number(elem_index) << "" << "" << ""; + TreeItem* elemItem = new TreeItem(elemData, _rootItem); + _rootItem->appendChild(elemItem); - QList<QVariant> volData; - volData << "Area/Volume: " << - QString::number(grid->getElement(elem_index)->getContent()); - TreeItem* volItem = new TreeItem(volData, elemItem); - elemItem->appendChild(volItem); + QList<QVariant> typeData; + typeData << "Element Type: " << QString::fromStdString(MshElemType2String(elem->getGeomType())); + TreeItem* typeItem = new TreeItem(typeData, elemItem); + elemItem->appendChild(typeItem); - QList<QVariant> nodeListData; - nodeListData << "Nodes" << "" << "" << ""; - TreeItem* nodeListItem = new TreeItem(nodeListData, elemItem); - elemItem->appendChild(nodeListItem); + QList<QVariant> materialData; + materialData << "MaterialID: " << QString::number(elem->getValue()); + TreeItem* matItem = new TreeItem(materialData, elemItem); + elemItem->appendChild(matItem); - //const std::vector<MeshLib::Node*> nodes_vec = grid->getNodes(); - size_t nElemNodes = elem->getNNodes(); - for (size_t i = 0; i < nElemNodes; i++) - { - const MeshLib::Node* node = elem->getNode(i); - QList<QVariant> nodeData; - nodeData << "Node " + QString::number(node->getID()) << - QString::number((*node)[0]) << QString::number((*node)[1]) << - QString::number((*node)[2]); - TreeItem* nodeItem = new TreeItem(nodeData, nodeListItem); - nodeListItem->appendChild(nodeItem); + QList<QVariant> volData; + volData << "Area/Volume: " << + QString::number(mesh->getElement(elem_index)->getContent()); + TreeItem* volItem = new TreeItem(volData, elemItem); + elemItem->appendChild(volItem); + + QList<QVariant> nodeListData; + nodeListData << "Nodes" << "" << "" << ""; + TreeItem* nodeListItem = new TreeItem(nodeListData, elemItem); + elemItem->appendChild(nodeListItem); + + //const std::vector<MeshLib::Node*> nodes_vec = grid->getNodes(); + size_t nElemNodes = elem->getNNodes(); + for (size_t i = 0; i < nElemNodes; i++) + { + const MeshLib::Node* node = elem->getNode(i); + QList<QVariant> nodeData; + nodeData << "Node " + QString::number(node->getID()) << + QString::number((*node)[0]) << QString::number((*node)[1]) << + QString::number((*node)[2]); + TreeItem* nodeItem = new TreeItem(nodeData, nodeListItem); + nodeListItem->appendChild(nodeItem); + } + reset(); } - reset(); } void ElementTreeModel::clearView() diff --git a/Gui/DataView/ElementTreeModel.h b/Gui/DataView/ElementTreeModel.h index cf85a7a5961bc148342911ed6f44a31c8a373bdc..2d58d75d94550a89d4f7e8fa607135e8b3ccf662 100644 --- a/Gui/DataView/ElementTreeModel.h +++ b/Gui/DataView/ElementTreeModel.h @@ -17,9 +17,7 @@ #include "TreeModel.h" -namespace MeshLib { - class Mesh; -} +class vtkUnstructuredGridAlgorithm; /** * \brief A model for the display of information concerning element information implemented as a TreeModel. @@ -33,14 +31,17 @@ public: ElementTreeModel( QObject* parent = 0 ); ~ElementTreeModel(); + vtkUnstructuredGridAlgorithm const*const getSource() const { return _mesh_source; }; + public slots: /// Clears the tree. void clearView(); /// Extracts information of the element with the given index from the given grid. - void setElement(const MeshLib::Mesh* grid, const std::size_t elem_index); + void setElement(vtkUnstructuredGridAlgorithm const*const grid, const unsigned elem_index); private: + vtkUnstructuredGridAlgorithm const* _mesh_source; }; #endif //ELEMENTTREEMODEL_H diff --git a/Gui/DataView/ElementTreeView.cpp b/Gui/DataView/ElementTreeView.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4502a1e3211edfe3c3f7789708e31d11c0549edd --- /dev/null +++ b/Gui/DataView/ElementTreeView.cpp @@ -0,0 +1,55 @@ +/** + * \file + * \author Karsten Rink + * \date 2013-04-09 + * \brief Implementation of the ElementTreeView class. + * + * \copyright + * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + * + */ + +#include "ElementTreeView.h" + +#include "ElementTreeModel.h" +#include "TreeItem.h" + +#include <QModelIndex> + +ElementTreeView::ElementTreeView( QWidget* parent) +: QTreeView(parent) +{ +} + +void ElementTreeView::updateView() +{ + setAlternatingRowColors(true); + setColumnWidth(0,125); + size_t nColumns = (this->model() != NULL) ? this->model()->columnCount() : 0; + for (size_t i = 1; i < nColumns; i++) + resizeColumnToContents(i); + this->expandAll(); +} + +void ElementTreeView::selectionChanged( const QItemSelection &selected, const QItemSelection &deselected ) +{ + Q_UNUSED(deselected); + if (!selected.isEmpty()) + { + emit removeSelectedMeshComponent(); + const QModelIndex idx = *(selected.indexes().begin()); + + + if (idx.parent().isValid()) // not root node + if (idx.parent().parent().isValid()) // not property node + { + const TreeItem* tree_item = static_cast<TreeModel*>(this->model())->getItem(idx); + const unsigned node_index = tree_item->data(0).toString().mid(5).toUInt(); + emit nodeSelected(static_cast<ElementTreeModel*>(this->model())->getSource(), node_index, false); + } + } +} \ No newline at end of file diff --git a/Gui/DataView/ElementTreeView.h b/Gui/DataView/ElementTreeView.h new file mode 100644 index 0000000000000000000000000000000000000000..0258a7f4f210dde7db3dfa57c45a182454b886d4 --- /dev/null +++ b/Gui/DataView/ElementTreeView.h @@ -0,0 +1,46 @@ +/** + * \file + * \author Karsten Rink + * \date 2013-04-09 + * \brief Definition of the ElementTreeView class. + * + * \copyright + * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ +#ifndef ELEMENTTREEVIEW_H +#define ELEMENTTREEVIEW_H + +#include <QTreeView> + +class vtkUnstructuredGridAlgorithm; + +/** + * A TreeView to display mesh element properties. + */ +class ElementTreeView : public QTreeView +{ + Q_OBJECT + +public: + /// Constructor + ElementTreeView(QWidget* parent = 0); + +public slots: + void updateView(); + +protected slots: + /// Is called when the selection of this view changes. + void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected); + +signals: + void nodeSelected(vtkUnstructuredGridAlgorithm const*const, unsigned, bool); + void removeSelectedMeshComponent(); +}; + + +#endif // ELEMENTTREEVIEW_H + diff --git a/Gui/DataView/GeoTreeView.cpp b/Gui/DataView/GeoTreeView.cpp index 99158557dff62a058603ad5942e48e396f669ad5..e825f0ae6d1aabe7f4d62d60cd400a9b13fc484f 100644 --- a/Gui/DataView/GeoTreeView.cpp +++ b/Gui/DataView/GeoTreeView.cpp @@ -50,31 +50,37 @@ void GeoTreeView::selectionChanged( const QItemSelection &selected, { const QModelIndex idx = *(selected.indexes().begin()); const TreeItem* tree_item = static_cast<TreeModel*>(this->model())->getItem(idx); + emit removeGeoItemSelection(); - const GeoObjectListItem* list_item = dynamic_cast<GeoObjectListItem*>(tree_item->parentItem()); - if (list_item) + const GeoObjectListItem* geo_object = dynamic_cast<GeoObjectListItem*>(tree_item->parentItem()); + if (geo_object) // geometry object { emit enableSaveButton(false); emit enableRemoveButton(false); - emit geoItemSelected(list_item->vtkSource(), tree_item->row()); + emit geoItemSelected(geo_object->vtkSource(), tree_item->row()); } else { - emit removeGeoItemSelection(); - if (!idx.parent().isValid()) // list item + if (!idx.parent().isValid()) // geometry item { emit enableSaveButton(true); emit enableRemoveButton(true); } else // line points or surface triangles { - // highlight a point for an expanded polyline - if (dynamic_cast<GeoObjectListItem*>(tree_item->parentItem()->parentItem())->getType() == GeoLib::POLYLINE) - geoItemSelected( - dynamic_cast<GeoObjectListItem*>(tree_item->parentItem()->parentItem()->parentItem()->child(0))->vtkSource(), - tree_item->data(0).toInt()); emit enableSaveButton(false); - emit enableRemoveButton(false); + const GeoObjectListItem* geo_type = dynamic_cast<const GeoObjectListItem*>(tree_item); + if (geo_type) // geometry list item + emit enableRemoveButton(true); + else + { + // highlight a point for an expanded polyline + if (dynamic_cast<GeoObjectListItem*>(tree_item->parentItem()->parentItem())->getType() == GeoLib::POLYLINE) + geoItemSelected( + dynamic_cast<GeoObjectListItem*>(tree_item->parentItem()->parentItem()->parentItem()->child(0))->vtkSource(), + tree_item->data(0).toInt()); + emit enableRemoveButton(false); + } } } diff --git a/Gui/DataView/MshTabWidgetBase.ui b/Gui/DataView/MshTabWidgetBase.ui index 17885a9659558791dd419958834ffa1e53f32e2b..e51da631fba604c1f0c315b5e71d3b2a006f1a9b 100644 --- a/Gui/DataView/MshTabWidgetBase.ui +++ b/Gui/DataView/MshTabWidgetBase.ui @@ -170,7 +170,7 @@ </layout> </item> <item> - <widget class="MshView" name="elementView"/> + <widget class="ElementTreeView" name="elementView"/> </item> </layout> </widget> @@ -180,6 +180,11 @@ <extends>QTreeView</extends> <header>MshView.h</header> </customwidget> + <customwidget> + <class>ElementTreeView</class> + <extends>QTreeView</extends> + <header>ElementTreeView.h</header> + </customwidget> </customwidgets> <resources> <include location="../Img/icons.qrc"/> diff --git a/Gui/DataView/MshView.cpp b/Gui/DataView/MshView.cpp index 809b942cabff992aa6b270bb8f85191ef5c4dbff..af3aa424d5eb122c883af22382e947e3a182b405 100644 --- a/Gui/DataView/MshView.cpp +++ b/Gui/DataView/MshView.cpp @@ -62,6 +62,7 @@ void MshView::selectionChanged( const QItemSelection &selected, const QItemSelec Q_UNUSED(deselected); if (!selected.isEmpty()) { + emit removeSelectedMeshComponent(); const QModelIndex idx = *(selected.indexes().begin()); const TreeItem* tree_item = static_cast<TreeModel*>(this->model())->getItem(idx); @@ -75,11 +76,13 @@ void MshView::selectionChanged( const QItemSelection &selected, const QItemSelec { emit enableSaveButton(false); emit enableRemoveButton(false); + emit elementSelected(dynamic_cast<const MshItem*>(tree_item->parentItem())->vtkSource(), static_cast<unsigned>(tree_item->row()), true); } } //emit itemSelectionChanged(selected, deselected); //return QTreeView::selectionChanged(selected, deselected); } + void MshView::addMesh() { emit openMeshFile(ImportFileType::OGS_MSH); @@ -102,10 +105,11 @@ void MshView::contextMenuEvent( QContextMenuEvent* event ) { QModelIndex index = this->selectionModel()->currentIndex(); MshItem* item = dynamic_cast<MshItem*>(static_cast<TreeItem*>(index.internalPointer())); - bool is_3D_mesh (item->getMesh()->getDimension() == 3); if (item) { + bool is_3D_mesh (item->getMesh()->getDimension() == 3); + QMenu menu; QAction* editMeshAction = menu.addAction("Edit mesh..."); QAction* editValuesAction = menu.addAction("Edit material groups..."); diff --git a/Gui/DataView/MshView.h b/Gui/DataView/MshView.h index 02efdfeb23bc66c22f603cd4ea8e0090d1c95b6f..0e76957c5489843f87a3490e94e4aeced4777e57 100644 --- a/Gui/DataView/MshView.h +++ b/Gui/DataView/MshView.h @@ -20,6 +20,7 @@ class MshModel; class VtkMeshSource; +class vtkUnstructuredGridAlgorithm; namespace MeshLib { class Mesh; @@ -86,10 +87,12 @@ private slots: void checkMeshQuality(); signals: + void elementSelected(vtkUnstructuredGridAlgorithm const*const, unsigned, bool); void enableSaveButton(bool); void enableRemoveButton(bool); void openMeshFile(int); void qualityCheckRequested(VtkMeshSource*); + void removeSelectedMeshComponent(); void requestCondSetupDialog(const std::string&, const GeoLib::GEOTYPE, const std::size_t, bool on_points); void requestMeshRemoval(const QModelIndex&); void requestDIRECTSourceTerms(const std::string, const std::vector<GeoLib::Point*>*); diff --git a/Gui/VtkAct/VtkCustomInteractorStyle.cpp b/Gui/VtkAct/VtkCustomInteractorStyle.cpp index ebf8559be25a2facec6f0045cf440977bef91c9e..688c894c3a7fb24fc632f9cbd955cc8c46d0dc3a 100644 --- a/Gui/VtkAct/VtkCustomInteractorStyle.cpp +++ b/Gui/VtkAct/VtkCustomInteractorStyle.cpp @@ -33,11 +33,11 @@ #include <vtkSelectionNode.h> #include <vtkSmartPointer.h> #include <vtkUnstructuredGrid.h> +#include <vtkUnstructuredGridAlgorithm.h> #include <string> -#include "VtkMeshSource.h" -#include "VtkCompositeSelectionFilter.h" +#include "VtkCompositeElementSelectionFilter.h" vtkStandardNewMacro(VtkCustomInteractorStyle); @@ -105,6 +105,12 @@ void VtkCustomInteractorStyle::highlightActor( vtkProp3D* actor ) HighlightProp((vtkProp*)actor); } +void VtkCustomInteractorStyle::removeHighlightActor() +{ + this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()-> + RemoveActor(selectedActor); +} + void VtkCustomInteractorStyle::setHighlightActor(bool on) { _highlightActor = on; @@ -183,13 +189,16 @@ void VtkCustomInteractorStyle::OnLeftButtonDown() // check if the underlying object is a mesh and if so, send a signal to the element model for display of information about the picked element. vtkAlgorithm* data_set = picker->GetActor()->GetMapper()->GetInputConnection(0, 0)->GetProducer()->GetInputConnection(0,0)->GetProducer(); - VtkMeshSource* source = dynamic_cast<VtkMeshSource*>(data_set); + vtkUnstructuredGridAlgorithm* source = dynamic_cast<vtkUnstructuredGridAlgorithm*>(data_set); if (source) - emit elementPicked(source->GetMesh(), picker->GetCellId()); + emit elementPicked(source, static_cast<unsigned>(picker->GetCellId())); + else + emit clearElementView(); selectedMapper->SetInputConnection(selected->GetProducerPort()); this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()-> AddActor(selectedActor); + _highlightActor = true; } else this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()-> diff --git a/Gui/VtkAct/VtkCustomInteractorStyle.h b/Gui/VtkAct/VtkCustomInteractorStyle.h index 6e5a059f7725ef413a536321e37fb54ab19f4c0c..97e4b4aa2c1d6f464d486b00ec9628ab0fbe93e7 100644 --- a/Gui/VtkAct/VtkCustomInteractorStyle.h +++ b/Gui/VtkAct/VtkCustomInteractorStyle.h @@ -24,9 +24,7 @@ class vtkDataObject; class vtkDataSetMapper; class vtkActor; -namespace MeshLib { - class Mesh; -} +class vtkUnstructuredGridAlgorithm; /** * VtkCustomInteractorStyle implements highlighting of an active actor and @@ -60,6 +58,10 @@ public: public slots: void highlightActor(vtkProp3D* prop); + + /// @brief Removes the highlight actor from the visible scene. + void removeHighlightActor(); + void setHighlightActor(bool on); /// @brief Sets the highlightable vtk object. @@ -91,7 +93,12 @@ signals: void cursorChanged(Qt::CursorShape); /// @brief Emitted when a mesh element has been picked - void elementPicked(const MeshLib::Mesh*, const std::size_t); + void elementPicked(vtkUnstructuredGridAlgorithm const*const, unsigned); + + /// @brief Emitted when the current object type cannot be handled by the element model + void clearElementView(); + }; + #endif // VTKINTERACTORSTYLE_H diff --git a/Gui/VtkVis/CMakeLists.txt b/Gui/VtkVis/CMakeLists.txt index 69e8834a3b31d4a0f684ceae9d20da8759e3fe26..5df64c48fae9b59d242fb7ea1b68731d4a1bc531 100644 --- a/Gui/VtkVis/CMakeLists.txt +++ b/Gui/VtkVis/CMakeLists.txt @@ -8,6 +8,7 @@ SET( SOURCES VtkAlgorithmPropertyCheckbox.cpp VtkAlgorithmPropertyLineEdit.cpp VtkAlgorithmPropertyVectorEdit.cpp + VtkAppendArrayFilter.cpp VtkBGImageSource.cpp VtkColorByHeightFilter.cpp VtkColorLookupTable.cpp @@ -15,11 +16,12 @@ SET( SOURCES VtkCompositeColorByHeightFilter.cpp VtkCompositeColormapToImageFilter.cpp VtkCompositeContourFilter.cpp + VtkCompositeElementSelectionFilter.cpp VtkCompositeGeoObjectFilter.cpp VtkCompositeImageToCylindersFilter.cpp VtkCompositeLineToTubeFilter.cpp + VtkCompositeNodeSelectionFilter.cpp VtkCompositePointToGlyphFilter.cpp - VtkCompositeSelectionFilter.cpp VtkCompositeTextureOnSurfaceFilter.cpp VtkCompositeThresholdFilter.cpp VtkConditionSource.cpp @@ -31,7 +33,6 @@ SET( SOURCES VtkPolylinesSource.cpp VtkPointsSource.cpp VtkRaster.cpp - VtkSelectionFilter.cpp VtkStationSource.cpp VtkSurfacesSource.cpp VtkTextureOnSurfaceFilter.cpp @@ -65,6 +66,7 @@ SET( MOC_HEADERS # Header files SET( HEADERS + VtkAppendArrayFilter.h VtkBGImageSource.h VtkColorByHeightFilter.h VtkColorLookupTable.h @@ -72,11 +74,12 @@ SET( HEADERS VtkCompositeColorByHeightFilter.h VtkCompositeColormapToImageFilter.h VtkCompositeContourFilter.h + VtkCompositeElementSelectionFilter.h VtkCompositeGeoObjectFilter.h VtkCompositeImageToCylindersFilter.h VtkCompositeLineToTubeFilter.h + VtkCompositeNodeSelectionFilter.h VtkCompositePointToGlyphFilter.h - VtkCompositeSelectionFilter.h VtkCompositeTextureOnSurfaceFilter.h VtkCompositeThresholdFilter.h VtkConditionSource.h @@ -88,7 +91,6 @@ SET( HEADERS VtkPolylinesSource.h VtkPointsSource.h VtkRaster.h - VtkSelectionFilter.h VtkStationSource.h VtkSurfacesSource.h VtkTextureOnSurfaceFilter.h diff --git a/Gui/VtkVis/VtkSelectionFilter.cpp b/Gui/VtkVis/VtkAppendArrayFilter.cpp similarity index 59% rename from Gui/VtkVis/VtkSelectionFilter.cpp rename to Gui/VtkVis/VtkAppendArrayFilter.cpp index c9e6c2917fcc179e6a1d6bc33eb0a1ad748eb123..3ff9179dc369d89fe29e790e8ab37a0ade42aa49 100644 --- a/Gui/VtkVis/VtkSelectionFilter.cpp +++ b/Gui/VtkVis/VtkAppendArrayFilter.cpp @@ -2,7 +2,7 @@ * \file * \author Karsten Rink * \date 2011-02-09 - * \brief Implementation of the VtkSelectionFilter class. + * \brief Implementation of the VtkAppendArrayFilter class. * * \copyright * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) @@ -13,7 +13,7 @@ */ // ** VTK INCLUDES ** -#include "VtkSelectionFilter.h" +#include "VtkAppendArrayFilter.h" #include <vtkCellData.h> #include <vtkDoubleArray.h> @@ -25,31 +25,30 @@ #include <vtkStreamingDemandDrivenPipeline.h> #include <vtkUnstructuredGrid.h> -vtkStandardNewMacro(VtkSelectionFilter); -vtkCxxRevisionMacro(VtkSelectionFilter, "$Revision: 6995 $"); +vtkStandardNewMacro(VtkAppendArrayFilter); +vtkCxxRevisionMacro(VtkAppendArrayFilter, "$Revision$"); -VtkSelectionFilter::VtkSelectionFilter() - : _thresholdLower(0.0), _thresholdUpper(1.0) +VtkAppendArrayFilter::VtkAppendArrayFilter() { } -VtkSelectionFilter::~VtkSelectionFilter() +VtkAppendArrayFilter::~VtkAppendArrayFilter() { } -void VtkSelectionFilter::PrintSelf( ostream& os, vtkIndent indent ) +void VtkAppendArrayFilter::PrintSelf( ostream& os, vtkIndent indent ) { this->Superclass::PrintSelf(os,indent); - os << indent << "== VtkSelectionFilter ==" << endl; + os << indent << "== VtkAppendArrayFilter ==" << endl; } -int VtkSelectionFilter::RequestData( vtkInformation*, +int VtkAppendArrayFilter::RequestData( vtkInformation*, vtkInformationVector** inputVector, vtkInformationVector* outputVector ) { - if (this->_selection.empty()) + if (this->_array.empty()) { - std::cout << "VtkSelectionFilter - Error: Selection array is empty..." << std::endl; + std::cout << "VtkAppendArrayFilter - Error: Selection array is empty..." << std::endl; return 0; } vtkInformation* inInfo = inputVector[0]->GetInformationObject(0); @@ -61,14 +60,14 @@ int VtkSelectionFilter::RequestData( vtkInformation*, colors->SetName("Selection"); size_t nCells = input->GetNumberOfCells(); - size_t arrayLength = this->_selection.size(); + size_t arrayLength = this->_array.size(); if (nCells > arrayLength) std::cout << - "VtkSelectionFilter - Warning: Number of cells exceeds selection array length. Surplus cells won't be examined." + "VtkAppendArrayFilter - Warning: Number of cells exceeds selection array length. Surplus cells won't be examined." << std::endl; for (size_t i = 0; i < arrayLength; i++) - colors->InsertNextValue(_selection[i]); + colors->InsertNextValue(_array[i]); vtkInformation* outInfo = outputVector->GetInformationObject(0); vtkUnstructuredGrid* output = @@ -77,16 +76,14 @@ int VtkSelectionFilter::RequestData( vtkInformation*, output->GetPointData()->PassData(input->GetPointData()); output->GetCellData()->PassData(input->GetCellData()); output->GetCellData()->AddArray(colors); - output->GetCellData()->SetActiveScalars("Selection"); + output->GetCellData()->SetActiveScalars(_array_name.c_str()); return 1; } -void VtkSelectionFilter::SetSelectionArray(std::vector<double> selection, - double thresholdLower, - double thresholdUpper) +void VtkAppendArrayFilter::SetArray(const std::string &array_name, + const std::vector<double> &new_array) { - this->_selection = selection; - this->_thresholdLower = thresholdLower; - this->_thresholdUpper = thresholdUpper; + this->_array_name = array_name; + this->_array = new_array; } diff --git a/Gui/VtkVis/VtkSelectionFilter.h b/Gui/VtkVis/VtkAppendArrayFilter.h similarity index 60% rename from Gui/VtkVis/VtkSelectionFilter.h rename to Gui/VtkVis/VtkAppendArrayFilter.h index 42a3e23dd9b22a6f8b81d9c00d639ed934009ce0..7b89da662cf094ddeeff3dc7cf45684a524a38c5 100644 --- a/Gui/VtkVis/VtkSelectionFilter.h +++ b/Gui/VtkVis/VtkAppendArrayFilter.h @@ -2,7 +2,7 @@ * \file * \author Karsten Rink * \date 2010-02-09 - * \brief Definition of the VtkSelectionFilter class. + * \brief Definition of the VtkAppendArrayFilter class. * * \copyright * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) @@ -12,8 +12,8 @@ * */ -#ifndef VTKSELECTIONFILTER_H -#define VTKSELECTIONFILTER_H +#ifndef VTKAPPENDARRAYFILTER_H +#define VTKAPPENDARRAYFILTER_H // ** INCLUDES ** #include "VtkAlgorithmProperties.h" @@ -25,13 +25,13 @@ /** * \brief */ -class VtkSelectionFilter : public vtkUnstructuredGridAlgorithm, public VtkAlgorithmProperties +class VtkAppendArrayFilter : public vtkUnstructuredGridAlgorithm, public VtkAlgorithmProperties { public: /// @brief Create new objects with New() because of VTKs object reference counting. - static VtkSelectionFilter* New(); + static VtkAppendArrayFilter* New(); - vtkTypeRevisionMacro(VtkSelectionFilter, vtkUnstructuredGridAlgorithm); + vtkTypeRevisionMacro(VtkAppendArrayFilter, vtkUnstructuredGridAlgorithm); /// @brief Prints the mesh data to an output stream. void PrintSelf(ostream& os, vtkIndent indent); @@ -43,13 +43,11 @@ public: Q_UNUSED(value); } - void SetSelectionArray(std::vector<double> selection, - double thresholdLower, - double thresholdUpper); + void SetArray(const std::string &array_name, const std::vector<double> &selection); protected: - VtkSelectionFilter(); - ~VtkSelectionFilter(); + VtkAppendArrayFilter(); + ~VtkAppendArrayFilter(); /// @brief The filter logic. int RequestData(vtkInformation* request, @@ -57,10 +55,8 @@ protected: vtkInformationVector* outputVector); private: - std::vector<double> _selection; - double _thresholdLower; - double _thresholdUpper; - double _ifSmaller; + std::vector<double> _array; + std::string _array_name; }; -#endif // VTKSELECTIONFILTER_H +#endif // VTKAPPENDARRAYFILTER_H diff --git a/Gui/VtkVis/VtkCompositeElementSelectionFilter.cpp b/Gui/VtkVis/VtkCompositeElementSelectionFilter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..abfbd1d8659d12fa37ca682c5b99806bf4c20988 --- /dev/null +++ b/Gui/VtkVis/VtkCompositeElementSelectionFilter.cpp @@ -0,0 +1,108 @@ +/** + * \file + * \author Karsten Rink + * \date 2011-02-10 + * \brief Implementation of the VtkCompositeSelectionFilter class. + * + * \copyright + * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +// ** INCLUDES ** +#include "VtkCompositeElementSelectionFilter.h" +#include "VtkAppendArrayFilter.h" +#include "VtkCompositePointToGlyphFilter.h" +#include "VtkColorLookupTable.h" +#include "VtkPointsSource.h" + +#include <vtkDataSetSurfaceFilter.h> +#include <vtkSmartPointer.h> +#include <vtkThreshold.h> +#include <vtkIdFilter.h> +#include <vtkUnstructuredGrid.h> + +#include <vtkUnstructuredGridAlgorithm.h> +#include <vtkPointData.h> + + +VtkCompositeElementSelectionFilter::VtkCompositeElementSelectionFilter( vtkAlgorithm* inputAlgorithm ) + : VtkCompositeFilter(inputAlgorithm), _selection_name("Selection") +{ + //this->init(); +} + +void VtkCompositeElementSelectionFilter::init() +{ + double thresholdLower(0.0), thresholdUpper(1.0); + this->_inputDataObjectType = VTK_UNSTRUCTURED_GRID; + this->_outputDataObjectType = VTK_UNSTRUCTURED_GRID; + + this->SetLookUpTable(QString::fromStdString(_selection_name), this->GetLookupTable()); + vtkSmartPointer<VtkAppendArrayFilter> selFilter (NULL); + if (!_selection.empty()) + { + selFilter = vtkSmartPointer<VtkAppendArrayFilter>::New(); + selFilter->SetInputConnection(_inputAlgorithm->GetOutputPort()); + selFilter->SetArray(_selection_name, _selection); + selFilter->Update(); + } + + vtkSmartPointer<vtkIdFilter> idFilter = vtkSmartPointer<vtkIdFilter>::New(); + if (_selection.empty()) // if the array is empty it is assumed that an existing array should be used + idFilter->SetInputConnection(_inputAlgorithm->GetOutputPort()); + else + idFilter->SetInputConnection(selFilter->GetOutputPort()); + idFilter->PointIdsOn(); + idFilter->CellIdsOn(); + idFilter->FieldDataOn(); + idFilter->Update(); + + vtkThreshold* threshold = vtkThreshold::New(); + threshold->SetInputConnection(idFilter->GetOutputPort()); + threshold->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_CELLS, _selection_name.c_str()); + threshold->SetSelectedComponent(0); + threshold->ThresholdBetween(thresholdLower, thresholdUpper); + threshold->Update(); + + QList<QVariant> thresholdRangeList; + thresholdRangeList.push_back(thresholdLower); + thresholdRangeList.push_back(thresholdUpper); + (*_algorithmUserVectorProperties)["Threshold Between"] = thresholdRangeList; + _outputAlgorithm = threshold; +} + +void VtkCompositeElementSelectionFilter::setSelectionArray(const std::string &selection_name, const std::vector<double> &selection) +{ + _selection_name = selection_name; + _selection = selection; + init(); +} + +void VtkCompositeElementSelectionFilter::SetUserVectorProperty( QString name, QList<QVariant> values) +{ + VtkAlgorithmProperties::SetUserVectorProperty(name, values); + + if (name.compare("Threshold Between") == 0) + static_cast<vtkThreshold*>(_outputAlgorithm)->ThresholdBetween( + values[0].toDouble(), values[1].toDouble()); +} + +VtkColorLookupTable* VtkCompositeElementSelectionFilter::GetLookupTable() +{ + VtkColorLookupTable* lut = VtkColorLookupTable::New(); + lut->SetTableRange(0,1); + unsigned char a[4] = { 0, 0, 255, 255 }; // blue + unsigned char b[4] = { 0, 255, 0, 255 }; // green + unsigned char c[4] = { 255, 255, 0, 255 }; // yellow + unsigned char d[4] = { 255, 0, 0, 255 }; // red + lut->setColor(1.0, a); + lut->setColor(0.5, b); + lut->setColor(0.25, c); + lut->setColor(0.1, d); + lut->Build(); + return lut; +} diff --git a/Gui/VtkVis/VtkCompositeSelectionFilter.h b/Gui/VtkVis/VtkCompositeElementSelectionFilter.h similarity index 65% rename from Gui/VtkVis/VtkCompositeSelectionFilter.h rename to Gui/VtkVis/VtkCompositeElementSelectionFilter.h index ea3c2b9349f8157aa0eb2255bb1878acb901eaca..8819ea3d6b4a56ad6dd7cdf514e32f9361dab7b6 100644 --- a/Gui/VtkVis/VtkCompositeSelectionFilter.h +++ b/Gui/VtkVis/VtkCompositeElementSelectionFilter.h @@ -19,19 +19,20 @@ #include <vector> +class vtkThreshold; + class VtkColorLookupTable; -/// @brief This filter colors the input by the points z-value. -class VtkCompositeSelectionFilter : public VtkCompositeFilter +/// @brief This filter selects/thresholds elements based on the selected array. +class VtkCompositeElementSelectionFilter : public VtkCompositeFilter { public: - VtkCompositeSelectionFilter(vtkAlgorithm* inputAlgorithm); - virtual ~VtkCompositeSelectionFilter() {} + VtkCompositeElementSelectionFilter(vtkAlgorithm* inputAlgorithm); + virtual ~VtkCompositeElementSelectionFilter() {} virtual void init(); - void setSelectionArray(std::vector<double> selection) { _selection = selection; - init(); } + void setSelectionArray(const std::string &selection_name, const std::vector<double> &selection = std::vector<double>()); virtual void SetUserVectorProperty(QString name, QList<QVariant> values); @@ -39,6 +40,7 @@ private: /// Returns a colour lookup table optimised for quality measures VtkColorLookupTable* GetLookupTable(); + std::string _selection_name; std::vector<double> _selection; }; diff --git a/Gui/VtkVis/VtkCompositeFilter.cpp b/Gui/VtkVis/VtkCompositeFilter.cpp index 9341f0bc61ab6eb17e45c96ee4bcfe4d7d8e111b..13e186bc346d422faa86f88f21127cadfa48b9d6 100644 --- a/Gui/VtkVis/VtkCompositeFilter.cpp +++ b/Gui/VtkVis/VtkCompositeFilter.cpp @@ -16,6 +16,7 @@ #include "VtkCompositeFilter.h" #include <vtkAlgorithm.h> +#include <vtkPolyData.h> #include <QMapIterator> #include <QString> @@ -31,3 +32,19 @@ VtkCompositeFilter::~VtkCompositeFilter() { _outputAlgorithm->Delete(); } + + +float VtkCompositeFilter::GetInitialRadius() const +{ + double bounding_box[6]; + static_cast<vtkPolyData*>(this->_inputAlgorithm->GetOutputDataObject(0))->GetBounds(bounding_box); + double x_diff = fabs(bounding_box[0]-bounding_box[1]); + double y_diff = fabs(bounding_box[2]-bounding_box[3]); + double z_diff = fabs(bounding_box[4]-bounding_box[5]); + + double max = (x_diff == 0) ? 1 : x_diff; + max = (max > y_diff) ? max : y_diff; + max = (max > z_diff) ? max : z_diff; + + return max/200.0; +} diff --git a/Gui/VtkVis/VtkCompositeFilter.h b/Gui/VtkVis/VtkCompositeFilter.h index 8220b80e1cd9476df73af03431aa6ceaaf7dbe42..7f73d82c631a74f55bbbc5660beec9c1b81ba60e 100644 --- a/Gui/VtkVis/VtkCompositeFilter.h +++ b/Gui/VtkVis/VtkCompositeFilter.h @@ -67,6 +67,9 @@ public: vtkAlgorithm* GetOutputAlgorithm() const { return _outputAlgorithm; } protected: + /// Calculates a 1/200th of the largest extension of the bounding box (this is used as default radius for various filters) + float GetInitialRadius() const; + /// See [vtkSetGet.h](https://github.com/Kitware/VTK/blob/master/Common/Core/vtkSetGet.h) /// for the defines int _inputDataObjectType; diff --git a/Gui/VtkVis/VtkCompositeGeoObjectFilter.cpp b/Gui/VtkVis/VtkCompositeGeoObjectFilter.cpp index f88c4bd389daaa741cc9b1d53e6e1e09eb7c3323..0e454970c4e1ceac1b35ac981c735be622c91afa 100644 --- a/Gui/VtkVis/VtkCompositeGeoObjectFilter.cpp +++ b/Gui/VtkVis/VtkCompositeGeoObjectFilter.cpp @@ -93,16 +93,4 @@ void VtkCompositeGeoObjectFilter::SetIndex(size_t idx) _threshold->ThresholdBetween(idx, idx); } -float VtkCompositeGeoObjectFilter::GetInitialRadius() const -{ - double bounding_box[6]; - static_cast<vtkPolyData*>(this->_inputAlgorithm->GetOutputDataObject(0))->GetBounds(bounding_box); - double x_diff = fabs(bounding_box[0]-bounding_box[1]); - double y_diff = fabs(bounding_box[2]-bounding_box[3]); - double z_diff = fabs(bounding_box[4]-bounding_box[5]); - - double max = (x_diff > y_diff) ? x_diff : y_diff; - max = (max > z_diff) ? max : z_diff; - return max/150.0; -} diff --git a/Gui/VtkVis/VtkCompositeGeoObjectFilter.h b/Gui/VtkVis/VtkCompositeGeoObjectFilter.h index 15306b117aeded38b7089e04b566f9681a53bba9..cb1bea548dc349d481212c4e8ba6b17cfd9cb609 100644 --- a/Gui/VtkVis/VtkCompositeGeoObjectFilter.h +++ b/Gui/VtkVis/VtkCompositeGeoObjectFilter.h @@ -39,8 +39,6 @@ public: void SetIndex(std::size_t idx); private: - float GetInitialRadius() const; - GeoLib::GEOTYPE _type; vtkThreshold* _threshold; }; diff --git a/Gui/VtkVis/VtkCompositeLineToTubeFilter.cpp b/Gui/VtkVis/VtkCompositeLineToTubeFilter.cpp index 1e29038339e7d80c751d34ab9c62552594e89fa2..ea473f27741455ce7c79a66cb2c6f2fc863d81cf 100644 --- a/Gui/VtkVis/VtkCompositeLineToTubeFilter.cpp +++ b/Gui/VtkVis/VtkCompositeLineToTubeFilter.cpp @@ -71,17 +71,3 @@ void VtkCompositeLineToTubeFilter::SetUserProperty( QString name, QVariant value else if (name.compare("Capping") == 0) static_cast<vtkTubeFilter*>(_outputAlgorithm)->SetCapping(value.toBool()); } - -float VtkCompositeLineToTubeFilter::GetInitialRadius() const -{ - double bounding_box[6]; - static_cast<vtkPolyData*>(this->_inputAlgorithm->GetOutputDataObject(0))->GetBounds(bounding_box); - double x_diff = fabs(bounding_box[0]-bounding_box[1]); - double y_diff = fabs(bounding_box[2]-bounding_box[3]); - double z_diff = fabs(bounding_box[4]-bounding_box[5]); - - double max = (x_diff > y_diff) ? x_diff : y_diff; - max = (max > z_diff) ? max : z_diff; - - return max/200.0; -} diff --git a/Gui/VtkVis/VtkCompositeLineToTubeFilter.h b/Gui/VtkVis/VtkCompositeLineToTubeFilter.h index 83540c58caa15ccd92e1e2d911c55699a962c95f..3a23c8c1ec54000326bbc62a0a7b92801d5821e5 100644 --- a/Gui/VtkVis/VtkCompositeLineToTubeFilter.h +++ b/Gui/VtkVis/VtkCompositeLineToTubeFilter.h @@ -29,7 +29,7 @@ public: virtual void SetUserProperty(QString name, QVariant value); private: - float GetInitialRadius() const; + }; #endif // VTKCOMPOSITELINETOTUBEFILTER_H diff --git a/Gui/VtkVis/VtkCompositeNodeSelectionFilter.cpp b/Gui/VtkVis/VtkCompositeNodeSelectionFilter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..01d0937ac6e3e88dd7ec4d619a60b471bff6550f --- /dev/null +++ b/Gui/VtkVis/VtkCompositeNodeSelectionFilter.cpp @@ -0,0 +1,74 @@ +/** + * \file + * \author Karsten Rink + * \date 2013-04-16 + * \brief Implementation of the VtkCompositeNodeSelectionFilter class. + * + * \copyright + * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +// ** INCLUDES ** +#include <memory> + +#include "VtkCompositeNodeSelectionFilter.h" +//#include "VtkCompositePointToGlyphFilter.h" +#include "VtkPointsSource.h" + +#include <vtkDataSetAlgorithm.h> +#include <vtkSmartPointer.h> +#include <vtkSphereSource.h> +#include <vtkGlyph3D.h> + + +VtkCompositeNodeSelectionFilter::VtkCompositeNodeSelectionFilter( vtkAlgorithm* inputAlgorithm ) +: VtkCompositeFilter(inputAlgorithm) +{ + //this->init(); +} + +VtkCompositeNodeSelectionFilter::~VtkCompositeNodeSelectionFilter() +{ + for (unsigned i=0; i<_selection.size(); ++i) + delete _selection[i]; +} + +void VtkCompositeNodeSelectionFilter::init() +{ + this->_inputDataObjectType = VTK_DATA_SET; + this->_outputDataObjectType = VTK_POLY_DATA; + + if (!_selection.empty()) + { + vtkSmartPointer<VtkPointsSource> point_source = vtkSmartPointer<VtkPointsSource>::New(); + point_source->setPoints(&_selection); + + vtkSmartPointer<vtkSphereSource> _glyphSource = vtkSmartPointer<vtkSphereSource>::New(); + _glyphSource->SetRadius(this->GetInitialRadius()); + + vtkGlyph3D* glyphFilter = vtkGlyph3D::New(); + glyphFilter->SetSource(_glyphSource->GetOutput()); + glyphFilter->SetInputConnection(point_source->GetOutputPort()); + + _outputAlgorithm = glyphFilter; + } + else + _outputAlgorithm = nullptr; +} + +void VtkCompositeNodeSelectionFilter::setSelectionArray(const std::vector<unsigned> &point_indeces) +{ + for (unsigned i=0; i<point_indeces.size(); ++i) + { + unsigned idx = point_indeces[i]; + double * coords = static_cast<vtkDataSetAlgorithm*>(_inputAlgorithm)->GetOutput()->GetPoint(point_indeces[i]); + GeoLib::Point* p (new GeoLib::Point(coords)); + _selection.push_back(p); + } + init(); +} + diff --git a/Gui/VtkVis/VtkCompositeNodeSelectionFilter.h b/Gui/VtkVis/VtkCompositeNodeSelectionFilter.h new file mode 100644 index 0000000000000000000000000000000000000000..89f6b7834e7e13c9a4daf2ba9dd81b154a335fd5 --- /dev/null +++ b/Gui/VtkVis/VtkCompositeNodeSelectionFilter.h @@ -0,0 +1,39 @@ +/** + * \file + * \author Karsten Rink + * \date 2013-04-16 + * \brief Definition of the VtkCompositeNodeSelectionFilter class. + * + * \copyright + * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#ifndef VTKCOMPOSITENODESELECTIONFILTER_H +#define VTKCOMPOSITENODESELECTIONFILTER_H + +#include "VtkCompositeFilter.h" +#include "Point.h" + +#include <vector> + +/// @brief This filter displays the points/nodes given in the index field as spheres. +class VtkCompositeNodeSelectionFilter : public VtkCompositeFilter +{ +public: + VtkCompositeNodeSelectionFilter(vtkAlgorithm* inputAlgorithm); + virtual ~VtkCompositeNodeSelectionFilter(); + + virtual void init(); + + /// Sets the point indeces to be highlighted + void setSelectionArray(const std::vector<unsigned> &point_indeces); + +private: + std::vector<GeoLib::Point*> _selection; +}; + +#endif // VTKCOMPOSITENODESELECTIONFILTER_H diff --git a/Gui/VtkVis/VtkCompositePointToGlyphFilter.cpp b/Gui/VtkVis/VtkCompositePointToGlyphFilter.cpp index 58e61815840c343a3f3c90568efce5336dcb3da2..77a777bd7e41520d9a3d71dd08690012152373c9 100644 --- a/Gui/VtkVis/VtkCompositePointToGlyphFilter.cpp +++ b/Gui/VtkVis/VtkCompositePointToGlyphFilter.cpp @@ -93,18 +93,3 @@ void VtkCompositePointToGlyphFilter::SetUserProperty( QString name, QVariant val else if (name.compare("Orient") == 0) static_cast<vtkGlyph3D*>(_outputAlgorithm)->SetOrient(value.toBool()); } - -float VtkCompositePointToGlyphFilter::GetInitialRadius() const -{ - double bounding_box[6]; - static_cast<vtkPolyData*>(this->_inputAlgorithm->GetOutputDataObject(0))->GetBounds(bounding_box); - double x_diff = fabs(bounding_box[0]-bounding_box[1]); - double y_diff = fabs(bounding_box[2]-bounding_box[3]); - double z_diff = fabs(bounding_box[4]-bounding_box[5]); - - double max = (x_diff == 0) ? 1 : x_diff; - max = (max > y_diff) ? max : y_diff; - max = (max > z_diff) ? max : z_diff; - - return max/150.0; -} diff --git a/Gui/VtkVis/VtkCompositePointToGlyphFilter.h b/Gui/VtkVis/VtkCompositePointToGlyphFilter.h index aca27c35fa00a2a5f3ddd09fb5d5723d6b98a96d..2750583bd574be717f59d3cf9e2b0300a0cfbc96 100644 --- a/Gui/VtkVis/VtkCompositePointToGlyphFilter.h +++ b/Gui/VtkVis/VtkCompositePointToGlyphFilter.h @@ -31,8 +31,6 @@ public: virtual void SetUserProperty(QString name, QVariant value); private: - float GetInitialRadius() const; - vtkSphereSource* _glyphSource; }; diff --git a/Gui/VtkVis/VtkCompositeSelectionFilter.cpp b/Gui/VtkVis/VtkCompositeSelectionFilter.cpp deleted file mode 100644 index e29e545ccdad37c095688865ce90a280e44880d8..0000000000000000000000000000000000000000 --- a/Gui/VtkVis/VtkCompositeSelectionFilter.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/** - * \file - * \author Karsten Rink - * \date 2011-02-10 - * \brief Implementation of the VtkCompositeSelectionFilter class. - * - * \copyright - * Copyright (c) 2013, OpenGeoSys Community (http://www.opengeosys.org) - * Distributed under a Modified BSD License. - * See accompanying file LICENSE.txt or - * http://www.opengeosys.org/project/license - * - */ - -// ** INCLUDES ** -#include "VtkCompositeSelectionFilter.h" -#include "VtkSelectionFilter.h" -#include "VtkColorLookupTable.h" - -#include <vtkDataSetSurfaceFilter.h> -#include <vtkSmartPointer.h> -#include <vtkThreshold.h> -#include <vtkIdFilter.h> -#include <vtkUnstructuredGrid.h> - -VtkCompositeSelectionFilter::VtkCompositeSelectionFilter( vtkAlgorithm* inputAlgorithm ) - : VtkCompositeFilter(inputAlgorithm) -{ - //this->init(); -} - -void VtkCompositeSelectionFilter::init() -{ - const char* filter_name("Selection"); - double thresholdLower(0.0), thresholdUpper(1.0); - this->_inputDataObjectType = VTK_UNSTRUCTURED_GRID; - this->_outputDataObjectType = VTK_UNSTRUCTURED_GRID; - - this->SetLookUpTable(QString(filter_name), this->GetLookupTable()); - - VtkSelectionFilter* selFilter = VtkSelectionFilter::New(); - selFilter->SetInputConnection(_inputAlgorithm->GetOutputPort()); - selFilter->SetSelectionArray(_selection, thresholdLower, thresholdUpper); - selFilter->Update(); - - vtkIdFilter* idFilter = vtkIdFilter::New(); - idFilter->SetInputConnection(selFilter->GetOutputPort()); - idFilter->PointIdsOn(); - idFilter->CellIdsOn(); - idFilter->FieldDataOn(); - idFilter->Update(); - - vtkThreshold* threshold = vtkThreshold::New(); - threshold->SetInputConnection(idFilter->GetOutputPort()); - threshold->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_CELLS, filter_name); - threshold->SetSelectedComponent(0); - threshold->ThresholdBetween(thresholdLower, thresholdUpper); - threshold->Update(); - - QList<QVariant> thresholdRangeList; - thresholdRangeList.push_back(0.0); - thresholdRangeList.push_back(1.0); - (*_algorithmUserVectorProperties)["Threshold Between"] = thresholdRangeList; - - _outputAlgorithm = threshold; -} - -void VtkCompositeSelectionFilter::SetUserVectorProperty( QString name, QList<QVariant> values) -{ - VtkAlgorithmProperties::SetUserVectorProperty(name, values); - - if (name.compare("Threshold Between") == 0) - static_cast<vtkThreshold*>(_outputAlgorithm)->ThresholdBetween( - values[0].toDouble(), values[1].toDouble()); -} - -VtkColorLookupTable* VtkCompositeSelectionFilter::GetLookupTable() -{ - VtkColorLookupTable* lut = VtkColorLookupTable::New(); - lut->SetTableRange(0,1); - unsigned char a[4] = { 0, 0, 255, 255 }; // blue - unsigned char b[4] = { 0, 255, 0, 255 }; // green - unsigned char c[4] = { 255, 255, 0, 255 }; // yellow - unsigned char d[4] = { 255, 0, 0, 255 }; // red - lut->setColor(1.0, a); - lut->setColor(0.5, b); - lut->setColor(0.25, c); - lut->setColor(0.1, d); - lut->Build(); - return lut; -} diff --git a/Gui/VtkVis/VtkFilterFactory.cpp b/Gui/VtkVis/VtkFilterFactory.cpp index 17a489099c7fb808b1498b997652e74157c9d653..c9b3fc0776b309217b565dcfe5a8db059be030d5 100644 --- a/Gui/VtkVis/VtkFilterFactory.cpp +++ b/Gui/VtkVis/VtkFilterFactory.cpp @@ -18,11 +18,12 @@ #include "VtkCompositeColorByHeightFilter.h" #include "VtkCompositeColormapToImageFilter.h" #include "VtkCompositeContourFilter.h" +#include "VtkCompositeElementSelectionFilter.h" #include "VtkCompositeGeoObjectFilter.h" #include "VtkCompositeImageToCylindersFilter.h" #include "VtkCompositeLineToTubeFilter.h" +#include "VtkCompositeNodeSelectionFilter.h" #include "VtkCompositePointToGlyphFilter.h" -#include "VtkCompositeSelectionFilter.h" #include "VtkCompositeTextureOnSurfaceFilter.h" #include "VtkCompositeThresholdFilter.h" #include "VtkImageDataToLinePolyDataFilter.h" @@ -122,8 +123,10 @@ VtkCompositeFilter* VtkFilterFactory::CreateCompositeFilter( QString type, return new VtkCompositeThresholdFilter(inputAlgorithm); else if (type.compare(QString("VtkCompositeColorByHeightFilter")) == 0) return new VtkCompositeColorByHeightFilter(inputAlgorithm); - else if (type.compare(QString("VtkCompositeSelectionFilter")) == 0) - return new VtkCompositeSelectionFilter(inputAlgorithm); + else if (type.compare(QString("VtkCompositeElementSelectionFilter")) == 0) + return new VtkCompositeElementSelectionFilter(inputAlgorithm); + else if (type.compare(QString("VtkCompositeNodeSelectionFilter")) == 0) + return new VtkCompositeNodeSelectionFilter(inputAlgorithm); else if (type.compare(QString("VtkCompositeContourFilter")) == 0) return new VtkCompositeContourFilter(inputAlgorithm); else if (type.compare(QString("VtkCompositeGeoObjectFilter")) == 0) diff --git a/Gui/VtkVis/VtkMeshSource.h b/Gui/VtkVis/VtkMeshSource.h index 689a77f54c166ab46aed5792fc716775450ab46a..224d2e25749cb3e815cd0e5c45f45e3f85338d5d 100644 --- a/Gui/VtkVis/VtkMeshSource.h +++ b/Gui/VtkVis/VtkMeshSource.h @@ -41,7 +41,7 @@ public: const char* GetMaterialArrayName() const { return _matName; } /// Returns the base object of this grid - const MeshLib::Mesh* GetMesh() { return this->_grid; } + const MeshLib::Mesh* GetMesh() const { return this->_grid; } /// Sets the grid object that should be visualized void SetMesh(const MeshLib::Mesh* grid) { _grid = grid; } diff --git a/Gui/VtkVis/VtkVisPipeline.cpp b/Gui/VtkVis/VtkVisPipeline.cpp index bcd82492fb6c61d0eebb2a4b0868aa8cca4a1e7f..57d5bbaae5161d98c60c88b10da3e065c022efab 100644 --- a/Gui/VtkVis/VtkVisPipeline.cpp +++ b/Gui/VtkVis/VtkVisPipeline.cpp @@ -30,7 +30,8 @@ #include "StationTreeModel.h" #include "TreeModel.h" #include "VtkAlgorithmProperties.h" -#include "VtkCompositeSelectionFilter.h" +#include "VtkCompositeNodeSelectionFilter.h" +#include "VtkCompositeElementSelectionFilter.h" #include "VtkCompositeGeoObjectFilter.h" #include "VtkFilterFactory.h" #include "VtkMeshSource.h" @@ -67,7 +68,7 @@ #include <QTime> VtkVisPipeline::VtkVisPipeline( vtkRenderer* renderer, QObject* parent /*= 0*/ ) - : TreeModel(parent), _renderer(renderer), _highlighted_geo_index(QModelIndex()) + : TreeModel(parent), _renderer(renderer), _highlighted_geo_index(QModelIndex()), _highlighted_mesh_component(QModelIndex()) { QList<QVariant> rootData; rootData << "Object name" << "Visible"; @@ -512,11 +513,8 @@ void VtkVisPipeline::checkMeshQuality(VtkMeshSource* source, MshQualityType::typ VtkFilterFactory::CreateCompositeFilter( "VtkCompositeSelectionFilter", parentItem->transformFilter()); - static_cast<VtkCompositeSelectionFilter*>(filter)-> - setSelectionArray(quality); - VtkVisPointSetItem* item = new VtkVisPointSetItem(filter, - parentItem, - itemData); + static_cast<VtkCompositeElementSelectionFilter*>(filter)->setSelectionArray("Selection", quality); + VtkVisPointSetItem* item = new VtkVisPointSetItem(filter, parentItem, itemData); this->addPipelineItem(item, this->createIndex(i, 0, item)); break; } @@ -591,3 +589,49 @@ void VtkVisPipeline::removeHighlightedGeoObject() _highlighted_geo_index = QModelIndex(); } } + +void VtkVisPipeline::highlightMeshComponent(vtkUnstructuredGridAlgorithm const*const source, unsigned index, bool is_element) +{ + int nSources = this->_rootItem->childCount(); + for (int i = 0; i < nSources; i++) + { + VtkVisPipelineItem* parentItem = static_cast<VtkVisPipelineItem*>(_rootItem->child(i)); + if (parentItem->algorithm() == source) + { + QList<QVariant> itemData; + itemData << "Selected Mesh Component" << true; + QList<QVariant> selected_index; + selected_index << index << index; + + VtkCompositeFilter* filter (nullptr); + if (is_element) + { + filter = VtkFilterFactory::CreateCompositeFilter("VtkCompositeElementSelectionFilter", + parentItem->transformFilter()); + static_cast<VtkCompositeElementSelectionFilter*>(filter)->setSelectionArray("vtkIdFilter_Ids"); + static_cast<VtkCompositeElementSelectionFilter*>(filter)->SetUserVectorProperty("Threshold Between", selected_index); + } + else + { + filter = VtkFilterFactory::CreateCompositeFilter("VtkCompositeNodeSelectionFilter", + parentItem->transformFilter()); + std::vector<unsigned> indeces(1); + indeces[0] = index; + static_cast<VtkCompositeNodeSelectionFilter*>(filter)->setSelectionArray(indeces); + } + VtkVisPointSetItem* item = new VtkVisPointSetItem(filter, parentItem, itemData); + QModelIndex parent_index = static_cast<TreeModel*>(this)->index(i, 0, QModelIndex()); + _highlighted_mesh_component = this->addPipelineItem(item, parent_index); + break; + } + } +} + +void VtkVisPipeline::removeHighlightedMeshComponent() +{ + if (_highlighted_mesh_component != QModelIndex()) + { + this->removePipelineItem(_highlighted_mesh_component); + _highlighted_mesh_component = QModelIndex(); + } +} \ No newline at end of file diff --git a/Gui/VtkVis/VtkVisPipeline.h b/Gui/VtkVis/VtkVisPipeline.h index 908855bf33d4563e2fcc31b70df0b6f0a1579e65..3fa2f0508e0fb7556b0bb3aeec95065c049c6c02 100644 --- a/Gui/VtkVis/VtkVisPipeline.h +++ b/Gui/VtkVis/VtkVisPipeline.h @@ -31,10 +31,13 @@ class vtkDataSet; class vtkLight; class vtkPointSet; class vtkPolyDataAlgorithm; -class vtkRenderer; class vtkProp3D; +class vtkRenderer; +class vtkUnstructuredGridAlgorithm; + class QModelIndex; class QString; + class GeoTreeModel; class ProcessModel; class MshModel; @@ -116,9 +119,19 @@ public slots: /// Checks the quality of a mesh and cal a filter to highlight deformed elements. void checkMeshQuality(VtkMeshSource* mesh, MshQualityType::type t); + /// Applies a VtkCompositeGeoObjectFilter to add a specific index of the given geometry-source to the pipeline for highlighted display in the render window. void highlightGeoObject(const vtkPolyDataAlgorithm* source, int index); + + /// Removes the currently highlighted geometry-object void removeHighlightedGeoObject(); + /// Applies a VtkCompositeSelectionFilter to add a specific component of the given mesh-source to the pipeline for highlighted display in the render window. + void highlightMeshComponent(vtkUnstructuredGridAlgorithm const*const source, unsigned index, bool is_element); + + /// Removes the currently highlighted mesh component + void removeHighlightedMeshComponent(); + + private: void listArrays(vtkDataSet* dataSet); @@ -129,7 +142,7 @@ private: bool _resetCameraOnAddOrRemove; QModelIndex _highlighted_geo_index; - + QModelIndex _highlighted_mesh_component; signals: /// \brief Is emitted when a pipeline item was added or removed. diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp index a30193f80c26dd73dbeb9b951bb278c96b4ddcbf..779e05e71bf5a2dbe58fbc0dee057729788dcdae 100644 --- a/Gui/mainwindow.cpp +++ b/Gui/mainwindow.cpp @@ -201,6 +201,22 @@ MainWindow::MainWindow(QWidget* parent /* = 0*/) this, SLOT(showMshQualitySelectionDialog(VtkMeshSource*))); connect(mshTabWidget->treeView, SIGNAL(requestCondSetupDialog(const std::string&, const GeoLib::GEOTYPE, std::size_t, bool)), this, SLOT(showCondSetupDialog(const std::string&, const GeoLib::GEOTYPE, std::size_t, bool))); + connect(mshTabWidget->treeView, SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const*const, unsigned, bool)), + _vtkVisPipeline, SLOT(highlightMeshComponent(vtkUnstructuredGridAlgorithm const*const, unsigned, bool))); + connect(mshTabWidget->treeView, SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const*const, unsigned, bool)), + this->_elementModel, SLOT(setElement(vtkUnstructuredGridAlgorithm const*const, unsigned))); + connect(mshTabWidget->treeView, SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const*const, unsigned, bool)), + mshTabWidget->elementView, SLOT(updateView())); + connect(mshTabWidget->treeView, SIGNAL(elementSelected(vtkUnstructuredGridAlgorithm const*const, unsigned, bool)), + (QObject*) (visualizationWidget->interactorStyle()), SLOT(removeHighlightActor())); + connect(mshTabWidget->elementView, SIGNAL(nodeSelected(vtkUnstructuredGridAlgorithm const*const, unsigned, bool)), + (QObject*) (visualizationWidget->interactorStyle()), SLOT(removeHighlightActor())); + connect(mshTabWidget->treeView, SIGNAL(removeSelectedMeshComponent()), + _vtkVisPipeline, SLOT(removeHighlightedMeshComponent())); + connect(mshTabWidget->elementView, SIGNAL(nodeSelected(vtkUnstructuredGridAlgorithm const*const, unsigned, bool)), + _vtkVisPipeline, SLOT(highlightMeshComponent(vtkUnstructuredGridAlgorithm const*const, unsigned, bool))); + connect(mshTabWidget->elementView, SIGNAL(removeSelectedMeshComponent()), + _vtkVisPipeline, SLOT(removeHighlightedMeshComponent())); // Setup connections for process model to GUI connect(modellingTabWidget->treeView, SIGNAL(conditionsRemoved(const FiniteElement::ProcessType, const std::string&, const FEMCondition::CondType)), @@ -265,11 +281,16 @@ MainWindow::MainWindow(QWidget* parent /* = 0*/) SIGNAL(actorPicked(vtkProp3D*)), vtkVisTabWidget->vtkVisPipelineView, SLOT(selectItem(vtkProp3D*))); connect((QObject*) (visualizationWidget->interactorStyle()), - SIGNAL(elementPicked(const MeshLib::Mesh *, const std::size_t)), - this->_elementModel, SLOT(setElement(const MeshLib::Mesh *, const std::size_t))); + SIGNAL(elementPicked(vtkUnstructuredGridAlgorithm const*const, const unsigned)), + this->_elementModel, SLOT(setElement(vtkUnstructuredGridAlgorithm const*const, const unsigned))); connect((QObject*) (visualizationWidget->interactorStyle()), - SIGNAL(elementPicked(const MeshLib::Mesh *, const std::size_t)), + SIGNAL(elementPicked(vtkUnstructuredGridAlgorithm const*const, const unsigned)), mshTabWidget->elementView, SLOT(updateView())); + connect((QObject*) (visualizationWidget->interactorStyle()), SIGNAL(clearElementView()), + this->_elementModel, SLOT(clearView())); + connect((QObject*) (visualizationWidget->interactorStyle()), + SIGNAL(elementPicked(vtkUnstructuredGridAlgorithm const*const, const unsigned)), + this->_vtkVisPipeline, SLOT(removeHighlightedMeshComponent())); connect(vtkVisTabWidget->vtkVisPipelineView, SIGNAL(meshAdded(MeshLib::Mesh*)), _meshModels, SLOT(addMesh(MeshLib::Mesh*)));