[vtkusers] vtkImageNotReader??

John Vard jvard at tcd.ie
Fri Nov 14 07:28:46 EST 2003


I'm having recurring problems regarding the rendering of a raw image file. The 
code below once worked for the select few files and now works for none. The 
end result is a blank canvas projected in 3D-space. This would appear to be 
due to incorrect pixel spacing or Col/Row size or even a problematic raw 
file. But the VTK driven Paraview program opens said example. I'd appreciate 
any help in explaining this problem... Could it be my vtk version

# Read .raw file
reader = vtkImageReader2()
reader.SetFileName("file.raw")
reader.SetDataScalarTypeToUnsignedShort()
reader.SetDataByteOrderToLittleEndian()
reader.SetDataOrigin(<PosX>,<PosY>,0.0)
reader.SetDataSpacing(<PSpacX>,<PSpacY>,1.0)
reader.SetDataExtent(0,<Col-1>,0,<Row-1>,0,0)

data = reader.GetOutput()
data.Update()

# Determine scalar range of image
scalarmin,scalarmax = data.GetScalarRange()
scale = 255/(scalarmax-scalarmin)

shiftScale = vtkImageShiftScale()
shiftScale.SetInput(reader.GetOutput())
shiftScale.SetShift(0)
shiftScale.SetScale(scale)
shiftScale.SetOutputScalarTypeToUnsignedChar()

#Setup Actor
ia = vtkImageActor()
ia.SetInput(shiftScale.GetOutput())

# Create the RenderWindow, Renderer
ren = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren)

#initiate window interactor
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

#Add Actor to Render and set Win size
ren.AddActor2D(ia)
renWin.SetSize(400, 400)

iren.Initialize()
renWin.Render()
iren.Start()
-- 
Regards
John Vard




More information about the vtkusers mailing list