[vtkusers] vtkpython: GetCellData().SetScalars(array) bug?

Garegin Papoian gap5 at cornell.edu
Thu Nov 20 17:12:37 EST 2003


In the code below, I would like to color different faces of a cube with 
different colors. I am creating an array of six numbers and assigning 
that array as Scalars to the vtkCellData associated with the 
corresponding vtkPolyData. The problem is that the effect of 
pd.GetCellData().SetScalars(scal_arr), see Line B at the end of listing 
below, depends on its position in the code. If it is moved above where 
it is now, (e.g. switch Lines A and B), than the cube comes out all 
white. Is this is a bug or there is some step them I am omitting in 
initializing the data structures?

I am using VTK 4.2. This behavior reproduces on RedHat 9 & OS X 10.3. It 
also reproduces when I am using Mayavi to set up the rendering. In the 
latter case, while in the interactive mode (python -i), when I type 
"pd.GetCellData().GetScalars()", it produces "None", if again Line B is 
not immediately preceding the last line to draw the window.

Garyk

--------------------------------------------------------------------
from vtkpython import *

box_width=0.2
cube = vtk.vtkCubeSource()

cube.SetXLength(box_width)
cube.SetYLength(box_width)
cube.SetZLength(1.0)
cube.SetCenter(0.5,0.5,0)

pd=cube.GetOutput()


lut = vtkLookupTable()
lut.SetNumberOfColors(2)
lut.Build()
lut.SetTableValue(0.0,0.5,0,0,1)
lut.SetTableValue(1.0,0.0,0.2,0.5,1)

scal_arr=vtkFloatArray()
scal_arr.SetNumberOfComponents(1)
scal_arr.InsertNextValue(1.0)
scal_arr.InsertNextValue(2.0)
scal_arr.InsertNextValue(1.0)
scal_arr.InsertNextValue(2.0)
scal_arr.InsertNextValue(1.0)
scal_arr.InsertNextValue(2.0)
scal_arr.SetName("color")
scal_arr.SetLookupTable(lut)

cubeMapper = vtk.vtkPolyDataMapper()
cubeMapper.SetInput(pd)
cubeMapper.SetScalarModeToUseCellData()
cubeMapper.SetScalarRange(1.0,2.0)

cubeActor = vtk.vtkActor()
cubeActor.SetMapper(cubeMapper)
cubeActor.SetOrigin(0,0,0)

ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

ren.AddActor(cubeActor)
ren.SetBackground(0, 0, 0)
renWin.SetSize(400, 400)

iren.Initialize()
renWin.Render()                               # Line A
pd.GetCellData().SetScalars(scal_arr) # Line B, this line seems to have 
no effect if it is moved upwards in the code
iren.Start()





More information about the vtkusers mailing list