From 1789728cb48cd1b083fce101554a0d29e192b4a0 Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 26 Nov 2013 11:43:33 +0000 Subject: [PATCH] Extract Field filter for Paraview --- src/Plugins/CMakeLists.txt | 1 + src/Plugins/ExtraxtFieldFilter/CMakeLists.txt | 40 +++++ .../ExtraxtFieldFilter/ExtractFieldFilter.xml | 52 ++++++ .../ExtraxtFieldFilter/ExtractFieldGUI.xml | 8 + .../ExtraxtFieldFilter/pqExtractField.qrc | 5 + .../resources/extract_field.png | Bin 0 -> 1254 bytes .../vtkExtractFieldFilter.cxx | 167 ++++++++++++++++++ .../vtkExtractFieldFilter.h | 82 +++++++++ 8 files changed, 355 insertions(+) create mode 100755 src/Plugins/ExtraxtFieldFilter/CMakeLists.txt create mode 100755 src/Plugins/ExtraxtFieldFilter/ExtractFieldFilter.xml create mode 100644 src/Plugins/ExtraxtFieldFilter/ExtractFieldGUI.xml create mode 100644 src/Plugins/ExtraxtFieldFilter/pqExtractField.qrc create mode 100644 src/Plugins/ExtraxtFieldFilter/resources/extract_field.png create mode 100644 src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.cxx create mode 100644 src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.h 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 0000000000000000000000000000000000000000..a8a50e87bd6a9d886f8de2dfa8a58de4ae1c709e GIT binary patch literal 1254 zcmVI^(OhJ_5KnS#=iDXQWAkn2PG`jH*(4AnSD>o*tj2kgg z+~8JarHMOrWi&Q~DopSrSP+ELfxt{>I-PlM=6&3IkBd^;X{QxE$;-Pr@166z=bYa; zhp>sh_xrHc!t*?MsS#w;9vsKHZ|^@D_ANB`73Wb!nY7!?JNHi#wL97J~ zujw&ucfR}GA-Ms-bsS9Y+Y2Ir=Hepm-mSy;10-5wZQ~IEN=g{FgBqVh5S#UFwT*%F zrYtHH@)#d4p*ULDltn6K@tge`&7i#&_)8+pSc~@<*e-?u{Q7TAMMQ|WhabA1<7T&p zASMJcp&zNUVM4Ec^wP|Sk)}hjraK!V=!NlZ5AKctw-f?}LLO2O!Z1V-_~->a^dcV(+(4k3 zuw;;vB}}9qM@EhziR0Rh>(|OBj=w&97M(tQ8l(9v+Dl#det;kdHn1q|jiQW$gZdZ< zOc&R#UO}tb95h)uR4NsmIdjH!loFHs_Ts6^lh|E;6rMK%V+_J5LO%@eKVcL?8x7Z0 zD30b4hdo4LC}w76+)AY~2yjm!gCN*$jBx;9v{1m*$>jXMypgR0>Bs%O$s5V zN~Kcy`D4eXCU)-JrIadZtuy_8-wneMTInBOls@LoD=g*&?ZMWNV*4oR=JPV*z ztyb-N0059glqMlcf@r%CqDVw}5+Y4RE&&omU}nS22{ZTD+K#oh$;^#=?*M?QR;wF# za-~uMEsGFBI7H+MAyP!-5|IMYGV7QvGizp!EpyD)MwU5YYb`VLigN(?2lYiiH#E1R QdH?_b07*qoM6N<$g66q79RL6T literal 0 HcmV?d00001 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 -- 2.39.2