VTK (Visualization Toolkit)

9.6.1 · active · verified Sat Apr 11

VTK is an open-source software system for 3D computer graphics, image processing, volume rendering, and scientific visualization. It provides a vast array of algorithms and rendering techniques. Currently at version 9.6.1, VTK follows a regular release cadence, with minor releases typically occurring every six months.

Warnings

Install

Imports

Quickstart

This quickstart code creates a simple 3D sphere visualization using VTK's Python bindings. It sets up a sphere source, maps it to a graphical representation, creates an actor, and then displays it within a render window with user interaction capabilities.

import vtk

# Create a sphere
sphereSource = vtk.vtkSphereSource()
sphereSource.SetCenter(0.0, 0.0, 0.0)
sphereSource.SetRadius(1.0)
sphereSource.Update()

# Create a mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(sphereSource.GetOutputPort())

# Create an actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Create a renderer, render window, and interactor
renderer = vtk.vtkRenderer()
renderWindow = vtk.vtkRenderWindow()
renderWindow.AddRenderer(renderer)
renderWindowInteractor = vtk.vtkRenderWindowInteractor()
renderWindowInteractor.SetRenderWindow(renderWindow)

# Add the actor to the scene
renderer.AddActor(actor)
renderer.SetBackground(0.1, 0.2, 0.4) # Dark blue background

# Render and interact
renderWindow.Render()
renderWindowInteractor.Start()

view raw JSON →