[vtkusers] SetScalars of SG from Field
Randy Heiland
heiland at ncsa.uiuc.edu
Mon Apr 8 12:45:53 EDT 2002
I'm trying to update scalars in a struct grid from a FIELD file, but the
results don't get re-rendered properly. What am I missing?
Here's some Python code & files to demonstrate (using VTK 4.0):
from vtk import *
ren1 = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren1)
iren= vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
#--------------------------------------------------
sgr = vtkStructuredGridReader()
sgr.SetFileName("sg.vtk")
sgr.Update()
sg = sgr.GetOutput()
srange= sg.GetPointData().GetScalars().GetRange()
print 'srange = ',srange
#----------------------
mapper = vtkDataSetMapper()
mapper.SetInput(sg)
#mapper.SetScalarRange(0.,1.)
#mapper.SetLookupTable(lutBlueRed)
actor = vtkActor()
actor.SetMapper(mapper)
ren1.AddActor(actor)
#ren1.GetActiveCamera().Elevation(-90)
#ren1.GetActiveCamera().Roll(-90)
renWin.Render()
w2if = vtkWindowToImageFilter()
w2if.SetInput( renWin )
pnmWriter = vtkPNMWriter()
pnmWriter.SetInput(w2if.GetOutput())
pnmWriter.SetFileName("sg1.pnm")
pnmWriter.Write()
#--------------------------------
# Now try to update scalars from a Field file
dor = vtkDataObjectReader()
dor.DebugOn()
dor.SetFileName('field.vtk')
dor.Update()
so = vtkFloatArray()
so = dor.GetOutput().GetFieldData().GetArray(0)
sg.GetPointData().SetScalars(so)
# does this help?
sg.GetPointData().Modified()
sg.Update()
srange= sg.GetPointData().GetScalars().GetRange()
print 'srange = ',srange
actor.Modified()
renWin.Render()
pnmWriter.SetFileName("sg2.pnm")
pnmWriter.Write()
iren.Start()
------------ sg.vtk:
# vtk DataFile Version 1.0
title line
ASCII
DATASET STRUCTURED_GRID
DIMENSIONS 3 2 1
POINTS 6 float
0.0 0.0 0.0 1.0 0.0 0.0 2.0 0.0 0.0
0.0 1.0 0.0 1.0 1.0 0.0 2.0 1.0 0.0
POINT_DATA 6
SCALARS foo float
LOOKUP_TABLE default
0.0
1.0
2.0
0.0
1.0
2.0
----------- field.vtk
# vtk DataFile Version 1.0
dummy field data
ASCII
FIELD all 1
temp 1 6 float
0 0 0 1 1 1
More information about the vtkusers
mailing list