From dde81ba64b1ec80a480d9853e94d5080a102763f Mon Sep 17 00:00:00 2001 From: Karsten Rink <karsten.rink@ufz.de> Date: Tue, 9 Apr 2013 16:44:43 +0200 Subject: [PATCH] moved initial radius calculation if various filters to CompositeFilter parent class --- Gui/DataView/MshView.cpp | 2 +- Gui/DataView/MshView.h | 2 +- Gui/VtkVis/VtkCompositeFilter.cpp | 17 +++++++++++ Gui/VtkVis/VtkCompositeFilter.h | 3 ++ Gui/VtkVis/VtkCompositeGeoObjectFilter.cpp | 12 -------- Gui/VtkVis/VtkCompositeGeoObjectFilter.h | 2 -- Gui/VtkVis/VtkCompositeLineToTubeFilter.cpp | 14 ---------- Gui/VtkVis/VtkCompositeLineToTubeFilter.h | 2 +- Gui/VtkVis/VtkCompositePointToGlyphFilter.cpp | 15 ---------- Gui/VtkVis/VtkCompositePointToGlyphFilter.h | 2 -- Gui/VtkVis/VtkCompositeSelectionFilter.cpp | 28 +++++++++++++------ Gui/VtkVis/VtkCompositeSelectionFilter.h | 3 +- Gui/VtkVis/VtkVisPipeline.cpp | 6 ++-- Gui/VtkVis/VtkVisPipeline.h | 2 +- Gui/mainwindow.cpp | 4 +-- 15 files changed, 51 insertions(+), 63 deletions(-) diff --git a/Gui/DataView/MshView.cpp b/Gui/DataView/MshView.cpp index 8315d52c057..6b712ca3988 100644 --- a/Gui/DataView/MshView.cpp +++ b/Gui/DataView/MshView.cpp @@ -76,7 +76,7 @@ void MshView::selectionChanged( const QItemSelection &selected, const QItemSelec { emit enableSaveButton(false); emit enableRemoveButton(false); - emit elementSelected(dynamic_cast<const MshItem*>(tree_item->parentItem())->vtkSource(), tree_item->row()); + emit elementSelected(dynamic_cast<const MshItem*>(tree_item->parentItem())->vtkSource(), true, tree_item->row()); } } //emit itemSelectionChanged(selected, deselected); diff --git a/Gui/DataView/MshView.h b/Gui/DataView/MshView.h index c187ad6d1bc..1b4a7a64ecf 100644 --- a/Gui/DataView/MshView.h +++ b/Gui/DataView/MshView.h @@ -87,7 +87,7 @@ private slots: void checkMeshQuality(); signals: - void elementSelected(const vtkUnstructuredGridAlgorithm*, int); + void elementSelected(const vtkUnstructuredGridAlgorithm*, bool, int); void enableSaveButton(bool); void enableRemoveButton(bool); void openMeshFile(int); diff --git a/Gui/VtkVis/VtkCompositeFilter.cpp b/Gui/VtkVis/VtkCompositeFilter.cpp index 9341f0bc61a..13e186bc346 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 8220b80e1cd..7f73d82c631 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 f88c4bd389d..0e454970c4e 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 15306b117ae..cb1bea548dc 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 1e29038339e..ea473f27741 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 83540c58caa..3a23c8c1ec5 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/VtkCompositePointToGlyphFilter.cpp b/Gui/VtkVis/VtkCompositePointToGlyphFilter.cpp index 58e61815840..77a777bd7e4 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 aca27c35fa0..2750583bd57 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 index e6b009af7cf..3f1981e5731 100644 --- a/Gui/VtkVis/VtkCompositeSelectionFilter.cpp +++ b/Gui/VtkVis/VtkCompositeSelectionFilter.cpp @@ -15,6 +15,7 @@ // ** INCLUDES ** #include "VtkCompositeSelectionFilter.h" #include "VtkAppendArrayFilter.h" +#include "VtkCompositePointToGlyphFilter.h" #include "VtkColorLookupTable.h" #include <vtkDataSetSurfaceFilter.h> @@ -24,7 +25,7 @@ #include <vtkUnstructuredGrid.h> VtkCompositeSelectionFilter::VtkCompositeSelectionFilter( vtkAlgorithm* inputAlgorithm ) - : VtkCompositeFilter(inputAlgorithm), _selection_name("Selection") + : VtkCompositeFilter(inputAlgorithm), _selection_name("Selection"), _is_element_array(true) { //this->init(); } @@ -57,23 +58,34 @@ void VtkCompositeSelectionFilter::init() 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(); + threshold->SetInputConnection(idFilter->GetOutputPort()); + if (_is_element_array) + threshold->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_CELLS, _selection_name.c_str()); + else + threshold->SetInputArrayToProcess(0,0,0,vtkDataObject::FIELD_ASSOCIATION_POINTS, _selection_name.c_str()); + 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; + if (!_is_element_array) + { + VtkCompositeFilter* composite = new VtkCompositePointToGlyphFilter(threshold); + composite->SetUserProperty("Radius", this->GetInitialRadius()); + _outputAlgorithm = composite->GetOutputAlgorithm(); + } + else + _outputAlgorithm = threshold; } -void VtkCompositeSelectionFilter::setSelectionArray(const std::string &selection_name, const std::vector<double> &selection) +void VtkCompositeSelectionFilter::setSelectionArray(const std::string &selection_name, bool is_element_array, const std::vector<double> &selection) { _selection_name = selection_name; + _is_element_array = is_element_array; _selection = selection; init(); } diff --git a/Gui/VtkVis/VtkCompositeSelectionFilter.h b/Gui/VtkVis/VtkCompositeSelectionFilter.h index b11d5516763..d0a868ebf25 100644 --- a/Gui/VtkVis/VtkCompositeSelectionFilter.h +++ b/Gui/VtkVis/VtkCompositeSelectionFilter.h @@ -30,7 +30,7 @@ public: virtual void init(); - void setSelectionArray(const std::string &selection_name, const std::vector<double> &selection = std::vector<double>()); + void setSelectionArray(const std::string &selection_name, bool is_element_array = true, const std::vector<double> &selection = std::vector<double>()); virtual void SetUserVectorProperty(QString name, QList<QVariant> values); @@ -40,6 +40,7 @@ private: std::string _selection_name; std::vector<double> _selection; + bool _is_element_array; }; #endif // VTKCOMPOSITESELECTIONFILTER_H diff --git a/Gui/VtkVis/VtkVisPipeline.cpp b/Gui/VtkVis/VtkVisPipeline.cpp index b40ec725605..cd9092c6285 100644 --- a/Gui/VtkVis/VtkVisPipeline.cpp +++ b/Gui/VtkVis/VtkVisPipeline.cpp @@ -513,7 +513,7 @@ void VtkVisPipeline::checkMeshQuality(VtkMeshSource* source, MshQualityType::typ "VtkCompositeSelectionFilter", parentItem->transformFilter()); static_cast<VtkCompositeSelectionFilter*>(filter)-> - setSelectionArray("Selection", quality); + setSelectionArray("Selection", true, quality); VtkVisPointSetItem* item = new VtkVisPointSetItem(filter, parentItem, itemData); @@ -592,7 +592,7 @@ void VtkVisPipeline::removeHighlightedGeoObject() } } -void VtkVisPipeline::highlightMeshComponent(const vtkUnstructuredGridAlgorithm* source, int index) +void VtkVisPipeline::highlightMeshComponent(const vtkUnstructuredGridAlgorithm* source, bool is_element, int index) { int nSources = this->_rootItem->childCount(); for (int i = 0; i < nSources; i++) @@ -608,7 +608,7 @@ void VtkVisPipeline::highlightMeshComponent(const vtkUnstructuredGridAlgorithm* VtkCompositeFilter* filter = VtkFilterFactory::CreateCompositeFilter( "VtkCompositeSelectionFilter", parentItem->transformFilter()); - static_cast<VtkCompositeSelectionFilter*>(filter)->setSelectionArray("vtkIdFilter_Ids"); + static_cast<VtkCompositeSelectionFilter*>(filter)->setSelectionArray("vtkIdFilter_Ids", is_element); static_cast<VtkCompositeSelectionFilter*>(filter)->SetUserVectorProperty("Threshold Between", selected_index); VtkVisPointSetItem* item = new VtkVisPointSetItem(filter, parentItem, itemData); diff --git a/Gui/VtkVis/VtkVisPipeline.h b/Gui/VtkVis/VtkVisPipeline.h index b48ee88019a..2d6debb5c4d 100644 --- a/Gui/VtkVis/VtkVisPipeline.h +++ b/Gui/VtkVis/VtkVisPipeline.h @@ -126,7 +126,7 @@ public slots: 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(const vtkUnstructuredGridAlgorithm* source, int index); + void highlightMeshComponent(const vtkUnstructuredGridAlgorithm* source, bool is_element, int index); /// Removes the currently highlighted mesh component void removeHighlightedMeshComponent(); diff --git a/Gui/mainwindow.cpp b/Gui/mainwindow.cpp index 1c6664f4962..d29de28553c 100644 --- a/Gui/mainwindow.cpp +++ b/Gui/mainwindow.cpp @@ -201,8 +201,8 @@ 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(const vtkUnstructuredGridAlgorithm*, int)), - _vtkVisPipeline, SLOT(highlightMeshComponent(const vtkUnstructuredGridAlgorithm*, int))); + connect(mshTabWidget->treeView, SIGNAL(elementSelected(const vtkUnstructuredGridAlgorithm*, bool, int)), + _vtkVisPipeline, SLOT(highlightMeshComponent(const vtkUnstructuredGridAlgorithm*, bool, int))); connect(mshTabWidget->treeView, SIGNAL(removeSelectedMeshComponent()), _vtkVisPipeline, SLOT(removeHighlightedMeshComponent())); -- GitLab