]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Fix for IPAL10048 : Changing rotation point in GUI visualization.
authormkr <mkr@opencascade.com>
Tue, 21 Nov 2006 14:06:47 +0000 (14:06 +0000)
committermkr <mkr@opencascade.com>
Tue, 21 Nov 2006 14:06:47 +0000 (14:06 +0000)
src/VTKViewer/VTKViewer_Utilities.cxx
src/VTKViewer/VTKViewer_Utilities.h
src/VTKViewer/resources/VTKViewer_images.po
src/VTKViewer/resources/view_rotation_point.png [new file with mode: 0755]

index 5f061a64bc52ef94caacb6cac3bc00f9f4a64045..b436045ed11d0712594436a090e800ad86c6184a 100755 (executable)
@@ -20,6 +20,8 @@
 #include "VTKViewer_Utilities.h"
 #include "VTKViewer_Actor.h"
 
+//#include "SALOME_Actor.h"
+
 #include <algorithm>
 
 // VTK Includes
@@ -214,3 +216,138 @@ ComputeTrihedronSize( vtkRenderer* theRenderer,
   return fabs( theNewSize - theSize) > theSize * EPS_SIZE ||
          fabs( theNewSize-theSize ) > theNewSize * EPS_SIZE;
 }
+
+bool IsBBEmpty(vtkRenderer* theRenderer)
+{
+  if(!theRenderer)
+    return false;
+
+  vtkFloatingPointType aNewBndBox[6];
+  aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_LARGE_FLOAT;
+  aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT;
+  
+  // iterate through displayed objects and set size if necessary
+  vtkActorCollection* anActors = theRenderer->GetActors();
+  anActors->InitTraversal();
+  bool isAny = false;
+  while(vtkActor* anAct = anActors->GetNextActor())
+    //if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(anAct))
+    if(VTKViewer_Actor* anActor = VTKViewer_Actor::SafeDownCast(anAct))
+      if(anActor->GetVisibility() && !anActor->IsInfinitive())
+      {
+       vtkFloatingPointType *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)
+         isAny = true;
+      }
+  
+  return !isAny;
+}
+
+bool ComputeBBCenter(vtkRenderer* theRenderer, vtkFloatingPointType theCenter[3])
+{  
+  theCenter[0] = theCenter[1] = theCenter[2] = 0.0;
+  
+  if(!theRenderer)
+    return false;
+
+  vtkFloatingPointType aNewBndBox[6];
+  aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_LARGE_FLOAT;
+  aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT;
+
+  // iterate through displayed objects and set size if necessary
+  vtkActorCollection* anActors = theRenderer->GetActors();
+  anActors->InitTraversal();
+  bool isAny = false;
+  while(vtkActor* anAct = anActors->GetNextActor())
+  {
+    //if(SALOME_Actor* anActor = dynamic_cast<SALOME_Actor*>(anAct))
+    if(VTKViewer_Actor* anActor = VTKViewer_Actor::SafeDownCast(anAct))
+    {
+      if(anActor->GetVisibility() && !anActor->IsInfinitive())
+      {
+       vtkFloatingPointType *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)
+       {
+         for(int i = 0; i < 5; i = i + 2){
+           if(aBounds[i] < aNewBndBox[i]) 
+             aNewBndBox[i] = aBounds[i];
+           if(aBounds[i+1] > aNewBndBox[i+1]) 
+             aNewBndBox[i+1] = aBounds[i+1];
+         }
+         isAny = true;
+       }
+      }
+    }
+  }
+  
+  if ( !isAny )
+  {
+    // null bounding box => the center is (0,0,0)
+    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)
+  {
+    static vtkFloatingPointType MIN_DISTANCE = 1.0 / VTK_LARGE_FLOAT;
+    
+    vtkFloatingPointType aLength = aNewBndBox[1]-aNewBndBox[0];
+    aLength = max((aNewBndBox[3]-aNewBndBox[2]),aLength);
+    aLength = max((aNewBndBox[5]-aNewBndBox[4]),aLength);
+    
+    if(aLength < MIN_DISTANCE)
+      return false;
+
+    vtkFloatingPointType aWidth = 
+      sqrt((aNewBndBox[1]-aNewBndBox[0])*(aNewBndBox[1]-aNewBndBox[0]) +
+          (aNewBndBox[3]-aNewBndBox[2])*(aNewBndBox[3]-aNewBndBox[2]) +
+          (aNewBndBox[5]-aNewBndBox[4])*(aNewBndBox[5]-aNewBndBox[4]));
+    
+    if(aWidth < MIN_DISTANCE)
+      return false;
+
+    theCenter[0] = (aNewBndBox[0] + aNewBndBox[1])/2.0;
+    theCenter[1] = (aNewBndBox[2] + aNewBndBox[3])/2.0;
+    theCenter[2] = (aNewBndBox[4] + aNewBndBox[5])/2.0;
+    return true;
+  }
+
+  return false;
+
+  /*
+  vtkFloatingPointType aBounds[6];
+  int aCount = ComputeVisiblePropBounds(theRenderer,aBounds);
+  printf("aNewBndBox[0] = %f, aNewBndBox[1] = %f,\naNewBndBox[2] = %f, aNewBndBox[3] = %f,\naNewBndBox[4] = %f, aNewBndBox[5] = %f\n",
+          aBounds[0],aBounds[1],aBounds[2],aBounds[3],aBounds[4],aBounds[5]);
+  printf("aCount = %d\n",aCount);
+
+  if(aCount){
+    static vtkFloatingPointType MIN_DISTANCE = 1.0 / VTK_LARGE_FLOAT;
+
+    vtkFloatingPointType aLength = aBounds[1]-aBounds[0];
+    aLength = max((aBounds[3]-aBounds[2]),aLength);
+    aLength = max((aBounds[5]-aBounds[4]),aLength);
+    
+    if(aLength < MIN_DISTANCE)
+      return false;
+
+    vtkFloatingPointType aWidth = 
+      sqrt((aBounds[1]-aBounds[0])*(aBounds[1]-aBounds[0]) +
+          (aBounds[3]-aBounds[2])*(aBounds[3]-aBounds[2]) +
+          (aBounds[5]-aBounds[4])*(aBounds[5]-aBounds[4]));
+    
+    if(aWidth < MIN_DISTANCE)
+      return false;
+
+    theCenter[0] = (aBounds[0] + aBounds[1])/2.0;
+    theCenter[1] = (aBounds[2] + aBounds[3])/2.0;
+    theCenter[2] = (aBounds[4] + aBounds[5])/2.0;
+    return true;
+  }
+  return false;*/
+}
index 7ef9cc550c63e20bf47310a7d1eda3b28fb76d4b..f9bd70e0f628a9ad086651a73651d5b95de749ba 100755 (executable)
@@ -47,4 +47,11 @@ ComputeTrihedronSize(vtkRenderer* theRenderer,
                     const vtkFloatingPointType theSize, 
                     const vtkFloatingPointType theSizeInPercents);
 
+VTKVIEWER_EXPORT
+extern
+bool IsBBEmpty(vtkRenderer* theRenderer);
+VTKVIEWER_EXPORT
+extern
+bool ComputeBBCenter(vtkRenderer* theRenderer, 
+                    vtkFloatingPointType theCenter[3]);
 #endif
index 0f618ddc518502fb6aed4e1ee2600219d2ff6aab..895766a66b88557fee5d72bb1ca04f5bc1950cf4 100755 (executable)
@@ -62,6 +62,9 @@ msgstr "view_reset.png"
 msgid "ICON_VTKVIEWER_VIEW_RIGHT"
 msgstr "view_right.png"
 
+msgid "ICON_VTKVIEWER_VIEW_ROTATION_POINT"
+msgstr "view_rotation_point.png"
+
 msgid "ICON_VTKVIEWER_VIEW_ROTATE"
 msgstr "view_rotate.png"
 
diff --git a/src/VTKViewer/resources/view_rotation_point.png b/src/VTKViewer/resources/view_rotation_point.png
new file mode 100755 (executable)
index 0000000..59f5931
Binary files /dev/null and b/src/VTKViewer/resources/view_rotation_point.png differ