Salome HOME
Restore support of med-2.1 in MEDWrapper
[modules/visu.git] / src / PIPELINE / VISU_PipeLineUtils.cxx
index 03c0edc7dbb4c46984fca3a43a6e76e563b17917..0219054d2aa7a5ef856d31835981cf24f991e84a 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2010  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
@@ -19,6 +19,7 @@
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  VISU OBJECT : interactive object for VISU entities implementation
 // File:    VISU_PipeLine.hxx
 // Author:  Alexey PETROV
@@ -161,14 +162,15 @@ namespace VISU
 
   //----------------------------------------------------------------------------
   void
-  ComputeBoundsParam(vtkDataSet* theDataSet,
+  ComputeBoundsParam(vtkFloatingPointType theBounds[6],
                      vtkFloatingPointType theDirection[3], 
                      vtkFloatingPointType theMinPnt[3],
                      vtkFloatingPointType& theMaxBoundPrj, 
                      vtkFloatingPointType& theMinBoundPrj)
   {
     vtkFloatingPointType aBounds[6];
-    theDataSet->GetBounds(aBounds);
+    for(int i = 0; i < 6; i++) 
+      aBounds[i] = theBounds[i];
     
     //Enlarge bounds in order to avoid conflicts of precision
     for(int i = 0; i < 6; i += 2){
@@ -210,13 +212,13 @@ namespace VISU
 
   //----------------------------------------------------------------------------
   void
-  DistanceToPosition(vtkDataSet* theDataSet,
+  DistanceToPosition(vtkFloatingPointType theBounds[6],
                      vtkFloatingPointType theDirection[3], 
                      vtkFloatingPointType theDist, 
                      vtkFloatingPointType thePos[3])
   {
     vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
-    ComputeBoundsParam(theDataSet,
+    ComputeBoundsParam(theBounds,
                        theDirection,
                        aMinPnt,
                        aMaxBoundPrj,
@@ -230,13 +232,13 @@ namespace VISU
 
   //----------------------------------------------------------------------------
   void
-  PositionToDistance(vtkDataSet* theDataSet,
+  PositionToDistance(vtkFloatingPointType theBounds[6],
                      vtkFloatingPointType theDirection[3], 
                      vtkFloatingPointType thePos[3], 
                      vtkFloatingPointType& theDist)
   {
     vtkFloatingPointType aMaxBoundPrj, aMinBoundPrj, aMinPnt[3];
-    ComputeBoundsParam(theDataSet,
+    ComputeBoundsParam(theBounds,
                        theDirection,
                        aMinPnt,
                        aMaxBoundPrj,
@@ -244,8 +246,7 @@ namespace VISU
     vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
     theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
   }
-
-
+  
   //----------------------------------------------------------------------------
   bool
   IsQuadraticData(vtkDataSet* theDataSet)
@@ -257,6 +258,53 @@ namespace VISU
     return false;
   }
 
-
   //----------------------------------------------------------------------------
+  //Compute bounds of the visible part of the dataset
+  void
+  ComputeVisibleBounds(vtkDataSet* theDataSet,  vtkFloatingPointType theBounds[6]) {
+    int nbCells, i, j, minIdx, maxIdx;
+    vtkFloatingPointType cellBounds[6];
+    
+    if( theDataSet && (nbCells = theDataSet->GetNumberOfCells()) ) {
+      theDataSet->GetCellBounds(0,theBounds);
+      for ( i = 1; i < nbCells;  i++ ) {
+       theDataSet->GetCellBounds(i, cellBounds);
+       for ( j = 0; j < 3; j++ ) {
+         minIdx = 2*j;
+         maxIdx = 2*j+1;
+         if ( cellBounds[minIdx] < theBounds[minIdx] ) {
+           theBounds[minIdx] = cellBounds[minIdx];
+         }     
+         if ( cellBounds[maxIdx] > theBounds[maxIdx] ) {
+           theBounds[maxIdx] = cellBounds[maxIdx];
+         }
+       }
+      } 
+    } else {
+      vtkMath::UninitializeBounds(theBounds);
+    }
+  }
+  
+  //----------------------------------------------------------------------------
+  //Compute center of the box, box defined as xmin, xmax, ymin, ymax, zmin, zmax
+  void
+  ComputeBoxCenter(vtkFloatingPointType theBounds[6], vtkFloatingPointType theCenter[3]) {
+    for (int i=0; i<3; i++) {
+      theCenter[i] = (theBounds[2*i+1] + theBounds[2*i]) / 2.0;
+    }
+  }
+  
+  //----------------------------------------------------------------------------
+  //Compute length of the box diagonal, box defined as xmin, xmax, ymin, ymax, zmin, zmax
+  double 
+  ComputeBoxDiagonal(vtkFloatingPointType theBounds[6]) {
+    double diff, len=0.0;
+    int i;
+    for (i=0; i<3; i++) {
+      diff = (double)(theBounds[2*i+1]) - (double)(theBounds[2*i]);
+      len += diff * diff;
+    }
+    diff = sqrt(len);
+    return diff;
+  }
 }