Salome HOME
Porting to VTK 6.
[modules/visu.git] / src / PIPELINE / VISU_PipeLine.cxx
index ea165bc078c1c073b603e35d5ab35e7f35cf4f2e..f840bbe4145ea692f8e48409cca0e7f6fa871006 100644 (file)
@@ -1,31 +1,30 @@
-//  VISU OBJECT : interactive object for VISU entities implementation
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 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
-//  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 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.
+// 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
+// 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
 //
-//
-//
+
+//  VISU OBJECT : interactive object for VISU entities implementation
 // File:    VISU_PipeLine.cxx
 // Author:  Alexey PETROV
 // Module : VISU
-
-
+//
 #include "VISU_PipeLine.hxx"
 #include "VISU_MapperHolder.hxx"
 
@@ -36,6 +35,8 @@
 
 #include <float.h>
 #include <algorithm>
+#include <climits>
+#include <limits>
 
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
@@ -47,9 +48,12 @@ static int MYDEBUG = 0;
 //----------------------------------------------------------------------------
 VISU_PipeLine
 ::VISU_PipeLine():
-  myIsShrinkable(true)
+  myIsShrinkable(true),
+  myIsFeatureEdgesAllowed(true)
 {
   if(MYDEBUG) MESSAGE("VISU_PipeLine::VISU_PipeLine - "<<this);
+  
+  vtkMath::UninitializeBounds(myVisibleBounds);
 }
 
 
@@ -93,7 +97,7 @@ VISU_PipeLine
 void 
 VISU_PipeLine
 ::ShallowCopy(VISU_PipeLine *thePipeLine,
-             bool theIsCopyInput)
+              bool theIsCopyInput)
 {
   SetImplicitFunction(thePipeLine->GetImplicitFunction());
   DoShallowCopy(thePipeLine, theIsCopyInput);
@@ -105,10 +109,14 @@ VISU_PipeLine
 void 
 VISU_PipeLine
 ::DoShallowCopy(VISU_PipeLine *thePipeLine,
-               bool theIsCopyInput)
+                bool theIsCopyInput)
 {
   GetMapperHolder()->ShallowCopy(thePipeLine->GetMapperHolder(),
-                                theIsCopyInput);
+                                 theIsCopyInput);
+  for( int i =0 ; i < 6 ; i++)
+    myVisibleBounds[i] = thePipeLine->myVisibleBounds[i];
+  
+  myVisibleComputeTime = thePipeLine->myVisibleComputeTime;
 }
 
 
@@ -175,7 +183,7 @@ bool
 VISU_PipeLine
 ::IsPlanarInput()
 {
-  vtkFloatingPointType aBounds[6];
+  double aBounds[6];
   GetInput()->GetBounds( aBounds ); // xmin,xmax, ymin,ymax, zmin,zmax
   if (fabs( aBounds[0] - aBounds[1] ) <= FLT_MIN ||
       fabs( aBounds[2] - aBounds[3] ) <= FLT_MIN ||
@@ -229,9 +237,9 @@ VISU_PipeLine
 }
 
 //----------------------------------------------------------------------------
-vtkFloatingPointType* 
+double* 
 VISU_PipeLine
-::GetNodeCoord(int theObjID)
+::GetNodeCoord(vtkIdType theObjID)
 {
   return GetMapperHolder()->GetNodeCoord(theObjID);
 }
@@ -282,6 +290,26 @@ VISU_PipeLine
 }
 
 
+//----------------------------------------------------------------------------
+bool 
+VISU_PipeLine
+::IsFeatureEdgesAllowed()
+{
+  return myIsFeatureEdgesAllowed;
+}
+
+void 
+VISU_PipeLine
+::SetIsFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed)
+{
+  if(myIsFeatureEdgesAllowed == theIsFeatureEdgesAllowed)
+    return;
+
+  myIsFeatureEdgesAllowed = theIsFeatureEdgesAllowed;
+  Modified();
+}
+
+
 //----------------------------------------------------------------------------
 void
 VISU_PipeLine
@@ -347,6 +375,12 @@ VISU_PipeLine
   return GetMapperHolder()->GetClippingPlane(theID);
 }
 
+//----------------------------------------------------------------------------
+void VISU_PipeLine::RemoveClippingPlane(vtkIdType theID)
+{
+  return GetMapperHolder()->RemoveClippingPlane(theID);
+}
+
 //----------------------------------------------------------------------------
 vtkDataSet* 
 VISU_PipeLine
@@ -355,21 +389,32 @@ VISU_PipeLine
   return GetMapperHolder()->GetClippedInput();
 }
 
+//----------------------------------------------------------------------------
+vtkAlgorithmOutput* 
+VISU_PipeLine
+::GetClippedInputPort()
+{
+  return GetMapperHolder()->GetClippedInputPort();
+}
+
 
 //----------------------------------------------------------------------------
 void
 VISU_PipeLine
-::SetPlaneParam(vtkFloatingPointType theDir[3], 
-               vtkFloatingPointType theDist, 
-               vtkPlane* thePlane)
+::SetPlaneParam(double theDir[3], 
+                double theDist, 
+                vtkPlane* thePlane)
 {
   thePlane->SetNormal(theDir);
 
-  vtkFloatingPointType anOrigin[3];
-  VISU::DistanceToPosition(GetInput(),
-                          theDir,
-                          theDist,
-                          anOrigin);
+  double anOrigin[3];
+
+  //Make sure that bounds are calculated
+  ComputeVisibleBounds();
+  VISU::DistanceToPosition(myVisibleBounds,
+                           theDir,
+                           theDist,
+                           anOrigin);
 
   thePlane->SetOrigin(anOrigin);
 }
@@ -378,19 +423,21 @@ VISU_PipeLine
 //----------------------------------------------------------------------------
 void
 VISU_PipeLine
-::GetPlaneParam(vtkFloatingPointType theDir[3], 
-               vtkFloatingPointType& theDist, 
-               vtkPlane* thePlane)
+::GetPlaneParam(double theDir[3], 
+                double& theDist, 
+                vtkPlane* thePlane)
 {
   thePlane->GetNormal(theDir);
-
-  vtkFloatingPointType anOrigin[3];
+  
+  double anOrigin[3];
   thePlane->GetOrigin(anOrigin);
-
-  VISU::PositionToDistance(GetInput(),
-                            theDir,
-                            anOrigin,
-                            theDist);
+  
+  //Make sure that bounds are calculated
+  ComputeVisibleBounds();
+  VISU::PositionToDistance(myVisibleBounds,
+                          theDir,
+                          anOrigin,
+                          theDist);
 }
 
 
@@ -403,8 +450,8 @@ VISU_PipeLine
     try{
       size_t aSize = size_t(theSize);
       if(char *aCheck = new char[aSize]){
-       delete [] aCheck;
-       return aSize;
+        delete [] aCheck;
+        return aSize;
       }
     }catch(std::bad_alloc& exc){
     }catch(...){
@@ -417,8 +464,8 @@ VISU_PipeLine
 //----------------------------------------------------------------------------
 size_t
 VISU_PipeLine
-::GetAvailableMemory(size_t theSize, 
-                    size_t theMinSize)
+::GetAvailableMemory(double theSize, 
+                     double theMinSize)
 {
   // Finds acceptable memory size by half-deflection methods
   static double EPSILON = 2 * 1024;
@@ -437,4 +484,22 @@ VISU_PipeLine
 }
 
 
+//----------------------------------------------------------------------------
+// Re-compute visible bounds if need
+void VISU_PipeLine::ComputeVisibleBounds() {
+  if(GetMTime() > myVisibleComputeTime) {
+    VISU::ComputeVisibleBounds(GetMapperHolder()->GetOutput(), myVisibleBounds);
+    myVisibleComputeTime.Modified();
+  }
+}
+
+//----------------------------------------------------------------------------
+void VISU_PipeLine::GetVisibleBounds(double theBounds[6]) {
+  // Compute or get cached bounds
+  ComputeVisibleBounds(); 
+  for (int i=0; i<6; i++) {
+    theBounds[i] = myVisibleBounds[i];
+  }
+}
+
 //----------------------------------------------------------------------------