1# 2# This example creates a polygonal model of a mace made of a sphere 3# and a set of cones adjusted on its surface using glyphing. 4# 5# The sphere is rendered to the screen through the usual VTK render window 6# and interactions is performed using vtkRenderWindowInteractor. 7# The basic setup of source -> mapper -> actor -> renderer -> 8# renderwindow is typical of most VTK programs. 9# 10 11# 12# First we include the VTK Tcl packages which will make available 13# all of the vtk commands to Tcl 14# 15package require vtk 16package require vtkinteraction 17 18# 19# Next we create an instance of vtkSphereSource and set some of its 20# properties 21# 22vtkSphereSource sphere 23 sphere SetThetaResolution 8 24 sphere SetPhiResolution 8 25 26# 27# We create an instance of vtkPolyDataMapper to map the polygonal data 28# into graphics primitives. We connect the output of the sphere source 29# to the input of this mapper 30# 31vtkPolyDataMapper sphereMapper 32 sphereMapper SetInputConnection [sphere GetOutputPort] 33 34# 35# Create an actor to represent the sphere. The actor coordinates rendering of 36# the graphics primitives for a mapper. We set this actor's mapper to be 37# the mapper which we created above. 38# 39vtkActor sphereActor 40 sphereActor SetMapper sphereMapper 41 42# 43# Next we create an instance of vtkConeSource that will be used to 44# set the glyphs on the sphere's surface 45# 46vtkConeSource cone 47 cone SetResolution 6 48 49# 50# Glyphing is a visualization technique that represents data by using 51# symbol or glyphs. In VTK, the vtkGlyph3D class allows you to create 52# glyphs that can be scaled, colored and oriented along a 53# direction. The glyphs (here, cones) are copied at each point of the 54# input dataset (the sphere's vertices). 55# 56# Create a vtkGlyph3D to dispatch the glyph/cone geometry (SetSource) on the 57# sphere dataset (SetInput). Each glyph is oriented through the dataset 58# normals (SetVectorModeToUseNormal). The resulting dataset is a set 59# of cones laying on a sphere surface. 60# 61vtkGlyph3D glyph 62 glyph SetInputConnection [sphere GetOutputPort] 63 glyph SetSourceConnection [cone GetOutputPort] 64 glyph SetVectorModeToUseNormal 65 glyph SetScaleModeToScaleByVector 66 glyph SetScaleFactor 0.25 67 68# 69# We create an instance of vtkPolyDataMapper to map the polygonal data 70# into graphics primitives. We connect the output of the glyph3d 71# to the input of this mapper 72# 73vtkPolyDataMapper spikeMapper 74 spikeMapper SetInputConnection [glyph GetOutputPort] 75 76# 77# Create an actor to represent the glyphs. The actor coordinates rendering of 78# the graphics primitives for a mapper. We set this actor's mapper to be 79# the mapper which we created above. 80# 81vtkActor spikeActor 82 spikeActor SetMapper spikeMapper 83 84# 85# Create the Renderer and assign actors to it. A renderer is like a 86# viewport. It is part or all of a window on the screen and it is responsible 87# for drawing the actors it has. We also set the background color here. 88# 89vtkRenderer renderer 90 renderer AddActor sphereActor 91 renderer AddActor spikeActor 92 renderer SetBackground 1 1 1 93 94# 95# We create the render window which will show up on the screen 96# We put our renderer into the render window using AddRenderer. We also 97# set the size to be 300 pixels by 300 98# 99vtkRenderWindow renWin 100 renWin AddRenderer renderer 101 renWin SetSize 300 300 102 103# 104# Finally we create the render window interactor handling user 105# interactions. vtkRenderWindowInteractor provides a 106# platform-independent interaction mechanism for mouse/key/time 107# events. vtkRenderWindowInteractor also provides controls for 108# picking, rendering frame rate, and headlights. It is associated 109# to a render window. 110# 111vtkRenderWindowInteractor iren 112 iren SetRenderWindow renWin 113 114# 115# vtkRenderWindowInteractor provides default key bindings. The 'u' 116# key will trigger its "user method", provided that it has been 117# defined. Similarly the 'e' or 'q' key will trigger its "exit 118# method". The lines below set these methods through the AddObserver 119# method with the events "UserEvent" and "ExitEvent". The corresponding 120# "user-method" Tcl code will bring up the .vtkInteract widget and 121# allow the user to evaluate any Tcl code and get access to all 122# previously-created VTK objects. The 123# "exit-method" Tcl code will exit (do not try to free up any objects 124# we created using 'vtkCommand DeleteAllObjects' because you are right 125# inside a VTK object. 126# 127iren AddObserver UserEvent {wm deiconify .vtkInteract} 128iren AddObserver ExitEvent {exit} 129 130# 131# Render the image 132# 133renWin Render 134 135# 136# Hide the default . widget 137# 138wm withdraw . 139iren Start 140# 141# You only need this line if you run this script from a Tcl shell 142# (tclsh) instead of a Tk shell (wish) 143# 144tkwait window . 145