Permalink
Newer
Older
100644 79 lines (59 sloc) 2.43 KB
1
2
import Slicer
3
import time
4
5
def newPlane():
6
7
# create a plane polydata
8
plane = Slicer.slicer.vtkPlaneSource()
9
plane.SetOrigin( 0., 0., 0. )
10
plane.SetPoint1( 100., 0., 0. )
11
plane.SetPoint2( 0., 0., 100. )
12
plane.GetOutput().Update()
13
14
# create a simple texture image
15
imageSource = Slicer.slicer.vtkImageEllipsoidSource()
16
imageSource.GetOutput().Update()
17
18
# set up display node that includes the texture
19
modelDisplayNode = Slicer.slicer.vtkMRMLModelDisplayNode()
20
modelDisplayNode.SetBackfaceCulling(0)
21
# VTK6 TODO
22
modelDisplayNode.SetAndObserveTextureImageData(imageSource.GetOutput())
23
Slicer.slicer.MRMLScene.AddNode(modelDisplayNode)
24
25
# transform node
26
transformNode = Slicer.slicer.vtkMRMLLinearTransformNode()
27
transformNode.SetName('PlaneToWorld')
28
Slicer.slicer.MRMLScene.AddNode(transformNode)
29
30
# set up model node
31
modelNode = Slicer.slicer.vtkMRMLModelNode()
32
# VTK6 TODO
33
modelNode.SetAndObservePolyData( plane.GetOutput() )
34
modelNode.SetAndObserveDisplayNodeID( modelDisplayNode.GetID() )
35
modelNode.SetAndObserveTransformNodeID( transformNode.GetID() )
36
modelNode.SetName("Plane")
37
Slicer.slicer.MRMLScene.AddNode(modelNode)
38
39
# need to invoke a NodeAddedEvent since some GUI elements
40
# don't respond to each event (for efficiency). In C++
41
# you would use the vtkMRMLScene::NodeAddedEvent enum but
42
# it's not directly available from scripts
43
Slicer.slicer.MRMLScene.InvokeEvent(66000)
44
45
return (modelNode, transformNode, imageSource)
46
47
48
def texturedPlane():
49
50
# create the plane and modify the texture and transform
51
# every iteration. Call Modified on the PolyData so the
52
# viewer will know to update. Call Tk's "update" to flush
53
# the event queue so the Render will appear on screen
54
# (update is called here as part of the demo - most applications
55
# should not directly call update since it can lead to duplicate
56
# renders and choppy interaction)
57
58
steps = 200
59
startTime = time.time()
60
61
modelNode,transformNode,imageSource = newPlane()
62
63
toParent = vtk.vtkMatrix4x4()
64
transformNode.GetMatrixTransformToParent(toParent)
65
for i in xrange(steps):
66
imageSource.SetInValue( 200*(i%2) )
67
68
toParent.SetElement(0, 3, i)
69
transformNode.SetMatrixTransformToParent(toParent)
70
71
modelNode.GetPolyData().Modified()
72
Slicer.TkCall( "update" )
73
74
endTime = time.time()
75
ellapsed = endTime - startTime
76
hertz = steps/ellapsed
77
print 'ran %d iterations in %g seconds (%g hertz)' % (steps, ellapsed, hertz)