Salome HOME
Add missing resource item
[modules/gui.git] / src / VTKViewer / VTKViewer_ExtractUnstructuredGrid.cxx
index 25ca840fbd9c749570e77d77842b7c321f72c6b4..e4522508135448aac0cdc978d8dcc38c9d0c35cf 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -32,6 +32,7 @@
 #include <vtkCellArray.h>
 #include <vtkIdList.h>
 #include <vtkCell.h>
+#include <vtkCellData.h>
 #include <vtkInformation.h>
 #include <vtkInformationVector.h>
 #include <vtkVersion.h>
@@ -95,7 +96,7 @@ vtkIdType VTKViewer_ExtractUnstructuredGrid::GetOutputId(int theInId) const{
 }
 
 
-inline void InsertCell(vtkUnstructuredGrid *theInput,
+inline int InsertCell(vtkUnstructuredGrid *theInput,
                        vtkCellArray *theConnectivity, 
                        vtkUnsignedCharArray* theCellTypesArray,
                        vtkIdTypeArray*& theFaces,
@@ -110,6 +111,7 @@ inline void InsertCell(vtkUnstructuredGrid *theInput,
   vtkCell *aCell = theInput->GetCell(theCellId);
   vtkIdList *aPntIds = aCell->GetPointIds();
   vtkIdType aNbIds = aPntIds->GetNumberOfIds();
+  vtkIdType aCellId = -1;
   theIdList->SetNumberOfIds(aNbIds);
   for(vtkIdType i = 0; i < aNbIds; i++){
     theIdList->SetId(i,aPntIds->GetId(i));
@@ -119,7 +121,7 @@ inline void InsertCell(vtkUnstructuredGrid *theInput,
   if (aCellType != VTK_POLYHEDRON)
     {
 #endif
-      theConnectivity->InsertNextCell(theIdList);
+      aCellId = theConnectivity->InsertNextCell(theIdList);
       if (theFaceLocations)
         theFaceLocations->InsertNextValue(-1);
 #if VTK_XVERSION > 50700
@@ -152,11 +154,12 @@ inline void InsertCell(vtkUnstructuredGrid *theInput,
     }
 #endif
 
-  theCellTypesArray->InsertNextValue(aCellType);
+  vtkIdType anID = theCellTypesArray->InsertNextValue(aCellType);
   if(theStoreMapping){
     theOut2InId.push_back(theCellId);
     theIn2OutId[theCellId] = theOutId;
   }
+  return aCellId;
 }
 
 inline void InsertPointCell(vtkCellArray *theConnectivity, 
@@ -178,15 +181,10 @@ inline void InsertPointCell(vtkCellArray *theConnectivity,
 }
 
 
-// int VTKViewer_ExtractUnstructuredGrid::RequestData(
-//   vtkInformation *vtkNotUsed(request),
-//   vtkInformationVector **inputVector,
-//   vtkInformationVector *outputVector)
-void VTKViewer_ExtractUnstructuredGrid::Execute()
+int VTKViewer_ExtractUnstructuredGrid::RequestData(vtkInformation *vtkNotUsed(request),
+                                                   vtkInformationVector **inputVector,
+                                                   vtkInformationVector *outputVector)
 {
-  /*
-  not ported yet to the new executive-based pipeline architecture.
-
   // get the info objects
   vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
   vtkInformation *outInfo = outputVector->GetInformationObject(0);
@@ -196,9 +194,9 @@ void VTKViewer_ExtractUnstructuredGrid::Execute()
     inInfo->Get(vtkDataObject::DATA_OBJECT()));
   vtkUnstructuredGrid *anOutput = vtkUnstructuredGrid::SafeDownCast(
     outInfo->Get(vtkDataObject::DATA_OBJECT()));
-  */
-  vtkUnstructuredGrid *anInput = this->GetInput();
-  vtkUnstructuredGrid *anOutput = this->GetOutput();
+
+  //vtkUnstructuredGrid *anInput = this->GetInput();
+  //vtkUnstructuredGrid *anOutput = this->GetOutput();
   
   myOut2InId.clear();  myIn2OutId.clear();
 
@@ -229,6 +227,7 @@ void VTKViewer_ExtractUnstructuredGrid::Execute()
       vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
       aCellTypesArray->SetNumberOfComponents(1);
       aCellTypesArray->Allocate(aNbElems*aCellTypesArray->GetNumberOfComponents());
+      anOutput->GetCellData()->CopyAllocate(anInput->GetCellData(),aNbElems,aNbElems/2);
 
       vtkIdTypeArray *newFaces = 0;
       vtkIdTypeArray *newFaceLocations = 0;
@@ -238,15 +237,17 @@ void VTKViewer_ExtractUnstructuredGrid::Execute()
         if(myChangeMode == eAdding){
           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
             if(myCellIds.find(aCellId) != myCellIds.end()){
-              InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
+              vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
                          myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+             anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
             }
           }
         }else{
           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
             if(myCellIds.find(aCellId) == myCellIds.end()){
-              InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
+              vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
                          myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+             anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
             }
           }
         }
@@ -255,16 +256,18 @@ void VTKViewer_ExtractUnstructuredGrid::Execute()
           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
             vtkIdType aType = anInput->GetCellType(aCellId);
             if(myCellTypes.find(aType) != myCellTypes.end()){
-              InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
+              vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
                          myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+             anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
             }
           }
         }else{
           for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
             vtkIdType aType = anInput->GetCellType(aCellId);
             if(myCellTypes.find(aType) == myCellTypes.end()){
-              InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
+              vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
                          myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+             anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
             }
           }
         }
@@ -274,8 +277,9 @@ void VTKViewer_ExtractUnstructuredGrid::Execute()
             vtkIdType aType = anInput->GetCellType(aCellId);
             if(myCellTypes.find(aType) != myCellTypes.end()){
               if(myCellIds.find(aCellId) != myCellIds.end()){
-                InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
+                vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
                            myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+               anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
               }
             }
           }
@@ -284,8 +288,9 @@ void VTKViewer_ExtractUnstructuredGrid::Execute()
             vtkIdType aType = anInput->GetCellType(aCellId);
             if(myCellTypes.find(aType) == myCellTypes.end()){
               if(myCellIds.find(aCellId) == myCellIds.end()){
-                InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
+                vtkIdType newId = InsertCell(anInput,aConnectivity,aCellTypesArray,newFaces,newFaceLocations,aCellId,anIdList,
                            myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+               anOutput->GetCellData()->CopyData(anInput->GetCellData(),aCellId,newId);
               }
             }
           }
@@ -310,6 +315,8 @@ void VTKViewer_ExtractUnstructuredGrid::Execute()
       aCellTypesArray->Delete();
       aConnectivity->Delete();
       anIdList->Delete();
+      if ( newFaceLocations ) newFaceLocations->Delete();
+      if ( newFaces ) newFaces->Delete();
     }
   }else{
     vtkIdList *anIdList = vtkIdList::New();
@@ -414,5 +421,5 @@ void VTKViewer_ExtractUnstructuredGrid::Execute()
       MESSAGE("Execute - myIn2OutId.size() = "<<myIn2OutId.size());
     }
   }*/
-//  return 1;
+  return 1;
 }