[vtkusers] Artifacts in volume rendering
Elvis Stansvik
elvis.stansvik at orexplore.com
Tue Apr 12 09:56:23 EDT 2016
Hi all,
Following Berk Geveci's great blog post from 2014 on writing a custom HDF5
reader in Python [1], I tried to take his code and modify it to load HDF5
files where the densities are float32 and vary between 0 and 64.
The only change I did to his reader was to modify RequestData to scale the
loaded data and convert it to uint16, like this:
data = (data * 1023).astype(uint16)
(should get me roughly in the range 0-65535).
I then generated a test HDF5 file containing a cylindrical volume like this:
def create_cylinder_file(filename, height, radius):
"""Create a cylindrical volume and save it in test.hdf5.
The densities are saved as float32 and will vary sinusoidically
from 0 to 64 along the cylinder height.
The result is saved in the "test" dataset in the output file.
"""
z_values = 32 + 32 * sin(linspace(0, 2*pi, height))
diameter = radius * 2
data = zeros(shape=(diameter, diameter, height), dtype=float32)
for x in range(diameter):
for y in range(diameter):
if (x - radius)**2 + (y - radius)**2 <= radius**2:
data[x, y, :] = z_values
# Write array to HDF5 file.
with h5py.File(filename, 'w') as file_:
data_set = file_.create_dataset(
name='test',
shape=data.shape,
dtype=data.dtype,
data=data
)
I then test it all out using a vtkVolumeRayCastMapper based pipeline like
this:
reader = HDF5Source()
reader.SetFileName('test.hdf5')
rayCastFunction = vtk.vtkVolumeRayCastCompositeFunction()
mapper = vtk.vtkVolumeRayCastMapper()
mapper.SetVolumeRayCastFunction(rayCastFunction)
mapper.SetInputConnection(reader.GetOutputPort())
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(0, 0, 0, 0) # Black
colorTransferFunction.AddRGBPoint(20000, 1, 0, 0) # Red
colorTransferFunction.AddRGBPoint(40000, 0, 1, 0) # Green
colorTransferFunction.AddRGBPoint(65535, 0, 0, 1) # Blue
opacityTransferFunction = vtk.vtkPiecewiseFunction()
opacityTransferFunction.AddPoint(0, 0) # Transparent
opacityTransferFunction.AddPoint(65535, 1) # Opaque
volumeProperty = vtk.vtkVolumeProperty()
volumeProperty.SetColor(colorTransferFunction)
volumeProperty.SetScalarOpacity(opacityTransferFunction)
volumeProperty.ShadeOff()
volumeProperty.SetInterpolationTypeToLinear()
volume = vtk.vtkVolume()
volume.SetMapper(mapper)
volume.SetProperty(volumeProperty)
renderer = vtk.vtkRenderer()
renderer.AddVolume(volume)
renderer.SetBackground(.85, .84, .83)
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindow.SetSize(600, 600)
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderWindow)
interactor.Initialize()
renderWindow.Render()
interactor.Start()
I'm attaching a main.py which contains the full code, including the
HDFSource reader with my slight modification, and a screenshot showing the
result.
Noticy how there's some strange artifacts in the denser (greener, bluer)
parts of the cylinder. Anyone know where these artifacts may come from?
It's entirely possible that it has nothing to with the custom reader, but
something with my pipeline..?
Very grateful for any ideas!
Cheers,
Elvis
[1]
https://blog.kitware.com/developing-hdf5-readers-using-vtkpythonalgorithm/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160412/68912af7/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.py
Type: application/x-download
Size: 4269 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160412/68912af7/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: artifacts.png
Type: image/png
Size: 62129 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160412/68912af7/attachment-0001.png>
More information about the vtkusers
mailing list