[vtkusers] Problems while saving cropped volume

Amy Squillacote amy.squillacote at kitware.com
Thu Jul 7 13:35:45 EDT 2005


Hi Tiago,

There are two problems with what you're trying to do.  First, if you're 
trying to write out a volume, then using a vtkRendererSource is not what 
you want to do.  The output of a vtkRendererSource will be a 2D image 
because it is intended to allow you to use the image in your vtkRenderer in 
a VTK pipeline.  If you're trying to save an image of the rendering window, 
try using vtkWindowToImageFilter instead.

Second, the cropping region planes you are using are not actually modifying 
your data; they're only changing what portion of your data is rendered.  To 
actually save out a subset of your volume data, try using a filter like 
vtkExtractVOI.  (It's input would be cast.GetOutput().)  Then pass the 
output of the vtkExtractVOI filter to a vtkXMLImageDataWriter.  You could 
also try using vtkClipVolume, but it creates vtkUnstructuredGrid as output, 
not vtkImageData.  You would then pass its output to a 
vtkXMLUnstructuredGridWriter.

- Amy

At 12:57 PM 7/7/2005, Tiago wrote:
>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()
>
>_______________________________________________
>This is the private VTK discussion list. Please keep messages on-topic. 
>Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list