#!/usr/bin/env python

import vtk

RAYCAST = 1

r = vtk.vtkStructuredPointsReader()
r.SetFileName('volumeBug.vtk')

vm = None
if RAYCAST:
    cf = vtk.vtkVolumeRayCastCompositeFunction()
    vm = vtk.vtkVolumeRayCastMapper()
    vm.SetVolumeRayCastFunction(cf)
else:
    vm = vtk.vtkVolumeTextureMapper2D()
vm.SetInput(r.GetOutput())

otf = vtk.vtkPiecewiseFunction()
otf.AddPoint(0, 0.2)
otf.AddPoint(255, 0.2)

ctf = vtk.vtkColorTransferFunction()
ctf.AddRGBPoint(0.0, 1.0, 0.0, 0.0)
ctf.AddRGBPoint(255.0, 1.0, 0.0, 0.0)

vp = vtk.vtkVolumeProperty()
vp.SetColor(ctf)
vp.SetScalarOpacity(otf)
vp.ShadeOn()
vp.SetInterpolationTypeToLinear()

v = vtk.vtkVolume()
v.SetMapper(vm)
v.SetProperty(vp)

ren = vtk.vtkRenderer()
ren.AddVolume(v)
ren.SetBackground(0.9, 0.9, 0.9)

rw = vtk.vtkRenderWindow()
rw.AddRenderer(ren)
rw.SetSize(600, 600)

rwi = vtk.vtkRenderWindowInteractor()
rwi.SetRenderWindow(rw)
rwi.Initialize()
rw.Render()
rwi.Start()
