[vtkusers] Problems while saving cropped volume

Tiago tiago.faria at cenpra.gov.br
Thu Jul 7 12:57:37 EDT 2005


Hi, I'm newbie with vtk, hope someone may help me with this.

I'm having a problem while trying to save modified vtk images.

Having several n slices in vtk format, I view a 3d model. Then, I cut a part 
of it (this is already working), and I try to save it in n new files. When I 
check the files created, to my surprise, there is only one file. When I try 
to read this file, I see just two dimensions (plane x,y) and no image. I've 
tried doing this in a lot of ways, but none of them worked fine.

What mistake am I doing while I try to save the modified slices? You may see 
the code in the end of this e-mail.

Thanks!

Tiago

------------------------------------------------

# pipeline
root = Tk()
ren = vtk.vtkRenderer()
ren.SetBackground(0.2,0.3,0.4)
ren.GetActiveCamera().Elevation(90)
ren.GetActiveCamera().SetViewUp(0,0,-1)
ren.GetActiveCamera().Azimuth(0)
ren.ResetCameraClippingRange()
renwin = vtk.vtkRenderWindow()
renwin.AddRenderer(ren)
iren = vtkTkRenderWindowInteractor(root,rw=renwin,width=400,height=400)
renwin.Render()
iren.pack()
# end of the pipeline

# reading the original images
v16 = vtk.vtkVolume16Reader()
v16.SetDataDimensions(256,256) #64,64
v16.GetOutput().SetOrigin(0.0,0.0,0.0)
v16.SetDataByteOrderToLittleEndian()
v16.SetFilePrefix("C:\Images\images")
v16.SetImageRange(1,78)
v16.SetDataSpacing(0.468,0.468,1.0)
v16.Update()
# original images read

gaussian = vtk.vtkImageGaussianSmooth()
gaussian.SetDimensionality(3)
gaussian.SetStandardDeviation(0,.5,.5)
gaussian.SetRadiusFactor(3)
gaussian.SetInput(v16.GetOutput())
cast = vtk.vtkImageCast()
cast.SetInput(gaussian.GetOutput())
cast.SetOutputScalarTypeToUnsignedShort()
opacityTransferFunction = vtk.vtkPiecewiseFunction()
opacityTransferFunction.AddPoint(0.0,0)
opacityTransferFunction.AddPoint(1200,1)
colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(0.0,1.0,1.2,1.0)
colorTransferFunction.AddRGBPoint(1200,2.10,1.80,1.40)
function = vtk.vtkVolumeRayCastCompositeFunction()

# ray cast mapper creation & mapper crop
isoMapper = vtk.vtkVolumeRayCastMapper()
isoMapper.SetInput(cast.GetOutput())
isoMapper.SetVolumeRayCastFunction(function)
isoMapper.SetCroppingRegionPlanes(40,80,0,0,40,80)
isoMapper.SetCroppingRegionFlagsToInvertedCross()
isoMapper.CroppingOn()
isoMapper.Update()

# volume creation (properties)
volumeProperty = vtk.vtkVolumeProperty()
volumeProperty.SetColor(colorTransferFunction)
volumeProperty.SetScalarOpacity(opacityTransferFunction)
volumeProperty.SetSpecularPower(1,5)
volumeProperty.ShadeOn()
volumeProperty.SetInterpolationTypeToLinear()
isoActor = vtk.vtkVolume()
isoActor.SetMapper(isoMapper)
isoActor.SetProperty(volumeProperty)
outline = vtk.vtkOutlineFilter()
outline.SetInput(v16.GetOutput())
outlineMapper = vtk.vtkPolyDataMapper()
outlineMapper.SetInput(outline.GetOutput())
outlineActor = vtk.vtkActor()
outlineActor.SetMapper(outlineMapper)
outlineActor.VisibilityOn()
ren.AddActor(outlineActor)
ren.AddActor(isoActor)
iren.GetRenderWindow().Render()

rensrc = vtk.vtkRendererSource()
rensrc.WholeWindowOn()
rensrc.SetInput(ren)
rensrc.Update()

# writing modified volume to new files
write = vtk.vtkImageWriter()
write.SetFileDimensionality(2)
write.SetFilePattern("%s.%d")
write.SetInput(rensrc.GetOutput())
write.SetFilePrefix("test")
write.Update()
write.Write()

root.mainloop()




More information about the vtkusers mailing list