[vtkusers] vtkImageResliceMapper and vtkImageSliceMapper

José M. Rodriguez Bacallao jmrbcu at gmail.com
Tue Jul 3 09:18:43 EDT 2012


ohhhh, it works now, thank you very much, but I think that this need
to be pointed out in the documentation.

On Mon, Jul 2, 2012 at 5:21 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> The SliceAtFocalPointOn() should not be used if the mapper input
> is just one slice.  This method is meant to be used when you want
> to show one slice out of a whole volume.  Because your input is just
> one slice, use SliceAtFocalPointOff().
>
> About the gfx board issue, I suspect that the difference is that your
> laptop has a low-precision depth buffer and/or does camera clipping
> differently from your desktop.  Try resetting the depth clipping with
> renderer.ResetCameraClippingRange() after changing slices.
>
>  - David
>
> On Mon, Jul 2, 2012 at 2:30 PM, José M. Rodriguez Bacallao
> <jmrbcu at gmail.com> wrote:
>> hi folks, I am testing the following code, this example just change
>> from one slice to another in a mapper (slices are in a list of 2D
>> images, not a single 3D one) and update the render window:
>>
>> import os, sys
>> import vtk, vtkgdcm, gdcm
>>
>> def files_to_read(path):
>>     files = os.listdir(path)
>>     return [os.path.join(path, x) for x in files]
>>
>> def sort_files(files):
>>     ipp = gdcm.IPPSorter()
>>     ipp.SetComputeZSpacing(True)
>>     ipp.SetZSpacingTolerance(1e-3);
>>     result = ipp.Sort(files);
>>     if result:
>>         return (ipp.GetFilenames(), ipp.GetZSpacing())
>>
>>     return files, 0
>>
>> def to_vtk_file_array(files):
>>     vtk_files = vtk.vtkStringArray()
>>     map(vtk_files.InsertNextValue, files)
>>     return vtk_files
>>
>> images = []
>> current = 0
>> def next(o, e):
>>     global im, renWind, current, iren
>>
>>     if iren.GetKeySym() == 'Right':
>>         current = (current + 1) % 200
>>     elif iren.GetKeySym() == 'Left':
>>         current = (current - 1) % 200
>>
>>     im.SetInput(images[current])
>>     renWin.Render()
>>
>>
>> if __name__ == '__main__':
>>     # 200 images
>>     path = '/home/jmrbcu/pictures/workpictures/dicom/BRAIN/'
>>     print 'Reading files from %s' % path
>>
>>     sorted_files, zspacing = sort_files(files_to_read(path))
>>     #sorted_files = to_vtk_file_array(sorted_files)
>>     print 'Files sorted, Z spacing is: %s' % zspacing
>>
>>     for name in sorted_files:
>>         reader = vtkgdcm.vtkGDCMImageReader()
>>         reader.SetFileName(name)
>>         reader.Update()
>>         images.append(reader.GetOutput())
>>
>>     ren1 = vtk.vtkRenderer()
>>     renWin = vtk.vtkRenderWindow()
>>     renWin.AddRenderer(ren1)
>>
>>     im = vtk.vtkImageResliceMapper()
>>     im.SetInput(images[current])
>>     im.SliceFacesCameraOn()
>>     im.SliceAtFocalPointOn()
>>     im.BorderOff()
>>
>>     ip = vtk.vtkImageProperty()
>>     ip.SetColorWindow(255)
>>     ip.SetColorLevel(128)
>>     ip.SetAmbient(0.0)
>>     ip.SetDiffuse(1.0)
>>     ip.SetOpacity(1.0)
>>     ip.SetInterpolationTypeToLinear()
>>
>>     ia = vtk.vtkImageSlice()
>>     ia.SetMapper(im)
>>     ia.SetProperty(ip)
>>
>>     ren1.AddViewProp(ia)
>>     ren1.SetBackground(0, 0, 0)
>>     renWin.SetSize(300, 300)
>>
>>     iren = vtk.vtkRenderWindowInteractor()
>>     style = vtk.vtkInteractorStyleImage()
>>     style.SetInteractionModeToImageSlicing()
>>     style.SetImageOrientation([1, 0, 0], [0, -1, 0])
>>     style.AddObserver('KeyPressEvent', next)
>>     iren.SetInteractorStyle(style)
>>     renWin.SetInteractor(iren)
>>
>>     renWin.Render();
>>     cam1 = ren1.GetActiveCamera()
>>     cam1.ParallelProjectionOn()
>>     ren1.ResetCameraClippingRange()
>>     renWin.Render()
>>
>>     iren.Start()
>>
>>
>> the problem is that with my main machine (graphic card Intel G33,
>> Ubuntu Linux), it work flawlessly but with my laptop (Intel i845g
>> without hardware acceleration, Archlinux), it just show the first
>> slice (the mapper is not updated very well I think). The problem is
>> solved in the laptop changing from vtkImageResliceMapper to
>> vtkImageSliceMapper and all slice are showed when the slice change
>> action is requested, so, what to do, I really like to use
>> vtkImageResliceMapper over vtkImageSliceMapper as documentation says.



More information about the vtkusers mailing list