Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 79 lines (59 sloc) 2.489 kb
b8f915f @pieper ENH: example scripts for interacting with MRML API
pieper authored
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)
5028115 @finetjul ENH: Add VTK 6 support 1/2
finetjul authored
21 # VTK6 TODO
b8f915f @pieper ENH: example scripts for interacting with MRML API
pieper authored
22 modelDisplayNode.SetAndObserveTextureImageData(imageSource.GetOutput())
106407f @finetjul BUG: Don't use vtkMRMLScene::AddNodeNoNotify
finetjul authored
23 Slicer.slicer.MRMLScene.AddNode(modelDisplayNode)
b8f915f @pieper ENH: example scripts for interacting with MRML API
pieper authored
24
25 # transform node
26 transformNode = Slicer.slicer.vtkMRMLLinearTransformNode()
27 transformNode.SetName('PlaneToWorld')
106407f @finetjul BUG: Don't use vtkMRMLScene::AddNodeNoNotify
finetjul authored
28 Slicer.slicer.MRMLScene.AddNode(transformNode)
b8f915f @pieper ENH: example scripts for interacting with MRML API
pieper authored
29
30 # set up model node
31 modelNode = Slicer.slicer.vtkMRMLModelNode()
5028115 @finetjul ENH: Add VTK 6 support 1/2
finetjul authored
32 # VTK6 TODO
b8f915f @pieper ENH: example scripts for interacting with MRML API
pieper authored
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
a331fb0 STYLE: Remove end of line spaces
hjohnson authored
40 # don't respond to each event (for efficiency). In C++
41 # you would use the vtkMRMLScene::NodeAddedEvent enum but
b8f915f @pieper ENH: example scripts for interacting with MRML API
pieper authored
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
a331fb0 STYLE: Remove end of line spaces
hjohnson authored
50 # create the plane and modify the texture and transform
b8f915f @pieper ENH: example scripts for interacting with MRML API
pieper authored
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
29dc6a6 ENH: Several fixes and improvements in transform handling
lassoan authored
63 toParent = vtk.vtkMatrix4x4()
64 transformNode.GetMatrixTransformToParent(toParent)
b8f915f @pieper ENH: example scripts for interacting with MRML API
pieper authored
65 for i in xrange(steps):
66 imageSource.SetInValue( 200*(i%2) )
29dc6a6 ENH: Several fixes and improvements in transform handling
lassoan authored
67
68 toParent.SetElement(0, 3, i)
69 transformNode.SetMatrixTransformToParent(toParent)
70
b8f915f @pieper ENH: example scripts for interacting with MRML API
pieper authored
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)
a331fb0 STYLE: Remove end of line spaces
hjohnson authored
78
Something went wrong with that request. Please try again.