Commit 5eb0cf0c authored by Dave DeMarle's avatar Dave DeMarle
Browse files

Merge branch 'fix-int-overflows-in-volume-rendering-rel' into release

Change-Id: I1005acf98e18eaf98593aa0c97b386ef7f04fd04
parents c44bf3a0 49e4f9c8
......@@ -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;
}
}
......
......@@ -50,7 +50,7 @@ vtkVolumeRayCastSpaceLeapingImageFilter::vtkVolumeRayCastSpaceLeapingImageFilter
this->MinNonZeroScalarIndex = NULL;
this->MinNonZeroGradientMagnitudeIndex = NULL;
this->GradientMagnitude = NULL;
for (unsigned int i = 0; i < 4; i++)
for (int i = 0; i < 4; i++)
{
this->TableSize[i] = 0;
this->TableShift[i] = 0;
......@@ -146,7 +146,7 @@ void
vtkVolumeRayCastSpaceLeapingImageFilterClearOutput(vtkDataArray *scalars,
vtkImageData *outData,
int outExt[6],
unsigned int nComponents )
int nComponents )
{
unsigned short *tmpPtr = static_cast< unsigned short * >(
outData->GetScalarPointerForExtent(outExt));
......@@ -160,7 +160,7 @@ vtkVolumeRayCastSpaceLeapingImageFilterClearOutput(vtkDataArray *scalars,
// A. Initialize the arrays with a blank flag.
int i,j,k;
unsigned int c;
int c;
for (k = outExt[4]; k <= outExt[5]; ++k, tmpPtr += outInc2)
{
for (j = outExt[2]; j <= outExt[3]; ++j, tmpPtr += outInc1)
......@@ -180,13 +180,13 @@ vtkVolumeRayCastSpaceLeapingImageFilterClearOutput(vtkDataArray *scalars,
//----------------------------------------------------------------------------
void vtkVolumeRayCastSpaceLeapingImageFilter
::ComputeInputExtentsForOutput( int inExt[6], unsigned int inDim[3],
::ComputeInputExtentsForOutput( int inExt[6], int inDim[3],
int outExt[6], vtkImageData *inData )
{
int inWholeExt[6];
inData->GetExtent(inWholeExt);
for ( unsigned int i = 0; i < 3; i++ )
for ( int i = 0; i < 3; i++ )
{
inExt[2*i] = outExt[2*i] * VTK_SL_BLK + inWholeExt[2*i];
......@@ -224,14 +224,14 @@ vtkVolumeRayCastSpaceLeapingImageFilterMinMaxExecute(
vtkDataArray * scalars = self->GetCurrentScalars();
const int components = scalars->GetNumberOfComponents();
const int independent = self->GetIndependentComponents();
const unsigned int nComponents = (independent) ? components : 1;
const int nComponents = (independent) ? components : 1;
// B. Now fill in the max-min-gradient volume structure
// B.1 First compute the extents of the input that contribute to this structure
int inExt[6], inWholeExt[6];
unsigned int inDim[3];
int inDim[3];
int outWholeDim[3];
vtkVolumeRayCastSpaceLeapingImageFilter::ComputeInputExtentsForOutput(
inExt, inDim, outExt, inData );
......@@ -251,16 +251,16 @@ vtkVolumeRayCastSpaceLeapingImageFilterMinMaxExecute(
// Get increments to march through the output extents
const unsigned long outInc0 = 3*nComponents;
const unsigned long outInc1 = 3*outWholeDim[0]*nComponents;
const unsigned long outInc2 = 3*outWholeDim[0]*outWholeDim[1]*nComponents;
const vtkIdType outInc0 = 3*nComponents;
const vtkIdType outInc1 = outInc0*outWholeDim[0];
const vtkIdType outInc2 = outInc1*outWholeDim[1];
// B.3 Now fill in the min-max volume.
unsigned int i, j, k;
unsigned int c;
unsigned int sx1, sx2, sy1, sy2, sz1, sz2;
unsigned int x, y, z;
int i, j, k;
int c;
int sx1, sx2, sy1, sy2, sz1, sz2;
int x, y, z;
T *dptr = static_cast< T * >(scalars->GetVoidPointer(0));
unsigned short val;
......@@ -275,53 +275,53 @@ vtkVolumeRayCastSpaceLeapingImageFilterMinMaxExecute(
for ( k = 0; k < inDim[2]; k++, dptr += inInc2 )
{
sz1 = (k < 1)?(0):(static_cast<unsigned int>((k-1)/4));
sz2 = static_cast<unsigned int>((k )/4);
sz1 = (k < 1)?(0):((k-1)/4);
sz2 = ((k )/4);
sz2 = ( k == inDim[2]-1 )?(sz1):(sz2);
sz1 += outExt[4];
sz2 += outExt[4];
// Bounds check
if ((int)sz2 > outExt[5])
if (sz2 > outExt[5])
{
sz2 = outExt[5];
}
tmpPtrK = outBasePtr + sz1 * outInc2;
for ( j = 0; j < inDim[1]; j++, dptr+= inInc1 )
{
sy1 = (j < 1)?(0):(static_cast<unsigned int>((j-1)/4));
sy2 = static_cast<unsigned int>((j )/4);
sy1 = (j < 1)?(0):((j-1)/4);
sy2 = ((j )/4);
sy2 = ( j == inDim[1]-1 )?(sy1):(sy2);
sy1 += outExt[2];
sy2 += outExt[2];
// Bounds check
if ((int)sy2 > outExt[3])
if (sy2 > outExt[3])
{
sy2 = outExt[3];
}
tmpPtrJ = tmpPtrK + sy1 * outInc1;
for ( i = 0; i < inDim[0]; i++ )
{
sx1 = (i < 1)?(0):(static_cast<unsigned int>((i-1)/4));
sx2 = static_cast<unsigned int>((i )/4);
sx1 = (i < 1)?(0):((i-1)/4);
sx2 = ((i )/4);
sx2 = ( i == inDim[0]-1 )?(sx1):(sx2);
sx1 += outExt[0];
sx2 += outExt[0];
// Bounds check
if ((int)sx2 > outExt[1])
if (sx2 > outExt[1])
{
sx2 = outExt[1];
}
tmpPtrI = tmpPtrJ + sx1 * outInc0;
for ( c = 0; c < nComponents; c++, tmpPtrI += 3 )
......@@ -374,8 +374,7 @@ vtkVolumeRayCastSpaceLeapingImageFilterMaxGradientMagnitudeExecute(
{
// the number of independent components for which we need to keep track of
// min/max
const unsigned int nComponents = static_cast< unsigned int >(
self->GetNumberOfIndependentComponents());
const int nComponents = self->GetNumberOfIndependentComponents();
// B. Now fill in the max-min-gradient volume structure
......@@ -383,7 +382,7 @@ vtkVolumeRayCastSpaceLeapingImageFilterMaxGradientMagnitudeExecute(
// B.1 First compute the extents of the input that contribute to this structure
int inExt[6], inWholeExt[6];
unsigned int inDim[3];
int inDim[3];
int outWholeDim[3];
vtkVolumeRayCastSpaceLeapingImageFilter::ComputeInputExtentsForOutput(
inExt, inDim, outExt, inData );
......@@ -403,16 +402,16 @@ vtkVolumeRayCastSpaceLeapingImageFilterMaxGradientMagnitudeExecute(
// Get increments to march through the output extents
const unsigned long outInc0 = 3*nComponents;
const unsigned long outInc1 = 3*outWholeDim[0]*nComponents;
const unsigned long outInc2 = 3*outWholeDim[0]*outWholeDim[1]*nComponents;
const vtkIdType outInc0 = 3*nComponents;
const vtkIdType outInc1 = outInc0*outWholeDim[0];
const vtkIdType outInc2 = outInc1*outWholeDim[1];
// B.3 Now fill in the min-max volume.
unsigned int i, j, k;
unsigned int c;
unsigned int sx1, sx2, sy1, sy2, sz1, sz2;
unsigned int x, y, z;
int i, j, k;
int c;
int sx1, sx2, sy1, sy2, sz1, sz2;
int x, y, z;
unsigned char val;
unsigned short *outBasePtr = static_cast< unsigned short * >(
......@@ -429,54 +428,54 @@ vtkVolumeRayCastSpaceLeapingImageFilterMaxGradientMagnitudeExecute(
for ( k = 0; k < inDim[2]; k++, ++gsptr )
{
sz1 = (k < 1)?(0):(static_cast<unsigned int>((k-1)/4));
sz2 = static_cast<unsigned int>((k )/4);
sz1 = (k < 1)?(0):((k-1)/4);
sz2 = ((k )/4);
sz2 = ( k == inDim[2]-1 )?(sz1):(sz2);
sz1 += outExt[4];
sz2 += outExt[4];
// Bounds check
if ((int)sz2 > outExt[5])
if (sz2 > outExt[5])
{
sz2 = outExt[5];
}
tmpPtrK = outBasePtr + sz1 * outInc2;
unsigned char *gptr = *gsptr;
for ( j = 0; j < inDim[1]; j++, gptr+= inInc1 )
{
sy1 = (j < 1)?(0):(static_cast<unsigned int>((j-1)/4));
sy2 = static_cast<unsigned int>((j )/4);
sy1 = (j < 1)?(0):((j-1)/4);
sy2 = ((j )/4);
sy2 = ( j == inDim[1]-1 )?(sy1):(sy2);
sy1 += outExt[2];
sy2 += outExt[2];
// Bounds check
if ((int)sy2 > outExt[3])
if (sy2 > outExt[3])
{
sy2 = outExt[3];
}
tmpPtrJ = tmpPtrK + sy1 * outInc1;
for ( i = 0; i < inDim[0]; i++ )
{
sx1 = (i < 1)?(0):(static_cast<unsigned int>((i-1)/4));
sx2 = static_cast<unsigned int>((i )/4);
sx1 = (i < 1)?(0):((i-1)/4);
sx2 = ((i )/4);
sx2 = ( i == inDim[0]-1 )?(sx1):(sx2);
sx1 += outExt[0];
sx2 += outExt[0];
// Bounds check
if ((int)sx2 > outExt[1])
if (sx2 > outExt[1])
{
sx2 = outExt[1];
}
}
tmpPtrI = tmpPtrJ + sx1 * outInc0;
......@@ -527,13 +526,13 @@ vtkVolumeRayCastSpaceLeapingImageFilterMinMaxAndMaxGradientMagnitudeExecute(
vtkDataArray * scalars = self->GetCurrentScalars();
const int components = scalars->GetNumberOfComponents();
const int independent = self->GetIndependentComponents();
const unsigned int nComponents = (independent) ? components : 1;
const int nComponents = (independent) ? components : 1;
// B.1 First compute the extents of the input that contribute to this structure
int inExt[6], inWholeExt[6];
unsigned int inDim[3];
int inDim[3];
int outWholeDim[3];
vtkVolumeRayCastSpaceLeapingImageFilter::ComputeInputExtentsForOutput(
inExt, inDim, outExt, inData );
......@@ -553,16 +552,16 @@ vtkVolumeRayCastSpaceLeapingImageFilterMinMaxAndMaxGradientMagnitudeExecute(
// Get increments to march through the output extents
const unsigned long outInc0 = 3*nComponents;
const unsigned long outInc1 = 3*outWholeDim[0]*nComponents;
const unsigned long outInc2 = 3*outWholeDim[0]*outWholeDim[1]*nComponents;
const vtkIdType outInc0 = 3*nComponents;
const vtkIdType outInc1 = outInc0*outWholeDim[0];
const vtkIdType outInc2 = outInc1*outWholeDim[1];
// B.3 Now fill in the min-max and gradient max structure
unsigned int i, j, k;
unsigned int c;
unsigned int sx1, sx2, sy1, sy2, sz1, sz2;
unsigned int x, y, z;
int i, j, k;
int c;
int sx1, sx2, sy1, sy2, sz1, sz2;
int x, y, z;
T *dptr = static_cast< T * >(scalars->GetVoidPointer(0));
......@@ -583,55 +582,55 @@ vtkVolumeRayCastSpaceLeapingImageFilterMinMaxAndMaxGradientMagnitudeExecute(
for ( k = 0; k < inDim[2]; k++, dptr += inInc2, ++gsptr )
{
sz1 = (k < 1)?(0):(static_cast<unsigned int>((k-1)/4));
sz2 = static_cast<unsigned int>((k )/4);
sz1 = (k < 1)?(0):((k-1)/4);
sz2 = ((k )/4);
sz2 = ( k == inDim[2]-1 )?(sz1):(sz2);
sz1 += outExt[4];
sz2 += outExt[4];
// Bounds check
if ((int)sz2 > outExt[5])
if (sz2 > outExt[5])
{
sz2 = outExt[5];
}
tmpPtrK = outBasePtr + sz1 * outInc2;
unsigned char *gptr = *gsptr;
for ( j = 0; j < inDim[1]; j++, dptr+= inInc1, gptr+= inInc1 )
{
sy1 = (j < 1)?(0):(static_cast<unsigned int>((j-1)/4));
sy2 = static_cast<unsigned int>((j )/4);
sy1 = (j < 1)?(0):((j-1)/4);
sy2 = ((j )/4);
sy2 = ( j == inDim[1]-1 )?(sy1):(sy2);
sy1 += outExt[2];
sy2 += outExt[2];
// Bounds check
if ((int)sy2 > outExt[3])
if (sy2 > outExt[3])
{
sy2 = outExt[3];
}
tmpPtrJ = tmpPtrK + sy1 * outInc1;
for ( i = 0; i < inDim[0]; i++ )
{
sx1 = (i < 1)?(0):(static_cast<unsigned int>((i-1)/4));
sx2 = static_cast<unsigned int>((i )/4);
sx1 = (i < 1)?(0):((i-1)/4);
sx2 = ((i )/4);
sx2 = ( i == inDim[0]-1 )?(sx1):(sx2);
sx1 += outExt[0];
sx2 += outExt[0];
// Bounds check
if ((int)sx2 > outExt[1])
if (sx2 > outExt[1])
{
sx2 = outExt[1];
}
tmpPtrI = tmpPtrJ + sx1 * outInc0;
for ( c = 0; c < nComponents; c++, tmpPtrI += 3 )
......@@ -871,7 +870,7 @@ void vtkVolumeRayCastSpaceLeapingImageFilter::ThreadedRequestData(
}
const int components = this->GetCurrentScalars()->GetNumberOfComponents();
const unsigned int nComponents = (this->GetIndependentComponents()) ? components : 1;
const int nComponents = (this->GetIndependentComponents()) ? components : 1;
// Clear the output if we are computing the min-max. In other cases, we
// will be re-using the cache. (See the method AllocateOutputData)
......@@ -1145,21 +1144,26 @@ unsigned short * vtkVolumeRayCastSpaceLeapingImageFilter
//----------------------------------------------------------------------------
// Fill in the min-max space leaping information.
unsigned long vtkVolumeRayCastSpaceLeapingImageFilter
::ComputeOffset( int ext[6], int wholeExt[6], int nComponents )
vtkIdType vtkVolumeRayCastSpaceLeapingImageFilter
::ComputeOffset( const int ext[6], const int wholeExt[6], int nComponents )
{
const unsigned int wDim[3] = { wholeExt[1]-wholeExt[0]+1,