]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Bug NPAL15278 - EDF 347 : ScalarMaponDeformedShape
authorapo <apo@opencascade.com>
Tue, 3 Apr 2007 08:33:53 +0000 (08:33 +0000)
committerapo <apo@opencascade.com>
Tue, 3 Apr 2007 08:33:53 +0000 (08:33 +0000)
src/CONVERTOR/Makefile.in
src/CONVERTOR/VISU_AppendFilter.cxx [new file with mode: 0644]
src/CONVERTOR/VISU_AppendFilter.hxx [new file with mode: 0644]
src/CONVERTOR/VISU_Convertor_impl.cxx
src/CONVERTOR/VISU_MergeFilter.cxx
src/CONVERTOR/VISU_MergeFilter.hxx
src/PIPELINE/VISU_PrsMergerPL.cxx
src/PIPELINE/VISU_PrsMergerPL.hxx

index 4f10fe78dcc3a334862da3e55e991ba2a41dfc5d..19d33a5ad94c960e66437411c6ad1063529269eb 100644 (file)
@@ -39,6 +39,7 @@ EXPORT_HEADERS = \
        VISU_Convertor_impl.hxx  \
        VISU_ConvertorUtils.hxx  \
        VISU_MergeFilter.hxx \
+       VISU_AppendFilter.hxx \
        VISU_ExtractUnstructuredGrid.hxx
 
 # Libraries targets
@@ -51,6 +52,7 @@ LIB_SRC = \
        VISU_ConvertorUtils.cxx \
        VISU_ExtractUnstructuredGrid.cxx \
        VISU_MergeFilter.cxx \
+       VISU_AppendFilter.cxx \
        VISU_MedConvertor.cxx
 
 # Executables targets
diff --git a/src/CONVERTOR/VISU_AppendFilter.cxx b/src/CONVERTOR/VISU_AppendFilter.cxx
new file mode 100644 (file)
index 0000000..f5e9993
--- /dev/null
@@ -0,0 +1,305 @@
+//  SALOME OBJECT : kernel of SALOME component
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  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
+//
+//
+//
+//  File   : VISU_GeometryFilter.cxx
+//  Author : 
+//  Module : SALOME
+//  $Header$
+
+#include "VISU_AppendFilter.hxx"
+
+#include <vtkCell.h>
+#include <vtkCellData.h>
+#include <vtkDataSetAttributes.h>
+#include <vtkDataSetCollection.h>
+#include <vtkObjectFactory.h>
+#include <vtkPointData.h>
+#include <vtkUnstructuredGrid.h>
+
+#include <vtkPoints.h>
+#include <vtkIntArray.h>
+
+#include <algorithm>
+#include <vector>
+#include <map>
+
+vtkCxxRevisionMacro(VISU_AppendFilter, "$Revision$");
+vtkStandardNewMacro(VISU_AppendFilter);
+
+VISU_AppendFilter
+::VISU_AppendFilter():
+  myIsMergingInputs(false)
+{}
+
+VISU_AppendFilter
+::~VISU_AppendFilter()
+{}
+
+void
+VISU_AppendFilter
+::SetPoints(vtkPoints* thePoints)
+{
+  if(GetPoints() == thePoints)
+    return;
+
+  myPoints = thePoints;
+
+  Modified();
+}
+
+vtkPoints*
+VISU_AppendFilter
+::GetPoints()
+{
+  return myPoints.GetPointer();
+}
+
+void
+VISU_AppendFilter
+::SetMergingInputs(bool theIsMergingInputs)
+{
+  if(myIsMergingInputs == theIsMergingInputs)
+    return;
+
+  myIsMergingInputs = theIsMergingInputs;
+  Modified();
+}
+  
+bool
+VISU_AppendFilter
+::IsMergingInputs()
+{
+  return myIsMergingInputs;
+}
+  
+
+namespace
+{
+  typedef vtkIdType TCellId;
+  typedef vtkIdType TInputId;
+  typedef std::pair<TInputId, TCellId> TInputCellId;
+
+  typedef vtkIdType TObjectId;
+  typedef std::map<TObjectId, TInputCellId> TObject2InputIdMap;
+  
+  void
+  DoMergingInputs(vtkCellData *theCellData, 
+                 TInputId theInputId,
+                 TObject2InputIdMap& theResult)
+  {
+    if(vtkDataArray *aDataArray = theCellData->GetArray("VISU_CELLS_MAPPER")){
+      if(vtkIntArray *anIntArray = dynamic_cast<vtkIntArray*>(aDataArray)){
+       int aMaxId = anIntArray->GetMaxId();
+       int* aPointer = anIntArray->GetPointer(0);
+       int* anEndPointer = anIntArray->GetPointer(aMaxId + 1);
+       for(vtkIdType aCellId = 0; aPointer != anEndPointer; aPointer++, aCellId++){
+         TObjectId anObjectId = *aPointer;
+         TObject2InputIdMap::iterator anIter = theResult.find(anObjectId);
+         if(anIter != theResult.end())
+           continue;
+         TInputCellId anInputCellId(theInputId, aCellId);
+         theResult.insert(anIter, TObject2InputIdMap::value_type(anObjectId, anInputCellId));
+       }
+      }
+    }
+  }
+
+  struct TFillFieldList
+  {
+    vtkDataSetAttributes::FieldList myFieldList;
+    bool myIsFirstCellData;
+
+    TFillFieldList(vtkIdType theNbInputs):
+      myFieldList(theNbInputs),
+      myIsFirstCellData(true)
+    {}
+
+    void
+    operator()(TInputId theInputId, vtkDataSet* theDataSet)
+    {
+      vtkCellData *aCellData = theDataSet->GetCellData();
+      if(myIsFirstCellData){
+       myFieldList.InitializeFieldList(aCellData);
+       myIsFirstCellData = false;
+      }else{
+       myFieldList.IntersectFieldList(aCellData);
+      }
+    }
+    
+    virtual
+    vtkIdType
+    GetNbCells() const = 0;
+  };
+  
+  struct TCellCounter: TFillFieldList
+  {
+    vtkIdType myNbCells;
+    
+    TCellCounter(vtkIdType theNbInputs):
+      TFillFieldList(theNbInputs),
+      myNbCells(0)
+    {}
+
+    void
+    operator()(TInputId theInputId, vtkDataSet* theDataSet)
+    {
+      TFillFieldList::operator()(theInputId, theDataSet);
+      myNbCells += theDataSet->GetNumberOfCells();
+    }
+
+    virtual
+    vtkIdType
+    GetNbCells() const
+    {
+      return myNbCells;
+    }
+  };
+
+  struct TCellIdMerger: TFillFieldList
+  {
+    TObject2InputIdMap myObject2InputIdMap;
+
+    TCellIdMerger(vtkIdType theNbInputs):
+      TFillFieldList(theNbInputs)
+    {}
+
+    void
+    operator()(TInputId theInputId, vtkDataSet* theDataSet)
+    {
+      TFillFieldList::operator()(theInputId, theDataSet);
+      vtkCellData *aCellData = theDataSet->GetCellData();
+      DoMergingInputs(aCellData, theInputId, myObject2InputIdMap);
+    }
+
+    virtual
+    vtkIdType
+    GetNbCells() const
+    {
+      return myObject2InputIdMap.size();
+    }
+  };
+
+  template<class TFunctor>
+  void
+  ForEachInput(vtkDataObject** theInputs, vtkIdType theNbInputs, TFunctor& theFunctor)
+  {
+    for(vtkIdType anInputId = 0; anInputId < theNbInputs; anInputId++){
+      if(vtkDataSet *aDataSet = (vtkDataSet *)(theInputs[anInputId])){
+        if(aDataSet->GetNumberOfPoints() <= 0 && aDataSet->GetNumberOfCells() <= 0){
+          continue; //no input, just skip
+        }
+       theFunctor(anInputId, aDataSet);
+      }//if non-empty dataset
+    }//for all inputs
+  }
+}
+
+
+void
+VISU_AppendFilter
+::Execute()
+{
+  if(myPoints.GetPointer()){
+    if(myPoints->GetNumberOfPoints() < 1)
+      return;
+  
+    vtkUnstructuredGrid *anOutput = this->GetOutput(); 
+    if(IsMergingInputs()){
+      TCellIdMerger aFunctor(this->NumberOfInputs);
+      ForEachInput<TCellIdMerger>(this->Inputs, this->NumberOfInputs, aFunctor);
+
+      vtkDataSetAttributes::FieldList& aFieldList = aFunctor.myFieldList;
+      TObject2InputIdMap& anObject2InputIdMap = aFunctor.myObject2InputIdMap;
+      vtkIdType aNbCells = aFunctor.GetNbCells();
+      if(aNbCells < 1)
+       return;
+    
+      // Now can allocate memory
+      anOutput->Allocate(aNbCells); 
+      vtkCellData *anOutputCellData = anOutput->GetCellData();
+      anOutputCellData->CopyAllocate(aFieldList, aNbCells);
+      
+      // Append each input dataset together
+      // 1.points
+      anOutput->SetPoints(myPoints.GetPointer());
+      
+      // 2.cells
+      vtkIdList *anIdList = vtkIdList::New(); 
+      anIdList->Allocate(VTK_CELL_SIZE);
+      TObject2InputIdMap::const_iterator anIter = anObject2InputIdMap.begin();
+      TObject2InputIdMap::const_iterator anEndIter = anObject2InputIdMap.end();
+      for(; anIter != anEndIter; anIter++){
+       //TObjectId anObjectId = anIter->first;
+       const TInputCellId& anInputCellId = anIter->second;
+       TInputId anInputId = anInputCellId.first;
+       if(vtkDataSet *aDataSet = (vtkDataSet *)(this->Inputs[anInputId])){
+         TCellId aCellId = anInputCellId.second;
+         aDataSet->GetCellPoints(aCellId, anIdList);
+         
+         vtkIdType aCellType = aDataSet->GetCellType(aCellId);
+         vtkIdType aNewCellId = anOutput->InsertNextCell(aCellType, anIdList);
+         
+         vtkCellData *aCellData = aDataSet->GetCellData();
+         anOutputCellData->CopyData(aFieldList, aCellData, anInputId, aCellId, aNewCellId);
+       }
+      }
+      anIdList->Delete();
+    }else{
+      TCellCounter aFunctor(this->NumberOfInputs);
+      ForEachInput<TCellCounter>(this->Inputs, this->NumberOfInputs, aFunctor);
+
+      vtkDataSetAttributes::FieldList& aFieldList = aFunctor.myFieldList;
+      vtkIdType aNbCells = aFunctor.GetNbCells();
+      if(aNbCells < 1)
+       return;
+    
+      // Now can allocate memory
+      anOutput->Allocate(aNbCells); 
+      vtkCellData *anOutputCellData = anOutput->GetCellData();
+      anOutputCellData->CopyAllocate(aFieldList, aNbCells);
+      
+      // Append each input dataset together
+      // 1.points
+      anOutput->SetPoints(myPoints.GetPointer());
+      
+      // 2.cells
+      vtkIdList *anIdList = vtkIdList::New(); 
+      anIdList->Allocate(VTK_CELL_SIZE);
+      for(vtkIdType anInputId = 0; anInputId < this->NumberOfInputs; anInputId++) {
+       if(vtkDataSet *aDataSet = (vtkDataSet *)(this->Inputs[anInputId])){
+         vtkIdType aNbCells = aDataSet->GetNumberOfCells(); 
+         vtkCellData *aCellData = aDataSet->GetCellData();
+         // copy cell and cell data
+         for(vtkIdType aCellId = 0; aCellId < aNbCells; aCellId++){
+           aDataSet->GetCellPoints(aCellId, anIdList);
+           vtkIdType aCellType = aDataSet->GetCellType(aCellId);
+           vtkIdType aNewCellId = anOutput->InsertNextCell(aCellType, anIdList);
+           anOutputCellData->CopyData(aFieldList, aCellData, anInputId, aCellId, aNewCellId);
+         }
+       }
+      }
+      anIdList->Delete();
+    }
+  }else
+    Superclass::Execute();
+}
diff --git a/src/CONVERTOR/VISU_AppendFilter.hxx b/src/CONVERTOR/VISU_AppendFilter.hxx
new file mode 100644 (file)
index 0000000..91c7674
--- /dev/null
@@ -0,0 +1,71 @@
+// Copyright (C) 2005  CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA 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 VISU_APPENDFILTER_H
+#define VISU_APPENDFILTER_H
+
+#include <vtkAppendFilter.h>
+#include <vtkSmartPointer.h>
+
+class vtkPoints;
+
+/*! \brief This class used same as vtkAppendFilter. See documentation on VTK for more information.
+ */
+class VISU_AppendFilter : public vtkAppendFilter 
+{
+public:
+  /*! \fn static VISU_AppendFilter *New()
+   */
+  static VISU_AppendFilter *New();
+  
+  /*! \fn vtkTypeRevisionMacro(VISU_AppendFilter, vtkAppendFilter)
+   *  \brief VTK type revision macros.
+   */
+  vtkTypeRevisionMacro(VISU_AppendFilter, vtkAppendFilter);
+
+  void
+  SetPoints(vtkPoints* thePoints);
+
+  vtkPoints*
+  GetPoints();
+
+  void
+  SetMergingInputs(bool theIsMergingInputs);
+  
+  bool
+  IsMergingInputs();
+  
+protected:
+  /*! \fn VISU_AppendFilter();
+   * \brief Constructor
+   */
+  VISU_AppendFilter();
+  /*! \fn ~VISU_AppendFilter();
+   * \brief Destructor.
+   */
+  ~VISU_AppendFilter();
+  /*! \fn void Execute();
+   * \brief Filter culculation method.
+   */
+  virtual void Execute();
+
+  bool myIsMergingInputs;
+  vtkSmartPointer<vtkPoints> myPoints;
+};
+
+#endif
index d6ca21f7a76729a0c90a1a8a9dec8bdfe05882fa..22270f1dc00a76928db42519b846b0c83b40ced3 100644 (file)
@@ -591,25 +591,16 @@ namespace VISU
   TMeshOnEntityImpl
   ::GetElemVTKID(vtkIdType theID) const
   {
-    if(myElemObj2VTKID.empty())
-      return theID;
-    else{
-      TID2ID::const_iterator anIter = myElemObj2VTKID.find(theID);
-      if(anIter != myElemObj2VTKID.end())
-       return anIter->second;
-    }
-    return -1;
+    VISU::TVTKOutput* anOutput = GetFilter()->GetOutput();
+    return VISU::GetElemVTKID(anOutput, theID);
   }
 
   vtkIdType
   TMeshOnEntityImpl
   ::GetElemObjID(vtkIdType theID) const
   {
-    vtkIdType anInputID, aStartId, anInputDataSetID;
-    const TVTKAppendFilter& anAppendFilter = GetFilter();
-    anAppendFilter->GetCellInputID(theID,anInputID,aStartId,anInputDataSetID);
-    const PSubMeshImpl& aSubMesh = mySubMeshArr[anInputDataSetID];
-    return aSubMesh->GetElemObjID(anInputID);
+    VISU::TVTKOutput* anOutput = GetFilter()->GetOutput();
+    return VISU::GetElemObjID(anOutput, theID);
   }
 
   std::string 
@@ -1263,11 +1254,16 @@ namespace
     TSubMeshID& aMeshID = theFamily->myMeshID;
     aMeshID.resize(aNbCells);
 
+    vtkIntArray *aDataArray = vtkIntArray::New();
+    aDataArray->SetName("VISU_CELLS_MAPPER");
+    aDataArray->SetNumberOfComponents(1);
+    aDataArray->SetNumberOfTuples(aNbCells);
+
     VISU::TID2ID& anElemObj2VTKID = theFamily->myElemObj2VTKID;
 
     const VISU::TGeom2SubMesh& aGeom2SubMesh = theMeshOnEntity->myGeom2SubMesh;
     VISU::TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.begin();
-    for(vtkIdType i = 0, j = 0; anIter != aGeom2SubMesh.end(); anIter++){
+    for(vtkIdType aCellId = 0; anIter != aGeom2SubMesh.end(); anIter++){
       VISU::EGeometry aEGeom = anIter->first;
       vtkIdType aVGeom = VISUGeom2VTK(aEGeom);
 
@@ -1291,15 +1287,20 @@ namespace
              endl);
 
       VISU::TSubMeshID::const_iterator aSubMeshIDIter = aSubMeshID.begin();
-      for(; aSubMeshIDIter != aSubMeshID.end(); aSubMeshIDIter++, i++){
+      for(; aSubMeshIDIter != aSubMeshID.end(); aSubMeshIDIter++, aCellId++){
        vtkIdType anID = *aSubMeshIDIter;
-       PrintCells(i,aConnectivity,anArray[anID]);
-       aCellTypesArray->SetValue(j++,(unsigned char)aVGeom);
+       PrintCells(aCellId, aConnectivity, anArray[anID]);
+       aCellTypesArray->SetValue(aCellId, (unsigned char)aVGeom);
        vtkIdType anObjID = aSubMesh.GetElemObjID(anID);
-       anElemObj2VTKID[anObjID] = i;
-       aMeshID[i] = anObjID;
+       aDataArray->SetValue(aCellId, anObjID);
+       anElemObj2VTKID[anObjID] = aCellId;
+       aMeshID[aCellId] = anObjID;
       }
     }
+
+    theSource->GetCellData()->AddArray(aDataArray);
+    aDataArray->Delete();
+
     vtkIdType *pts = 0, npts = 0;
     VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
     aCellLocationsArray->SetNumberOfComponents(1);
@@ -1914,32 +1915,25 @@ VISU_Convertor_impl
       const TGeom2SubMesh& aGeom2SubMesh = aMeshOnEntity->myGeom2SubMesh;
       TGeom2SubMesh::const_iterator anIter = aGeom2SubMesh.begin();
 
-      TID2ID& anElemObj2VTKID = aMeshOnEntity->myElemObj2VTKID;
-      TSubMeshArr& aSubMeshArr = aMeshOnEntity->mySubMeshArr;
-      aSubMeshArr.resize(aGeom2SubMesh.size());
-
       for(vtkIdType anID = 0, aCellID = 0; anIter != aGeom2SubMesh.end(); anIter++, anID++){
        EGeometry aEGeom = anIter->first;
        vtkIdType aVGeom = VISUGeom2VTK(aEGeom);
        PSubMeshImpl aSubMesh = anIter->second;
+
        //ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
        aSubMesh->myIsStructured = aMesh->myIsStructured;
        aSubMesh->myType = aMesh->myType;
        aSubMesh->myGrilleStructure = aMesh->myGrilleStructure;
        aSubMesh->myObjID2StructureID = aMesh->myObjID2StructureID;
        //ENK: 23.11.2006
+
        const TVTKSource& aSource = aSubMesh->GetSource();
        aSource->SetPoints(GetPoints(aMesh));
-       GetCellsOnSubMesh(aSource, aMeshOnEntity, aSubMesh, aVGeom);
-       anAppendFilter->AddInput(aSource.GetPointer());
 
        aSubMesh->myStartID = aCellID;
-       vtkIdType aNbCells = aSource->GetNumberOfCells();
-       for(vtkIdType aCell = 0; aCell < aNbCells; aCell++, aCellID++){
-         vtkIdType anObjID = aSubMesh->GetElemObjID(aCell);
-         anElemObj2VTKID[anObjID] = aCellID;
-       }
-       aSubMeshArr[anID] = aSubMesh;
+       GetCellsOnSubMesh(aSource, aMeshOnEntity, aSubMesh, aVGeom);
+       anAppendFilter->AddInput(aSource.GetPointer());
+       aCellID += aSource->GetNumberOfCells();
       }
       aMeshOnEntity->myNamedPointCoords = aMesh->myNamedPointCoords;
       //ENK: 23.11.2006 - PAL13176 - EDF228 VISU : Enhancement of structured datas processing
index 3ede1c4d488dca337680f113a72079f48fb57998..cd324302b9dec23695ff3af0b458dbb2cf9229de 100644 (file)
@@ -158,7 +158,8 @@ vtkStandardNewMacro(VISU_MergeFilter);
 //------------------------------------------------------------------------------
 
 // Create object with no input or output.
-VISU_MergeFilter::VISU_MergeFilter()
+VISU_MergeFilter::VISU_MergeFilter():
+  myIsMergingInputs(false)
 {
   this->FieldList = new VISU::TFieldList;
 }
@@ -238,6 +239,12 @@ void VISU_MergeFilter::AddField(const char* name, vtkDataSet* input)
   this->FieldList->Add(name, input);
 }
 
+void VISU_MergeFilter::RemoveFields()
+{
+  delete this->FieldList;
+  this->FieldList = new VISU::TFieldList;
+}
+
 namespace
 {
   typedef std::vector<int> TSortedArray;
@@ -257,38 +264,23 @@ namespace
 
   typedef std::map<int,int> TId2IdMap;
 
-  template <class IT, class OT>
-  void DeepCopyArrayOfDifferentType(IT *theInputPtr, 
-                                   OT *theOutputPtr,
-                                   const TSortedArray& theIntersection,
-                                   const TId2IdMap& theObj2VTKMap,
-                                   vtkIdType theNbComp)
+  template <class TNumericType>
+  void DeepCopySwitchOnOutput(TNumericType *theInputPtr, 
+                             TNumericType *theOutputPtr,
+                             const TSortedArray& theIntersection,
+                             const TId2IdMap& theObj2VTKMap,
+                             vtkIdType theNbComp)
   {
     vtkIdType aNbIds = theIntersection.size();
     for(vtkIdType aTargetTupleId = 0; aTargetTupleId < aNbIds; aTargetTupleId++){
+      vtkIdType aTargetId = aTargetTupleId*theNbComp;
       vtkIdType anObjId = theIntersection[aTargetTupleId];
       TId2IdMap::const_iterator anIter = theObj2VTKMap.find(anObjId);
       vtkIdType aSourceTupleId = anIter->second;
-      for(vtkIdType aComp = 0; aComp < theNbComp; aComp++)
-       theOutputPtr[aTargetTupleId*theNbComp + aComp] = 
-         static_cast<OT>(theInputPtr[aSourceTupleId*theNbComp + aComp]);
-    }
-  }
-
-  template <class IT>
-  void DeepCopySwitchOnOutput(IT *theInputPtr, 
-                             vtkDataArray *theDataArray,
-                             const TSortedArray& theIntersection,
-                             const TId2IdMap& theObj2VTKMap, 
-                             vtkIdType theNbComp)
-  {
-    void *anOutputPtr = theDataArray->GetVoidPointer(0);       
-    switch(theDataArray->GetDataType()){
-      vtkTemplateMacro5(DeepCopyArrayOfDifferentType, theInputPtr, (VTK_TT*)anOutputPtr, 
-                       theIntersection, theObj2VTKMap,
-                       theNbComp);
-    default:
-      vtkGenericWarningMacro(<<"Unsupported data type!");
+      vtkIdType aSourceId = aSourceTupleId*theNbComp;
+      for(vtkIdType aComp = 0; aComp < theNbComp; aComp++){
+       theOutputPtr[aTargetId++] = theInputPtr[aSourceId++];
+      }
     }
   }
 
@@ -322,26 +314,31 @@ namespace
              theFixedNbTuples);
   }
 
-  void
+  vtkDataArray*
   DeepCopyArray(vtkDataArray* theDataArray,
                vtkDataSetAttributes* theOutput, 
                TSetAttribute theSetAttribute,
                const TSortedArray& theIntersection, 
                const TId2IdMap& theObj2VTKMap)
   {
+    vtkDataArray *aDataArray = NULL;
     if(theDataArray){
-      vtkIdType aNbTuples = theDataArray->GetNumberOfTuples();
+      void *anInputPtr = theDataArray->GetVoidPointer(0);
+      vtkIdType aNbTuples = theIntersection.size();
       vtkIdType aNbComp = theDataArray->GetNumberOfComponents();
 
-      vtkDataArray *aDataArray = vtkDataArray::CreateDataArray(theDataArray->GetDataType());
-      aDataArray->SetNumberOfTuples(aNbTuples);
+      aDataArray = vtkDataArray::CreateDataArray(theDataArray->GetDataType());
       aDataArray->SetNumberOfComponents(aNbComp);
-      void *anInputPtr = theDataArray->GetVoidPointer(0);
+      aDataArray->SetNumberOfTuples(aNbTuples);
+      void *anOutputPtr = aDataArray->GetVoidPointer(0);       
 
       switch(theDataArray->GetDataType()){
-       vtkTemplateMacro5(DeepCopySwitchOnOutput, (VTK_TT*)anInputPtr, aDataArray,
-                         theIntersection, theObj2VTKMap,
-                         aNbComp);
+       vtkTemplateMacro5(DeepCopySwitchOnOutput, 
+                         (VTK_TT*)anInputPtr, 
+                         (VTK_TT*)anOutputPtr, 
+                         theIntersection, 
+                         theObj2VTKMap,
+                         aNbComp);
       default:
         vtkGenericWarningMacro(<<"Unsupported data type!");
       }
@@ -349,6 +346,7 @@ namespace
       (theOutput->*theSetAttribute)(aDataArray);
       aDataArray->Delete();
     }
+    return aDataArray;
   }
 
   void
@@ -396,11 +394,14 @@ namespace
                const TSortedArray& theIntersection,
                const TId2IdMap& theObj2VTKMap)
   {
-    DeepCopyArray(theInput->GetArray(theFieldName), 
-                 theOutput, 
-                 &vtkDataSetAttributes::AddArray,
-                 theIntersection,
-                 theObj2VTKMap);
+    vtkDataArray* aDataArray = 
+      DeepCopyArray(theInput->GetArray(theFieldName), 
+                   theOutput, 
+                   &vtkFieldData::AddArray,
+                   theIntersection,
+                   theObj2VTKMap);
+    if(aDataArray)
+      aDataArray->SetName(theFieldName);
   }
 
   inline
@@ -493,6 +494,25 @@ namespace
   }
 }
 
+void
+VISU_MergeFilter
+::SetMergingInputs(bool theIsMergingInputs)
+{
+  if(myIsMergingInputs == theIsMergingInputs)
+    return;
+
+  myIsMergingInputs = theIsMergingInputs;
+  Modified();
+}
+  
+bool
+VISU_MergeFilter
+::IsMergingInputs()
+{
+  return myIsMergingInputs;
+}
+  
+
 void VISU_MergeFilter::Execute()
 {
   vtkUnstructuredGrid *anInput = this->GetInput();
@@ -515,14 +535,12 @@ void VISU_MergeFilter::Execute()
 
     bool anIsDifferent = aDataCellMapper &&
       aDataCellMapper->GetNumberOfTuples() != aGeometryCellMapper->GetNumberOfTuples();
-    if(anIsDifferent){
+    if(anIsDifferent || IsMergingInputs()){
       TSortedArray aGeometryCellArray;
       GetSortedArray(aGeometryCellMapper, aGeometryCellArray);
-      //cout<<aGeometryCellArray.size()<<endl;
     
       TSortedArray aDataCellArray;
       GetSortedArray(aDataCellMapper, aDataCellArray);
-      //cout<<aDataCellArray.size()<<endl;
       
       int aMaxLength = std::max(aGeometryCellArray.size(), aDataCellArray.size());
       TSortedArray anIntersectionArray(aMaxLength);
@@ -535,13 +553,11 @@ void VISU_MergeFilter::Execute()
       
       anIntersectionArray.erase(anArrayIter, anIntersectionArray.end());
       
-      //cout<<anIntersectionArray.size()<<endl<<endl;
-
       bool anIsCompletelyCoincide = 
        anIntersectionArray.size() == aGeometryCellArray.size() && 
        anIntersectionArray.size() == aDataCellArray.size();
 
-      if(!anIsCompletelyCoincide){
+      if(!anIsCompletelyCoincide || IsMergingInputs()){
        {
          TId2IdMap anObj2VTKGeometryMap;
          vtkIdType aNbCells = aGeometryCellMapper->GetNumberOfTuples();
@@ -574,8 +590,11 @@ void VISU_MergeFilter::Execute()
            anObj2VTKDataMap[anObjID] = aCellId;
          }
        
-         DeepCopyDataSetAttributes(this, anOutput, this->FieldList,
-                                   anIntersectionArray, anObj2VTKDataMap);
+         DeepCopyDataSetAttributes(this, 
+                                   anOutput, 
+                                   this->FieldList,
+                                   anIntersectionArray, 
+                                   anObj2VTKDataMap);
        }
        return;
       }
index 21d583e10f426ed99d06bac7be780cec860ade6d..3379f5d6388a1460e125d9afbfcb9c240966ddaf 100644 (file)
@@ -83,6 +83,19 @@ public:
   // of the field
   void AddField(const char* name, vtkDataSet* input);
 
+  // Description:
+  // Removes all previously added fields
+  void RemoveFields();
+
+  // Description:
+  // Defines whether to perform merging of data with the geometry according to
+  // the ids of the cell or not
+  void
+  SetMergingInputs(bool theIsMergingInputs);
+  
+  bool
+  IsMergingInputs();
+  
 protected:
   VISU_MergeFilter();
   ~VISU_MergeFilter();
@@ -92,6 +105,8 @@ protected:
   void Execute();
 
   VISU::TFieldList* FieldList;
+  bool myIsMergingInputs;
+
 private:
   VISU_MergeFilter(const VISU_MergeFilter&);  // Not implemented.
   void operator=(const VISU_MergeFilter&);  // Not implemented.
index 9b46c9fb7e6e4845ac60a198fec6e71652099eda..529dc3a2d659c2ce5d55747fdf342ed5f9271112 100644 (file)
@@ -31,6 +31,9 @@
 #include "VISU_IDMapper.hxx"
 #include "VTKViewer_AppendFilter.h"
 
+#include "VISU_AppendFilter.hxx"
+#include "VISU_MergeFilter.hxx"
+
 #include "VISU_PipeLineUtils.hxx"
 
 #include <vtkMapper.h>
@@ -61,19 +64,21 @@ using namespace std;
 vtkStandardNewMacro(VISU_PrsMergerPL);
 
 VISU_PrsMergerPL
-::VISU_PrsMergerPL()
+::VISU_PrsMergerPL():
+  myAppendFilter(VISU_AppendFilter::New()),
+  myMergeFilter(VISU_MergeFilter::New()),
+  myScalars(NULL)
 {
-  myScalars = NULL;
-  
-  //myMergeFilter->Delete();
-  myMeshGeometryList.clear();
+  myAppendFilter->SetMergingInputs(true);
+  myAppendFilter->Delete();
+
+  myMergeFilter->SetMergingInputs(true);
+  myMergeFilter->Delete();
 }
 
 VISU_PrsMergerPL
 ::~VISU_PrsMergerPL()
-{
-  myMeshGeometryList.clear();
-}
+{}
 
 void
 VISU_PrsMergerPL
@@ -297,107 +302,46 @@ VISU_PrsMergerPL
    * 2.1 Group Cell         - OK
    * 2.2 Group Point        - ERR (remove points groups)
    */
-
-
-
   if(MYDEBUG) MESSAGE("VISU_PrsMergerPL::Execute()");
 
-  if(myMeshGeometryList.size() != 0)
-    {
-      
-      typedef std::vector<int> TVec;
-      
-      vtkUnstructuredGrid* output = vtkUnstructuredGrid::New();
-      TVec aObjIds; // vector with object ids
-      vtkFloatArray* newArray = vtkFloatArray::New();
+  myAppendFilter->RemoveAllInputs();
+  if(!myMeshGeometryList.empty()){
+    const VISU::PIDMapper& aScalarsIDMapper = myScalars->GetIDMapper();
+    VISU::TVTKOutput* aScalarsOutput = aScalarsIDMapper->GetVTKOutput();
 
-      VISU_ScalarMapPL* aScalarMap = dynamic_cast<VISU_ScalarMapPL*>(this->GetScalars());
-      const VISU::PIDMapper& aScalarMapper  = myScalars->GetIDMapper();
+    // copy points to output from input scalar map
+    myAppendFilter->SetPoints(aScalarsOutput->GetPoints());
       
-      // copy points to output from input scalar map
-      output->SetPoints(aScalarMapper->GetVTKOutput()->GetPoints());
+    vtkIdType aNbGeoms = this->GetNbGeometry();
+    for(vtkIdType aGeomId = 0; aGeomId < aNbGeoms; aGeomId++){
+      VISU_PipeLine* aGeomPipeLine  = this->GetGeometry(aGeomId);
+      const VISU::PIDMapper& aGeomIDMapper = aGeomPipeLine->GetIDMapper();
+      VISU::TVTKOutput* aGeomOutput = aGeomIDMapper->GetVTKOutput();
+      vtkIdType aNbCells = aGeomOutput->GetNumberOfCells();
+      if(aNbCells > 0)
+       if(aGeomOutput->GetCell(0)->GetCellType() == VTK_VERTEX )
+         continue;
       
-      int newCellId;
-      int anbGeoms = this->GetNbGeometry();
-      for(int i=0; i < anbGeoms; i++) {
-       VISU_PipeLine* aCurrGeometry  = this->GetGeometry(i);
-       const VISU::PIDMapper& aGM  = aCurrGeometry->GetIDMapper();
-       int aNbCells = aGM->GetVTKOutput()->GetNumberOfCells();
-       if (aNbCells >0 )
-         if (aGM->GetVTKOutput()->GetCell(0)->GetCellType() == VTK_VERTEX )
-           continue;
-
-       vtkIdList* ptIds = vtkIdList::New(); 
-       ptIds->Allocate(VTK_CELL_SIZE);
-
-       for(int j=0; j < aNbCells; j++){
-
-         int anObjID = aGM->GetElemObjID(j);
-         aObjIds.push_back(anObjID);
-         
-         // copy cells to output from input geoms
-         aGM->GetVTKOutput()->GetCellPoints(j, ptIds);
-         newCellId = output->InsertNextCell(aGM->GetVTKOutput()->GetCellType(j),ptIds);
-       }
-       ptIds->Delete();
-      }      
-      
-
-      //copy array values
-      vtkDataArray* da;
-      if((da = aScalarMapper->GetVTKOutput()->GetPointData()->GetArray("VISU_FIELD"))){
-       output->GetPointData()->AddArray(da);
-       vtkDataArray* vc = aScalarMapper->GetVTKOutput()->GetPointData()->GetVectors();
-       if(vc)
-         output->GetPointData()->SetVectors(vc);
-      }
-      if((da = aScalarMapper->GetVTKOutput()->GetCellData()->GetArray("VISU_FIELD"))){
-       if(MYDEBUG){
-         MESSAGE("aScalarMapper NumberOfComponents="<<da->GetNumberOfComponents());
-         MESSAGE("aScalarMapper NumberOfTuples    ="<<da->GetNumberOfTuples());
-       }
-
-       newArray->SetNumberOfComponents(da->GetNumberOfComponents());
-       newArray->SetNumberOfTuples(aObjIds.size());
-       newArray->SetName("VISU_FIELD");
-       
-       TVec::const_iterator aIdsIter = aObjIds.begin();
-       for(int i=0; aIdsIter != aObjIds.end(); aIdsIter++){
-         int anObjID = *aIdsIter;
-         int aVTKID  = aScalarMapper->GetElemVTKID(anObjID);
-         newArray->SetTuple(i,da->GetTuple(aVTKID));
-         i++;
-       }
-       output->GetCellData()->AddArray(newArray);
-
-       // need in vectors array and scalars array
-       if(vtkDataArray* vc = aScalarMapper->GetVTKOutput()->GetCellData()->GetVectors()){
-         output->GetCellData()->SetVectors(newArray);
-       }
-       else if(vtkDataArray* sc = aScalarMapper->GetVTKOutput()->GetCellData()->GetScalars())
-         output->GetCellData()->SetScalars(newArray);
-      }
-      
-      if(MYDEBUG){
-       MESSAGE("output:");
-       output->Print(cout);
-      }
+      myAppendFilter->AddInput(aGeomOutput);
+    }
+    myAppendFilter->Update();
+    vtkUnstructuredGrid* aGeomDataSet = myAppendFilter->GetOutput();
+    myMergeFilter->SetGeometry(aGeomDataSet);
 
+    //copy array values
+    myMergeFilter->SetScalars(aScalarsOutput);
+    myMergeFilter->SetVectors(aScalarsOutput);
 
-      SetInput(output);
-      
-      output->Delete();
-      newArray->Delete();
-    }
-  else
-    {
-      if(myScalars != NULL)
-       {
-         VISU_ScalarMapPL* aScalarMap = dynamic_cast<VISU_ScalarMapPL*>(this->GetScalars());
-         VISU_PrsMergerPL* aPrsMerger = dynamic_cast<VISU_PrsMergerPL*>(this->GetScalars());
-         if(aScalarMap != NULL){
-           SetInput(aScalarMap->GetInput());
-         }
-       }
+    myMergeFilter->RemoveFields();
+    myMergeFilter->AddField("VISU_FIELD", aScalarsOutput);
+    myMergeFilter->AddField("VISU_CELLS_MAPPER", aScalarsOutput);
+    
+    myMergeFilter->Update();
+    SetInput(myMergeFilter->GetOutput());
+  }else{
+    if(myScalars != NULL){
+      if(VISU_ScalarMapPL* aScalarMap = dynamic_cast<VISU_ScalarMapPL*>(this->GetScalars()))
+       SetInput(aScalarMap->GetInput());
     }
+  }
 }
index e0cc94ff585677f0e2550600533c443b01aa3afa..a89567162cc30973db1458078a78c4035b43f384 100644 (file)
 
 #include "VISU_ScalarMapPL.hxx"
 
+class VISU_AppendFilter;
+class VISU_MergeFilter;
+
+
 class VISU_PrsMergerPL : public VISU_ScalarMapPL
 {
   typedef VISU_ScalarMapPL TSupperClass;
@@ -154,11 +158,12 @@ public:
   void SetInitialRange();
 
 protected:
-  TPipeLines     myMeshGeometryList;
+  TPipeLines myMeshGeometryList;
+  vtkSmartPointer<VISU_AppendFilter> myAppendFilter;
+  vtkSmartPointer<VISU_MergeFilter> myMergeFilter;
   
-  TPipeLine      myScalars;
-
   vtkFloatingPointType* myScalarRanges;
+  TPipeLine myScalars;
 
 private:
   
@@ -182,7 +187,6 @@ private:
 
   void
   Execute();
-
 };
 
 #endif