[vtkusers] individually colored points in Python?

Lucas wsacul at gmail.com
Wed Feb 2 16:27:20 EST 2011


I'd like to render a point cloud with points individually colored, so I
combined the example
http://www.vtk.org/Wiki/VTK/Examples/Python/TriangleColoredPoints with
others that sets up the interactive render window.  But the points are all
white, unless I call SetColor which gives them all the same color.  What am
I missing?

import vtk

# create a rendering window and renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(400,400)

# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

#setup points and vertices
Points = vtk.vtkPoints()
Vertices = vtk.vtkCellArray()

for i in range(255):
  for j in range(255):
    id = Points.InsertNextPoint(i, j, 1)
    Vertices.InsertNextCell(1)
    Vertices.InsertCellPoint(id)

    #setup colors
    Colors = vtk.vtkUnsignedCharArray()
    Colors.SetNumberOfComponents(3)
    Colors.SetName("Colors")
    Colors.InsertNextTuple3(255,i,j)

polydata = vtk.vtkPolyData()
polydata.SetPoints(Points)
polydata.SetVerts(Vertices)
polydata.GetPointData().SetVectors(Colors)
polydata.Modified()
polydata.Update()

######
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(polydata)

actor = vtk.vtkActor()
actor.SetMapper(mapper)
ren.AddActor(actor)

# enable user interface interactor
renWin.Render()
iren.Initialize()
iren.Start()


Replacing SetVectors() with SetScalars produces some point coloring, but the
colors seem random.

I'm using vtk 5.4.2 and Python 2.6.6 on Ubuntu.

Thanks,

Lucas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110202/cf119149/attachment.htm>


More information about the vtkusers mailing list