[vtkusers] scalats to colors

Tushar Udeshi tudeshi at zyvex.com
Tue Jan 2 18:37:49 EST 2001


Hello vtk users!
I'm having trouble with a rather trivial operation. I would like to assign 
Red, Green and Blue values as 3 components of vtkScalar of unsigned char 
type.  Having done that I set the vtkMapper to the default color mode. 
However, I get only gray scale images. In fact only the first component of 
vtkScalars appears to make a difference since even if iI leave the other 
components unassigned, there is no difference. What am i doing wrong? I'm 
enclosing a code snippet.

Thanks in advance

Regards,
Tushar

source $VTK_TCL/vtkInt.tcl

vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
    renWin SetWindowName "scalars to colors"
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

# create a sphere source and actor
#
vtkSphereSource sphere
    sphere Update    

# create scalars
vtkScalars scalars
    scalars SetNumberOfComponents 3
    scalars SetDataTypeToUnsignedChar

for {set i 0} {$i < [[sphere GetOutput] GetNumberOfPoints]} {incr i} {
    scalars SetActiveComponent 0
    scalars InsertScalar $i [expr ($i*10)%255]
    scalars SetActiveComponent 1
    scalars InsertScalar $i [expr ($i*20)%255]
    scalars SetActiveComponent 2
    scalars InsertScalar $i [expr ($i*30)%255]
}

scalars SetActiveComponent 0
[[sphere GetOutput] GetPointData] SetScalars scalars


vtkPolyDataMapper   sphereMapper
    sphereMapper SetInput [sphere GetOutput]
    sphereMapper ScalarVisibilityOn
    sphereMapper SetScalarRange 0 255
    sphereMapper SetColorModeToDefault

vtkActor sphereActor
    sphereActor SetMapper sphereMapper

# Add the actors to the renderer, set the background and size
#
ren1 AddActor sphereActor
ren1 SetBackground 0.1 0.2 0.4
renWin SetSize 300 300

# render the image
#
iren Initialize






More information about the vtkusers mailing list