]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Fix for Bug NPAL15278:
authorenk <enk@opencascade.com>
Wed, 2 May 2007 09:13:38 +0000 (09:13 +0000)
committerenk <enk@opencascade.com>
Wed, 2 May 2007 09:13:38 +0000 (09:13 +0000)
EDF 347 : ScalarMaponDeformedShape
On comments from 2007-04-30 10:32

src/CONVERTOR/VISU_MergeFilter.cxx

index 220888f16e9b470c2abaaa684e9e5eab518f1c2f..f7b384ffccbae121e45264523321a7bda974b0e6 100644 (file)
@@ -562,13 +562,13 @@ namespace
                        TId2IdMap& theOldId2NewIdPointsMap,
                        vtkUnstructuredGrid* theOutputUG)
   {
-    vtkIntArray* theOuputIDSArray = vtkIntArray::New();
-    theOuputIDSArray->SetName("VISU_CELLS_MAPPER");
+    vtkIntArray* theOutputIDSArray = vtkIntArray::New();
+    theOutputIDSArray->SetName("VISU_CELLS_MAPPER");
     // the [0] component is element object ID
     // the [1] component is entity type
-    theOuputIDSArray->SetNumberOfComponents(2);
-    theOuputIDSArray->SetNumberOfTuples(theNbElements);
-    int* aOuputIDSPtr = theOuputIDSArray->GetPointer(0);
+    theOutputIDSArray->SetNumberOfComponents(2);
+    theOutputIDSArray->SetNumberOfTuples(theNbElements);
+    int* aOutputIDSPtr = theOutputIDSArray->GetPointer(0);
     
     vtkIntArray* aInputCellsMapper =
       dynamic_cast<vtkIntArray*>(theInputUG->GetCellData()->GetArray("VISU_CELLS_MAPPER"));
@@ -589,17 +589,18 @@ namespace
       theOutputUG->InsertNextCell(theInputUG->GetCellType(aCellId),
                                   aNewPointIds);
 
-      *aOuputIDSPtr = aInputCellsMapperPointer[2*aCellId];
-      aOuputIDSPtr++;
-      *aOuputIDSPtr = aInputCellsMapperPointer[2*aCellId+1];
-      aOuputIDSPtr++;
+      *aOutputIDSPtr = aInputCellsMapperPointer[2*aCellId];
+      aOutputIDSPtr++;
+      *aOutputIDSPtr = aInputCellsMapperPointer[2*aCellId+1];
+      aOutputIDSPtr++;
       
       aNewPointIds->Delete();
     }
-    theOutputUG->GetCellData()->AddArray(theOuputIDSArray);
-    theOuputIDSArray->Delete();
+    theOutputUG->GetCellData()->AddArray(theOutputIDSArray);
+    theOutputIDSArray->Delete();
   }
 
+  inline
   void
   copyOneToOneComponent(vtkIntArray* input,
                         vtkIntArray* output)
@@ -623,6 +624,25 @@ namespace
       }
     }
   }
+
+  inline
+  bool
+  isTwoArraysSame(vtkIntArray* theFirst,
+                  vtkIntArray* theSecond)
+  {
+    int* theFirstPtr  = theFirst->GetPointer(0);
+    int* theSecondPtr = theSecond->GetPointer(0);
+    int nbTuples1     = theFirst->GetNumberOfTuples();
+    int nbTuples2     = theSecond->GetNumberOfTuples();
+    if(nbTuples1 != nbTuples2)
+      return false;
+    for(int i=0;i<nbTuples1;i++,theFirstPtr++,theSecondPtr++){
+      if(*theFirstPtr != *theSecondPtr)
+        return false;
+    }
+      
+    return true;
+  }
 }
 
 bool 
@@ -770,48 +790,21 @@ VISU_MergeFilter
   }
   
   if(aDataPointMapper){
-    TSortedArray aGeometryPointArray;
-    GetSortedArray(aGeometryPointMapper, aGeometryPointArray);
-    
-    TSortedArray aDataPointArray;
-    GetSortedArray(aDataPointMapper, aDataPointArray);
-    
+    bool isArraysEqual = isTwoArraysSame(aDataPointMapper,aGeometryPointMapper);
     {
       TId2IdMap anObj2VTKGeometryPointsMap;
-      vtkIdType aNbCells = aDataPointMapper->GetNumberOfTuples();
-      vtkIdType aNbComp = aDataPointMapper->GetNumberOfComponents();
-      int * aPtr = aDataPointMapper->GetPointer(0);
-      if(aNbComp==2){
-        for(int aCellId = 0; aCellId < aNbCells; aCellId++){
-          vtkIdType anObjID = *aPtr;
-          aPtr++;aPtr++;
-          anObj2VTKGeometryPointsMap[anObjID] = aCellId;
-        }
-      } else if (aNbComp == 1 ){
-        for(int aCellId = 0; aCellId < aNbCells; aCellId++){
-          vtkIdType anObjID = *aPtr;
-          aPtr++;
-          anObj2VTKGeometryPointsMap[anObjID] = aCellId;
-        }
+      vtkIdType aNbPoints = aDataPointMapper->GetNumberOfTuples();
+      if(isArraysEqual){
+        for(int aCellId = 0; aCellId < aNbPoints; aCellId++)
+          anObj2VTKGeometryPointsMap[aCellId] = aCellId;
+      } else {
+        // situation: the numbering of points are different in geometry and in scalars
+        cout << "------------------"<<endl;
+        cout << "Warning! Incorrect data are used in "<<__FILE__<<"["<<__LINE__<<"]"<<endl;
+        cout << "------------------"<<endl;
       }
 
-      TId2IdMap anObj2VTKGeometryCellsMap;
-      aNbCells = aGeometryCellMapper->GetNumberOfTuples();
-      aNbComp  = aGeometryCellMapper->GetNumberOfComponents();
-      int *aPtr2 = aGeometryCellMapper->GetPointer(0);
-      if(aNbComp == 1)
-        for(int aCellId = 0; aCellId < aNbCells; aCellId++){
-          vtkIdType anObjID = *aPtr2;
-          aPtr2++;
-          anObj2VTKGeometryCellsMap[anObjID] = aCellId;
-        }
-      else if (aNbComp == 2){
-        for(int aCellId = 0; aCellId < aNbCells; aCellId++){
-          vtkIdType anObjID = *aPtr2;
-          aPtr2++;aPtr2++;
-          anObj2VTKGeometryCellsMap[anObjID] = aCellId;
-        }
-      }
+      int aNbCells = aGeometryCellMapper->GetNumberOfTuples();
       
       // copy points to output
       vtkUnstructuredGrid* aUnstructuredScalars = dynamic_cast<vtkUnstructuredGrid*>(aInputScalars);