[vtkusers] How to size glyphs with one scalar field, and colour with another?
Craig N. Scott
craig.scott at csiro.au
Tue Oct 19 00:51:49 EDT 2004
I had to do something similar myself recently, only with scalars and
vectors (not fields). I got little response from the mailing list, but I
eventually worked out a solution using vtkProgammableGlyphFilter. It
involves saving the scalar data array to be used for scaling, then
setting the scalar array for the reader to the one I wanted to color by.
What follows is a brief snippet of Tcl code. It should draw spheres with
radius corresponding to a scalar point data set called "radius" and
color the spheres according to a different scalar point data set called
"colorValues". I haven't tested the code below (I've pulled it out from
pieces of some of my work), but it should do the trick.
PS: I don't claim that it is good Tcl coding style, nor particularly
efficient!
======================================
vtkUnstructuredGridReader reader
reader SetFileName "something.vtk"
reader SetScalarsName "radius"
reader Update
set srcArray [[[reader GetOutput] GetPointData] GetArray "radius"]
vtkDoubleArray radiusArray
radiusArray DeepCopy $srcArray
reader SetScalarsName "colorValues"
vtkSphereSource sphere
# procedure for generating glyphs
proc Glyph {} {
set ptId [glypher GetPointId]
set xyz [glypher GetPoint]
set x [lindex $xyz 0]
set y [lindex $xyz 1]
set z [lindex $xyz 2]
set radius [radiusArray GetTuple1 $ptId]
eval sphere SetRadius $radius
eval sphere SetCenter $xyz
}
vtkProgrammableGlyphFilter glypher
glypher SetInput [reader GetOutput]
glypher SetSource [sphere GetOutput]
glypher SetGlyphMethod {Glyph}
vtkDataSetMapper resultMapper
resultMapper SetInput [glypher GetOutput]
:
(set up an actor, renderer, etc. as per usual)
:
On Tue, 2004-10-19 at 13:54, s comp wrote:
> Hi All,
>
> How can I size glyphs with one scalar field and colour them with
> another?
>
> Thanks,
>
> Sonam
--
Dr Craig Scott, CSIRO (CMIS)
Melbourne, Australia
Computers are easy to reboot. Attitudes are much harder.
More information about the vtkusers
mailing list