coneMapper = vtkPolyDataMapper()
coneMapper.SetInput(cone.GetOutput())
cone = vtkConeSource()
cone.SetResolution(10)
coneActor = vtkActor()
coneActor.SetMapper(coneMapper)
ren = vtkRenderer()
ren.AddActor(coneActor)
renWin = vtkRenderWindow()
renWin.SetWindowName("Cone")
renWin.SetSize(300,300)
renWin.AddRenderer(ren)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
iren.Initialize()
iren.Start()
reader = vtkBMPReader()
reader.SetDataSpacing(1.0, 1.0, 2.0)
reader.SetDataOrigin(0.0, 0.0, 0.0)
reader.SetFileName("image.bmp")
resize = vtkImageReslice()
resize.SetInput(reader.GetOutput())
resize.SetOutputSpacing(0.25, 0.25, 2)
resize.SetInterpolationModeToCubic()
viewer = vtkImageViewer()
viewer.SetInput(resize.GetOutput())
viewer.SetColorWindow(255)
viewer.SetColorLevel(127.5)
viewer.Render()
A VTK Filter can never "force" any changes to occur further down the pipeline.
It has to wait until it is requested to Update, then it can only do the following:
request an Update of its Input data
create new data (the Output) from the Input data
Data does not "flow" along the pipeline. Each filter has its own copy of data,
which it creates from its Input data.
If you have one Source and two Filters, you will have three copies of the data
(yup, VTK can be a memory hog). You can force a filter to delete its data once
the next filter is done with it.
Homework:
Copy these files to your home directory
(this page is at http://osric.irus.rri.on.ca/vtk/vtkcourse/ )
Cone.py
Image.py
WindowLevelInterface.py
image.bmp (use shift-click to download)
1. Run Cone.py and Image.py to ensure that they work
2. Edit Cone.py and change the cone resolution to 100. Run Cone.py again.
3. Look at the on-line documentation for vtkProperty and vtkActor, and change the
Cone.py so that the cone is red.
4. Comment out the last line with a "#", i.e. #iren.Start(), and think about what
happens. Can you explain it?
5. In Image.py, change reader.SetDataSpacing to (0.5, 0.5, 0.5) and explain what
happens and why.
You can also look at this more complicated example: Slice.py