1#!/usr/bin/env python 2import vtk 3from vtk.util.misc import vtkGetDataRoot 4VTK_DATA_ROOT = vtkGetDataRoot() 5 6# Derived from Cursor3D. This script increases the coverage of the 7# vtkImageInplaceFilter super class. 8# global values 9CURSOR_X = 20 10CURSOR_Y = 20 11CURSOR_Z = 20 12IMAGE_MAG_X = 2 13IMAGE_MAG_Y = 2 14IMAGE_MAG_Z = 1 15 16# pipeline stuff 17reader = vtk.vtkSLCReader() 18reader.SetFileName(VTK_DATA_ROOT + "/Data/nut.slc") 19 20# make the image a little bigger 21magnify1 = vtk.vtkImageMagnify() 22magnify1.SetInputConnection(reader.GetOutputPort()) 23magnify1.SetMagnificationFactors(IMAGE_MAG_X, IMAGE_MAG_Y, IMAGE_MAG_Z) 24magnify1.ReleaseDataFlagOn() 25 26magnify2 = vtk.vtkImageMagnify() 27magnify2.SetInputConnection(reader.GetOutputPort()) 28magnify2.SetMagnificationFactors(IMAGE_MAG_X, IMAGE_MAG_Y, IMAGE_MAG_Z) 29magnify2.ReleaseDataFlagOn() 30 31# a filter that does in place processing (magnify ReleaseDataFlagOn) 32cursor = vtk.vtkImageCursor3D() 33cursor.SetInputConnection(magnify1.GetOutputPort()) 34cursor.SetCursorPosition(CURSOR_X * IMAGE_MAG_X, 35 CURSOR_Y * IMAGE_MAG_Y, 36 CURSOR_Z * IMAGE_MAG_Z) 37cursor.SetCursorValue(255) 38cursor.SetCursorRadius(50 * IMAGE_MAG_X) 39 40# stream to increase coverage of in place filter. 41# put the two together in one image 42imageAppend = vtk.vtkImageAppend() 43imageAppend.SetAppendAxis(0) 44imageAppend.AddInputConnection(magnify2.GetOutputPort()) 45imageAppend.AddInputConnection(cursor.GetOutputPort()) 46 47viewer = vtk.vtkImageViewer() 48viewer.SetInputConnection(imageAppend.GetOutputPort()) 49viewer.SetZSlice(CURSOR_Z * IMAGE_MAG_Z) 50viewer.SetColorWindow(200) 51viewer.SetColorLevel(80) 52# viewer DebugOn 53viewer.Render() 54viewer.SetPosition(50, 50) 55# make interface 56viewer.Render() 57