[vtkusers] SetScalars of SG from Field

Randy Heiland heiland at ncsa.uiuc.edu
Mon Apr 8 17:28:22 EDT 2002


On Apr 8, 11:45am, Randy Heiland wrote:
> Subject: [vtkusers] SetScalars of SG from Field
> 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?
>

Sorry to be a pest, but I'm feeling some pressure to figure out why this
doesn't work as I expect.  To better explain what I meant above -- by not
getting "re-rendered properly", I mean it simply doesn't change (in spite of
the fact that the scalar range changes).  The rectangle is colored red->blue,
left->right.  However, replacing the scalars with the field array should
re-render it blue->red, bottom->top -- but it doesn't.

This time I'll send the corresponding Tcl script.  Can someone confirm/deny my
results?

thanks,
Randy
-----------------------------------------

package require vtk
package require vtkinteraction

vtkRenderer ren1
vtkRenderWindow renWin
 renWin AddRenderer ren1

vtkRenderWindowInteractor iren
iren SetRenderWindow renWin

#--------------------------------------------------
vtkStructuredGridReader sgr
sgr SetFileName "sg.vtk"
sgr Update
set sg [sgr GetOutput]

#srange sgr GetOutput GetPointData GetScalars GetRange
#put 'srange = ', [sgr GetOutput] GetPointData GetScalars GetRange
#puts 'srange = ', sg GetPointData GetScalars GetRange

#----------------------

vtkDataSetMapper mapper
mapper SetInput [sgr GetOutput]

vtkActor actor
actor SetMapper mapper

ren1 AddActor actor

renWin Render

vtkWindowToImageFilter w2if
w2if SetInput renWin
vtkPNMWriter pnmWriter
pnmWriter SetInput [w2if GetOutput]
pnmWriter SetFileName "sg1.pnm"
pnmWriter Write

#-------------------------------
vtkDataObjectReader dor
dor DebugOn
dor SetFileName "field.vtk"
dor Update

vtkFloatArray so
#set max [lindex [[[[rf GetOutput] GetPointData] GetArray $scalar] GetRange 0]
1]
set so [[[dor GetOutput] GetFieldData] GetArray 0]

# eval ??
[$sg GetPointData] SetScalars so
# does this help?
[$sg GetPointData] Modified
$sg Update

#set srange  sg GetPointData GetScalars GetRange
#puts 'srange = ' srange

actor Modified
renWin Render
pnmWriter SetFileName "sg2.pnm"
pnmWriter Write


iren Initialize
iren AddObserver UserEvent {wm deiconify .vtkInteract}

# prevent the tk window from showing up then start the event loop
wm withdraw .

------------- 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