From: vsv Date: Tue, 26 Nov 2013 11:43:33 +0000 (+0000) Subject: Extract Field filter for Paraview X-Git-Tag: V7_3_0a1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1789728cb48cd1b083fce101554a0d29e192b4a0;p=modules%2Fparavis.git Extract Field filter for Paraview --- diff --git a/src/Plugins/CMakeLists.txt b/src/Plugins/CMakeLists.txt index 64238c27..0312b37f 100755 --- a/src/Plugins/CMakeLists.txt +++ b/src/Plugins/CMakeLists.txt @@ -29,6 +29,7 @@ SET(_subdirs IntegrationPoints ElevationSurface ScaleVector + ExtraxtFieldFilter ) FOREACH(_dir ${_subdirs}) diff --git a/src/Plugins/ExtraxtFieldFilter/CMakeLists.txt b/src/Plugins/ExtraxtFieldFilter/CMakeLists.txt new file mode 100755 index 00000000..79b10e6a --- /dev/null +++ b/src/Plugins/ExtraxtFieldFilter/CMakeLists.txt @@ -0,0 +1,40 @@ +# Copyright (C) 2010-2013 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +# create a paraview plugin containing server manager xml and the server +# manager classes to build +# this plugin can be loaded on the server side + + +cmake_minimum_required(VERSION 2.8) + +FIND_PACKAGE(ParaView REQUIRED) +INCLUDE(${PARAVIEW_USE_FILE}) + +ADD_PARAVIEW_PLUGIN(ExtractFieldFilter "1.0" + SERVER_MANAGER_XML ExtractFieldFilter.xml + SERVER_MANAGER_SOURCES vtkExtractFieldFilter.cxx + GUI_RESOURCES pqExtractField.qrc + GUI_RESOURCE_FILES ExtractFieldGUI.xml + ) + +INSTALL( + TARGETS ExtractFieldFilter + DESTINATION lib/paraview +) diff --git a/src/Plugins/ExtraxtFieldFilter/ExtractFieldFilter.xml b/src/Plugins/ExtraxtFieldFilter/ExtractFieldFilter.xml new file mode 100755 index 00000000..b3265834 --- /dev/null +++ b/src/Plugins/ExtraxtFieldFilter/ExtractFieldFilter.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + This property lists the names of fields which can be used for extraction of mesh support. + + + + + + diff --git a/src/Plugins/ExtraxtFieldFilter/ExtractFieldGUI.xml b/src/Plugins/ExtraxtFieldFilter/ExtractFieldGUI.xml new file mode 100644 index 00000000..91661773 --- /dev/null +++ b/src/Plugins/ExtraxtFieldFilter/ExtractFieldGUI.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Plugins/ExtraxtFieldFilter/pqExtractField.qrc b/src/Plugins/ExtraxtFieldFilter/pqExtractField.qrc new file mode 100644 index 00000000..7f06fb19 --- /dev/null +++ b/src/Plugins/ExtraxtFieldFilter/pqExtractField.qrc @@ -0,0 +1,5 @@ + + + resources/extract_field.png + + \ No newline at end of file diff --git a/src/Plugins/ExtraxtFieldFilter/resources/extract_field.png b/src/Plugins/ExtraxtFieldFilter/resources/extract_field.png new file mode 100644 index 00000000..a8a50e87 Binary files /dev/null and b/src/Plugins/ExtraxtFieldFilter/resources/extract_field.png differ diff --git a/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.cxx b/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.cxx new file mode 100644 index 00000000..fcec1452 --- /dev/null +++ b/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.cxx @@ -0,0 +1,167 @@ +// Copyright (C) 2010-2013 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#include "vtkExtractFieldFilter.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace std; + +vtkStandardNewMacro(vtkExtractFieldFilter); + +vtkExtractFieldFilter::vtkExtractFieldFilter() +:vtkMultiBlockDataSetAlgorithm() +{ + this->FieldName = NULL; +} + + +vtkExtractFieldFilter::~vtkExtractFieldFilter() +{ +} + +//---------------------------------------------------------------------------- +int vtkExtractFieldFilter::RequestData(vtkInformation* vtkNotUsed(request), + vtkInformationVector** theInputVector, + vtkInformationVector* theOutputVector) +{ + // get the info objects + vtkMultiBlockDataSet* aInput = vtkMultiBlockDataSet::GetData(theInputVector[0], 0); + vtkMultiBlockDataSet* aOutput = vtkMultiBlockDataSet::GetData(theOutputVector, 0); + + aOutput->CopyStructure(aInput); + + // Copy selected blocks over to the output. + vtkDataObjectTreeIterator* aIter = aInput->NewTreeIterator(); + aIter->VisitOnlyLeavesOff(); + for (aIter->InitTraversal(); !aIter->IsDoneWithTraversal(); aIter->GoToNextItem()) { + this->CopySubTree(aIter, aOutput, aInput); + } + aIter->Delete(); + return 1; +} + + +//---------------------------------------------------------------------------- +void vtkExtractFieldFilter::CopySubTree(vtkDataObjectTreeIterator* theLoc, + vtkMultiBlockDataSet* theOutput, + vtkMultiBlockDataSet* theInput) +{ + vtkDataObject* aInputNode = theInput->GetDataSet(theLoc); + if (!aInputNode->IsA("vtkCompositeDataSet")) { + if (IsToCopy(aInputNode)) { + vtkDataObject* aClone = aInputNode->NewInstance(); + aClone->ShallowCopy(aInputNode); + theOutput->SetDataSet(theLoc, aClone); + aClone->Delete(); + } + } else { + vtkCompositeDataSet* aCInput = vtkCompositeDataSet::SafeDownCast(aInputNode); + vtkCompositeDataSet* aCOutput = vtkCompositeDataSet::SafeDownCast(theOutput->GetDataSet(theLoc)); + vtkCompositeDataIterator* aIter = aCInput->NewIterator(); + vtkDataObjectTreeIterator* aTreeIter = vtkDataObjectTreeIterator::SafeDownCast(aIter); + if (aTreeIter) { + aTreeIter->VisitOnlyLeavesOff(); + } + for (aIter->InitTraversal(); !aIter->IsDoneWithTraversal(); aIter->GoToNextItem()) { + vtkDataObject* aCurNode = aIter->GetCurrentDataObject(); + if (IsToCopy(aInputNode)) { + vtkDataObject* aClone = aCurNode->NewInstance(); + aClone->ShallowCopy(aCurNode); + aCOutput->SetDataSet(aIter, aClone); + aClone->Delete(); + } + } + aIter->Delete(); + } + +} + + +//---------------------------------------------------------------------------- +void vtkExtractFieldFilter::GetListOfFields(vtkDataObject* theObject, std::list& theList) const +{ + theList.clear(); + + if (theObject->IsA("vtkDataSet")) { + vtkDataSet* aDataSet = vtkDataSet::SafeDownCast(theObject); + vtkPointData* aPntData = aDataSet->GetPointData(); + int aNbArrays = aPntData->GetNumberOfArrays(); + for (int i = 0; i < aNbArrays; i++) { + const char* aName = aPntData->GetArrayName(i); + theList.push_back(aName); + } + vtkCellData* aCellData = aDataSet->GetCellData(); + aNbArrays = aCellData->GetNumberOfArrays(); + for (int i = 0; i < aNbArrays; i++) { + const char* aName = aCellData->GetArrayName(i); + theList.push_back(aName); + } + } + +} + + +//---------------------------------------------------------------------------- +bool vtkExtractFieldFilter::IsToCopy(vtkDataObject* theObject) const +{ + if (this->FieldName == NULL) + return true; + + std::list aList; + GetListOfFields(theObject, aList); + + std::list::const_iterator aIt; + std::string aTestStr = this->FieldName; + for (aIt = aList.begin(); aIt != aList.end(); ++aIt) + if (aTestStr.compare(*aIt) == 0) + return true; + + return false; +} + + + +//---------------------------------------------------------------------------- +void vtkExtractFieldFilter::SetInputArrayToProcess(int idx, int port, int connection, + int fieldAssociation, const char* name) +{ + this->SetFieldName(name); +} + + +//---------------------------------------------------------------------------- +void vtkExtractFieldFilter::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); + os << indent << "Field name: " << FieldName << endl; +} + diff --git a/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.h b/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.h new file mode 100644 index 00000000..4a93ccbb --- /dev/null +++ b/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.h @@ -0,0 +1,82 @@ +// Copyright (C) 2010-2013 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +#ifndef __vtkExtractFieldFilter_h +#define __vtkExtractFieldFilter_h + +#include +#include +#include + +class vtkDataObjectTreeIterator; + + +/** + * Implements a class of a filter which extract a support mesh of a data field. + * It processes MultiBlockDataSet data structure extracting blocks which contain + * a field with FieldName. + * If field name is not defined then the filter just copies input data to output data +*/ +class vtkExtractFieldFilter : public vtkMultiBlockDataSetAlgorithm +{ +public: + /// Returns pointer on a new instance of the class + static vtkExtractFieldFilter* New(); + + vtkTypeMacro(vtkExtractFieldFilter, vtkMultiBlockDataSetAlgorithm); + + /// Prints current state of the objects + virtual void PrintSelf(ostream& os, vtkIndent indent); + + /// This method is used for definition of a field name for filtering from GUI + virtual void SetInputArrayToProcess(int idx, int port, int connection, + int fieldAssociation, const char* name); + + /// Set and Get methods for FieldName + vtkSetStringMacro(FieldName); + vtkGetStringMacro(FieldName); + +protected: + /// Constructor + vtkExtractFieldFilter(); + + /// Destructor + virtual ~vtkExtractFieldFilter(); + + /// A method which is called on filtering data + virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + + /// Copies a sub-tree defined by a Data Set Block + void CopySubTree(vtkDataObjectTreeIterator* theLoc, vtkMultiBlockDataSet* theOutput, vtkMultiBlockDataSet* theInput); + + /// Returns a list of strings with names of fields defined in the given Data Object + void GetListOfFields(vtkDataObject* theObject, std::list& theList) const; + + /// Returns True if the given Data Object has to be copied into output + bool IsToCopy(vtkDataObject* theObject) const; + +private: + /// Methods for copy of the filter: Not implemented + vtkExtractFieldFilter(const vtkExtractFieldFilter&); // Not implemented + void operator=(const vtkExtractFieldFilter&); // Not implemented + + char* FieldName; +}; + +#endif