[vtkusers] Python and vtkPoints/vtkFloatArray problem
Viksit Gaur
vik.list.vtk at gmail.com
Wed May 17 15:29:06 EDT 2006
Hi All,
I've just been experimenting with a program to render particles on
screen given coordinates for each as well as a scalar for each point -
as spheres. I found an article/tutorial on LinuxJournal which uses VTK
3, and I think I've ported it to VTK4 - since I don't get any errors.
But, all I see is the render window, without any display of points, or
any errors to point out what might be going wrong. The program is
given below - I'd appreciate any help on this.
Thanks,
Viksit
=== Begin Program ==
import vtk
import time
sphere = vtk.vtkSphereSource()
glyphs = vtk.vtkGlyph3D()
glMapper = vtk.vtkPolyDataMapper()
glActor = vtk.vtkActor()
points = vtk.vtkPoints()
scalars = vtk.vtkFloatArray()
scalars.SetNumberOfComponents(1);
scalars.SetNumberOfTuples(10);
for i in range(0,10):
points.InsertPoint(i,i+1,i+2, i+3)
scalars.SetTuple1(i, 2.2)
pointset = vtk.vtkPolyData()
pointset.SetPoints(points)
pointset.GetPointData().SetScalars(scalars)
sphere.SetPhiResolution(2)
sphere.SetThetaResolution(2)
sphere.SetReleaseDataFlag(1)
#Set the attributes of the glyph objects
glyphs.ScalingOn()
glyphs.SetScaleModeToScaleByScalar()
#Set the mapper attributes
glMapper.ScalarVisibilityOff()
#Build the pipeline:
glyphs.SetSource(sphere.GetOutput())
glyphs.SetInput(pointset)
#The glyphs need position and geometry information (two inputs)
glMapper.SetInput(glyphs.GetOutput())
glActor.SetMapper(glMapper)
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
iren = vtk.vtkRenderWindowInteractor()
renWin.AddRenderer(ren)
iren.SetRenderWindow(renWin)
ren.AddActor(glActor)
iren.Initialize()
== End Program ==
--
Viksit Gaur
Social Robotics Lab, Dept. of Computer Science,
Yale University
http://gundam.cs.yale.edu
http://viksit.com
More information about the vtkusers
mailing list