Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / PIPELINE / VISU_PipeLine.cxx
index d670a681c9628bf6bfccf38c7e55871f2591c04e..9fcd66fdc9a6fec787350d49acd4c93a8a69ceb3 100644 (file)
@@ -40,6 +40,7 @@
 #include <vtkPlane.h>
 #include <vtkExtractGeometry.h>
 #include <vtkImplicitBoolean.h>
+#include <vtkImplicitFunction.h>
 #include <vtkImplicitFunctionCollection.h>
 #include <vtkMath.h>
 
@@ -51,70 +52,115 @@ static int MYDEBUG = 0;
 static int MYDEBUG = 0;
 #endif
 
-VISU_PipeLine::VISU_PipeLine()
+VISU_PipeLine
+::VISU_PipeLine():
+  myMapper(vtkDataSetMapper::New()),
+  myExtractGeometry(SALOME_ExtractGeometry::New())
 {
-  if(MYDEBUG) MESSAGE("VISU_PipeLine - "<<this);
+  if(MYDEBUG) MESSAGE("VISU_PipeLine::VISU_PipeLine - "<<this);
+  SetDebug(MYVTKDEBUG);
+
+  myMapper->Delete();
+
   // Clipping planes
-  myExtractGeometry = SALOME_ExtractGeometry::New();
-  //myExtractGeometry->SetReleaseDataFlag(true);
   myExtractGeometry->Delete();
-  //myExtractGeometry->DebugOn();
+  myExtractGeometry->SetStoreMapping(true);
 
   vtkImplicitBoolean* anImplicitBoolean = vtkImplicitBoolean::New();
-  myExtractGeometry->SetImplicitBoolean(anImplicitBoolean);
+  myExtractGeometry->SetImplicitFunction(anImplicitBoolean);
   anImplicitBoolean->SetOperationTypeToIntersection();
   anImplicitBoolean->Delete();
 
-  // Mapper
-  myMapper = TMapper::New();
-  myInput = NULL;
-
   myIsShrinkable = false;
 
-  SetDebug(MYVTKDEBUG);
 }
 
-VISU_PipeLine::~VISU_PipeLine()
+VISU_PipeLine
+::~VISU_PipeLine()
 {
-  if(MYDEBUG) MESSAGE("~VISU_PipeLine - "<<this);
-  myMapper->Delete();
+  if(MYDEBUG) MESSAGE("VISU_PipeLine::~VISU_PipeLine - "<<this);
 }
 
-void VISU_PipeLine::ShallowCopy(VISU_PipeLine *thePipeLine){
-  SetInput(thePipeLine->GetInput());
-  myMapper->ShallowCopy(thePipeLine->GetMapper());
-  myExtractGeometry->SetImplicitBoolean(thePipeLine->myExtractGeometry->GetImplicitBoolean());
+// Turn debugging output on.
+void
+VISU_PipeLine
+::DebugOn()
+{
+  myExtractGeometry->DebugOn();
+  Superclass::DebugOn();
+}
+
+// Turn debugging output off.
+void
+VISU_PipeLine
+::DebugOff()
+{
+  myExtractGeometry->DebugOff();
+  Superclass::DebugOff();
+}
+
+void 
+VISU_PipeLine
+::ShallowCopy(VISU_PipeLine *thePipeLine)
+{
+  SetImplicitFunction(thePipeLine->GetImplicitFunction());
+
+  // To restore mapper input from pipeline
+  vtkDataSet* aDatsSet = myMapper->GetInput();
+  GetMapper()->ShallowCopy(thePipeLine->GetMapper());
+  myMapper->SetInput(aDatsSet);
+
   Build();
 }
 
-void VISU_PipeLine::SameAs(VISU_PipeLine *thePipeLine){
+void
+VISU_PipeLine
+::SameAs(VISU_PipeLine *thePipeLine)
+{
   ShallowCopy(thePipeLine);
-  myExtractGeometry->SetImplicitBoolean(vtkImplicitBoolean::New());
-  myExtractGeometry->GetImplicitBoolean()->Delete();
+  SetImplicitFunction(vtkImplicitBoolean::New());
+  GetImplicitFunction()->Delete();
 }
 
-TInput* VISU_PipeLine::GetInput() const
+TInput* 
+VISU_PipeLine
+::GetInput() const
 {
-  return myInput;
+  return myInput.GetPointer();
 }
 
-TInput* VISU_PipeLine::GetInput2() const
+vtkDataSet* 
+VISU_PipeLine
+::GetOutput()
+{
+  return GetMapper()->GetInput();
+}
+
+TInput* 
+VISU_PipeLine
+::GetInput2() const
 {
   vtkUnstructuredGrid* aDataSet = myExtractGeometry->GetOutput();
   aDataSet->Update();
   return aDataSet;
 }
 
-void VISU_PipeLine::SetInput(TInput* theInput)
+void
+VISU_PipeLine
+::SetInput(TInput* theInput)
 {
+  if(theInput)
+    theInput->Update();
+
   myExtractGeometry->SetInput(theInput);
-  if((myInput = theInput))
-    myInput->Update();
+  myInput = theInput;
 
   Modified();
 }
 
-VISU_PipeLine::TMapper* VISU_PipeLine::GetMapper()
+VISU_PipeLine::TMapper* 
+VISU_PipeLine
+::GetMapper()
 {
   if(GetInput()){
     if(!myMapper->GetInput()){
@@ -123,15 +169,19 @@ VISU_PipeLine::TMapper* VISU_PipeLine::GetMapper()
     }
     myMapper->Update();
   }
-  return myMapper;
+  return myMapper.GetPointer();
 }
 
-void VISU_PipeLine::Update()
+void 
+VISU_PipeLine
+::Update()
 {
   myMapper->Update();
 }
 
-int VISU_PipeLine::CheckAvailableMemory(const float& theSize)
+int
+VISU_PipeLine
+::CheckAvailableMemory(const float& theSize)
 {
   try{
     if(theSize > ULONG_MAX) return 0;
@@ -152,7 +202,10 @@ int VISU_PipeLine::CheckAvailableMemory(const float& theSize)
   return 0;
 }
 
-float VISU_PipeLine::GetAvailableMemory(float theSize, float theMinSize)
+float
+VISU_PipeLine
+::GetAvailableMemory(float theSize, 
+                    float theMinSize)
 {
   while(!CheckAvailableMemory(theSize))
     if(theSize > theMinSize)
@@ -163,8 +216,9 @@ float VISU_PipeLine::GetAvailableMemory(float theSize, float theMinSize)
 }
 
 //------------------------ Clipping planes -----------------------------------
-
-bool VISU_PipeLine::AddClippingPlane(vtkPlane* thePlane)
+bool 
+VISU_PipeLine
+::AddClippingPlane(vtkPlane* thePlane)
 {
   if (thePlane) {
     if (vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()) {
@@ -182,7 +236,9 @@ bool VISU_PipeLine::AddClippingPlane(vtkPlane* thePlane)
   return true;
 }
 
-vtkPlane* VISU_PipeLine::GetClippingPlane(vtkIdType theID) const
+vtkPlane* 
+VISU_PipeLine
+::GetClippingPlane(vtkIdType theID) const
 {
   vtkPlane* aPlane = NULL;
   if(theID >= 0 && theID < GetNumberOfClippingPlanes()){
@@ -198,7 +254,9 @@ vtkPlane* VISU_PipeLine::GetClippingPlane(vtkIdType theID) const
   return aPlane;
 }
 
-void VISU_PipeLine::RemoveAllClippingPlanes()
+void
+VISU_PipeLine
+::RemoveAllClippingPlanes()
 {
   if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
     vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
@@ -207,7 +265,9 @@ void VISU_PipeLine::RemoveAllClippingPlanes()
   }
 }
 
-vtkIdType VISU_PipeLine::GetNumberOfClippingPlanes() const
+vtkIdType
+VISU_PipeLine
+::GetNumberOfClippingPlanes() const
 {
   if(vtkImplicitBoolean* aBoolean = myExtractGeometry->GetImplicitBoolean()){
     vtkImplicitFunctionCollection* aFunction = aBoolean->GetFunction();
@@ -216,9 +276,13 @@ vtkIdType VISU_PipeLine::GetNumberOfClippingPlanes() const
   return 0;
 }
 
-static void ComputeBoundsParam (vtkDataSet* theDataSet,
-                                float theDirection[3], float theMinPnt[3],
-                                float& theMaxBoundPrj, float& theMinBoundPrj)
+static
+void
+ComputeBoundsParam (vtkDataSet* theDataSet,
+                   float theDirection[3], 
+                   float theMinPnt[3],
+                   float& theMaxBoundPrj, 
+                   float& theMinBoundPrj)
 {
   float aBounds[6];
   theDataSet->GetBounds(aBounds);
@@ -260,8 +324,12 @@ static void ComputeBoundsParam (vtkDataSet* theDataSet,
   theMinPnt[2] = aMinPnt[2];
 }
 
-static void DistanceToPosition (vtkDataSet* theDataSet,
-                                float theDirection[3], float theDist, float thePos[3])
+static
+void
+DistanceToPosition(vtkDataSet* theDataSet,
+                  float theDirection[3], 
+                  float theDist, 
+                  float thePos[3])
 {
   float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
@@ -271,8 +339,12 @@ static void DistanceToPosition (vtkDataSet* theDataSet,
   thePos[2] = aMinPnt[2]-theDirection[2]*aLength;
 }
 
-static void PositionToDistance (vtkDataSet* theDataSet,
-                                float theDirection[3], float thePos[3], float& theDist)
+static
+void
+PositionToDistance (vtkDataSet* theDataSet,
+                   float theDirection[3], 
+                   float thePos[3], 
+                   float& theDist)
 {
   float aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
   ComputeBoundsParam(theDataSet,theDirection,aMinPnt,aMaxBoundPrj,aMinBoundPrj);
@@ -280,7 +352,11 @@ static void PositionToDistance (vtkDataSet* theDataSet,
   theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
 }
 
-void VISU_PipeLine::SetPlaneParam (float theDir[3], float theDist, vtkPlane* thePlane)
+void
+VISU_PipeLine
+::SetPlaneParam(float theDir[3], 
+               float theDist, 
+               vtkPlane* thePlane)
 {
   thePlane->SetNormal(theDir);
   float anOrigin[3];
@@ -288,7 +364,11 @@ void VISU_PipeLine::SetPlaneParam (float theDir[3], float theDist, vtkPlane* the
   thePlane->SetOrigin(anOrigin);
 }
 
-void VISU_PipeLine::GetPlaneParam (float theDir[3], float& theDist, vtkPlane* thePlane)
+void
+VISU_PipeLine
+::GetPlaneParam(float theDir[3], 
+               float& theDist, 
+               vtkPlane* thePlane)
 {
   thePlane->GetNormal(theDir);
 
@@ -301,7 +381,9 @@ void VISU_PipeLine::GetPlaneParam (float theDir[3], float& theDist, vtkPlane* th
 //function : IsPlanarInput
 //purpose  :
 //=======================================================================
-bool VISU_PipeLine::IsPlanarInput() const
+bool
+VISU_PipeLine
+::IsPlanarInput() const
 {
   float aBounds[6];
   GetInput()->GetBounds( aBounds ); // xmin,xmax, ymin,ymax, zmin,zmax
@@ -312,3 +394,89 @@ bool VISU_PipeLine::IsPlanarInput() const
 
   return false;
 }
+
+//=======================================================================
+vtkIdType 
+VISU_PipeLine
+::GetNodeObjID(vtkIdType theID)
+{
+  vtkIdType anID = myExtractGeometry->GetNodeObjId(theID);
+  return myIDMapper->GetNodeObjID(anID);
+}
+
+vtkIdType 
+VISU_PipeLine
+::GetNodeVTKID(vtkIdType theID)
+{
+  vtkIdType anID = myIDMapper->GetNodeVTKID(theID);
+  return myExtractGeometry->GetNodeVTKId(anID);
+}
+
+float* 
+VISU_PipeLine
+::GetNodeCoord(int theObjID)
+{
+  return myIDMapper->GetNodeCoord(theObjID);
+}
+
+//=======================================================================
+vtkIdType 
+VISU_PipeLine
+::GetElemObjID(vtkIdType theID)
+{
+  vtkIdType anID = myExtractGeometry->GetElemObjId(theID);
+  return myIDMapper->GetElemObjID(anID);
+}
+
+vtkIdType
+VISU_PipeLine
+::GetElemVTKID(vtkIdType theID)
+{
+  vtkIdType anID = myIDMapper->GetElemVTKID(theID);
+  return myExtractGeometry->GetElemVTKId(anID);
+}
+
+vtkCell* 
+VISU_PipeLine
+::GetElemCell(vtkIdType  theObjID)
+{
+  return myIDMapper->GetElemCell(theObjID);
+}
+
+//=======================================================================
+void
+VISU_PipeLine
+::SetIDMapper(const VISU::PIDMapper& theIDMapper)
+{
+  myIDMapper = theIDMapper;
+  SetInput(myIDMapper->GetVTKOutput());
+}
+
+const VISU::PIDMapper&  
+VISU_PipeLine
+::GetIDMapper() const
+{
+  return myIDMapper;
+}
+
+//=======================================================================
+void
+VISU_PipeLine
+::SetImplicitFunction(vtkImplicitFunction *theFunction)
+{
+  myExtractGeometry->SetImplicitFunction(theFunction);
+} 
+
+vtkImplicitFunction * 
+VISU_PipeLine
+::GetImplicitFunction()
+{
+  return myExtractGeometry->GetImplicitFunction();
+}
+
+SALOME_ExtractGeometry*
+VISU_PipeLine
+::GetExtractGeometryFilter()
+{
+  return myExtractGeometry.GetPointer();
+}