<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="GtkHTML/4.6.6">
</head>
<body>
For the benefit of anyone else struggling to get a vtkProgrammableSource to work for ImageData / StructuredPoints, it seems<br>
the secret sauce (and it really is a secret ... there are no examples or documentation on this that I could find) is to set the OutputInformation (and set the WHOLE_EXTENT in particular). My example script is given below. This works in VTK-6.0.0 . More recent
versions of VTK have added a SetRequestInformationMethod to the ProgrammableSource which allows you to provide a script to set the OutputInformation as part of the new pipeline execution.
<br>
<br>
In my solution, I set the OutputInformation once after creating the ProgrammableSource object which is OK for my purposes (small images where I'm always updating the whole extent). I also tried editing the OutputInformation data in the ExecuteMethod; this worked
sort of, if I forced the method of execute the first time with a call to .Update(); I don't think this will give the correct behaviour for proper pipeline execution though. I guess you could update OutputInformation using the VTK observer framework to mimic
pipeline execution if you need the OutputInformation to change dynamically and your VTK version doesn't have the SetRequestInformationMethod call.<br>
<br>
The other important point is that you must specify which output port you want in both the GetOutputPort and GetOutputInformation methods (port 1 for StructurePoints).<br>
<br>
HTH,<br>
BC<br>
=====================<br>
<br>
import vtk<br>
from vtk.util.numpy_support import numpy_to_vtk<br>
import numpy<br>
<br>
x,y,z = numpy.ogrid[-10:10:50j,-10:10:50j,-10:10:50j]<br>
data = (x**2 + y**2 + z**2)/(5**2)<br>
data = data.ravel().astype("f")<br>
<br>
<br>
src = vtk.vtkProgrammableSource()<br>
###Initialise the OutputInformation on the ProgrammableSource<br>
executive = src.GetExecutive()<br>
outInfo = executive.GetOutputInformation(1)<br>
outInfo.Set(executive.WHOLE_EXTENT(), 0, 49, 0, 49, 0, 49)<br>
<br>
def make_grid(): <br>
sp = src.GetStructuredPointsOutput()<br>
sp.SetExtent(0,49,0,49,0,49)<br>
sp.SetOrigin(-10,-10,-10)<br>
sp.SetSpacing(0.4,0.4,0.4)<br>
sp.GetPointData().SetScalars(numpy_to_vtk(data))<br>
<br>
src.SetExecuteMethod(make_grid)<br>
<br>
func = vtk.vtkSphere()<br>
func.SetCenter(0,0,0)<br>
func.SetRadius(5.0)<br>
<br>
clip = vtk.vtkImageMarchingCubes()<br>
clip.SetInputConnection(0,src.GetOutputPort(1))<br>
clip.SetValue(0,1.0)<br>
<br>
map = vtk.vtkPolyDataMapper()<br>
map.SetInputConnection(clip.GetOutputPort(0))<br>
map.ScalarVisibilityOff()<br>
<br>
surfaceActor = vtk.vtkActor()<br>
surfaceActor.SetMapper(map)<br>
<br>
ren = vtk.vtkRenderer()<br>
renWin = vtk.vtkRenderWindow()<br>
renWin.AddRenderer(ren)<br>
iren = vtk.vtkRenderWindowInteractor()<br>
iren.SetRenderWindow(renWin)<br>
ren.AddActor(surfaceActor)<br>
iren.Initialize()<br>
renWin.Render()<br>
iren.Start()<br>
<br>
===============================<br>
<br>
<br>
<br>
<br>
<table cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>-- <br>
Group Leader, Technical Development Group - Teraview Ltd.<br>
Platinum Building, St. John's Innovation Park, Cambridge CB4 0DS, UK.<br>
tel: +44 (0)1223 435386, fax: +44 (0)1223 435382, web: <a href="http://www.teraview.com/">www.teraview.com</a> Registered Number: 04126946, VAT Number: 770 8883 84<br>
<br>
...preferred document formats: ODF (ISO/IEC 26300:2006), PDF </td>
</tr>
</tbody>
</table>
</body>
</html>