Salome HOME
Merge from V5_1_main 10/06/2010
[modules/visu.git] / src / PIPELINE / SALOME_ExtractGeometry.cxx
index 13655093f9dec9d295721a61059706aff983f355..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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
-
+//  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__
@@ -41,105 +44,192 @@ using namespace std;
 #endif
 
 
+//----------------------------------------------------------------------------
 vtkStandardNewMacro(SALOME_ExtractGeometry);
 
 
-SALOME_ExtractGeometry::SALOME_ExtractGeometry()
+//----------------------------------------------------------------------------
+SALOME_ExtractGeometry
+::SALOME_ExtractGeometry():
+  myStoreMapping(false),
+  myIsDoneShallowCopy(false)
 {}
 
-SALOME_ExtractGeometry::~SALOME_ExtractGeometry()
+SALOME_ExtractGeometry
+::~SALOME_ExtractGeometry()
 {}
 
-vtkIdType SALOME_ExtractGeometry::GetElemObjId(int theVtkID)
+
+//----------------------------------------------------------------------------
+vtkImplicitBoolean* 
+SALOME_ExtractGeometry
+::GetImplicitBoolean() 
 {
-  if (myElemVTK2ObjIds.empty())
-    return theVtkID;
+  return myImplicitBoolean.GetPointer();
+}
 
-  if (theVtkID < 0 || myElemVTK2ObjIds.size() <= theVtkID)
-    return -1;
 
-#if defined __GNUC_2__
-  return myElemVTK2ObjIds[theVtkID];
-#else
-  return myElemVTK2ObjIds.at(theVtkID);
-#endif
+void
+SALOME_ExtractGeometry
+::SetImplicitFunction(vtkImplicitFunction* theImplicitFunction)  
+{
+  myImplicitBoolean = dynamic_cast<vtkImplicitBoolean*>(theImplicitFunction);
+  Superclass::SetImplicitFunction(theImplicitFunction);
 }
 
 
-vtkIdType SALOME_ExtractGeometry::GetNodeObjId(int theVtkID)
+//----------------------------------------------------------------------------
+void 
+SALOME_ExtractGeometry
+::SetStoreMapping(bool theStoreMapping)
 {
-  if (myNodeVTK2ObjIds.empty())
-    return theVtkID;
+  if(myStoreMapping != theStoreMapping){
+    myStoreMapping = theStoreMapping;
+    Modified();
+  }
+}
 
-  if (theVtkID < 0 || myNodeVTK2ObjIds.size() <= theVtkID)
-    return -1;
+bool 
+SALOME_ExtractGeometry
+::GetStoreMapping() const
+{
+  return myStoreMapping;
+}
 
-#if defined __GNUC_2__
-  return myNodeVTK2ObjIds[theVtkID];
-#else
-  return myNodeVTK2ObjIds.at(theVtkID);
-#endif
+
+//----------------------------------------------------------------------------
+vtkIdType
+SALOME_ExtractGeometry
+::GetElemVTKId(vtkIdType theID)
+{
+  if(!myStoreMapping || myIsDoneShallowCopy)
+    return theID;
+
+  vtkIdType iEnd = myElemVTK2ObjIds.size();
+  for(vtkIdType i = 0; i < iEnd; i++)
+    if(myElemVTK2ObjIds[i] == theID)
+      return i;
+
+  return -1;
 }
 
+vtkIdType
+SALOME_ExtractGeometry
+::GetNodeVTKId(vtkIdType theID)
+{
+  if(!myStoreMapping || myIsDoneShallowCopy)
+    return theID;
 
-void SALOME_ExtractGeometry::SetImplicitBoolean(vtkImplicitBoolean* theImplicitBoolean)
+  vtkIdType iEnd = myNodeVTK2ObjIds.size();
+  for(vtkIdType i = 0; i < iEnd; i++)
+    if(myNodeVTK2ObjIds[i] == theID)
+      return i;
+
+  return -1;
+}
+
+
+//----------------------------------------------------------------------------
+vtkIdType
+SALOME_ExtractGeometry
+::GetElemObjId(vtkIdType theVtkID)
 {
-  myImplicitBoolean = theImplicitBoolean;
-  SetImplicitFunction(theImplicitBoolean);
+  if(!myStoreMapping || myIsDoneShallowCopy)
+    return theVtkID;
+
+  if(theVtkID < myElemVTK2ObjIds.size())
+    return myElemVTK2ObjIds[theVtkID];
+
+  return -1;
 }
 
 
-void SALOME_ExtractGeometry::SetStoreMapping(bool theStoreMapping)
+vtkIdType
+SALOME_ExtractGeometry
+::GetNodeObjId(vtkIdType theVtkID)
 {
-  myStoreMapping = theStoreMapping;
-  Modified();
+  if(!myStoreMapping || myIsDoneShallowCopy)
+    return theVtkID;
+
+  if(theVtkID < myNodeVTK2ObjIds.size())
+    return myNodeVTK2ObjIds[theVtkID];
+
+  return -1;
 }
 
 
-void SALOME_ExtractGeometry::Execute()
+//----------------------------------------------------------------------------
+int
+SALOME_ExtractGeometry
+::RequestData(vtkInformation *request,
+              vtkInformationVector **inputVector,
+              vtkInformationVector *outputVector)
 {
-  if(myImplicitBoolean.GetPointer()){
-    if(vtkImplicitFunctionCollection* aFunction = myImplicitBoolean->GetFunction()){
-      if(aFunction->GetNumberOfItems() == 0){
-        myElemVTK2ObjIds.clear();
-        myNodeVTK2ObjIds.clear();
-
-       vtkDebugMacro(<< "Extracting geometry - ShallowCopy");
-       GetOutput()->ShallowCopy(GetInput());
-        Modified();
-       return;
-      }
-    }
+  // 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())
+      myIsDoneShallowCopy = aFunction->GetNumberOfItems() == 0;
+
+  if(myIsDoneShallowCopy){
+    output->ShallowCopy(input);
+    return 1;
   }
-  Execute2();
+  
+  return RequestData2(request,inputVector,outputVector);
 }
 
-void SALOME_ExtractGeometry::Execute2()
+
+//----------------------------------------------------------------------------
+int
+SALOME_ExtractGeometry
+::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;
   int numCellPts;
-  float *x;
-  float multiplier;
+  vtkFloatingPointType *x;
+  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;
   numCells = input->GetNumberOfCells();
   numPts = input->GetNumberOfPoints();
 
-  vtkDebugMacro(<< "Extracting geometry");
-
   if ( ! this->ImplicitFunction )
     {
     vtkErrorMacro(<<"No implicit function specified");
-    return;
+    return 0;
     }
 
   newCellPts = vtkIdList::New();
@@ -171,9 +261,7 @@ void SALOME_ExtractGeometry::Execute2()
   vtkFloatArray *newScalars = NULL;
 
   if(myStoreMapping){
-    myElemVTK2ObjIds.clear();
     myElemVTK2ObjIds.reserve(numCells);
-    myNodeVTK2ObjIds.clear();
     myNodeVTK2ObjIds.reserve(numPts);
   }
 
@@ -186,7 +274,8 @@ void SALOME_ExtractGeometry::Execute2()
         {
         newId = newPts->InsertNextPoint(x);
         pointMap[ptId] = newId;
-       myNodeVTK2ObjIds.push_back(ptId);
+        if(myStoreMapping)
+          myNodeVTK2ObjIds.push_back(ptId);
         outputPD->CopyData(pd,ptId,newId);
         }
       }
@@ -196,7 +285,7 @@ void SALOME_ExtractGeometry::Execute2()
     // To extract boundary cells, we have to create supplemental information
     if ( this->ExtractBoundaryCells )
       {
-      float val;
+      vtkFloatingPointType val;
       newScalars = vtkFloatArray::New();
       newScalars->SetNumberOfValues(numPts);
 
@@ -209,7 +298,8 @@ void SALOME_ExtractGeometry::Execute2()
           {
           newId = newPts->InsertNextPoint(x);
           pointMap[ptId] = newId;
-         myNodeVTK2ObjIds.push_back(ptId);
+          if(myStoreMapping)
+            myNodeVTK2ObjIds.push_back(ptId);
           outputPD->CopyData(pd,ptId,newId);
           }
         }
@@ -262,7 +352,8 @@ void SALOME_ExtractGeometry::Execute2()
             x = input->GetPoint(ptId);
             newId = newPts->InsertNextPoint(x);
             pointMap[ptId] = newId;
-           myNodeVTK2ObjIds.push_back(ptId);
+            if(myStoreMapping)
+              myNodeVTK2ObjIds.push_back(ptId);
             outputPD->CopyData(pd,ptId,newId);
             }
           newCellPts->InsertId(i,pointMap[ptId]);
@@ -273,7 +364,8 @@ void SALOME_ExtractGeometry::Execute2()
     if ( npts >= numCellPts || (this->ExtractBoundaryCells && npts > 0) )
       {
       newCellId = output->InsertNextCell(cell->GetCellType(),newCellPts);
-      myElemVTK2ObjIds.push_back(cellId);
+      if(myStoreMapping)
+        myElemVTK2ObjIds.push_back(cellId);
       outputCD->CopyData(cd,cellId,newCellId);
       }
     }//for all cells
@@ -291,4 +383,6 @@ void SALOME_ExtractGeometry::Execute2()
     }
 
   output->Squeeze();
+
+  return 1;
 }