[vtkusers] getting a blank volume when trying to perform an x-ray projection in Java
Mark Roden
mmroden at gmail.com
Tue Jan 4 16:26:58 EST 2011
I will answer my own question.
The vtkVolumeRayCastMapper requires that the data be unsigned short or
unsigned char. CT data is short, so the following code will work:
//the following function will initialize a ray-cast volume to display.
//the result is stored in the vtkVolume in the class so it can be removed
//when the display is toggled off.
//set these all as new and then null them all in the dispose method,
//to ensure that they are around as long as necessary but
//also that they are cleaned up properly.
vtkVolume mVolumeViewProp = new vtkVolume();
vtkVolumeRayCastCompositeFunction rayCastFunction = new
vtkVolumeRayCastCompositeFunction();
vtkVolumeRayCastMapper rayCastMapper = new vtkVolumeRayCastMapper();
vtkColorTransferFunction volumeColor = new vtkColorTransferFunction();
vtkPiecewiseFunction volumeScalarOpacity = new vtkPiecewiseFunction();
vtkPiecewiseFunction volumeGradientOpacity = new vtkPiecewiseFunction();
vtkVolumeProperty volumeProperty = new vtkVolumeProperty();
vtkImageData theRecastData = new vtkImageData();
private void InitializeRayCasting(){
vtkImageShiftScale theShifter = new vtkImageShiftScale();
theShifter.SetShift(2000);//in case there are values less than
-1000, just
//add 2000 to all volumes and scale accordingly, assuming that
//0 (now 2000) should be properly calibrated for water in HUs.
theShifter.SetOutputScalarTypeToUnsignedShort();
theShifter.SetInput(imageData);
theShifter.Update();
vtkImageData theOutput = theShifter.GetOutput();
theRecastData.DeepCopy(theOutput);
rayCastMapper.SetInput(theRecastData);
rayCastMapper.SetVolumeRayCastFunction(rayCastFunction);
volumeColor.AddRGBPoint(1000, 0.0, 0.0, 0.0);
volumeColor.AddRGBPoint(1400, 1.0, 0.5, 0.3);
volumeColor.AddRGBPoint(1800, 1.0, 0.5, 0.3);
volumeColor.AddRGBPoint(2150, 1.0, 1.0, 0.9);
volumeScalarOpacity.AddPoint(1000, 0.00);
volumeScalarOpacity.AddPoint(1400, 0.05);
volumeScalarOpacity.AddPoint(1800, 0.05);
volumeScalarOpacity.AddPoint(2150, 0.25);//don't want it to be
too opaque,
//then it's impossible to see internal organs
volumeGradientOpacity.AddPoint(0, 0.0);
volumeGradientOpacity.AddPoint(90, 0.5);
volumeGradientOpacity.AddPoint(100, 0.25);
volumeProperty.SetColor(volumeColor);
volumeProperty.SetScalarOpacity(volumeScalarOpacity);
volumeProperty.SetGradientOpacity(volumeGradientOpacity);
volumeProperty.SetInterpolationTypeToLinear();
volumeProperty.ShadeOn();
volumeProperty.SetAmbient(0.1);
volumeProperty.SetDiffuse(0.9);
volumeProperty.SetSpecular(0.2);
mVolumeViewProp.SetMapper(rayCastMapper);
mVolumeViewProp.SetProperty(volumeProperty);
mVolumeViewProp.Update();
}
On Mon, Jan 3, 2011 at 1:09 PM, Mark Roden <mmroden at gmail.com> wrote:
> Hi all,
>
> Happy New Year :)
>
> I'm trying to create an average intensity projection through a CT
> volume using Java and vtk 5.6.1. I have the following function in my
> panel class, with each vtk object defined as a member object just to
> be on the safe side viz garbage collection:
>
> //the following function will initialize a ray-cast volume to display.
> //the result is stored in the vtkVolume in the class so it can be removed
> //when the display is toggled off.
> vtkVolume mVolumeViewProp = new vtkVolume();;
> vtkVolumeRayCastCompositeFunction rayCastFunction = new
> vtkVolumeRayCastCompositeFunction();
> vtkVolumeRayCastMapper rayCastMapper = new vtkVolumeRayCastMapper();
> vtkColorTransferFunction volumeColor = new vtkColorTransferFunction();
> vtkPiecewiseFunction volumeScalarOpacity = new vtkPiecewiseFunction();
> vtkPiecewiseFunction volumeGradientOpacity = new vtkPiecewiseFunction();
> vtkVolumeProperty volumeProperty = new vtkVolumeProperty();
> private void InitializeRayCasting(){
> rayCastMapper.SetInput(imageData);
> rayCastMapper.SetVolumeRayCastFunction(rayCastFunction);
>
> volumeColor.AddRGBPoint(-1000, 0.0, 0.0, 0.0);
> volumeColor.AddRGBPoint(-400, 1.0, 0.5, 0.3);
> volumeColor.AddRGBPoint(300, 1.0, 0.5, 0.3);
> volumeColor.AddRGBPoint(550, 1.0, 1.0, 0.9);
> volumeScalarOpacity.AddPoint(-1000, 0.00);
> volumeScalarOpacity.AddPoint(-400, 0.15);
> volumeScalarOpacity.AddPoint(300, 0.15);
> volumeScalarOpacity.AddPoint(550, 0.85);
> volumeGradientOpacity.AddPoint(0, 0.0);
> volumeGradientOpacity.AddPoint(90, 0.5);
> volumeGradientOpacity.AddPoint(100, 1.0);
> volumeProperty.SetColor(volumeColor);
> volumeProperty.SetScalarOpacity(volumeScalarOpacity);
> volumeProperty.SetGradientOpacity(volumeGradientOpacity);
> volumeProperty.SetInterpolationTypeToLinear();
> volumeProperty.ShadeOn();
> volumeProperty.SetAmbient(0.4);
> volumeProperty.SetDiffuse(0.6);
> volumeProperty.SetSpecular(0.2);
> mVolumeViewProp.SetMapper(rayCastMapper);
> mVolumeViewProp.SetProperty(volumeProperty);
> }
>
> When the user hits the appropriate button, the following code is run
> to initialize the display:
>
> InitializeRayCasting();
> renWin.GetRenderer().AddViewProp(mVolumeViewProp);
> Render();
>
> Right now, the displayed volume is blank. What can I do to track this
> down? This code is the medical sample code, but changing the color
> and opacity defaults there to something I estimate as being closer to
> CT (which ranges in value from -1000 to 3000 in values). I would
> expect something strange looking while I tweak those values, but I
> wouldn't expect complete blankness.
>
> There are other objects that get rendered into this same volume
> (segmentations of organs)-- will the order of the actors matter when
> adding props?
>
> Thanks,
> Mark
>
More information about the vtkusers
mailing list