Salome HOME
Copyright update 2022
[modules/gui.git] / src / VTKViewer / VTKViewer_Utilities.cxx
old mode 100755 (executable)
new mode 100644 (file)
index 67916a8..8fc6451
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  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
@@ -48,7 +48,7 @@ ResetCamera(vtkRenderer* theRenderer,
   int aCount = ComputeVisiblePropBounds(theRenderer,aBounds);
 
   if(theUsingZeroFocalPoint || aCount){
-    static double MIN_DISTANCE = 1.0 / VTK_LARGE_FLOAT;
+    static double MIN_DISTANCE = 1.0 / VTK_FLOAT_MAX;
 
     double aLength = aBounds[1]-aBounds[0];
     aLength = std::max((aBounds[3]-aBounds[2]),aLength);
@@ -109,24 +109,31 @@ int
 ComputeVisiblePropBounds(vtkRenderer* theRenderer, 
                          double theBounds[6])
 {
-  int aCount = 0;
-  
-  theBounds[0] = theBounds[2] = theBounds[4] = VTK_LARGE_FLOAT;
-  theBounds[1] = theBounds[3] = theBounds[5] = -VTK_LARGE_FLOAT;
-  
-  // loop through all props
   VTK::ActorCollectionCopy aCopy(theRenderer->GetActors());
   vtkActorCollection* aCollection = aCopy.GetActors();
-  aCollection->InitTraversal();
-  while (vtkActor* aProp = aCollection->GetNextActor()) {
-    // if it's invisible, or has no geometry, we can skip the rest 
+  return ComputeBounds( aCollection, theBounds );
+}
+
+/*! Compute the bounds of actors*/
+int
+ComputeBounds(vtkActorCollection* theCollection, double theBounds[6])
+{
+  int aCount = 0;
+
+  theBounds[0] = theBounds[2] = theBounds[4] = VTK_FLOAT_MAX;
+  theBounds[1] = theBounds[3] = theBounds[5] = -VTK_FLOAT_MAX;
+
+  // loop through all props
+  theCollection->InitTraversal();
+  while (vtkActor* aProp = theCollection->GetNextActor()) {
+    // if it's invisible, or has no geometry, we can skip the rest
     if(aProp->GetVisibility() && aProp->GetMapper() && vtkMath::AreBoundsInitialized(aProp->GetBounds())){
       if(VTKViewer_Actor* anActor = VTKViewer_Actor::SafeDownCast(aProp))
         if(anActor->IsInfinitive())
           continue;
       double *aBounds = aProp->GetBounds();
-      static double MIN_DISTANCE = 1./VTK_LARGE_FLOAT;
-      static double MAX_DISTANCE = 0.9*VTK_LARGE_FLOAT;
+      static double MIN_DISTANCE = 1./VTK_FLOAT_MAX;
+      static double MAX_DISTANCE = 0.9*VTK_FLOAT_MAX;
 
       if(fabs(aBounds[1] - aBounds[0]) < MIN_DISTANCE) {
         aBounds[0]-=0.001;
@@ -241,8 +248,8 @@ bool IsBBEmpty(vtkRenderer* theRenderer)
     return false;
 
   double aNewBndBox[6];
-  aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_LARGE_FLOAT;
-  aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT;
+  aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_FLOAT_MAX;
+  aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_FLOAT_MAX;
   
   // iterate through displayed objects and set size if necessary
   VTK::ActorCollectionCopy aCopy(theRenderer->GetActors());
@@ -255,9 +262,9 @@ bool IsBBEmpty(vtkRenderer* theRenderer)
       if(anActor->GetVisibility() && !anActor->IsInfinitive())
       {
         double *aBounds = anActor->GetBounds();
-        if(aBounds[0] > -VTK_LARGE_FLOAT && aBounds[1] < VTK_LARGE_FLOAT &&
-           aBounds[2] > -VTK_LARGE_FLOAT && aBounds[3] < VTK_LARGE_FLOAT &&
-           aBounds[4] > -VTK_LARGE_FLOAT && aBounds[5] < VTK_LARGE_FLOAT)
+        if(aBounds[0] > -VTK_FLOAT_MAX && aBounds[1] < VTK_FLOAT_MAX &&
+           aBounds[2] > -VTK_FLOAT_MAX && aBounds[3] < VTK_FLOAT_MAX &&
+           aBounds[4] > -VTK_FLOAT_MAX && aBounds[5] < VTK_FLOAT_MAX)
           isAny = true;
       }
   
@@ -285,8 +292,8 @@ bool ComputeBBCenter(vtkRenderer* theRenderer, double theCenter[3])
     return false;
 
   double aNewBndBox[6];
-  aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_LARGE_FLOAT;
-  aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT;
+  aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_FLOAT_MAX;
+  aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_FLOAT_MAX;
 
   // iterate through displayed objects and set size if necessary
   VTK::ActorCollectionCopy aCopy(theRenderer->GetActors());
@@ -305,9 +312,9 @@ bool ComputeBBCenter(vtkRenderer* theRenderer, double theCenter[3])
        //Ignore invalid bounds
        if(!isBoundValid(aBounds)) continue;
 
-        if(aBounds[0] > -VTK_LARGE_FLOAT && aBounds[1] < VTK_LARGE_FLOAT &&
-           aBounds[2] > -VTK_LARGE_FLOAT && aBounds[3] < VTK_LARGE_FLOAT &&
-           aBounds[4] > -VTK_LARGE_FLOAT && aBounds[5] < VTK_LARGE_FLOAT)
+        if(aBounds[0] > -VTK_FLOAT_MAX && aBounds[1] < VTK_FLOAT_MAX &&
+           aBounds[2] > -VTK_FLOAT_MAX && aBounds[3] < VTK_FLOAT_MAX &&
+           aBounds[4] > -VTK_FLOAT_MAX && aBounds[5] < VTK_FLOAT_MAX)
         {
           for(int i = 0; i < 5; i = i + 2){
             if(aBounds[i] < aNewBndBox[i]) 
@@ -327,11 +334,11 @@ bool ComputeBBCenter(vtkRenderer* theRenderer, double theCenter[3])
     return true;
   }
 
-  if(aNewBndBox[0] > -VTK_LARGE_FLOAT && aNewBndBox[1] < VTK_LARGE_FLOAT &&
-     aNewBndBox[2] > -VTK_LARGE_FLOAT && aNewBndBox[3] < VTK_LARGE_FLOAT &&
-     aNewBndBox[4] > -VTK_LARGE_FLOAT && aNewBndBox[5] < VTK_LARGE_FLOAT)
+  if(aNewBndBox[0] > -VTK_FLOAT_MAX && aNewBndBox[1] < VTK_FLOAT_MAX &&
+     aNewBndBox[2] > -VTK_FLOAT_MAX && aNewBndBox[3] < VTK_FLOAT_MAX &&
+     aNewBndBox[4] > -VTK_FLOAT_MAX && aNewBndBox[5] < VTK_FLOAT_MAX)
   {
-    static double MIN_DISTANCE = 1.0 / VTK_LARGE_FLOAT;
+    static double MIN_DISTANCE = 1.0 / VTK_FLOAT_MAX;
     
     double aLength = aNewBndBox[1]-aNewBndBox[0];
     aLength = std::max((aNewBndBox[3]-aNewBndBox[2]),aLength);
@@ -364,7 +371,7 @@ bool ComputeBBCenter(vtkRenderer* theRenderer, double theCenter[3])
   printf("aCount = %d\n",aCount);
 
   if(aCount){
-    static double MIN_DISTANCE = 1.0 / VTK_LARGE_FLOAT;
+    static double MIN_DISTANCE = 1.0 / VTK_FLOAT_MAX;
 
     double aLength = aBounds[1]-aBounds[0];
     aLength = max((aBounds[3]-aBounds[2]),aLength);