Commit a3feef0d authored by David Gobbi's avatar David Gobbi

BUG 12810: Fix for int overflows in volume rendering module

Use vtkIdType for increment calculations in order to avoid 32-bit
overflow in the volume mapper.

Change-Id: Ib1ca8994cee938e7b3b94bdf22c7a3a751a7a462
parent 3a4ef838
......@@ -785,10 +785,10 @@
scalarOpacityTable[c] = mapper->GetScalarOpacityTable(c); \
} \
\
unsigned int inc[3]; \
vtkIdType inc[3]; \
inc[0] = components; \
inc[1] = dim[0]*components; \
inc[2] = dim[0]*dim[1]*components;
inc[1] = inc[0]*dim[0]; \
inc[2] = inc[1]*dim[1];
//ETX
//BTX
......@@ -809,7 +809,7 @@
} \
unsigned char **gradientMag = mapper->GetGradientMagnitude(); \
\
unsigned int mInc[3]; \
vtkIdType mInc[3]; \
if ( vol->GetProperty()->GetIndependentComponents() ) \
{ \
mInc[0] = inc[0]; \
......@@ -819,8 +819,8 @@
else \
{ \
mInc[0] = 1; \
mInc[1] = dim[0]; \
mInc[2] = dim[0]*dim[1]; \
mInc[1] = mInc[0]*dim[0]; \
mInc[2] = mInc[1]*dim[1]; \
}
//ETX
......@@ -834,7 +834,7 @@
specularShadingTable[c] = mapper->GetSpecularShadingTable(c); \
} \
unsigned short **gradientDir = mapper->GetGradientNormal(); \
unsigned int dInc[3]; \
vtkIdType dInc[3]; \
if ( vol->GetProperty()->GetIndependentComponents() ) \
{ \
dInc[0] = inc[0]; \
......@@ -844,25 +844,25 @@
else \
{ \
dInc[0] = 1; \
dInc[1] = dim[0]; \
dInc[2] = dim[0]*dim[1]; \
dInc[1] = dInc[0]*dim[0]; \
dInc[2] = dInc[1]*dim[1]; \
}
//ETX
//BTX
#define VTKKWRCHelper_InitializeTrilinVariables() \
unsigned int Binc = components; \
unsigned int Cinc = dim[0]*components; \
unsigned int Dinc = dim[0]*components + components; \
unsigned int Einc = dim[0]*dim[1]*components; \
unsigned int Finc = dim[0]*dim[1]*components + components; \
unsigned int Ginc = dim[0]*dim[1]*components + dim[0]*components; \
unsigned int Hinc = dim[0]*dim[1]*components + dim[0]*components + components;
#define VTKKWRCHelper_InitializeTrilinVariables() \
vtkIdType Binc = components; \
vtkIdType Cinc = Binc*dim[0]; \
vtkIdType Dinc = Cinc + Binc; \
vtkIdType Einc = Cinc*dim[1]; \
vtkIdType Finc = Einc + Binc; \
vtkIdType Ginc = Einc + Cinc; \
vtkIdType Hinc = Ginc + Binc;
//ETX
//BTX
#define VTKKWRCHelper_InitializeTrilinVariablesGO() \
int magOffset; \
vtkIdType magOffset; \
if ( vol->GetProperty()->GetIndependentComponents() ) \
{ \
magOffset = components; \
......@@ -872,14 +872,14 @@
magOffset = 1; \
} \
\
unsigned int mBFinc = magOffset; \
unsigned int mCGinc = dim[0]*magOffset; \
unsigned int mDHinc = dim[0]*magOffset + magOffset;
vtkIdType mBFinc = magOffset; \
vtkIdType mCGinc = dim[0]*magOffset; \
vtkIdType mDHinc = dim[0]*magOffset + magOffset;
//ETX
//BTX
#define VTKKWRCHelper_InitializeTrilinVariablesShade() \
int dirOffset; \
vtkIdType dirOffset; \
if ( vol->GetProperty()->GetIndependentComponents() ) \
{ \
dirOffset = components; \
......@@ -889,9 +889,9 @@
dirOffset = 1; \
} \
\
unsigned int dBFinc = dirOffset; \
unsigned int dCGinc = dim[0]*dirOffset; \
unsigned int dDHinc = dim[0]*dirOffset + dirOffset;
vtkIdType dBFinc = dirOffset; \
vtkIdType dCGinc = dim[0]*dirOffset; \
vtkIdType dDHinc = dim[0]*dirOffset + dirOffset;
//ETX
//BTX
......@@ -911,7 +911,7 @@
{ \
break; \
} \
imagePtr = image + 4*(j*imageMemorySize[0] + rowBounds[j*2]);
imagePtr = image + 4*(j*imageMemorySize[0] + rowBounds[j*2]);
//ETX
......@@ -961,13 +961,13 @@
oldSPos[1] = 0; \
oldSPos[2] = 0; \
\
unsigned int w1X, w1Y, w1Z; \
unsigned int w2X, w2Y, w2Z; \
unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y; \
unsigned int w1X, w1Y, w1Z; \
unsigned int w2X, w2Y, w2Z; \
unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y; \
\
unsigned short maxValue=0; \
unsigned short val; \
unsigned int A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0;
unsigned int A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0;
//ETX
//BTX
......@@ -979,9 +979,9 @@
oldSPos[1] = 0; \
oldSPos[2] = 0; \
\
unsigned int w1X, w1Y, w1Z; \
unsigned int w2X, w2Y, w2Z; \
unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y; \
unsigned int w1X, w1Y, w1Z; \
unsigned int w2X, w2Y, w2Z; \
unsigned int w1Xw1Y, w2Xw1Y, w1Xw2Y, w2Xw2Y; \
\
unsigned short maxValue[4]; \
unsigned short val[4]; \
......
......@@ -586,30 +586,30 @@ inline void vtkFixedPointVolumeRayCastMapper::ShiftVectorDown( unsigned int in[3
out[0] = in[0] >> VTKKW_FP_SHIFT;
out[1] = in[1] >> VTKKW_FP_SHIFT;
out[2] = in[2] >> VTKKW_FP_SHIFT;
}
}
inline int vtkFixedPointVolumeRayCastMapper::CheckMinMaxVolumeFlag( unsigned int mmpos[3], int c )
{
unsigned int offset =
static_cast<unsigned int>(this->MinMaxVolumeSize[3]) *
( mmpos[2]*static_cast<unsigned int>(
vtkIdType offset =
static_cast<vtkIdType>(this->MinMaxVolumeSize[3]) *
( mmpos[2]*static_cast<vtkIdType>(
this->MinMaxVolumeSize[0]*this->MinMaxVolumeSize[1]) +
mmpos[1]*static_cast<unsigned int>(this->MinMaxVolumeSize[0]) +
mmpos[0] ) + static_cast<unsigned int>(c);
mmpos[1]*static_cast<vtkIdType>(this->MinMaxVolumeSize[0]) +
mmpos[0] ) + static_cast<vtkIdType>(c);
return ((*(this->MinMaxVolume + 3*offset + 2))&0x00ff);
}
inline int vtkFixedPointVolumeRayCastMapper::CheckMIPMinMaxVolumeFlag( unsigned int mmpos[3], int c,
inline int vtkFixedPointVolumeRayCastMapper::CheckMIPMinMaxVolumeFlag( unsigned int mmpos[3], int c,
unsigned short maxIdx, int flip )
{
unsigned int offset =
static_cast<unsigned int>(this->MinMaxVolumeSize[3]) *
( mmpos[2]*static_cast<unsigned int>(
vtkIdType offset =
static_cast<vtkIdType>(this->MinMaxVolumeSize[3]) *
( mmpos[2]*static_cast<vtkIdType>(
this->MinMaxVolumeSize[0]*this->MinMaxVolumeSize[1]) +
mmpos[1]*static_cast<unsigned int>(this->MinMaxVolumeSize[0]) +
mmpos[0] ) + static_cast<unsigned int>(c);
mmpos[1]*static_cast<vtkIdType>(this->MinMaxVolumeSize[0]) +
mmpos[0] ) + static_cast<vtkIdType>(c);
if ( (*(this->MinMaxVolume + 3*offset + 2)&0x00ff) )
{
if (flip)
......@@ -622,7 +622,7 @@ inline int vtkFixedPointVolumeRayCastMapper::CheckMIPMinMaxVolumeFlag( unsigned
}
}
else
{
{
return 0;
}
}
......
......@@ -122,7 +122,7 @@ public:
// generate an output min-max structure given by outExt.
// INTERNAL - Do not use
static void ComputeInputExtentsForOutput( int inExt[6],
unsigned int inDim[3], int outExt[6], vtkImageData *inData );
int inDim[3], int outExt[6], vtkImageData *inData );
// Description:
// Get the first non-zero scalar opacity and gradient opacity indices for
......@@ -150,7 +150,8 @@ public:
// INTERNAL - Do not use
// Compute the offset within an image of whole extents wholeExt, to access
// the data starting at extents ext.
unsigned long ComputeOffset(int ext[6], int wholeExt[6], int nComponents);
vtkIdType ComputeOffset(const int ext[6], const int wholeExt[6],
int nComponents);
//BTX
// This method helps debug. It writes out a specific component of the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment