Volume Rendering - Using different scalars for opacity and color transfer function

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Volume Rendering - Using different scalars for opacity and color transfer function

Paul
Hello everyone,
 
I have a three dimensional volume (vtkImageData) which is rendered using ray casting (vtkFixedPointVolumeRayCastMapper). I attached an opacity (vtkPiecewiseFunction) and colour transfer function (vtkColorTransferFunction) to it using vtkVolumeProperty.
 
The volume consists of two scalar attributes. I want to map the first scalar attribute of a voxel to opacity and the second attribute of the same voxel to the colour. I'm stuck on figuring out how to do that! At the moment, I create two vtkVolume for rendering each scalar attribute itself. However, the result is not satisfying.

Here is a minimal code example in python to describe the problem:

volume = scaledInput.GetOutput()
 
opacityTF = vtkPiecewiseFunction()
opacityTF.AddPoint(self.minimum, 0.0)
opacityTF.AddPoint(self.maximum, 0.1)
 
# At this point I want to use the scalars which stem from the magnitude field of the vector field
colorTF = vtkColorTransferFunction()
colorTF.AddRGBPoint(self.minimum, 0, 1, 0)
colorTF.AddRGBPoint(self.maximum, 1, 0, 0)
 
volprop = vtkVolumeProperty()
volprop.SetColor(colorTF)
volprop.SetScalarOpacity(opacityTF)
 
compositeFunction = vtkVolumeRayCastCompositeFunction()
volumeMapper = vtkVolumeRayCastMapper()
volumeMapper.AutoAdjustSampleDistancesOn()
volumeMapper.SetVolumeRayCastFunction(compositeFunction)
volumeMapper.SetInput(volume)
 
volumeActor = vtkVolume()
volumeActor.SetMapper(volumeMapper)
volumeActor.SetProperty(volprop)
 
renderer = self.ui.qvtkWidget.GetRenderWindow().GetRenderers().GetFirstRenderer()
renderer.AddVolume(volumeActor)
self.repaint()

Cheers,
Paul
Reply | Threaded
Open this post in threaded view
|

Re: Volume Rendering - Using different scalars for opacity and color transfer function

Taha Ceritli
Hi,

I think you need to use vtkVolumeRayCastFunction instead of vtkVolumeRayCastCompositeFunction as follows:

CastFunction = vtkVolumeRayCastFunction()
volumeMapper.SetVolumeRayCastFunction(CastFunction)

It's not appropriate to send a composite function to raycastcompositefunction. Let me know if it works or not.

Good luck paule :)
Reply | Threaded
Open this post in threaded view
|

Re: Volume Rendering - Using different scalars for opacity and color transfer function

Paul
Hi Taha,

maybe I'll overlooked something, but it is not possible to use vtkVolumeRayCastFunction in the way you suggested, because it is an abstract class.

This produces the error
rayCastFunction = vtkVolumeRayCastFunction()
TypeError: this is an abstract class and cannot be instantiated

Also I'm not sure on how a different composite function would use different scalars for the coloring of the volume.

Thanks,
Paul