Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / PIPELINE / SALOME_ExtractGeometry.cxx
index d4b03f4ebc9398ef83a1694bbe3ed14db6603778..03cf524cb6eac36bec31a1eb56b99213ff7ebffa 100755 (executable)
@@ -1,21 +1,21 @@
 //  Copyright (C) 2003  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 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  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 
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  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
 
 
 #include "SALOME_ExtractGeometry.h"
 
 using namespace std;
 
+#if defined __GNUC__
+  #if __GNUC__ == 2
+    #define __GNUC_2__
+  #endif
+#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 theID){
-  if(myElemVTK2ObjIds.empty() || theID > myElemVTK2ObjIds.size()) 
-    return theID;
-  return myElemVTK2ObjIds[theID];
+//----------------------------------------------------------------------------
+unsigned long int 
+SALOME_ExtractGeometry
+::GetMTime()
+{
+  unsigned long int aTime = vtkExtractGeometry::GetMTime();
+  return aTime;
 }
 
 
-vtkIdType SALOME_ExtractGeometry::GetNodeObjId(int theID){
-  if(myNodeVTK2ObjIds.empty() || theID > myNodeVTK2ObjIds.size()) 
-    return theID;
-  return myNodeVTK2ObjIds[theID];
+//----------------------------------------------------------------------------
+vtkImplicitBoolean* 
+SALOME_ExtractGeometry
+::GetImplicitBoolean() 
+{
+  return myImplicitBoolean.GetPointer();
 }
 
 
-void SALOME_ExtractGeometry::SetImplicitBoolean(vtkImplicitBoolean* theImplicitBoolean)
+void
+SALOME_ExtractGeometry
+::SetImplicitFunction(vtkImplicitFunction* theImplicitFunction)  
 {
-  myImplicitBoolean = theImplicitBoolean;
-  SetImplicitFunction(theImplicitBoolean);
+  myImplicitBoolean = dynamic_cast<vtkImplicitBoolean*>(theImplicitFunction);
+  vtkExtractGeometry::SetImplicitFunction(theImplicitFunction);
 }
 
 
-void SALOME_ExtractGeometry::SetStoreMapping(bool theStoreMapping)
+//----------------------------------------------------------------------------
+void 
+SALOME_ExtractGeometry
+::SetStoreMapping(bool theStoreMapping)
 {
   myStoreMapping = theStoreMapping;
   Modified();
 }
 
+bool 
+SALOME_ExtractGeometry
+::GetStoreMapping() const
+{
+  return myStoreMapping;
+}
 
-void SALOME_ExtractGeometry::Execute()
+
+//----------------------------------------------------------------------------
+vtkIdType
+SALOME_ExtractGeometry
+::GetElemVTKId(vtkIdType theID)
 {
-  if(myImplicitBoolean.GetPointer()){
+  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;
+  }
+  vtkIdType iEnd = myNodeVTK2ObjIds.size();
+  for(vtkIdType i = 0; i < iEnd; i++)
+    if(myNodeVTK2ObjIds[i] == theID)
+      return i;
+
+  return -1;
+}
+
+
+//----------------------------------------------------------------------------
+vtkIdType
+SALOME_ExtractGeometry
+::GetElemObjId(int theVtkID)
+{
+  if (!myStoreMapping||myIsDoneShallowCopy){
+    return theVtkID;
+  }
+  //
+  if (theVtkID<myElemVTK2ObjIds.size()){
+    return myElemVTK2ObjIds[theVtkID];
+  }
+  return -1;
+}
+
+
+vtkIdType
+SALOME_ExtractGeometry
+::GetNodeObjId(int theVtkID)
+{
+  if (!myStoreMapping||myIsDoneShallowCopy){
+    return theVtkID;
+  }
+  //
+  if (theVtkID<myNodeVTK2ObjIds.size()){
+    return myNodeVTK2ObjIds[theVtkID];
+  }
+  return -1;
+}
+
+
+//----------------------------------------------------------------------------
+void
+SALOME_ExtractGeometry
+::Execute()
+{
+  myElemVTK2ObjIds.clear();
+  myNodeVTK2ObjIds.clear();
+  //
+  myIsDoneShallowCopy = !this->ImplicitFunction;
+
+  if(!myIsDoneShallowCopy && myImplicitBoolean.GetPointer()){
     if(vtkImplicitFunctionCollection* aFunction = myImplicitBoolean->GetFunction()){
-      if(aFunction->GetNumberOfItems() == 0){
-       vtkDebugMacro(<< "Extracting geometry - ShallowCopy");
-       GetOutput()->ShallowCopy(GetInput());
-       return;
-      }
+      myIsDoneShallowCopy = aFunction->GetNumberOfItems() == 0;
     }
   }
+
+  if(myIsDoneShallowCopy){
+    GetOutput()->ShallowCopy(GetInput());
+    Modified();
+    return;
+  }
+
   Execute2();
 }
 
-void SALOME_ExtractGeometry::Execute2()
+void
+SALOME_ExtractGeometry
+::Execute2()
 {
   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();
@@ -106,8 +211,6 @@ void SALOME_ExtractGeometry::Execute2()
   int npts;
   numCells = input->GetNumberOfCells();
   numPts = input->GetNumberOfPoints();
-  
-  vtkDebugMacro(<< "Extracting geometry");
 
   if ( ! this->ImplicitFunction )
     {
@@ -122,7 +225,7 @@ void SALOME_ExtractGeometry::Execute2()
     {
     multiplier = 1.0;
     }
-  else 
+  else
     {
     multiplier = -1.0;
     }
@@ -142,11 +245,9 @@ void SALOME_ExtractGeometry::Execute2()
   outputPD->CopyAllocate(pd);
   outputCD->CopyAllocate(cd);
   vtkFloatArray *newScalars = NULL;
-  
+
   if(myStoreMapping){
-    myElemVTK2ObjIds.clear();
     myElemVTK2ObjIds.reserve(numCells);
-    myNodeVTK2ObjIds.clear();
     myNodeVTK2ObjIds.reserve(numPts);
   }
 
@@ -159,7 +260,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);
         }
       }
@@ -169,7 +271,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);
 
@@ -182,7 +284,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);
           }
         }
@@ -214,7 +317,7 @@ void SALOME_ExtractGeometry::Execute2()
           }
         }
       } //if don't want to extract boundary cells
-    
+
     else //want boundary cells
       {
       for ( npts=0, i=0; i < numCellPts; i++ )
@@ -235,18 +338,20 @@ 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]);
           }
         }//a boundary or interior cell
       }//if mapping boundary cells
-      
+
     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
@@ -257,7 +362,7 @@ void SALOME_ExtractGeometry::Execute2()
   newCellPts->Delete();
   output->SetPoints(newPts);
   newPts->Delete();
-  
+
   if ( this->ExtractBoundaryCells )
     {
     newScalars->Delete();