Commit a3fd9cfe authored by Utkarsh Ayachit's avatar Utkarsh Ayachit Committed by Kitware Robot
Browse files

Merge subbranch 'pv-master'

916700f5 Merge topic 'FixingTextureVolumeMapper' into pv-master
b8bb136f BUG:Fixed a problem with volume rendering with non-active scalars
da1de9a0 BUG:Fixed crash due to internal mappers not finding the correct scalars
3175ffa3 BUG:Removed the assumption of Active Scalars
parents e9cfaa14 916700f5
......@@ -1210,7 +1210,7 @@ void vtkImageData::SetNumberOfScalarComponents(int num)
vtkErrorMacro("SetNumberOfScalarComponents called with no "
"executive producing this image data object.");
}
this->ComputeIncrements();
this->ComputeIncrements(num);
}
//----------------------------------------------------------------------------
......@@ -1239,6 +1239,16 @@ vtkIdType *vtkImageData::GetIncrements()
return this->Increments;
}
//----------------------------------------------------------------------------
vtkIdType *vtkImageData::GetIncrements(vtkDataArray *scalars)
{
// Make sure the increments are up to date. The filter bypass and update
// mechanism make it tricky to update the increments anywhere other than here
this->ComputeIncrements(scalars);
return this->Increments;
}
//----------------------------------------------------------------------------
void vtkImageData::GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ)
{
......@@ -1249,6 +1259,17 @@ void vtkImageData::GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &in
incZ = inc[2];
}
//----------------------------------------------------------------------------
void vtkImageData::GetIncrements(vtkDataArray *scalars,
vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ)
{
vtkIdType inc[3];
this->ComputeIncrements(scalars, inc);
incX = inc[0];
incY = inc[1];
incZ = inc[2];
}
//----------------------------------------------------------------------------
void vtkImageData::GetIncrements(vtkIdType inc[3])
{
......@@ -1256,9 +1277,24 @@ void vtkImageData::GetIncrements(vtkIdType inc[3])
}
//----------------------------------------------------------------------------
void vtkImageData::GetIncrements(vtkDataArray *scalars, vtkIdType inc[3])
{
this->ComputeIncrements(inc);
}
//----------------------------------------------------------------------------
void vtkImageData::GetContinuousIncrements(int extent[6], vtkIdType &incX,
vtkIdType &incY, vtkIdType &incZ)
{
this->GetContinuousIncrements(this->GetPointData()->GetScalars(),
extent, incX, incY, incZ);
}
//----------------------------------------------------------------------------
void vtkImageData::GetContinuousIncrements(vtkDataArray *scalars,
int extent[6], vtkIdType &incX,
vtkIdType &incY, vtkIdType &incZ)
{
int e0, e1, e2, e3;
......@@ -1288,7 +1324,7 @@ void vtkImageData::GetContinuousIncrements(int extent[6], vtkIdType &incX,
// Make sure the increments are up to date
vtkIdType inc[3];
this->ComputeIncrements(inc);
this->ComputeIncrements(scalars, inc);
incY = inc[1] - (e1 - e0 + 1)*inc[0];
incZ = inc[2] - (e3 - e2 + 1)*inc[1];
......@@ -1297,15 +1333,32 @@ void vtkImageData::GetContinuousIncrements(int extent[6], vtkIdType &incX,
//----------------------------------------------------------------------------
// This method computes the increments from the MemoryOrder and the extent.
// This version assumes we are using the Active Scalars
void vtkImageData::ComputeIncrements(vtkIdType inc[3])
{
int idx;
// make sure we have data before computing incrments to traverse it
if (!this->GetPointData()->GetScalars())
this->ComputeIncrements(this->GetPointData()->GetScalars(), inc);
}
//----------------------------------------------------------------------------
// This method computes the increments from the MemoryOrder and the extent.
void vtkImageData::ComputeIncrements(vtkDataArray *scalars, vtkIdType inc[3])
{
if (!scalars)
{
return;
vtkErrorMacro("No Scalar Field has been specified - assuming 1 component!");
this->ComputeIncrements(1, inc);
}
else
{
this->ComputeIncrements(scalars->GetNumberOfComponents(), inc);
}
vtkIdType incr = this->GetPointData()->GetScalars()->GetNumberOfComponents();
}
//----------------------------------------------------------------------------
// This method computes the increments from the MemoryOrder and the extent.
void vtkImageData::ComputeIncrements(int numberOfComponents, vtkIdType inc[3])
{
int idx;
vtkIdType incr = numberOfComponents;
const int* extent = this->Extent;
for (idx = 0; idx < 3; ++idx)
......
......@@ -189,10 +189,15 @@ public:
// Description:
// Different ways to get the increments for moving around the data.
// GetIncrements() calls ComputeIncrements() to ensure the increments are
// up to date.
// up to date. The first three methods compute the increments based on the
// active scalar field while the next three, the scalar field is passed in.
virtual vtkIdType *GetIncrements();
virtual void GetIncrements(vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
virtual void GetIncrements(vtkIdType inc[3]);
virtual vtkIdType *GetIncrements(vtkDataArray *scalars);
virtual void GetIncrements(vtkDataArray *scalars,
vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
virtual void GetIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
// Description:
// Different ways to get the increments for moving around the data.
......@@ -204,8 +209,12 @@ public:
// over Z, Y, X, C, incrementing the pointer by 1 after each
// component. When the end of the component is reached, the pointer
// is set to the beginning of the next pixel, thus incX is properly set to 0.
// The first form of GetContinuousIncrements uses the active scalar field
// while the second form allows the scalar array to be passed in.
virtual void GetContinuousIncrements(
int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
virtual void GetContinuousIncrements(vtkDataArray *scalars,
int extent[6], vtkIdType &incX, vtkIdType &incY, vtkIdType &incZ);
// Description:
// Access the native pointer for the scalar data
......@@ -376,8 +385,19 @@ protected:
int Extent[6];
// The first method assumes Active Scalars
void ComputeIncrements();
// This one is given the number of components of the
// scalar field explicitly
void ComputeIncrements(int numberOfComponents);
void ComputeIncrements(vtkDataArray *scalars);
// The first method assumes Acitive Scalars
void ComputeIncrements(vtkIdType inc[3]);
// This one is given the number of components of the
// scalar field explicitly
void ComputeIncrements(int numberOfComponents, vtkIdType inc[3]);
void ComputeIncrements(vtkDataArray *scalars, vtkIdType inc[3]);
void CopyOriginAndSpacingFromPipeline();
vtkTimeStamp ExtentComputeTime;
......@@ -412,6 +432,18 @@ inline void vtkImageData::ComputeIncrements()
this->ComputeIncrements(this->Increments);
}
//----------------------------------------------------------------------------
inline void vtkImageData::ComputeIncrements(int numberOfComponents)
{
this->ComputeIncrements(numberOfComponents, this->Increments);
}
//----------------------------------------------------------------------------
inline void vtkImageData::ComputeIncrements(vtkDataArray *scalars)
{
this->ComputeIncrements(scalars, this->Increments);
}
//----------------------------------------------------------------------------
inline void vtkImageData::GetPoint(vtkIdType id, double x[3])
{
......
......@@ -375,6 +375,15 @@ void vtkSmartVolumeMapper::ComputeRenderMode(vtkRenderer *ren, vtkVolume *vol)
{
// We are rendering with the vtkFixedPointVolumeRayCastMapper
case vtkSmartVolumeMapper::RayCastRenderMode:
if (this->ArrayAccessMode == VTK_GET_ARRAY_BY_NAME)
{
this->RayCastMapper->SelectScalarArray(this->ArrayName);
}
else if (this->ArrayAccessMode == VTK_GET_ARRAY_BY_ID)
{
this->RayCastMapper->SelectScalarArray(this->ArrayId);
}
this->RayCastMapper->SetScalarMode(this->GetScalarMode());
this->ConnectMapperInput(this->RayCastMapper);
this->RayCastMapper->SetClippingPlanes(this->GetClippingPlanes());
this->RayCastMapper->SetCropping(this->GetCropping());
......@@ -389,6 +398,15 @@ void vtkSmartVolumeMapper::ComputeRenderMode(vtkRenderer *ren, vtkVolume *vol)
// We are rendering with the vtkVolumeTextureMapper3D
case vtkSmartVolumeMapper::TextureRenderMode:
if (this->ArrayAccessMode == VTK_GET_ARRAY_BY_NAME)
{
this->TextureMapper->SelectScalarArray(this->ArrayName);
}
else if (this->ArrayAccessMode == VTK_GET_ARRAY_BY_ID)
{
this->TextureMapper->SelectScalarArray(this->ArrayId);
}
this->TextureMapper->SetScalarMode(this->GetScalarMode());
this->ConnectMapperInput(this->TextureMapper);
if ( this->RequestedRenderMode == vtkSmartVolumeMapper::DefaultRenderMode ||
this->RequestedRenderMode == vtkSmartVolumeMapper::RayCastAndTextureRenderMode )
......@@ -410,6 +428,15 @@ void vtkSmartVolumeMapper::ComputeRenderMode(vtkRenderer *ren, vtkVolume *vol)
// We are rendering with the vtkGPUVolumeRayCastMapper
case vtkSmartVolumeMapper::GPURenderMode:
if (this->ArrayAccessMode == VTK_GET_ARRAY_BY_NAME)
{
this->GPUMapper->SelectScalarArray(this->ArrayName);
}
else if (this->ArrayAccessMode == VTK_GET_ARRAY_BY_ID)
{
this->GPUMapper->SelectScalarArray(this->ArrayId);
}
this->GPUMapper->SetScalarMode(this->GetScalarMode());
this->GPUMapper->SetMaxMemoryInBytes(this->MaxMemoryInBytes);
this->GPUMapper->SetMaxMemoryFraction(this->MaxMemoryFraction);
this->GPUMapper->SetSampleDistance(
......
......@@ -143,8 +143,10 @@ void vtkVolumeRayCastSpaceLeapingImageFilter
//----------------------------------------------------------------------------
void
vtkVolumeRayCastSpaceLeapingImageFilterClearOutput(
vtkImageData *outData, int outExt[6], unsigned int nComponents )
vtkVolumeRayCastSpaceLeapingImageFilterClearOutput(vtkDataArray *scalars,
vtkImageData *outData,
int outExt[6],
unsigned int nComponents )
{
unsigned short *tmpPtr = static_cast< unsigned short * >(
outData->GetScalarPointerForExtent(outExt));
......@@ -152,7 +154,8 @@ vtkVolumeRayCastSpaceLeapingImageFilterClearOutput(
// Get increments to march through the thread's output extents
vtkIdType outInc0, outInc1, outInc2;
outData->GetContinuousIncrements(outExt, outInc0, outInc1, outInc2);
outData->GetContinuousIncrements(scalars,
outExt, outInc0, outInc1, outInc2);
// A. Initialize the arrays with a blank flag.
......@@ -243,7 +246,8 @@ vtkVolumeRayCastSpaceLeapingImageFilterMinMaxExecute(
// B.2 Get increments to march through the input extents
vtkIdType inInc0, inInc1, inInc2;
inData->GetContinuousIncrements(inExt, inInc0, inInc1, inInc2);
inData->GetContinuousIncrements(scalars,
inExt, inInc0, inInc1, inInc2);
// Get increments to march through the output extents
......@@ -394,7 +398,8 @@ vtkVolumeRayCastSpaceLeapingImageFilterMaxGradientMagnitudeExecute(
// B.2 Get increments to march through the input extents
vtkIdType inInc0, inInc1, inInc2;
inData->GetContinuousIncrements(inExt, inInc0, inInc1, inInc2);
inData->GetContinuousIncrements(self->GetCurrentScalars(),
inExt, inInc0, inInc1, inInc2);
// Get increments to march through the output extents
......@@ -543,7 +548,8 @@ vtkVolumeRayCastSpaceLeapingImageFilterMinMaxAndMaxGradientMagnitudeExecute(
// B.2 Get increments to march through the input extents
vtkIdType inInc0, inInc1, inInc2;
inData->GetContinuousIncrements(inExt, inInc0, inInc1, inInc2);
inData->GetContinuousIncrements(scalars,
inExt, inInc0, inInc1, inInc2);
// Get increments to march through the output extents
......@@ -682,7 +688,8 @@ void vtkVolumeRayCastSpaceLeapingImageFilter
// Get increments to march through the output
vtkIdType outInc0, outInc1, outInc2;
outData->GetContinuousIncrements(outExt, outInc0, outInc1, outInc2);
outData->GetContinuousIncrements(this->CurrentScalars,
outExt, outInc0, outInc1, outInc2);
// Now process the flags
......@@ -769,7 +776,8 @@ void vtkVolumeRayCastSpaceLeapingImageFilter
// Get increments to march through the output
vtkIdType outInc0, outInc1, outInc2;
outData->GetContinuousIncrements(outExt, outInc0, outInc1, outInc2);
outData->GetContinuousIncrements(this->CurrentScalars,
outExt, outInc0, outInc1, outInc2);
// Now process the flags
......@@ -870,8 +878,8 @@ void vtkVolumeRayCastSpaceLeapingImageFilter::ThreadedRequestData(
if (this->ComputeMinMax)
{
vtkVolumeRayCastSpaceLeapingImageFilterClearOutput(
outData[0], outExt, nComponents );
vtkVolumeRayCastSpaceLeapingImageFilterClearOutput(this->CurrentScalars,
outData[0], outExt, nComponents );
}
......
......@@ -81,7 +81,7 @@ void vtkVolumeTextureMapper3DComputeScalars( T *dataPtr,
me->GetVolumeDimensions( outputDimensions );
me->GetVolumeSpacing( outputSpacing );
int components = input->GetNumberOfScalarComponents();
int components = me->GetNumberOfScalarComponents(input);
double wx, wy, wz;
double fx, fy, fz;
......@@ -434,7 +434,7 @@ void vtkVolumeTextureMapper3DComputeGradients( T *dataPtr,
sampleRate[1] = outputSpacing[1] / static_cast<double>(spacing[1]);
sampleRate[2] = outputSpacing[2] / static_cast<double>(spacing[2]);
int components = input->GetNumberOfScalarComponents();
int components = me->GetNumberOfScalarComponents(input);
int dim[3];
input->GetDimensions(dim);
......@@ -1035,8 +1035,26 @@ int vtkVolumeTextureMapper3D::UpdateVolumes(vtkVolume *vtkNotUsed(vol))
// How big does the Volume need to be?
int dim[3];
input->GetDimensions(dim);
int cellFlag;
vtkDataArray *scalarArray = this->GetScalars(input,this->ScalarMode,
this->ArrayAccessMode,
this->ArrayId,
this->ArrayName,
cellFlag);
if (!scalarArray)
{
vtkErrorMacro("No scalars found on input.");
return 0;
}
int components = input->GetNumberOfScalarComponents();
if (cellFlag)
{
vtkErrorMacro("Can not process Cell Data.");
return 0;
}
int components = scalarArray->GetNumberOfComponents();
int powerOfTwoDim[3];
......@@ -1116,7 +1134,7 @@ int vtkVolumeTextureMapper3D::UpdateVolumes(vtkVolume *vtkNotUsed(vol))
// Find the scalar range
double scalarRange[2];
input->GetPointData()->GetScalars()->GetRange(scalarRange, components-1);
scalarArray->GetRange(scalarRange, components-1);
// Is the difference between max and min less than 4096? If so, and if
// the data is not of float or double type, use a simple offset mapping.
......@@ -1129,7 +1147,7 @@ int vtkVolumeTextureMapper3D::UpdateVolumes(vtkVolume *vtkNotUsed(vol))
int arraySizeNeeded;
int scalarType = input->GetScalarType();
int scalarType = scalarArray->GetDataType();
if ( scalarType == VTK_FLOAT ||
scalarType == VTK_DOUBLE ||
......@@ -1165,7 +1183,7 @@ int vtkVolumeTextureMapper3D::UpdateVolumes(vtkVolume *vtkNotUsed(vol))
// Transfer the input volume to the RGBA volume
void *dataPtr = input->GetScalarPointer();
void *dataPtr = scalarArray->GetVoidPointer(0);
switch ( scalarType )
......@@ -1223,7 +1241,7 @@ int vtkVolumeTextureMapper3D::UpdateColorLookup( vtkVolume *vol )
}
// How many components?
int components = input->GetNumberOfScalarComponents();
int components = this->GetNumberOfScalarComponents(input);
// Has the sample distance changed?
if ( this->SavedSampleDistance != this->ActualSampleDistance )
......@@ -1317,7 +1335,18 @@ int vtkVolumeTextureMapper3D::UpdateColorLookup( vtkVolume *vol )
// Find the scalar range
double scalarRange[2];
input->GetPointData()->GetScalars()->GetRange(scalarRange, components-1);
int cellFlag;
vtkDataArray *scalarArray = this->GetScalars(input,this->ScalarMode,
this->ArrayAccessMode,
this->ArrayId,
this->ArrayName,
cellFlag);
if (!scalarArray)
{
vtkErrorMacro("No scalars found on input.");
return 0;
}
scalarArray->GetRange(scalarRange, components-1);
int arraySizeNeeded = this->ColorTableSize;
......@@ -1497,5 +1526,22 @@ void vtkVolumeTextureMapper3D::PrintSelf(ostream& os, vtkIndent indent)
<< endl;
}
//-----------------------------------------------------------------------------
int vtkVolumeTextureMapper3D::GetNumberOfScalarComponents(vtkImageData *input)
{
int cellFlag;
vtkDataArray *scalarArray = this->GetScalars(input,this->ScalarMode,
this->ArrayAccessMode,
this->ArrayId,
this->ArrayName,
cellFlag);
if (!scalarArray)
{
vtkErrorMacro("No scalars found on input.");
return 0;
}
return scalarArray->GetNumberOfComponents();
}
//-----------------------------------------------------------------------------
......@@ -140,6 +140,10 @@ public:
ATI_METHOD=2,
NO_METHOD=3
};
// Description:
// Returns the number of components of the point scalar field
int GetNumberOfScalarComponents(vtkImageData *input);
//ETX
// Description:
......
Supports Markdown
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