[vtkusers] Coloring polydata with scalars

bryan cole bryan.cole at teraview.co.uk
Tue Jan 14 07:47:23 EST 2003


The sphere dataset (and hence it's data-array) is not created until the
pipeline is executed. Thus, to force creation of the sphere, I've called
the Update() method on the sphere-object.

NB. a 20x20 resolution sphere doesn't have 400 points, although
mis-match between the float-array size and the vtkPolyData size doesn't
cause any fatal errors in this case

See my Python version of your script (I didn't have a suitable
float-array to hand so just used a linear range) below.

Bryan

---------------------------------------------------
from vtk import *

s=vtkSphereSource()
s.SetPhiResolution(20)
s.SetThetaResolution(20)

s.Update()
print s.GetOutput().GetNumberOfPoints()

fa=vtkFloatArray()
fa.SetNumberOfValues(362)
for j in range(362):
	fa.SetValue(j, float(j))

s.GetOutput().GetPointData().SetScalars(fa)

m=vtkPolyDataMapper()
m.SetInput(s.GetOutput())
m.SetScalarRange(0,400)

a=vtkActor()
a.SetMapper(m)

ren=vtkRenderer()
ren.AddActor(a)

renwin = vtkRenderWindow()
renwin.AddRenderer(ren)

iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renwin)

iren.Initialize()
iren.Start()

-- 
Bryan Cole
Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge CB4 0WG, United Kingdom.
tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382




More information about the vtkusers mailing list