From bc32ef56df625d056d73c4cbe4493df8f63eaf7f Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 19 Dec 2013 08:39:23 +0000 Subject: [PATCH] Modification according to EDF requewst: 1) List all fields 2) Remove empty blocks --- .../ExtraxtFieldFilter/ExtractFieldFilter.xml | 40 ++--- .../vtkExtractFieldFilter.cxx | 151 +++++++++++++----- .../vtkExtractFieldFilter.h | 24 +-- 3 files changed, 141 insertions(+), 74 deletions(-) diff --git a/src/Plugins/ExtraxtFieldFilter/ExtractFieldFilter.xml b/src/Plugins/ExtraxtFieldFilter/ExtractFieldFilter.xml index b3265834..d7d850eb 100755 --- a/src/Plugins/ExtraxtFieldFilter/ExtractFieldFilter.xml +++ b/src/Plugins/ExtraxtFieldFilter/ExtractFieldFilter.xml @@ -21,32 +21,22 @@ - - - - - - - - - - - - - - - - This property lists the names of fields which can be used for extraction of mesh support. - - + + + + + + + + + + diff --git a/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.cxx b/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.cxx index fcec1452..d707e3a3 100644 --- a/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.cxx +++ b/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.cxx @@ -30,22 +30,56 @@ #include #include #include +#include +#include + #include using namespace std; + + +bool isContainsName(const std::list& aList, const std::string& theName) +{ + std::list::const_iterator aIt; + for (aIt = aList.begin(); aIt != aList.end(); aIt++) { + if ((*aIt).compare(theName) == 0) + return true; + } + return false; +} + + +void appendIfNotExists(const std::list& theSrc, std::list& theDest) +{ + std::list::const_iterator aIt; + for (aIt = theSrc.begin(); aIt != theSrc.end(); aIt++) { + if (!isContainsName(theDest, *aIt)) + theDest.push_back(*aIt); + } +} + + + + vtkStandardNewMacro(vtkExtractFieldFilter); + + vtkExtractFieldFilter::vtkExtractFieldFilter() :vtkMultiBlockDataSetAlgorithm() { - this->FieldName = NULL; + this->Field = NULL; + this->FieldList = vtkStringArray::New(); } vtkExtractFieldFilter::~vtkExtractFieldFilter() { + this->FieldList->Delete(); + if (this->Field) + delete [] this->Field; } //---------------------------------------------------------------------------- @@ -60,32 +94,87 @@ int vtkExtractFieldFilter::RequestData(vtkInformation* vtkNotUsed(request), aOutput->CopyStructure(aInput); // Copy selected blocks over to the output. + int i; + std::list toDelList; + for (i = 0; i < aInput->GetNumberOfBlocks(); i++) { + this->CopySubTree(i, aOutput, aInput, toDelList); + } + std::list::const_reverse_iterator aIt; + for (aIt = toDelList.rbegin(); aIt != toDelList.rend(); ++aIt) + aOutput->RemoveBlock(*aIt); + return 1; +} + +//---------------------------------------------------------------------------- +int vtkExtractFieldFilter::RequestInformation(vtkInformation* reqInfo, + vtkInformationVector **theInputVector, + vtkInformationVector *theOutputVector) +{ + // get the info objects + vtkMultiBlockDataSet* aInput = vtkMultiBlockDataSet::GetData(theInputVector[0], 0); + vtkMultiBlockDataSet* aOutput = vtkMultiBlockDataSet::GetData(theOutputVector, 0); + vtkDataObjectTreeIterator* aIter = aInput->NewTreeIterator(); aIter->VisitOnlyLeavesOff(); + int i = 0; + std::list aList; for (aIter->InitTraversal(); !aIter->IsDoneWithTraversal(); aIter->GoToNextItem()) { - this->CopySubTree(aIter, aOutput, aInput); + std::list aSubList = this->GetListOfFields(aIter, aInput); + appendIfNotExists(aSubList, aList); + } + this->FieldList->SetNumberOfValues(aList.size()); + std::list::const_iterator aIt; + i = 0; + for (aIt = aList.begin(); aIt != aList.end(); aIt++) { + this->FieldList->SetValue(i, *aIt); + i++; } - aIter->Delete(); - return 1; -} + return this->Superclass::RequestInformation(reqInfo, theInputVector, theOutputVector); +} //---------------------------------------------------------------------------- -void vtkExtractFieldFilter::CopySubTree(vtkDataObjectTreeIterator* theLoc, +void vtkExtractFieldFilter::CopySubTree(int theLoc, vtkMultiBlockDataSet* theOutput, - vtkMultiBlockDataSet* theInput) + vtkMultiBlockDataSet* theInput, + std::list& toDel) { - vtkDataObject* aInputNode = theInput->GetDataSet(theLoc); - if (!aInputNode->IsA("vtkCompositeDataSet")) { + vtkDataObject* aInputNode = theInput->GetBlock(theLoc); + if (aInputNode->IsA("vtkCompositeDataSet")) { + vtkMultiBlockDataSet* aCInput = vtkMultiBlockDataSet::SafeDownCast(aInputNode); + vtkMultiBlockDataSet* aCOutput = vtkMultiBlockDataSet::SafeDownCast(theOutput->GetBlock(theLoc)); + std::list toDelList; + int i; + for (i = 0; i < aCInput->GetNumberOfBlocks(); i++) { + this->CopySubTree(i, aCOutput, aCInput, toDelList); + } + std::list::const_reverse_iterator aIt; + for (aIt = toDelList.rbegin(); aIt != toDelList.rend(); ++aIt) + aCOutput->RemoveBlock(*aIt); + if (aCOutput->GetNumberOfBlocks() == 0) + toDel.push_back(theLoc); + } else { if (IsToCopy(aInputNode)) { vtkDataObject* aClone = aInputNode->NewInstance(); aClone->ShallowCopy(aInputNode); - theOutput->SetDataSet(theLoc, aClone); + theOutput->SetBlock(theLoc, aClone); aClone->Delete(); + } else { + toDel.push_back(theLoc); } + } +} + +//---------------------------------------------------------------------------- +std::list vtkExtractFieldFilter::GetListOfFields(vtkDataObjectTreeIterator* theLoc, vtkMultiBlockDataSet* theInput) +{ + std::list aList; + vtkDataObject* aInputNode = theInput->GetDataSet(theLoc); + if (!aInputNode->IsA("vtkCompositeDataSet")) { + std::list aSubList = this->GetListOfFields(aInputNode); + appendIfNotExists(aSubList, aList); } else { vtkCompositeDataSet* aCInput = vtkCompositeDataSet::SafeDownCast(aInputNode); - vtkCompositeDataSet* aCOutput = vtkCompositeDataSet::SafeDownCast(theOutput->GetDataSet(theLoc)); vtkCompositeDataIterator* aIter = aCInput->NewIterator(); vtkDataObjectTreeIterator* aTreeIter = vtkDataObjectTreeIterator::SafeDownCast(aIter); if (aTreeIter) { @@ -93,23 +182,18 @@ void vtkExtractFieldFilter::CopySubTree(vtkDataObjectTreeIterator* theLoc, } 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(); - } + std::list aSubList = this->GetListOfFields(aCurNode); + appendIfNotExists(aSubList, aList); } aIter->Delete(); } - + return aList; } - //---------------------------------------------------------------------------- -void vtkExtractFieldFilter::GetListOfFields(vtkDataObject* theObject, std::list& theList) const +std::list vtkExtractFieldFilter::GetListOfFields(vtkDataObject* theObject) const { - theList.clear(); + std::list aList; if (theObject->IsA("vtkDataSet")) { vtkDataSet* aDataSet = vtkDataSet::SafeDownCast(theObject); @@ -117,30 +201,29 @@ void vtkExtractFieldFilter::GetListOfFields(vtkDataObject* theObject, std::list< int aNbArrays = aPntData->GetNumberOfArrays(); for (int i = 0; i < aNbArrays; i++) { const char* aName = aPntData->GetArrayName(i); - theList.push_back(aName); + aList.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); + aList.push_back(aName); } } - + return aList; } //---------------------------------------------------------------------------- bool vtkExtractFieldFilter::IsToCopy(vtkDataObject* theObject) const { - if (this->FieldName == NULL) + if (this->Field == NULL) return true; - std::list aList; - GetListOfFields(theObject, aList); + std::list aList = this->GetListOfFields(theObject); std::list::const_iterator aIt; - std::string aTestStr = this->FieldName; + std::string aTestStr = this->Field; for (aIt = aList.begin(); aIt != aList.end(); ++aIt) if (aTestStr.compare(*aIt) == 0) return true; @@ -149,19 +232,11 @@ bool vtkExtractFieldFilter::IsToCopy(vtkDataObject* theObject) const } - -//---------------------------------------------------------------------------- -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; + os << indent << "Field name: " << this->Field << endl; + this->FieldList->PrintSelf(os, indent); } diff --git a/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.h b/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.h index 4a93ccbb..80049fba 100644 --- a/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.h +++ b/src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.h @@ -25,7 +25,7 @@ #include class vtkDataObjectTreeIterator; - +class vtkStringArray; /** * Implements a class of a filter which extract a support mesh of a data field. @@ -44,13 +44,8 @@ public: /// 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); + virtual vtkStringArray* GetFieldList() { return FieldList; } + vtkSetStringMacro(Field); protected: /// Constructor @@ -62,11 +57,17 @@ protected: /// A method which is called on filtering data virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + virtual int RequestInformation(vtkInformation *, vtkInformationVector **, vtkInformationVector *); + /// Copies a sub-tree defined by a Data Set Block - void CopySubTree(vtkDataObjectTreeIterator* theLoc, vtkMultiBlockDataSet* theOutput, vtkMultiBlockDataSet* theInput); + void CopySubTree(int theLoc, + vtkMultiBlockDataSet* theOutput, + vtkMultiBlockDataSet* theInput, + std::list& toDel); /// Returns a list of strings with names of fields defined in the given Data Object - void GetListOfFields(vtkDataObject* theObject, std::list& theList) const; + std::list GetListOfFields(vtkDataObject* theObject) const; + std::list GetListOfFields(vtkDataObjectTreeIterator* theLoc, vtkMultiBlockDataSet* theInput); /// Returns True if the given Data Object has to be copied into output bool IsToCopy(vtkDataObject* theObject) const; @@ -76,7 +77,8 @@ private: vtkExtractFieldFilter(const vtkExtractFieldFilter&); // Not implemented void operator=(const vtkExtractFieldFilter&); // Not implemented - char* FieldName; + char* Field; + vtkStringArray* FieldList; }; #endif -- 2.39.2