]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Fix for problem Bug NPAL14169 on comments from 2007-04-16 16:54.
authorenk <enk@opencascade.com>
Wed, 18 Apr 2007 09:49:39 +0000 (09:49 +0000)
committerenk <enk@opencascade.com>
Wed, 18 Apr 2007 09:49:39 +0000 (09:49 +0000)
src/CONVERTOR/VISU_CommonCellsFilter.cxx
src/CONVERTOR/VISU_MergeFilter.cxx

index fb040b8f089b93c48ae2aef99dbda4f2ac1c131b..6be2c3e2ebcc3c2bb7d28613e831c1ff33eb3238 100644 (file)
@@ -68,11 +68,11 @@ namespace
         aPointCellIds.clear();
         vtkCell*   aCell = inputUGrid->GetCell(idCell);
         vtkIdList* ptIds = aCell->GetPointIds();
-        int aMaxId = ptIds->GetNumberOfIds();
         int nbPointsInCell = ptIds->GetNumberOfIds();
         bool aGoodCell = true;
         for(int i=0;i<nbPointsInCell;i++){
-          TSortedArray::iterator aResult = find(aSortedPointIds.begin(),aSortedPointIds.end(),ptIds->GetId(i));
+          int aSearchingId = ptIds->GetId(i);
+          TSortedArray::iterator aResult = find(aSortedPointIds.begin(),aSortedPointIds.end(),aSearchingId);
           if(aResult == aSortedPointIds.end()){
             aGoodCell = false;
             break;
index ec2d61f3dae4e60b28e30325df229ac610ae0ca3..138db50470e0d85ae87dbdba4cc60bf4b8718688 100644 (file)
@@ -511,23 +511,20 @@ namespace
         aPointCellIds.clear();
         vtkCell*   aCell = inputUGrid->GetCell(idCell);
         vtkIdList* ptIds = aCell->GetPointIds();
-        int aMaxId = ptIds->GetNumberOfIds();
-        int* aPointer = ptIds->GetPointer(0);
-        int* anEndPointer = ptIds->GetPointer(aMaxId + 1);
-        TSortedArray aSortedArray(aPointer, anEndPointer);
-        std::sort(aSortedArray.begin(), aSortedArray.end());
-
-        int aMaxLength = std::max(aSortedArray.size(), aSortedPointIds.size());
-        TSortedArray anIntersectionArray(aMaxLength);
-        TSortedArray::iterator anArrayIter = anIntersectionArray.begin();
-        anArrayIter = std::set_intersection(aSortedArray.begin(),
-                                            aSortedArray.end(),
-                                            aSortedPointIds.begin(),
-                                            aSortedPointIds.end(),
-                                            anArrayIter);
-        anIntersectionArray.erase(anArrayIter, anIntersectionArray.end());
-        if(anIntersectionArray.size() == aSortedArray.size())
+        int nbPointsInCell = ptIds->GetNumberOfIds();
+        bool aGoodCell = true;
+        for(int i=0;i<nbPointsInCell;i++){
+          int aSearchingId = ptIds->GetId(i);
+          TSortedArray::iterator aResult = find(aSortedPointIds.begin(),aSortedPointIds.end(),aSearchingId);
+          if(aResult == aSortedPointIds.end()){
+            aGoodCell = false;
+            break;
+          }
+        }
+        if(aGoodCell)
           aOutputCellIds.push_back(idCell);
+        else
+          continue;
       }
 
       outputSortedArray.swap(aOutputCellIds);
@@ -605,11 +602,19 @@ void VISU_MergeFilter::Execute()
   int nbPointsInGeometr = anInput->GetNumberOfPoints();
   vtkCellData *aCellData = anInput->GetCellData();
   
+  vtkDataArray* aScalarsOnCellsArray = NULL;
+  if(aInputScalars->GetCellData())
+    aScalarsOnCellsArray = aInputScalars->GetCellData()->GetArray("VISU_FIELD");
+  vtkDataArray* aScalarsOnPointsArray = NULL;
+  if(aInputScalars->GetPointData())
+    aScalarsOnPointsArray = aInputScalars->GetPointData()->GetArray("VISU_FIELD");
+  
   vtkDataArray *aPointMapper = aPointData->GetArray("VISU_POINTS_MAPPER");
   vtkIntArray *aGeometryPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
   vtkDataArray *aCellMapper = aCellData->GetArray("VISU_CELLS_MAPPER");
   vtkIntArray *aGeometryCellMapper = dynamic_cast<vtkIntArray*>(aCellMapper);
-  if(aGeometryCellMapper && (nbPointsInScalars == nbPointsInGeometr)){
+
+  if(aGeometryCellMapper && aScalarsOnCellsArray && (nbPointsInScalars == nbPointsInGeometr)){
     vtkIntArray* aDataCellMapper = NULL;
     VISU::TFieldListIterator anIter(this->FieldList);
     for(anIter.Begin(); !anIter.End() ; anIter.Next()){
@@ -621,10 +626,13 @@ void VISU_MergeFilter::Execute()
        break;
       }
     }
-
+    
     bool anIsDifferent = aDataCellMapper &&
       aDataCellMapper->GetNumberOfTuples() != aGeometryCellMapper->GetNumberOfTuples();
-    if(anIsDifferent || IsMergingInputs()){
+
+    if(anIsDifferent || IsMergingInputs() ){
+      // The situation for merging CELLS from anInput as Geometry
+      // and scalars on cell data
       TSortedArray aGeometryCellArray;
       GetSortedArray(aGeometryCellMapper, aGeometryCellArray);
     
@@ -688,7 +696,83 @@ void VISU_MergeFilter::Execute()
        return;
       }
     }
+  } else if (aGeometryCellMapper && aScalarsOnPointsArray && (nbPointsInScalars == nbPointsInGeometr)) {
+    // The situation for merging CELLS from anInput as Geometry
+    // and scalars on point data
+    vtkPointData* aInputScalarsPointData = aInputScalars->GetPointData();
+    
+    vtkIntArray* aDataPointMapper = NULL;
+    VISU::TFieldListIterator anIter(this->FieldList);
+    for(anIter.Begin(); !anIter.End() ; anIter.Next()){
+      const char* aFieldName = anIter.Get()->GetName();
+      if(strcmp(aFieldName, "VISU_POINTS_MAPPER") == 0){
+       vtkDataArray *aPointMapper = aInputScalarsPointData->GetArray(aFieldName);
+       aDataPointMapper = dynamic_cast<vtkIntArray*>(aPointMapper);
+       break;
+      }
+    }
+
+    if(aDataPointMapper){
+      TSortedArray aGeometryPointArray;
+      GetSortedArray(aGeometryPointMapper, aGeometryPointArray);
+      
+      TSortedArray aDataPointArray;
+      GetSortedArray(aDataPointMapper, aDataPointArray);
+      
+      {
+        TId2IdMap anObj2VTKGeometryPointsMap;
+        vtkIdType aNbCells = aDataPointMapper->GetNumberOfTuples();
+        for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+          vtkIdType anObjID = aDataPointMapper->GetValue(aCellId);
+          anObj2VTKGeometryPointsMap[anObjID] = aCellId;
+        }
+        
+        TId2IdMap anObj2VTKGeometryCellsMap;
+        aNbCells = aGeometryCellMapper->GetNumberOfTuples();
+        for(int aCellId = 0; aCellId < aNbCells; aCellId++){
+          vtkIdType anObjID = aGeometryCellMapper->GetValue(aCellId);
+          anObj2VTKGeometryCellsMap[anObjID] = aCellId;
+        }
+
+        // copy points to output
+        vtkUnstructuredGrid* aUnstructuredScalars = dynamic_cast<vtkUnstructuredGrid*>(aInputScalars);
+        if(aUnstructuredScalars)
+          anOutput->SetPoints(aUnstructuredScalars->GetPoints());
+        anOutput->GetPointData()->ShallowCopy(aInputScalars->GetPointData());
+        
+        // Calculate output cells
+        int nbCells=0;
+        TSortedArray aCellIdsForCopy_fromCellMapper;
+        GetSortedArray(aGeometryCellMapper, aCellIdsForCopy_fromCellMapper);
+        nbCells = aCellIdsForCopy_fromCellMapper.size();
+
+        TSortedArray aCellIdsForCopy;
+        for(int i=0;i<nbCells;i++)
+          aCellIdsForCopy.push_back(anObj2VTKGeometryCellsMap[aCellIdsForCopy_fromCellMapper[i]]);
+        
+        // copy cells to output
+        anOutput->Allocate(nbCells);
+        vtkIntArray* theOuputIDSArray = vtkIntArray::New();
+        theOuputIDSArray->SetName("VISU_CELLS_MAPPER");
+        theOuputIDSArray->SetNumberOfComponents(1);
+        theOuputIDSArray->SetNumberOfTuples(nbCells);
+        
+        if(nbCells>0)
+          CopyElementsToOutput(anInput,
+                               nbCells,
+                               aCellIdsForCopy,
+                               anObj2VTKGeometryPointsMap,
+                               theOuputIDSArray,
+                               anOutput);
+        theOuputIDSArray->Delete();
+        
+        return;
+      }
+    }
   } else if (aGeometryCellMapper && (nbPointsInScalars < nbPointsInGeometr)) {
+    // The situation for merging CELLS from anInput as Geometry
+    // and scalars on point data (there the number of points of point data less than
+    // number of points of Geometry)
 
     vtkPointData* aInputScalarsPointData = aInputScalars->GetPointData();
     
@@ -736,9 +820,9 @@ void VISU_MergeFilter::Execute()
       
       {
         TId2IdMap anObj2VTKGeometryMap;
-        vtkIdType aNbCells = aDataPointMapper/*aGeometryPointMapper*/->GetNumberOfTuples();
+        vtkIdType aNbCells = aDataPointMapper->GetNumberOfTuples();
         for(int aCellId = 0; aCellId < aNbCells; aCellId++){
-          vtkIdType anObjID = aDataPointMapper/*aGeometryPointMapper*/->GetValue(aCellId);
+          vtkIdType anObjID = aDataPointMapper->GetValue(aCellId);
           anObj2VTKGeometryMap[anObjID] = aCellId;
         }