]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Fix for the bug IPAL21936 bounding box does not account real size of object.
authorrnv <rnv@opencascade.com>
Tue, 30 Nov 2010 15:15:07 +0000 (15:15 +0000)
committerrnv <rnv@opencascade.com>
Tue, 30 Nov 2010 15:15:07 +0000 (15:15 +0000)
src/PIPELINE/VISU_PipeLine.cxx
src/PIPELINE/VISU_PipeLine.hxx
src/PIPELINE/VISU_PipeLineUtils.cxx
src/PIPELINE/VISU_PipeLineUtils.hxx
src/VISUGUI/VisuGUI_ClippingDlg.cxx

index d9809ae56cc51d9d4114c25bd9885ddd1fe11bb1..58820209514a39709f2383f24c1b31ab2285ca65 100644 (file)
@@ -52,6 +52,8 @@ VISU_PipeLine
   myIsFeatureEdgesAllowed(true)
 {
   if(MYDEBUG) MESSAGE("VISU_PipeLine::VISU_PipeLine - "<<this);
+  
+  vtkMath::UninitializeBounds(myVisibleBounds);
 }
 
 
@@ -111,6 +113,10 @@ VISU_PipeLine
 {
   GetMapperHolder()->ShallowCopy(thePipeLine->GetMapperHolder(),
                                  theIsCopyInput);
+  for( int i =0 ; i < 6 ; i++)
+    myVisibleBounds[i] = thePipeLine->myVisibleBounds[i];
+  
+  myVisibleComputeTime = thePipeLine->myVisibleComputeTime;
 }
 
 
@@ -394,7 +400,10 @@ VISU_PipeLine
   thePlane->SetNormal(theDir);
 
   vtkFloatingPointType anOrigin[3];
-  VISU::DistanceToPosition(GetInput(),
+
+  //Make sure that bounds are calculated
+  ComputeVisibleBounds();
+  VISU::DistanceToPosition(myVisibleBounds,
                            theDir,
                            theDist,
                            anOrigin);
@@ -411,14 +420,16 @@ VISU_PipeLine
                 vtkPlane* thePlane)
 {
   thePlane->GetNormal(theDir);
-
+  
   vtkFloatingPointType anOrigin[3];
   thePlane->GetOrigin(anOrigin);
-
-  VISU::PositionToDistance(GetInput(),
-                             theDir,
-                             anOrigin,
-                             theDist);
+  
+  //Make sure that bounds are calculated
+  ComputeVisibleBounds();
+  VISU::PositionToDistance(myVisibleBounds,
+                          theDir,
+                          anOrigin,
+                          theDist);
 }
 
 
@@ -465,4 +476,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(vtkFloatingPointType theBounds[6]) {
+  // Compute or get cached bounds
+  ComputeVisibleBounds(); 
+  for (int i=0; i<6; i++) {
+    theBounds[i] = myVisibleBounds[i];
+  }
+}
+
 //----------------------------------------------------------------------------
index d2bf38a5a069db9e51c1f5a3b82055ac9088c7f0..c712e05c67b9af686d95db23a18e25a10e460886 100644 (file)
@@ -40,6 +40,7 @@ class vtkMapper;
 class vtkDataSet;
 class vtkPointSet;
 class vtkImplicitFunction;
+class vtkTimeStamp;
 
 class VISU_MapperHolder;
 
@@ -179,6 +180,9 @@ public:
                 vtkFloatingPointType& theDist, 
                 vtkPlane* thePlane);
 
+  void                
+  GetVisibleBounds(vtkFloatingPointType theBounds[6]);
+
   //----------------------------------------------------------------------------
   static
   size_t
@@ -209,6 +213,10 @@ protected:
   void
   DoShallowCopy(VISU_PipeLine *thePipeLine,
                 bool theIsCopyInput);
+                
+  virtual
+  void
+  ComputeVisibleBounds();
 
   //----------------------------------------------------------------------------
   vtkDataSet* 
@@ -219,6 +227,10 @@ protected:
 
   void 
   SetIsFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed);
+  
+  //Visible bounds xmin, xmax, ymin, ymax, zmin, zmax
+  vtkFloatingPointType myVisibleBounds[6];
+  vtkTimeStamp myVisibleComputeTime;       // Time at which visible bounds computed
 
 private:
   //----------------------------------------------------------------------------
index b048a04c4c470fc3fc5512e5417dfe2356671670..0219054d2aa7a5ef856d31835981cf24f991e84a 100644 (file)
@@ -162,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){
@@ -211,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,
@@ -231,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,
@@ -245,8 +246,7 @@ namespace VISU
     vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
     theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
   }
-
-
+  
   //----------------------------------------------------------------------------
   bool
   IsQuadraticData(vtkDataSet* theDataSet)
@@ -258,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;
+  }
 }
index a6026293af0bef7a6a13515413458e9b160e35d0..c12718fa578e05db25f245f9cf898c372fe9f57e 100644 (file)
@@ -127,7 +127,7 @@ namespace VISU
 
   //----------------------------------------------------------------------------
   void VISU_PIPELINE_EXPORT
-  ComputeBoundsParam(vtkDataSet* theDataSet,
+  ComputeBoundsParam(vtkFloatingPointType theBounds[6],
                      vtkFloatingPointType theDirection[3], 
                      vtkFloatingPointType theMinPnt[3],
                      vtkFloatingPointType& theMaxBoundPrj, 
@@ -136,7 +136,7 @@ namespace VISU
 
   //----------------------------------------------------------------------------
   void VISU_PIPELINE_EXPORT
-  DistanceToPosition(vtkDataSet* theDataSet,
+  DistanceToPosition(vtkFloatingPointType theBounds[6],
                      vtkFloatingPointType theDirection[3], 
                      vtkFloatingPointType theDist, 
                      vtkFloatingPointType thePos[3]);
@@ -144,7 +144,7 @@ namespace VISU
 
   //----------------------------------------------------------------------------
   void VISU_PIPELINE_EXPORT
-  PositionToDistance(vtkDataSet* theDataSet,
+  PositionToDistance(vtkFloatingPointType theBounds[6],
                      vtkFloatingPointType theDirection[3], 
                      vtkFloatingPointType thePos[3], 
                      vtkFloatingPointType& theDist);
@@ -153,6 +153,20 @@ namespace VISU
   //----------------------------------------------------------------------------
   bool VISU_PIPELINE_EXPORT
   IsQuadraticData(vtkDataSet* theDataSet);
+
+  //----------------------------------------------------------------------------
+  void VISU_PIPELINE_EXPORT
+  ComputeVisibleBounds(vtkDataSet* theDataSet,
+                       vtkFloatingPointType theBounds[6]);
+
+  //----------------------------------------------------------------------------
+  void VISU_PIPELINE_EXPORT
+  ComputeBoxCenter(vtkFloatingPointType theBounds[6], vtkFloatingPointType theCenter[3]);
+
+  //----------------------------------------------------------------------------
+  double VISU_PIPELINE_EXPORT
+  ComputeBoxDiagonal(vtkFloatingPointType theBounds[6]);
+
 }
 
 #endif
index bd9c12c67bb1d13d66e33386c4359a6273593595..dc79af7c4dbeb8330f125d816c3b5868ed83dafa 100644 (file)
@@ -31,6 +31,7 @@
 #include "VISU_ColoredPrs3dHolder_i.hh"
 
 #include "VISU_PipeLine.hxx"
+#include "VISU_PipeLineUtils.hxx"
 #include "VISU_DataSetActor.h"
 
 #include <SalomeApp_IntSpinBox.h>
@@ -948,16 +949,23 @@ void VisuGUI_ClippingDlg::SetCurrentPlaneParam()
 
   myPrs3d->SetPlaneParam(aNormal, 1. - getDistance(), aPlane);
 
-  vtkDataSet* aDataSet = myPrs3d->GetInput();
-  vtkFloatingPointType *aPnt = aDataSet->GetCenter();
+  //Get bounds of the visible part of the dataset
+  vtkFloatingPointType aBounds[6];
+  myPrs3d->GetPipeLine()->GetVisibleBounds(aBounds);
 
-  vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
-  vtkFloatingPointType aDel = aDataSet->GetLength()/2.0;
+  //Get center 
+  vtkFloatingPointType aPnt[3];
+  VISU::ComputeBoxCenter(aBounds,aPnt);
 
+  vtkFloatingPointType* anOrigin = aPlane->GetOrigin();
+  
+  //Get Length of the diagonal
+  vtkFloatingPointType aDel = VISU::ComputeBoxDiagonal(aBounds)/2.0;
+  
   vtkFloatingPointType aDelta[2][3] = {{aDir[0][0]*aDel, aDir[0][1]*aDel, aDir[0][2]*aDel},
                                        {aDir[1][0]*aDel, aDir[1][1]*aDel, aDir[1][2]*aDel}};
   vtkFloatingPointType aParam, aPnt0[3], aPnt1[3], aPnt2[3];
-
+  
   vtkFloatingPointType aPnt01[3] = {aPnt[0] - aDelta[0][0] - aDelta[1][0],
                                     aPnt[1] - aDelta[0][1] - aDelta[1][1],
                                     aPnt[2] - aDelta[0][2] - aDelta[1][2]};