From: rnv Date: Tue, 30 Nov 2010 15:15:07 +0000 (+0000) Subject: Fix for the bug IPAL21936 bounding box does not account real size of object. X-Git-Tag: mergeto_V6_main_21Mar11~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c9a70a1f160f173d188c72c931471cfd06274a15;p=modules%2Fvisu.git Fix for the bug IPAL21936 bounding box does not account real size of object. --- diff --git a/src/PIPELINE/VISU_PipeLine.cxx b/src/PIPELINE/VISU_PipeLine.cxx index d9809ae5..58820209 100644 --- a/src/PIPELINE/VISU_PipeLine.cxx +++ b/src/PIPELINE/VISU_PipeLine.cxx @@ -52,6 +52,8 @@ VISU_PipeLine myIsFeatureEdgesAllowed(true) { if(MYDEBUG) MESSAGE("VISU_PipeLine::VISU_PipeLine - "<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]; + } +} + //---------------------------------------------------------------------------- diff --git a/src/PIPELINE/VISU_PipeLine.hxx b/src/PIPELINE/VISU_PipeLine.hxx index d2bf38a5..c712e05c 100644 --- a/src/PIPELINE/VISU_PipeLine.hxx +++ b/src/PIPELINE/VISU_PipeLine.hxx @@ -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: //---------------------------------------------------------------------------- diff --git a/src/PIPELINE/VISU_PipeLineUtils.cxx b/src/PIPELINE/VISU_PipeLineUtils.cxx index b048a04c..0219054d 100644 --- a/src/PIPELINE/VISU_PipeLineUtils.cxx +++ b/src/PIPELINE/VISU_PipeLineUtils.cxx @@ -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; + } } diff --git a/src/PIPELINE/VISU_PipeLineUtils.hxx b/src/PIPELINE/VISU_PipeLineUtils.hxx index a6026293..c12718fa 100644 --- a/src/PIPELINE/VISU_PipeLineUtils.hxx +++ b/src/PIPELINE/VISU_PipeLineUtils.hxx @@ -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 diff --git a/src/VISUGUI/VisuGUI_ClippingDlg.cxx b/src/VISUGUI/VisuGUI_ClippingDlg.cxx index bd9c12c6..dc79af7c 100644 --- a/src/VISUGUI/VisuGUI_ClippingDlg.cxx +++ b/src/VISUGUI/VisuGUI_ClippingDlg.cxx @@ -31,6 +31,7 @@ #include "VISU_ColoredPrs3dHolder_i.hh" #include "VISU_PipeLine.hxx" +#include "VISU_PipeLineUtils.hxx" #include "VISU_DataSetActor.h" #include @@ -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]};