[vtkusers] Scaling and colouring glyphs with different scalar arrays

Paul Cochrane cochrane at esscc.uq.edu.au
Wed Mar 30 02:33:35 EST 2005


Hi all,

I'm trying to colour and scale spherical glyphs using two different scalar
arrays in an unstructured grid.  Unfortunately, what I seem to be able to do
is to colour *and* scale according to the one scalar array (the one that is
the currently active scalar) but not be able to scale by one scalar and
colour by the other.  I've searched through the mailing list archives and
the docs, and have seen similar problems discussed, but when I tried the
solutions I haven't been able to make my problem work.  I've reduced the
problem down to a smallish script (attached) which illustrates the problem.

I have two named arrays "radius" and "tag" and want to scale the spherical
glyphs according to the radius, and colour according to the tag, but when I
call SelectColorArray("tag") on the mapper object, nothing happens; I get
the colouring being associated with the radius scalar data.  I've tried
setting SetScalarModeToUsePointFieldData() (which is supposed to work better
with SelectColorArray()) however, this doesn't give me any colouring at all.

What am I doing wrong?  Any ideas or help would be greatly appreciated.

Paul

-- 
Paul Cochrane
Computational Scientist/Software Developer
Earth Systems Science Computational Centre
University of Queensland
Brisbane
Queensland 4072
Australia

E: cochrane at esscc.uq.edu.au
P: +61 7 3346 9797
F: +61 7 3365 7347
-------------- next part --------------
#!/usr/bin/env python

import vtk

# some radii
radii = vtk.vtkFloatArray()
radii.InsertNextValue(1.0)
radii.InsertNextValue(0.1)
radii.InsertNextValue(0.2)
radii.SetName("radius")

# define the colours for the spheres
tags = vtk.vtkFloatArray()
tags.InsertNextValue(1.0)
tags.InsertNextValue(0.5)
tags.InsertNextValue(0.7)
tags.SetName("tag")

# define the locations of the spheres
points = vtk.vtkPoints()
points.InsertNextPoint(0, 0, 0)
points.InsertNextPoint(1, 0, 0)
points.InsertNextPoint(1, 1, 0)

# construct the grid
grid = vtk.vtkUnstructuredGrid()
grid.SetPoints(points)
grid.GetPointData().AddArray(radii)
grid.GetPointData().AddArray(tags)
grid.GetPointData().SetActiveScalars("radius")

# Create a sphere to use as a glyph source for vtkGlyph3D.
sphere = vtk.vtkSphereSource()
sphere.SetRadius(0.5)
sphere.SetPhiResolution(16)
sphere.SetThetaResolution(16)

# make the glyphs
glyph = vtk.vtkGlyph3D()
glyph.SetInput(grid)
glyph.SetSource(sphere.GetOutput())
glyph.ClampingOff()
glyph.SetScaleModeToScaleByScalar()
glyph.SetScaleFactor(1.0)

# set up the mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(glyph.GetOutput())
mapper.ScalarVisibilityOn()
mapper.SetScalarModeToUsePointData()
mapper.SelectColorArray("tag")

# set up the actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)

# do renderer setup stuff
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(640, 480)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# add the actor to the renderer
ren.AddActor(actor)

# render
iren.Initialize()
renWin.Render()
iren.Start()


More information about the vtkusers mailing list