]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
To fix Bug NPAL15278 - "EDF 347 : ScalarMaponDeformedShape"
authorapo <apo@opencascade.com>
Tue, 27 Mar 2007 14:19:01 +0000 (14:19 +0000)
committerapo <apo@opencascade.com>
Tue, 27 Mar 2007 14:19:01 +0000 (14:19 +0000)
13 files changed:
src/CONVERTOR/VISU_ConvertorUtils.cxx
src/CONVERTOR/VISU_ConvertorUtils.hxx
src/CONVERTOR/VISU_Convertor_impl.cxx
src/CONVERTOR/VISU_MergeFilter.cxx
src/CONVERTOR/VISU_MergeFilter.hxx
src/PIPELINE/VISU_Extractor.cxx
src/PIPELINE/VISU_FieldTransform.cxx
src/PIPELINE/VISU_PipeLineUtils.hxx
src/PIPELINE/VISU_Plot3DPL.cxx
src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.cxx
src/PIPELINE/VISU_ScalarMapOnDeformedShapePL.hxx
src/PIPELINE/VISU_ScalarMapPL.cxx
src/PIPELINE/VISU_StreamLinesPL.cxx

index f406e5578ea86dca11bd867e90f3102b05d4742c..a926628fa340fe2d3652b4cd2a41a62bf8643f9e 100644 (file)
@@ -28,6 +28,9 @@
 
 #include <vtkUnstructuredGridWriter.h>
 #include <vtkTimerLog.h>
+#include <vtkPointData.h>
+#include <vtkCellData.h>
+#include <vtkDataSet.h>
 
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
@@ -50,6 +53,26 @@ namespace VISU
   }
 
 
+  bool 
+  IsDataOnPoints(vtkDataSet* theDataSet)
+  {
+    theDataSet->Update();
+    if(theDataSet->GetPointData()->GetArray("VISU_POINTS_MAPPER"))
+      return theDataSet->GetPointData()->GetNumberOfArrays() > 1;
+    return theDataSet->GetPointData()->GetNumberOfArrays() > 0;
+  }
+
+
+  bool 
+  IsDataOnCells(vtkDataSet* theDataSet)
+  {
+    theDataSet->Update();
+    if(theDataSet->GetCellData()->GetArray("VISU_CELLS_MAPPER"))
+      return theDataSet->GetCellData()->GetNumberOfArrays() > 1;
+    return theDataSet->GetCellData()->GetNumberOfArrays() > 0;
+  }
+
+
   TTimerLog
   ::TTimerLog(int theIsDebug,
              const std::string& theName):
index c44d5c4393a9d4cc247458377ffe9063540c4a58..2a86f810b01bf2277effaaf664016a779f0f299f 100644 (file)
 
 class vtkUnstructuredGrid;
 class vtkTimerLog;
+class vtkDataSet;
 
 namespace MED
 {
   class PrefixPrinter;
 }
 
-namespace VISU{
+namespace VISU
+{
 
   void 
   WriteToFile(vtkUnstructuredGrid* theDataSet, const std::string& theFileName);
 
+  bool 
+  IsDataOnCells(vtkDataSet* theDataSet);
+
+  bool 
+  IsDataOnPoints(vtkDataSet* theDataSet);
+
   class TTimerLog
   {
     int myIsDebug;
index d3f33022b98e494b61673a742eb89a8bc958df06..242e03f3918af633ea02d601179b7a9e46c44903 100644 (file)
@@ -149,7 +149,7 @@ namespace VISU
   ::GetVTKOutput()
   {
     GetFilter()->Update();
-    return GetFilter()->GetUnstructuredGridOutput();
+    return GetFilter()->GetOutput();
   }
 
 
@@ -411,8 +411,10 @@ namespace VISU
       aFilter->SetScalars(aDataSet);
       aFilter->SetVectors(aDataSet);
       aFilter->AddField("VISU_FIELD",aDataSet);
+      aFilter->AddField("VISU_CELLS_MAPPER",aDataSet);
+      aFilter->AddField("VISU_POINTS_MAPPER",aDataSet);
     }
-    return myFilter->GetUnstructuredGridOutput();
+    return myFilter->GetOutput();
   }
 
   vtkIdType
@@ -1209,6 +1211,20 @@ namespace
       aCellTypesArray->SetValue(anID,(unsigned char)theGeom);
     }
 
+    {
+      int aNbTuples = aNbCells;
+      vtkIntArray *aDataArray = vtkIntArray::New();
+      aDataArray->SetName("VISU_CELLS_MAPPER");
+      aDataArray->SetNumberOfComponents(1);
+      aDataArray->SetNumberOfTuples(aNbTuples);
+      for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
+       int anObjID = theSubMesh->GetElemObjID(aTupleId);
+       aDataArray->SetValue(aTupleId, anObjID);
+      }
+      theSource->GetCellData()->AddArray(aDataArray);
+      aDataArray->Delete();
+    }
+
     vtkIdType *pts = 0, npts = 0;
     VTKViewer_CellLocationsArray* aCellLocationsArray = VTKViewer_CellLocationsArray::New();
     aCellLocationsArray->SetNumberOfComponents(1);
@@ -1321,6 +1337,38 @@ namespace
   {
     int aNbTuples = theField->myDataSize/theField->myNbComp;
     std::string aFieldName = GenerateFieldName(theField,theValForTime);
+
+    {
+      PIDMapperFilter anIDMapperFilter = theValForTime->myIDMapperFilter;
+      VISU::TVTKOutput* anOutput = anIDMapperFilter->GetVTKOutput();
+      anOutput->Update();
+      {
+       int aNbTuples = anOutput->GetNumberOfCells();
+       vtkIntArray *aDataArray = vtkIntArray::New();
+       aDataArray->SetName("VISU_CELLS_MAPPER");
+       aDataArray->SetNumberOfComponents(1);
+       aDataArray->SetNumberOfTuples(aNbTuples);
+       for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
+         int anObjID = anIDMapperFilter->GetElemObjID(aTupleId);
+         aDataArray->SetValue(aTupleId, anObjID);
+       }
+       theSource->GetCellData()->AddArray(aDataArray);
+       aDataArray->Delete();
+      }
+      {
+       int aNbTuples = anOutput->GetNumberOfPoints();
+       vtkIntArray *aDataArray = vtkIntArray::New();
+       aDataArray->SetName("VISU_POINTS_MAPPER");
+       aDataArray->SetNumberOfComponents(1);
+       aDataArray->SetNumberOfTuples(aNbTuples);
+       for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
+         int anObjID = anIDMapperFilter->GetNodeObjID(aTupleId);
+         aDataArray->SetValue(aTupleId, anObjID);
+       }
+       theSource->GetPointData()->AddArray(aDataArray);
+       aDataArray->Delete();
+      }
+    }
     
     vtkDataSetAttributes* aDataSetAttributes;
     switch(theEntity){
@@ -1456,6 +1504,20 @@ namespace
       aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
     theSource->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
     
+    {
+      int aNbTuples = aNbCells;
+      vtkIntArray *aDataArray = vtkIntArray::New();
+      aDataArray->SetName("VISU_CELLS_MAPPER");
+      aDataArray->SetNumberOfComponents(1);
+      aDataArray->SetNumberOfTuples(aNbTuples);
+      for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
+       int anObjID = theSubProfile->GetElemObjID(aTupleId);
+       aDataArray->SetValue(aTupleId, anObjID);
+      }
+      theSource->GetCellData()->AddArray(aDataArray);
+      aDataArray->Delete();
+    }
+    
     aCellLocationsArray->Delete();
     aCellTypesArray->Delete();
     aConnectivity->Delete();
@@ -1899,7 +1961,7 @@ VISU_Convertor_impl
        //ENK: 23.11.2006
        const TVTKSource& aSource = aSubMesh->GetSource();
        aSource->SetPoints(GetPoints(aMesh));
-       GetCellsOnSubMesh(aSource,aMeshOnEntity,aSubMesh,aVGeom);
+       GetCellsOnSubMesh(aSource, aMeshOnEntity, aSubMesh, aVGeom);
        anAppendFilter->AddInput(aSource.GetPointer());
 
        aSubMesh->myStartID = aCellID;
index 4cabc7fbe1bf39518abdc0076fb913eb5b901656..b294411af05a6dc2c29494a87f258566c4d297f4 100644 (file)
 #include <vtkStructuredPoints.h>
 #include <vtkUnstructuredGrid.h>
 
+#include <vtkIdList.h>
+#include <vtkCell.h>
+
+#include <algorithm>
+#include <vector>
+#include <map>
+
 namespace VISU
 {
 
@@ -231,163 +238,330 @@ void VISU_MergeFilter::AddField(const char* name, vtkDataSet* input)
   this->FieldList->Add(name, input);
 }
 
-void VISU_MergeFilter::Execute()
+namespace
 {
-  vtkIdType numPts, numScalars=0, numVectors=0, numNormals=0, numTCoords=0;
-  vtkIdType numTensors=0;
-  vtkIdType numCells, numCellScalars=0, numCellVectors=0, numCellNormals=0;
-  vtkIdType numCellTCoords=0, numCellTensors=0;
-  vtkPointData *pd;
-  vtkDataArray *scalars = NULL;
-  vtkDataArray *vectors = NULL;
-  vtkDataArray *normals = NULL;
-  vtkDataArray *tcoords = NULL;
-  vtkDataArray *tensors = NULL;
-  vtkCellData *cd;
-  vtkDataArray *cellScalars = NULL;
-  vtkDataArray *cellVectors = NULL;
-  vtkDataArray *cellNormals = NULL;
-  vtkDataArray *cellTCoords = NULL;
-  vtkDataArray *cellTensors = NULL;
-  vtkDataSet *output = this->GetOutput();
-  vtkPointData *outputPD = output->GetPointData();
-  vtkCellData *outputCD = output->GetCellData();
-  
-  vtkDebugMacro(<<"Merging data!");
+  typedef std::vector<int> TSortedArray;
 
-  // geometry needs to be copied
-  output->CopyStructure(this->GetInput());
-  if ( (numPts = this->GetInput()->GetNumberOfPoints()) < 1 )
-    {
-    vtkWarningMacro(<<"Nothing to merge!");
-    }
-  numCells = this->GetInput()->GetNumberOfCells();
-  
-  if ( this->GetScalars() ) 
-    {
-    pd = this->GetScalars()->GetPointData();
-    scalars = pd->GetScalars();
-    if ( scalars != NULL )
-      {
-      numScalars = scalars->GetNumberOfTuples();
-      }
-    cd = this->GetScalars()->GetCellData();
-    cellScalars = cd->GetScalars();
-    if ( cellScalars != NULL )
-      {
-      numCellScalars = cellScalars->GetNumberOfTuples();
-      }
-    }
+  inline
+  void
+  GetSortedArray(vtkIntArray *theArray, TSortedArray& theSortedArray)
+  {
+    int aMaxId = theArray->GetMaxId();
+    int* aPointer = theArray->GetPointer(0);
+    int* anEndPointer = theArray->GetPointer(aMaxId + 1);
+    TSortedArray aSortedArray(aPointer, anEndPointer);
+    std::sort(aSortedArray.begin(), aSortedArray.end());
+    theSortedArray.swap(aSortedArray);
+  }
 
-  if ( this->GetVectors() ) 
-    {
-    pd = this->GetVectors()->GetPointData();
-    vectors = pd->GetVectors();
-    if ( vectors != NULL )
-      {
-      numVectors= vectors->GetNumberOfTuples();
-      }
-    cd = this->GetVectors()->GetCellData();
-    cellVectors = cd->GetVectors();
-    if ( cellVectors != NULL )
-      {
-      numCellVectors = cellVectors->GetNumberOfTuples();
-      }
-    }
+  typedef std::map<int,int> TId2IdMap;
 
-  if ( this->GetNormals() ) 
-    {
-    pd = this->GetNormals()->GetPointData();
-    normals = pd->GetNormals();
-    if ( normals != NULL )
-      {
-      numNormals= normals->GetNumberOfTuples();
-      }
-    cd = this->GetNormals()->GetCellData();
-    cellNormals = cd->GetNormals();
-    if ( cellNormals != NULL )
-      {
-      numCellNormals = cellNormals->GetNumberOfTuples();
+  template <class IT, class OT>
+  void DeepCopyArrayOfDifferentType(IT *theInputPtr, OT *theOutputPtr,
+                                   const TSortedArray& theIntersection,
+                                   const TId2IdMap& theObj2VTKMap,
+                                   vtkIdType theNbComp)
+  {
+    vtkIdType aNbIds = theIntersection.size();
+    for(vtkIdType aTargetTupleId = 0; aTargetTupleId < aNbIds; aTargetTupleId++){
+      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!");
+    }
+  }
+
+  typedef vtkDataArray* (vtkDataSetAttributes::* TGetAttribute)();
+  typedef int (vtkDataSetAttributes::* TSetAttribute)(vtkDataArray*);
+
+  void
+  DeepCopyArray(vtkDataArray* theDataArray,
+               vtkDataSetAttributes* theOutput, TSetAttribute theSetAttribute,
+               const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+  {
+    if(theDataArray){
+      vtkIdType aNbTuples = theDataArray->GetNumberOfTuples();
+      vtkIdType aNbComp = theDataArray->GetNumberOfComponents();
+
+      vtkDataArray *aDataArray = vtkDataArray::CreateDataArray(theDataArray->GetDataType());
+      aDataArray->SetNumberOfTuples(aNbTuples);
+      aDataArray->SetNumberOfComponents(aNbComp);
+      void *anInputPtr = theDataArray->GetVoidPointer(0);
+
+      switch(theDataArray->GetDataType()){
+       vtkTemplateMacro5(DeepCopySwitchOnOutput, (VTK_TT*)anInputPtr, aDataArray,
+                         theIntersection, theObj2VTKMap,
+                         aNbComp);
+      default:
+        vtkGenericWarningMacro(<<"Unsupported data type!");
       }
+
+      (theOutput->*theSetAttribute)(aDataArray);
+      aDataArray->Delete();
     }
+  }
 
-  if ( this->GetTCoords() ) 
-    {
-    pd = this->GetTCoords()->GetPointData();
-    tcoords = pd->GetTCoords();
-    if ( tcoords != NULL )
-      {
-      numTCoords= tcoords->GetNumberOfTuples();
-      }
-    cd = this->GetTCoords()->GetCellData();
-    cellTCoords = cd->GetTCoords();
-    if ( cellTCoords != NULL )
-      {
-      numCellTCoords = cellTCoords->GetNumberOfTuples();
+  void
+  DeepCopyAttribute(vtkDataSetAttributes* theInput, TGetAttribute theGetAttribute,
+                   vtkDataSetAttributes* theOutput, TSetAttribute theSetAttribute,
+                   const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+  {
+    DeepCopyArray((theInput->*theGetAttribute)(),
+                 theOutput, theSetAttribute,
+                 theIntersection, theObj2VTKMap);
+  }
+
+  inline
+  void
+  DeepCopyDataSetAttribute(vtkDataSet* theInput, TGetAttribute theGetAttribute,
+                          vtkDataSet* theOutput, TSetAttribute theSetAttribute,
+                          const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+  {
+    DeepCopyAttribute(theInput->GetPointData(), theGetAttribute,
+                     theOutput->GetPointData(), theSetAttribute,
+                     theIntersection, theObj2VTKMap);
+    DeepCopyAttribute(theInput->GetCellData(), theGetAttribute,
+                     theOutput->GetCellData(), theSetAttribute,
+                     theIntersection, theObj2VTKMap);
+  }
+
+  void
+  DeepCopyField(vtkDataSetAttributes* theInput, const char* theFieldName, vtkDataSetAttributes* theOutput, 
+               const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+  {
+    DeepCopyArray(theInput->GetArray(theFieldName), theOutput, &vtkDataSetAttributes::AddArray,
+                 theIntersection, theObj2VTKMap);
+  }
+
+  inline
+  void
+  DeepCopyDataSetField(vtkDataSet* theInput, const char* theFieldName, vtkDataSet* theOutput,
+                      const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+  {
+    DeepCopyField(theInput->GetPointData(), theFieldName, theOutput->GetPointData(), 
+                 theIntersection, theObj2VTKMap);
+    DeepCopyField(theInput->GetCellData(), theFieldName, theOutput->GetCellData(), 
+                 theIntersection, theObj2VTKMap);
+  }
+
+  inline
+  void
+  DeepCopyDataSetAttributes(VISU_MergeFilter *theFilter, 
+                           vtkDataSet *theFilterOutput, VISU::TFieldList* theFieldList,
+                           const TSortedArray& theIntersection, const TId2IdMap& theObj2VTKMap)
+  {
+    if(vtkDataSet* aDataSet = theFilter->GetScalars())
+      DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetScalars,
+                              theFilterOutput, &vtkDataSetAttributes::SetScalars,
+                              theIntersection, theObj2VTKMap);
+    
+    if(vtkDataSet* aDataSet = theFilter->GetVectors())
+      DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetVectors,
+                              theFilterOutput, &vtkDataSetAttributes::SetVectors,
+                              theIntersection, theObj2VTKMap);
+    
+    if(vtkDataSet* aDataSet = theFilter->GetNormals())
+      DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetNormals,
+                              theFilterOutput, &vtkDataSetAttributes::SetNormals,
+                              theIntersection, theObj2VTKMap);
+    
+    if(vtkDataSet* aDataSet = theFilter->GetTCoords())
+      DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTCoords,
+                              theFilterOutput, &vtkDataSetAttributes::SetTCoords,
+                              theIntersection, theObj2VTKMap);
+    
+    if(vtkDataSet* aDataSet = theFilter->GetTensors())
+      DeepCopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTensors,
+                              theFilterOutput, &vtkDataSetAttributes::SetTensors,
+                              theIntersection, theObj2VTKMap);
+
+    VISU::TFieldListIterator anIter(theFieldList);
+    for(anIter.Begin(); !anIter.End() ; anIter.Next()){
+      vtkDataSet *aDataSet = anIter.Get()->Ptr;
+      const char* aFieldName = anIter.Get()->GetName();
+      DeepCopyDataSetField(aDataSet, aFieldName, theFilterOutput, 
+                          theIntersection, theObj2VTKMap);
+    }
+  }
+}
+
+void VISU_MergeFilter::Execute()
+{
+  vtkUnstructuredGrid *anInput = this->GetInput();
+  vtkUnstructuredGrid *anOutput = this->GetOutput();
+
+  vtkCellData *aCellData = anInput->GetCellData();
+  vtkDataArray *aCellMapper = aCellData->GetArray("VISU_CELLS_MAPPER");
+  if(vtkIntArray *aGeometryCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper)){
+    TSortedArray aGeometryCellArray;
+    GetSortedArray(aGeometryCellMapper, aGeometryCellArray);
+    //cout<<aGeometryCellArray.size()<<endl;
+    
+    vtkIntArray* aDataCellMapper = NULL;
+    VISU::TFieldListIterator anIter(this->FieldList);
+    for(anIter.Begin(); !anIter.End() ; anIter.Next()){
+      vtkCellData *aCellData = anIter.Get()->Ptr->GetCellData();
+      const char* aFieldName = anIter.Get()->GetName();
+      if(strcmp(aFieldName, "VISU_CELLS_MAPPER") == 0){
+       vtkDataArray *aCellMapper = aCellData->GetArray(aFieldName);
+       aDataCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper);
+       break;
       }
     }
+    if(aDataCellMapper){
+      TSortedArray aDataCellArray;
+      GetSortedArray(aDataCellMapper, aDataCellArray);
+      //cout<<aDataCellArray.size()<<endl;
+      
+      int aMaxLength = std::max(aGeometryCellArray.size(), aDataCellArray.size());
+      TSortedArray anIntersectionArray(aMaxLength);
+      TSortedArray::iterator anArrayIter = anIntersectionArray.begin();
+      anArrayIter = std::set_intersection(aGeometryCellArray.begin(),
+                                         aGeometryCellArray.end(),
+                                         aDataCellArray.begin(),
+                                         aDataCellArray.end(),
+                                         anArrayIter);
+      
+      anIntersectionArray.erase(anArrayIter, anIntersectionArray.end());
+      
+      //cout<<anIntersectionArray.size()<<endl<<endl;
 
-  if ( this->GetTensors() ) 
-    {
-    pd = this->GetTensors()->GetPointData();
-    tensors = pd->GetTensors();
-    if ( tensors != NULL )
-      {
-      numTensors = tensors->GetNumberOfTuples();
-      }
-    cd = this->GetTensors()->GetCellData();
-    cellTensors = cd->GetTensors();
-    if ( cellTensors != NULL )
-      {
-      numCellTensors = cellTensors->GetNumberOfTuples();
+      bool anIsCompletelyCoincide = 
+       anIntersectionArray.size() == aGeometryCellArray.size() && 
+       anIntersectionArray.size() == aDataCellArray.size();
+
+      if(!anIsCompletelyCoincide){
+       {
+         TId2IdMap anObj2VTKGeometryMap;
+         vtkIdType aNbCells = aGeometryCellMapper->GetNumberOfTuples();
+         for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+           vtkIdType anObjID = aGeometryCellMapper->GetValue(aCellId);
+           anObj2VTKGeometryMap[anObjID] = aCellId;
+         }
+         
+         vtkIdType aNbTuples = anIntersectionArray.size();
+         anOutput->Allocate(aNbTuples);
+         vtkIdList *aCellIds = vtkIdList::New();
+         for(int aTupleId = 0; aTupleId < aNbTuples; aTupleId++){
+           vtkIdType anObjID = anIntersectionArray[aTupleId];
+           vtkIdType aCellId = anObj2VTKGeometryMap[anObjID];
+           vtkCell *aCell = anInput->GetCell(aCellId);
+           aCellIds->Reset();
+           vtkIdType aNbPointIds = aCell->PointIds->GetNumberOfIds();
+           for(vtkIdType aPointId = 0; aPointId < aNbPointIds; aPointId++)
+             aCellIds->InsertNextId(aCell->GetPointIds()->GetId(aPointId));
+           anOutput->InsertNextCell(anInput->GetCellType(aCellId), aCellIds);
+         }
+         aCellIds->Delete();
+         anOutput->SetPoints(anInput->GetPoints());
+       }
+       {
+         TId2IdMap anObj2VTKDataMap;
+         vtkIdType aNbCells = aDataCellMapper->GetNumberOfTuples();
+         for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+           vtkIdType anObjID = aDataCellMapper->GetValue(aCellId);
+           anObj2VTKDataMap[anObjID] = aCellId;
+         }
+       
+         DeepCopyDataSetAttributes(this, anOutput, this->FieldList,
+                                   anIntersectionArray, anObj2VTKDataMap);
+       }
+       return;
       }
     }
+  }
 
-  // merge data only if it is consistent
-  if ( numPts == numScalars )
-    {
-    outputPD->SetScalars(scalars);
-    }
-  if ( numCells == numCellScalars )
-    {
-    outputCD->SetScalars(cellScalars);
-    }
+  anOutput->CopyStructure(anInput);
+  this->BasicExecute(anOutput);
+}
 
-  if ( numPts == numVectors )
-    {
-    outputPD->SetVectors(vectors);
-    }
-  if ( numCells == numCellVectors )
-    {
-    outputCD->SetVectors(cellVectors);
-    }
-    
-  if ( numPts == numNormals )
-    {
-    outputPD->SetNormals(normals);
-    }
-  if ( numCells == numCellNormals )
-    {
-    outputCD->SetNormals(cellNormals);
+namespace
+{
+  inline
+  void
+  CopyAttribute(vtkDataSetAttributes* theInput, TGetAttribute theGetAttribute,
+               vtkDataSetAttributes* theOutput, TSetAttribute theSetAttribute,
+               vtkIdType theFixedNbTuples)
+  {
+    if(vtkDataArray *anAttribute = (theInput->*theGetAttribute)()){
+      vtkIdType aNbTuples = anAttribute->GetNumberOfTuples();
+      if(theFixedNbTuples == aNbTuples)
+       (theOutput->*theSetAttribute)(anAttribute);
     }
+  }
 
-  if ( numPts == numTCoords )
-    {
-    outputPD->SetTCoords(tcoords);
-    }
-  if ( numCells == numCellTCoords )
-    {
-    outputCD->SetTCoords(cellTCoords);
-    }
+  inline
+  void
+  CopyDataSetAttribute(vtkDataSet *theInput, TGetAttribute theGetAttribute,
+                      vtkDataSet *theOutput, TSetAttribute theSetAttribute,
+                      vtkIdType theNbPoints, vtkIdType theNbCells)
+  {
+    CopyAttribute(theInput->GetPointData(), theGetAttribute,
+                 theOutput->GetPointData(), theSetAttribute,
+                 theNbPoints);
+    CopyAttribute(theInput->GetCellData(), theGetAttribute,
+                 theOutput->GetCellData(), theSetAttribute,
+                 theNbCells);
+  }
+}
 
-  if ( numPts == numTensors )
-    {
-    outputPD->SetTensors(tensors);
-    }
-  if ( numCells == numCellTensors )
+void VISU_MergeFilter::BasicExecute(vtkDataSet *output)
+{
+  vtkIdType numPts, numCells;
+  vtkPointData *outputPD = output->GetPointData();
+  vtkCellData *outputCD = output->GetCellData();
+  
+  vtkDebugMacro(<<"Merging data!");
+
+  if ( (numPts = output->GetNumberOfPoints()) < 1 )
     {
-    outputCD->SetTensors(cellTensors);
+    vtkWarningMacro(<<"Nothing to merge!");
     }
+  numCells = output->GetNumberOfCells();
+  
+  // merge data only if it is consistent
+  if(vtkDataSet* aDataSet = this->GetScalars())
+    CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetScalars,
+                        output, &vtkDataSetAttributes::SetScalars,
+                        numPts, numCells);
+
+  if(vtkDataSet* aDataSet = this->GetVectors())
+    CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetVectors,
+                        output, &vtkDataSetAttributes::SetVectors,
+                        numPts, numCells);
+
+  if(vtkDataSet* aDataSet = this->GetNormals())
+    CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetNormals,
+                        output, &vtkDataSetAttributes::SetNormals,
+                        numPts, numCells);
+
+  if(vtkDataSet* aDataSet = this->GetTCoords())
+    CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTCoords,
+                        output, &vtkDataSetAttributes::SetTCoords,
+                        numPts, numCells);
+
+  if(vtkDataSet* aDataSet = this->GetTensors())
+    CopyDataSetAttribute(aDataSet, &vtkDataSetAttributes::GetTensors,
+                        output, &vtkDataSetAttributes::SetTensors,
+                        numPts, numCells);
 
   VISU::TFieldListIterator it(this->FieldList);
   vtkDataArray* da;
@@ -395,8 +569,8 @@ void VISU_MergeFilter::Execute()
   vtkIdType num;
   for(it.Begin(); !it.End() ; it.Next())
     {
-    pd = it.Get()->Ptr->GetPointData();
-    cd = it.Get()->Ptr->GetCellData();
+    vtkPointData *pd = it.Get()->Ptr->GetPointData();
+    vtkCellData *cd = it.Get()->Ptr->GetCellData();
     name = it.Get()->GetName();
     if ( (da=pd->GetArray(name)) )
       {
index 29c4b701534b5978f30d430e66b94864693a4b72..21d583e10f426ed99d06bac7be780cec860ade6d 100644 (file)
@@ -29,7 +29,9 @@
 #ifndef VISU_MergeFilter_H
 #define VISU_MergeFilter_H
 
-#include <vtkDataSetToDataSetFilter.h>
+#include <vtkUnstructuredGridToUnstructuredGridFilter.h>
+
+class vtkDataSet;
 
 namespace VISU
 {
@@ -39,16 +41,16 @@ namespace VISU
 // Following class was redefined in order to fix VTK bug 
 //  (see code for more details)
 
-class VISU_MergeFilter : public vtkDataSetToDataSetFilter
+class VISU_MergeFilter : public vtkUnstructuredGridToUnstructuredGridFilter
 {
 public:
   static VISU_MergeFilter *New();
-  vtkTypeMacro(VISU_MergeFilter,vtkDataSetToDataSetFilter);
+  vtkTypeMacro(VISU_MergeFilter,vtkUnstructuredGridToUnstructuredGridFilter);
 
   // Description:
   // Specify object from which to extract geometry information.
-  void SetGeometry(vtkDataSet *input) {this->SetInput(input);};
-  vtkDataSet *GetGeometry() {return this->GetInput();};
+  void SetGeometry(vtkUnstructuredGrid *input) {this->SetInput(input);};
+  vtkUnstructuredGrid *GetGeometry() {return this->GetInput();};
 
   // Description:
   // Specify object from which to extract scalar information.
@@ -86,6 +88,7 @@ protected:
   ~VISU_MergeFilter();
 
   // Usual data generation method
+  void BasicExecute(vtkDataSet *output);
   void Execute();
 
   VISU::TFieldList* FieldList;
index c33d071a614944277d1bba6625e3dfe06ce802ac..f8d0940d29b2df24770b86b37755371c22d61e2a 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "VISU_Extractor.hxx"
 #include "VISU_PipeLineUtils.hxx"
+#include "VISU_ConvertorUtils.hxx"
 
 #include <sstream>
 
@@ -91,13 +92,14 @@ execute(int theNbElems,
   }
 }
 
-void VISU_Extractor::Execute(){
+void VISU_Extractor::Execute()
+{
   vtkDataSet *input = this->GetInput(), *output = this->GetOutput();
   output->CopyStructure(input);
-  output->GetPointData()->CopyAllOff();
-  output->GetCellData()->CopyAllOff();
-  if(input->GetPointData()->GetNumberOfArrays()){
+  if(VISU::IsDataOnPoints(input)){
     output->GetPointData()->CopyVectorsOn();
+    output->GetPointData()->CopyScalarsOff();
+
     int aNbElems = input->GetNumberOfPoints();
     vtkPointData *inData = input->GetPointData(), *outData = output->GetPointData();
     if(!inData->GetAttribute(vtkDataSetAttributes::SCALARS))
@@ -108,6 +110,8 @@ void VISU_Extractor::Execute(){
     outData->AddArray(inData->GetArray("VISU_FIELD"));
   }else{
     output->GetCellData()->CopyVectorsOn();
+    output->GetCellData()->CopyScalarsOff();
+
     int aNbElems = input->GetNumberOfCells();
     vtkCellData *inData = input->GetCellData(), *outData = output->GetCellData();
     if(inData->GetAttribute(vtkDataSetAttributes::VECTORS))
@@ -117,4 +121,10 @@ void VISU_Extractor::Execute(){
     outData->PassData(inData);
     outData->AddArray(inData->GetArray("VISU_FIELD"));
   }
+
+  if(vtkDataArray *aDataArray = input->GetCellData()->GetArray("VISU_CELLS_MAPPER"))
+    output->GetCellData()->AddArray(aDataArray);
+
+  if(vtkDataArray *aDataArray = input->GetPointData()->GetArray("VISU_POINTS_MAPPER"))
+    output->GetPointData()->AddArray(aDataArray);
 }
index 598a36e229be4add9444a28dad63335e11206291..12a693102f57e06e40cd9093bc6755ad4a447475 100644 (file)
@@ -237,19 +237,18 @@ VISU_FieldTransform
   vtkDataSet *input = this->GetInput(), *output = this->GetOutput();
   output->CopyStructure(input);
   if(myFunction != &Ident || (myTransform && !myTransform->IsIdentity())){
-    output->GetPointData()->CopyAllOff();
-    output->GetCellData()->CopyAllOff();
+    output->GetPointData()->CopyScalarsOff();
+    output->GetPointData()->CopyVectorsOff();
+
+    output->GetCellData()->CopyScalarsOff();
+    output->GetCellData()->CopyVectorsOff();
 
     ExecScalars(myFunction,myScalarRange,input->GetNumberOfPoints(),input->GetPointData(),output->GetPointData());
     ExecVectors(myFunction,myTransform,myScalarRange,input->GetNumberOfPoints(),input->GetPointData(),output->GetPointData());
 
     ExecScalars(myFunction,myScalarRange,input->GetNumberOfCells(),input->GetCellData(),output->GetCellData());
     ExecVectors(myFunction,myTransform,myScalarRange,input->GetNumberOfCells(),input->GetCellData(),output->GetCellData());
-  }else{
-    output->GetPointData()->CopyAllOn();
-    output->GetCellData()->CopyAllOn();
-
-    output->GetPointData()->PassData(input->GetPointData());
-    output->GetCellData()->PassData(input->GetCellData());
   }
+  output->GetPointData()->PassData(input->GetPointData());
+  output->GetCellData()->PassData(input->GetCellData());
 }
index 57e6347bed04467dc1168ed46b3bbee13c00c7ed..7b87e3627bf6792b0f485d6da67ff82d59657025 100644 (file)
@@ -30,6 +30,7 @@
 #include "VISU_FieldTransform.hxx"
 #include "VISU_LookupTable.hxx"
 #include "VISU_Extractor.hxx"
+#include "VISU_ConvertorUtils.hxx"
 
 #include <vtkProperty.h>
 #include <vtkObjectFactory.h>
@@ -74,7 +75,7 @@ namespace VISU
                  vtkDataSet* theDataSet,
                  VISU_FieldTransform *theFieldTransform)
   {
-    if(theDataSet->GetCellData()->GetNumberOfArrays()){
+    if(VISU::IsDataOnCells(theDataSet)){
       theFilter->SetInput(theFieldTransform->GetUnstructuredGridOutput());
       theFilter->PassCellDataOn();
       theTItem->SetInput(theFilter->GetUnstructuredGridOutput());
@@ -89,7 +90,7 @@ namespace VISU
                vtkDataSet* theDataSet,
                VISU_FieldTransform *theFieldTransform)
   {
-    if(theDataSet->GetCellData()->GetNumberOfArrays()){
+    if(VISU::IsDataOnCells(theDataSet)){
       theFilter->SetInput(theFieldTransform->GetUnstructuredGridOutput());
       theFilter->VertexCellsOn();
       theTItem->SetInput(theFilter->GetOutput());
index e5de36c4356c48f243145fb98dc10021b95a2a2c..4d0ebf651fab0b1152743233f41dd1257523127f 100644 (file)
@@ -182,7 +182,7 @@ Update()
   }
   if ( !myIsContour ) // surface prs
   {
-    if(aPolyData->GetCellData()->GetNumberOfArrays()) {
+    if(VISU::IsDataOnCells(aPolyData)) {
       myCellDataToPointData->SetInput(aPolyData);
       myCellDataToPointData->PassCellDataOn();
       myWarpScalar->SetInput(myCellDataToPointData->GetPolyDataOutput());
@@ -191,7 +191,7 @@ Update()
   }
   else // contour prs
   {
-    if(aPolyData->GetCellData()->GetNumberOfArrays()) {
+    if(VISU::IsDataOnCells(aPolyData)) {
       myCellDataToPointData->SetInput(aPolyData);
       myCellDataToPointData->PassCellDataOn();
       myContourFilter->SetInput(myCellDataToPointData->GetOutput());
index 60c3bf5b598830cbe110fcd18c9792b35b01e1b5..1a0e3e4bba196f3aff49a66876fae4217e161135 100644 (file)
 
 #include "VISU_ScalarMapOnDeformedShapePL.hxx"
 #include "VISU_DeformedShapePL.hxx"
+#include "VISU_MergeFilter.hxx"
+
 #include "VISU_PipeLineUtils.hxx"
 #include "VTKViewer_TransformFilter.h"
 #include "VTKViewer_Transform.h"
 
 #include <vtkWarpVector.h>
-#include <vtkMergeFilter.h>
 #include <vtkUnstructuredGrid.h>
 #include <vtkCellDataToPointData.h>
 #include <vtkPointDataToCellData.h>
 
-#include <VISU_Convertor.hxx>
+#include "VISU_Convertor.hxx"
+#include "VISU_ConvertorUtils.hxx"
 
 vtkStandardNewMacro(VISU_ScalarMapOnDeformedShapePL)
 
@@ -52,7 +54,7 @@ VISU_ScalarMapOnDeformedShapePL
 ::VISU_ScalarMapOnDeformedShapePL()
 {
   myDeformVectors = vtkWarpVector::New();
-  myMergeFilter   = vtkMergeFilter::New();
+  myMergeFilter   = VISU_MergeFilter::New();
   myExtractorScalars = VISU_Extractor::New();
   myCellDataToPointData = vtkCellDataToPointData::New();
 }
@@ -119,8 +121,11 @@ VISU_ScalarMapOnDeformedShapePL
                        GetInput2(),myFieldTransform);
   
   // Sets geometry for merge filter
-  myMergeFilter->SetGeometry(myDeformVectors->GetOutput());
+  myMergeFilter->SetGeometry(myDeformVectors->GetUnstructuredGridOutput());
   myMergeFilter->SetScalars(myExtractorScalars->GetOutput());
+  myMergeFilter->AddField("VISU_CELLS_MAPPER", myExtractorScalars->GetOutput());
+  myMergeFilter->Update();
+
   // Sets data to mapper
   myMapper->SetInput(myMergeFilter->GetOutput());
 }
@@ -189,6 +194,8 @@ VISU_ScalarMapOnDeformedShapePL
   vtkUnstructuredGrid* aScalars = GetScalarsUnstructuredGrid();
   vtkCellData *aInCellData = GetInput()->GetCellData();
 
+  std::string aFileName = std::string(getenv("HOME"))+"/"+getenv("USER")+"-SetScalars.vtk";
+  VISU::WriteToFile(aScalars, aFileName);
   if(aScalars->GetPointData()->GetScalars())
     myExtractorScalars->SetInput(aScalars);
   else if(aScalars->GetCellData()->GetScalars() &&
index 3f6750b5e140756b2f6698a1ef208b65e5e65636..6e731ab735e155184aeb070f67a9c147302d5158 100644 (file)
@@ -29,7 +29,7 @@
 
 #include "VISU_PrsMergerPL.hxx"
 
-class vtkMergeFilter;
+class VISU_MergeFilter;
 class vtkWarpVector;
 class vtkUnstructuredGrid;
 class vtkCellDataToPointData;
@@ -89,7 +89,7 @@ public:
 protected:
   vtkFloatingPointType myScaleFactor;
   vtkWarpVector  *myDeformVectors;
-  vtkMergeFilter *myMergeFilter;
+  VISU_MergeFilter *myMergeFilter;
   vtkSmartPointer<vtkUnstructuredGrid> myScalars;
   VISU_Extractor* myExtractorScalars;
   vtkCellDataToPointData* myCellDataToPointData;
index 0c6b990328b57d3bff5dabf721b35ae914757bd5..0fa68d13e5fbb0be732175c76d324918ef08ed99 100644 (file)
@@ -95,10 +95,10 @@ void
 VISU_ScalarMapPL
 ::SetScalarMode(int theScalarMode)
 {
-  vtkDataSet *input = GetInput();
-  if (input){
-    if(input->GetPointData()->GetNumberOfArrays()){
-      vtkPointData *inData = input->GetPointData();
+  vtkDataSet *anInput = GetInput();
+  if(anInput){
+    if(VISU::IsDataOnPoints(anInput)){
+      vtkPointData *inData = anInput->GetPointData();
       if(!inData->GetAttribute(vtkDataSetAttributes::VECTORS)) {
        if (theScalarMode==0){
          return;
@@ -106,7 +106,7 @@ VISU_ScalarMapPL
       }
     }
     else {
-      vtkCellData *inData = input->GetCellData();
+      vtkCellData *inData = anInput->GetCellData();
       if(!inData->GetAttribute(vtkDataSetAttributes::VECTORS)){
        if (theScalarMode==0){
          return;
index 6cae0bd7e03ff8922ded8d0bc9ad6913c3cc86f7..c9cdc8eded1c9489320a474a4e98c0909ce7f7dc 100644 (file)
@@ -177,7 +177,7 @@ VISU_StreamLinesPL
   if((!isOnlyTry && isAccepted) || (isOnlyTry && isAccepted == 1)){
     mySource = theSource;
     myPercents = thePercents;
-    if(GetInput2()->GetCellData()->GetNumberOfArrays()){
+    if(VISU::IsDataOnCells(GetInput2())){
       myCenters->SetInput(aDataSet);
       myCenters->VertexCellsOn();
       aDataSet = myCenters->GetOutput();