0

I want to Display a 3D image with the vtk module python. The image was saved in .vti format. I wrote the following simple code but it does not work correctly. How i can fix that?

import vtk

file_name = 'Vug.vti'

# Read the source file.
reader = vtk.vtkNrrdReader()
reader.SetFileName(file_name)
reader.Update()  

# Map the image through the lookup table
color = vtk.vtkImageMapToColors()
#color.SetLookupTable(table)
color.SetInputConnection(reader.GetOutputPort())

# Display the image
actor = vtk.vtkImageActor()
actor.GetMapper().SetInputConnection(color.GetOutputPort())

renderer = vtk.vtkRenderer()
renderer.AddActor(actor)

window = vtk.vtkRenderWindow()
window.AddRenderer(renderer)

# Set up the interaction
interactor = vtk.vtkRenderWindowInteractor()
window.SetInteractor(interactor)
window.Render()

# Start interaction
interactor.Start()
2
  • Could you explain what is wrong with the code? Commented Apr 16, 2020 at 16:36
  • It shows the image in 2D. Commented Apr 16, 2020 at 16:41

2 Answers 2

1

A vtkImageActor displays an image as a 2d object. If you want to render a 3d volume, you need to use a vtkVolume object.

This example shows how to volume render in VTK: https://github.com/Kitware/VTK/blob/master/Examples/VolumeRendering/Python/SimpleRayCast.py

Sign up to request clarification or add additional context in comments.

Comments

0

With vtkplotter this is simply:

from vtkplotter import load, datadir, show
vol = load(datadir + 'vase.vti') # returns vtkVolume
# set color and trasparency transfer functions along the scalar range
vol.color(["green", "pink", "blue"]).alpha([0, 0, 0.2, 0.5, 0.9])
show(vol)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.