]> SALOME platform Git repositories - modules/paravis.git/commitdiff
Salome HOME
Modification according to EDF requewst:
authorvsv <vsv@opencascade.com>
Thu, 19 Dec 2013 08:39:23 +0000 (08:39 +0000)
committervsv <vsv@opencascade.com>
Thu, 19 Dec 2013 08:39:23 +0000 (08:39 +0000)
1) List all fields
2) Remove empty blocks

src/Plugins/ExtraxtFieldFilter/ExtractFieldFilter.xml
src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.cxx
src/Plugins/ExtraxtFieldFilter/vtkExtractFieldFilter.h

index b32658349b14b7882b8481b07a436f814c5ed2ef..d7d850ebe5cac032fe1af1cb21d234f530e4840d 100755 (executable)
         </InputArrayDomain>
      </InputProperty>
      
-     <StringVectorProperty command="SetInputArrayToProcess"
-                            element_types="0 0 0 0 2"
-                            label="Field name"
-                            name="SelectInputScalars"
-                            number_of_elements="5">
-                            
-        <ArrayListDomain attribute_type="Scalars"
-                         name="array_list">
-          <RequiredProperties>
-            <Property function="Input"
-                      name="Input" />
-          </RequiredProperties>
-        </ArrayListDomain>
-        
-        <FieldDataDomain name="field_list">
-          <RequiredProperties>
-            <Property function="Input"
-                      name="Input" />
-          </RequiredProperties>
-        </FieldDataDomain>
-        
-        <Documentation>
-        This property lists the names of fields which can be used for extraction of mesh support.
-        </Documentation>
-      </StringVectorProperty>
+     <StringVectorProperty
+             name="FieldNameInfo"
+             command="GetFieldList"
+             information_only="1">
+             <StringArrayHelper/>
+     </StringVectorProperty>
       
+     <StringVectorProperty
+           name="FieldName"                                                                                                                                                                                                 command="SetField"
+           number_of_elements="1">                                                                                                                                                                                         <StringListDomain name="Input">
+             <RequiredProperties>
+               <Property name="FieldNameInfo" function="ArraySelection"/>
+             </RequiredProperties>
+          </StringListDomain>
+     </StringVectorProperty>
+     
    </SourceProxy>
  </ProxyGroup>
 </ServerManagerConfiguration>
index fcec14529bca78ad909da86c2cae5a284adec509..d707e3a303fe000ccd83cd4d0f82049cfe9facfa 100644 (file)
 #include <vtkPointData.h>
 #include <vtkCellData.h>
 #include <vtkDataArray.h>
+#include <vtkStringArray.h>
+#include <vtkCompositeDataToUnstructuredGridFilter.h>
+
 
 #include <string.h>
 
 using namespace std;
 
+
+
+bool isContainsName(const std::list<std::string>& aList, const std::string& theName)
+{
+       std::list<std::string>::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<std::string>& theSrc, std::list<std::string>& theDest)
+{
+       std::list<std::string>::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<int> toDelList;
+       for (i = 0; i < aInput->GetNumberOfBlocks(); i++) {
+               this->CopySubTree(i, aOutput, aInput, toDelList);
+       }
+       std::list<int>::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<std::string> aList;
        for (aIter->InitTraversal(); !aIter->IsDoneWithTraversal(); aIter->GoToNextItem()) {
-               this->CopySubTree(aIter, aOutput, aInput);
+               std::list<std::string> aSubList = this->GetListOfFields(aIter, aInput);
+               appendIfNotExists(aSubList, aList);
+       }
+       this->FieldList->SetNumberOfValues(aList.size());
+       std::list<std::string>::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<int>& 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<int> toDelList;
+               int i;
+               for (i = 0; i < aCInput->GetNumberOfBlocks(); i++) {
+                       this->CopySubTree(i, aCOutput, aCInput, toDelList);
+               }
+               std::list<int>::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<std::string> vtkExtractFieldFilter::GetListOfFields(vtkDataObjectTreeIterator* theLoc, vtkMultiBlockDataSet* theInput)
+{
+       std::list<std::string> aList;
+       vtkDataObject* aInputNode = theInput->GetDataSet(theLoc);
+       if (!aInputNode->IsA("vtkCompositeDataSet")) {
+               std::list<std::string> 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<std::string> aSubList = this->GetListOfFields(aCurNode);
+                       appendIfNotExists(aSubList, aList);
                }
                aIter->Delete();
        }
-
+       return aList;
 }
 
-
 //----------------------------------------------------------------------------
-void vtkExtractFieldFilter::GetListOfFields(vtkDataObject* theObject, std::list<std::string>& theList) const
+std::list<std::string> vtkExtractFieldFilter::GetListOfFields(vtkDataObject* theObject) const
 {
-       theList.clear();
+       std::list<std::string> 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<std::string> aList;
-       GetListOfFields(theObject, aList);
+       std::list<std::string> aList = this->GetListOfFields(theObject);
 
        std::list<std::string>::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);
 }
 
index 4a93ccbb2d3895ae31b4fb989d95f4b2eafaf477..80049fbab71ce90be9f06982e6f175b6eb512974 100644 (file)
@@ -25,7 +25,7 @@
 #include <string>
 
 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<int>& toDel);
 
        /// Returns a list of strings with names of fields defined in the given Data Object
-       void GetListOfFields(vtkDataObject* theObject, std::list<std::string>& theList) const;
+       std::list<std::string> GetListOfFields(vtkDataObject* theObject) const;
+       std::list<std::string> 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