Salome HOME
Merge from V5_1_main 14/05/2010
[modules/visu.git] / src / PIPELINE / SALOME_ExtractGeometry.cxx
index 03cf524cb6eac36bec31a1eb56b99213ff7ebffa..b057ef83ffadbaf5959f296c7862eb42e2285962 100755 (executable)
@@ -1,4 +1,6 @@
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  Copyright (C) 2007-2010  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
 //
 //  This library is free software; you can redistribute it and/or
@@ -15,8 +17,8 @@
 //  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
-
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include "SALOME_ExtractGeometry.h"
 
 #include <vtkPointData.h>
 #include <vtkUnstructuredGrid.h>
 
+#include <vtkInformation.h>
+#include <vtkInformationVector.h>
+
 #include <vtkImplicitBoolean.h>
 #include <vtkImplicitFunctionCollection.h>
 
-using namespace std;
-
 #if defined __GNUC__
   #if __GNUC__ == 2
     #define __GNUC_2__
@@ -57,16 +60,6 @@ SALOME_ExtractGeometry
 {}
 
 
-//----------------------------------------------------------------------------
-unsigned long int 
-SALOME_ExtractGeometry
-::GetMTime()
-{
-  unsigned long int aTime = vtkExtractGeometry::GetMTime();
-  return aTime;
-}
-
-
 //----------------------------------------------------------------------------
 vtkImplicitBoolean* 
 SALOME_ExtractGeometry
@@ -81,7 +74,7 @@ SALOME_ExtractGeometry
 ::SetImplicitFunction(vtkImplicitFunction* theImplicitFunction)  
 {
   myImplicitBoolean = dynamic_cast<vtkImplicitBoolean*>(theImplicitFunction);
-  vtkExtractGeometry::SetImplicitFunction(theImplicitFunction);
+  Superclass::SetImplicitFunction(theImplicitFunction);
 }
 
 
@@ -90,8 +83,10 @@ void
 SALOME_ExtractGeometry
 ::SetStoreMapping(bool theStoreMapping)
 {
-  myStoreMapping = theStoreMapping;
-  Modified();
+  if(myStoreMapping != theStoreMapping){
+    myStoreMapping = theStoreMapping;
+    Modified();
+  }
 }
 
 bool 
@@ -107,9 +102,9 @@ vtkIdType
 SALOME_ExtractGeometry
 ::GetElemVTKId(vtkIdType theID)
 {
-  if(!myStoreMapping||myIsDoneShallowCopy){
+  if(!myStoreMapping || myIsDoneShallowCopy)
     return theID;
-  }
+
   vtkIdType iEnd = myElemVTK2ObjIds.size();
   for(vtkIdType i = 0; i < iEnd; i++)
     if(myElemVTK2ObjIds[i] == theID)
@@ -122,9 +117,9 @@ vtkIdType
 SALOME_ExtractGeometry
 ::GetNodeVTKId(vtkIdType theID)
 {
-  if (!myStoreMapping||myIsDoneShallowCopy){
+  if(!myStoreMapping || myIsDoneShallowCopy)
     return theID;
-  }
+
   vtkIdType iEnd = myNodeVTK2ObjIds.size();
   for(vtkIdType i = 0; i < iEnd; i++)
     if(myNodeVTK2ObjIds[i] == theID)
@@ -137,63 +132,84 @@ SALOME_ExtractGeometry
 //----------------------------------------------------------------------------
 vtkIdType
 SALOME_ExtractGeometry
-::GetElemObjId(int theVtkID)
+::GetElemObjId(vtkIdType theVtkID)
 {
-  if (!myStoreMapping||myIsDoneShallowCopy){
+  if(!myStoreMapping || myIsDoneShallowCopy)
     return theVtkID;
-  }
-  //
-  if (theVtkID<myElemVTK2ObjIds.size()){
+
+  if(theVtkID < myElemVTK2ObjIds.size())
     return myElemVTK2ObjIds[theVtkID];
-  }
+
   return -1;
 }
 
 
 vtkIdType
 SALOME_ExtractGeometry
-::GetNodeObjId(int theVtkID)
+::GetNodeObjId(vtkIdType theVtkID)
 {
-  if (!myStoreMapping||myIsDoneShallowCopy){
+  if(!myStoreMapping || myIsDoneShallowCopy)
     return theVtkID;
-  }
-  //
-  if (theVtkID<myNodeVTK2ObjIds.size()){
+
+  if(theVtkID < myNodeVTK2ObjIds.size())
     return myNodeVTK2ObjIds[theVtkID];
-  }
+
   return -1;
 }
 
 
 //----------------------------------------------------------------------------
-void
+int
 SALOME_ExtractGeometry
-::Execute()
+::RequestData(vtkInformation *request,
+              vtkInformationVector **inputVector,
+              vtkInformationVector *outputVector)
 {
+  // get the info objects
+  vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
+  vtkInformation *outInfo = outputVector->GetInformationObject(0);
+
+  // get the input and ouptut
+  vtkDataSet *input = vtkDataSet::SafeDownCast(
+    inInfo->Get(vtkDataObject::DATA_OBJECT()));
+  vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
+    outInfo->Get(vtkDataObject::DATA_OBJECT()));
+
   myElemVTK2ObjIds.clear();
   myNodeVTK2ObjIds.clear();
   //
   myIsDoneShallowCopy = !this->ImplicitFunction;
 
-  if(!myIsDoneShallowCopy && myImplicitBoolean.GetPointer()){
-    if(vtkImplicitFunctionCollection* aFunction = myImplicitBoolean->GetFunction()){
+  if(!myIsDoneShallowCopy && myImplicitBoolean.GetPointer())
+    if(vtkImplicitFunctionCollection* aFunction = myImplicitBoolean->GetFunction())
       myIsDoneShallowCopy = aFunction->GetNumberOfItems() == 0;
-    }
-  }
 
   if(myIsDoneShallowCopy){
-    GetOutput()->ShallowCopy(GetInput());
-    Modified();
-    return;
+    output->ShallowCopy(input);
+    return 1;
   }
-
-  Execute2();
+  
+  return RequestData2(request,inputVector,outputVector);
 }
 
-void
+
+//----------------------------------------------------------------------------
+int
 SALOME_ExtractGeometry
-::Execute2()
+::RequestData2(vtkInformation *vtkNotUsed(request),
+               vtkInformationVector **inputVector,
+               vtkInformationVector *outputVector)
 {
+  // get the info objects
+  vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
+  vtkInformation *outInfo = outputVector->GetInformationObject(0);
+
+  // get the input and ouptut
+  vtkDataSet *input = vtkDataSet::SafeDownCast(
+    inInfo->Get(vtkDataObject::DATA_OBJECT()));
+  vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
+    outInfo->Get(vtkDataObject::DATA_OBJECT()));
+
   vtkIdType ptId, numPts, numCells, i, cellId, newCellId, newId, *pointMap;
   vtkIdList *cellPts;
   vtkCell *cell;
@@ -202,10 +218,8 @@ SALOME_ExtractGeometry
   vtkFloatingPointType multiplier;
   vtkPoints *newPts;
   vtkIdList *newCellPts;
-  vtkDataSet *input = this->GetInput();
   vtkPointData *pd = input->GetPointData();
   vtkCellData *cd = input->GetCellData();
-  vtkUnstructuredGrid *output = this->GetOutput();
   vtkPointData *outputPD = output->GetPointData();
   vtkCellData *outputCD = output->GetCellData();
   int npts;
@@ -215,7 +229,7 @@ SALOME_ExtractGeometry
   if ( ! this->ImplicitFunction )
     {
     vtkErrorMacro(<<"No implicit function specified");
-    return;
+    return 0;
     }
 
   newCellPts = vtkIdList::New();
@@ -260,8 +274,8 @@ SALOME_ExtractGeometry
         {
         newId = newPts->InsertNextPoint(x);
         pointMap[ptId] = newId;
-       if(myStoreMapping)
-         myNodeVTK2ObjIds.push_back(ptId);
+        if(myStoreMapping)
+          myNodeVTK2ObjIds.push_back(ptId);
         outputPD->CopyData(pd,ptId,newId);
         }
       }
@@ -284,8 +298,8 @@ SALOME_ExtractGeometry
           {
           newId = newPts->InsertNextPoint(x);
           pointMap[ptId] = newId;
-         if(myStoreMapping)
-           myNodeVTK2ObjIds.push_back(ptId);
+          if(myStoreMapping)
+            myNodeVTK2ObjIds.push_back(ptId);
           outputPD->CopyData(pd,ptId,newId);
           }
         }
@@ -338,8 +352,8 @@ SALOME_ExtractGeometry
             x = input->GetPoint(ptId);
             newId = newPts->InsertNextPoint(x);
             pointMap[ptId] = newId;
-           if(myStoreMapping)
-             myNodeVTK2ObjIds.push_back(ptId);
+            if(myStoreMapping)
+              myNodeVTK2ObjIds.push_back(ptId);
             outputPD->CopyData(pd,ptId,newId);
             }
           newCellPts->InsertId(i,pointMap[ptId]);
@@ -351,7 +365,7 @@ SALOME_ExtractGeometry
       {
       newCellId = output->InsertNextCell(cell->GetCellType(),newCellPts);
       if(myStoreMapping)
-       myElemVTK2ObjIds.push_back(cellId);
+        myElemVTK2ObjIds.push_back(cellId);
       outputCD->CopyData(cd,cellId,newCellId);
       }
     }//for all cells
@@ -369,4 +383,6 @@ SALOME_ExtractGeometry
     }
 
   output->Squeeze();
+
+  return 1;
 }