myIsFeatureEdgesAllowed(true)
{
if(MYDEBUG) MESSAGE("VISU_PipeLine::VISU_PipeLine - "<<this);
+
+ vtkMath::UninitializeBounds(myVisibleBounds);
}
{
GetMapperHolder()->ShallowCopy(thePipeLine->GetMapperHolder(),
theIsCopyInput);
+ for( int i =0 ; i < 6 ; i++)
+ myVisibleBounds[i] = thePipeLine->myVisibleBounds[i];
+
+ myVisibleComputeTime = thePipeLine->myVisibleComputeTime;
}
thePlane->SetNormal(theDir);
vtkFloatingPointType anOrigin[3];
- VISU::DistanceToPosition(GetInput(),
+
+ //Make sure that bounds are calculated
+ ComputeVisibleBounds();
+ VISU::DistanceToPosition(myVisibleBounds,
theDir,
theDist,
anOrigin);
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);
}
}
+//----------------------------------------------------------------------------
+// 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];
+ }
+}
+
//----------------------------------------------------------------------------
class vtkDataSet;
class vtkPointSet;
class vtkImplicitFunction;
+class vtkTimeStamp;
class VISU_MapperHolder;
vtkFloatingPointType& theDist,
vtkPlane* thePlane);
+ void
+ GetVisibleBounds(vtkFloatingPointType theBounds[6]);
+
//----------------------------------------------------------------------------
static
size_t
void
DoShallowCopy(VISU_PipeLine *thePipeLine,
bool theIsCopyInput);
+
+ virtual
+ void
+ ComputeVisibleBounds();
//----------------------------------------------------------------------------
vtkDataSet*
void
SetIsFeatureEdgesAllowed(bool theIsFeatureEdgesAllowed);
+
+ //Visible bounds xmin, xmax, ymin, ymax, zmin, zmax
+ vtkFloatingPointType myVisibleBounds[6];
+ vtkTimeStamp myVisibleComputeTime; // Time at which visible bounds computed
private:
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
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){
//----------------------------------------------------------------------------
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,
//----------------------------------------------------------------------------
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,
vtkFloatingPointType aPrj = vtkMath::Dot(theDirection,thePos);
theDist = (aPrj-aMinBoundPrj)/(aMaxBoundPrj-aMinBoundPrj);
}
-
-
+
//----------------------------------------------------------------------------
bool
IsQuadraticData(vtkDataSet* theDataSet)
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;
+ }
}
//----------------------------------------------------------------------------
void VISU_PIPELINE_EXPORT
- ComputeBoundsParam(vtkDataSet* theDataSet,
+ ComputeBoundsParam(vtkFloatingPointType theBounds[6],
vtkFloatingPointType theDirection[3],
vtkFloatingPointType theMinPnt[3],
vtkFloatingPointType& theMaxBoundPrj,
//----------------------------------------------------------------------------
void VISU_PIPELINE_EXPORT
- DistanceToPosition(vtkDataSet* theDataSet,
+ DistanceToPosition(vtkFloatingPointType theBounds[6],
vtkFloatingPointType theDirection[3],
vtkFloatingPointType theDist,
vtkFloatingPointType thePos[3]);
//----------------------------------------------------------------------------
void VISU_PIPELINE_EXPORT
- PositionToDistance(vtkDataSet* theDataSet,
+ PositionToDistance(vtkFloatingPointType theBounds[6],
vtkFloatingPointType theDirection[3],
vtkFloatingPointType thePos[3],
vtkFloatingPointType& theDist);
//----------------------------------------------------------------------------
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
#include "VISU_ColoredPrs3dHolder_i.hh"
#include "VISU_PipeLine.hxx"
+#include "VISU_PipeLineUtils.hxx"
#include "VISU_DataSetActor.h"
#include <SalomeApp_IntSpinBox.h>
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]};