[vtkusers] Volume rendering using predefined RGBA data
Maria Axelsson
maria at cb.uu.se
Wed Feb 27 11:11:10 EST 2008
Hello,
I am trying to visualise segmented volume data. The color is used to
represent the local orientation in the neighbourhood of each voxel in
3D. The data is structured points in a grid. The vtkfile I have given a
is an excerpt from** a small 3D image with predefined color values in a
4 x 4 x 4 grid which mimics the actual data I want to visualise.
The output I get in this case is a black cube when I run the example as
below.
I expect to see a cube where each individual voxel, that is not set to
opacity zero, is visible somehow in its given color from the file.
We did an example here at out lab with scalars and a color transfer
function and that works fine and we get colors and everything. My
problem is that orientation in 3D means two parameters and I want to
define the color already in MATLAB before any rendering.
Could you give an example of code that actually does the trick using
color scalars?
What sort of data are you visualising?
We are in doubt that the volume renderer supports the predefined colors
for volume data.
I would like to be proven wrong here.
--
Maria
Mark Wyszomierski wrote:
> Maria, what does your output look like? I render color datasets with
> an opacity transfer function daily, and it works ok. Maybe you can
> explain in more detail what you're expecting to see,
>
> Mark
>
> On Tue, Feb 26, 2008 at 9:06 AM, Maria Axelsson <maria at cb.uu.se> wrote:
>
>> Hi,
>>
>> I am quite new to VTK and have run into some problems regarding volume
>> rendering using predefined colors from segmented data.
>> I would like to specify the color of each voxel in a file (using RGBA)
>> and use the volume renderer to display the resulting image.
>> After reading the manual on this I have come up with the test code
>> below, but the result is not as expected. According to the specification
>> it should be possible to send the given color through the mapper using
>> IndependentComponentsOff(). Does anyone have experience on this? Can we
>> get this example to work so there is at least one example online on this?
>>
>> Best regards,
>> Maria Axelsson
>> PhD Student, Centre for Image Analysis
>>
>>
>> #!/usr/bin/env python
>>
>> import vtk
>>
>> # renderer, render window, and interactor
>> ren = vtk.vtkRenderer()
>> ren.SetBackground(1.0,1.0,1.0)
>> renWin = vtk.vtkRenderWindow()
>> renWin.AddRenderer(ren)
>> renWin.SetSize(400,400)
>> iren = vtk.vtkRenderWindowInteractor()
>> iren.SetRenderWindow(renWin)
>>
>> reader = vtk.vtkStructuredPointsReader()
>> reader.SetFileName("testvol.vtk")
>>
>> # transfer function that maps scalar value to opacity
>> opacityTF = vtk.vtkPiecewiseFunction()
>> opacityTF.AddPoint( 0.0, 0.0 )
>> opacityTF.AddPoint( 1.0, 1.0 )
>> opacityTF.AddPoint( 300.0, 1.0 )
>>
>> # property of the volume (lighting, transfer functions)
>> volprop = vtk.vtkVolumeProperty()
>> volprop.ShadeOn()
>> volprop.SetInterpolationTypeToLinear()
>> volprop.IndependentComponentsOff()
>>
>> # mapper
>> # the composite function is the line integrator
>> compositeFunction = vtk.vtkVolumeRayCastCompositeFunction()
>> compositeFunction.SetCompositeMethodToClassifyFirst()
>> volumeMapper = vtk.vtkVolumeRayCastMapper()
>> volumeMapper.SetVolumeRayCastFunction( compositeFunction )
>> volumeMapper.SetInput( reader.GetOutput() )
>> volumeMapper.SetSampleDistance(.5)
>>
>> # volume is a specialized actor
>> volume = vtk.vtkVolume()
>> volume.SetMapper(volumeMapper)
>> volume.SetProperty(volprop)
>>
>> # add the actors
>> ren.AddVolume( volume )
>>
>> # render the window
>> renWin.Render()
>>
>> # initialize and start the window interactor
>> iren.Initialize()
>> iren.Start()
>>
>>
>> --- Example of testvol.vtk ---
>>
>> # vtk DataFile Version 3.0
>> vtk output
>> ASCII
>> DATASET STRUCTURED_POINTS
>> DIMENSIONS 4 4 4
>> SPACING 1 1 1
>> ORIGIN 0 0 0
>> CELL_DATA 27
>> POINT_DATA 64
>> COLOR_SCALARS datapoints 4
>> 1.0 0.0 0.0 1.0
>> 1.0 0.0 0.0 1.0
>> 1.0 0.0 0.0 1.0
>> 1.0 0.0 0.0 1.0
>> 1.0 0.0 0.0 1.0
>> 1.0 0.0 0.0 1.0
>> 1.0 0.0 0.0 1.0
>> 1.0 0.0 0.0 1.0
>> 1.0 0.0 0.0 1.0
>> 1.0 0.0 0.0 1.0
>> ...
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>> 0.0 1.0 1.0 1.0
>>
>>
>> _______________________________________________
>> This is the private VTK discussion list.
>> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
>>
>>
More information about the vtkusers
mailing list