[vtkusers] Volume rendering using predefined RGBA data

Mark Wyszomierski markww at gmail.com
Wed Feb 27 00:07:48 EST 2008


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