[vtkusers] Announcement: New image rendering classes for VTK

David Gobbi david.gobbi at gmail.com
Fri Jul 15 11:39:59 EDT 2011


Hi Van,

You need to use nearest-neighbor interpolation:

slice->GetProperty()->SetInterpolationTypeToNearest();

 - David


On Fri, Jul 15, 2011 at 4:30 AM, Nam-Van TRAN <van.trannam at gmail.com> wrote:

> Hi David,
>
> I've just make a sample with your new image classes but i found that my
> final image seems not correct (vtkImageResice_slice4.png) in comparison with
> correct result issued from Paraview 3.10.1 (Paraview_slice4.png).
>
> My pipeline is composed by a vtkXMLImageDataReader + vtkImageSliceMapper +
> vtkImageSlice . The input data was a volume of binary images (scalar range
> is [0, 1]).
>
> Here is my sample code:
>
> ----
>
>   vtkSmartPointer<vtkXMLImageDataReader> reader =
> vtkSmartPointer<vtkXMLImageDataReader>::New();
>     std::string fileName = "example_10x10x10.vti"
>     reader->SetFileName(fileName.c_str());
>
>     double range[2] = {0, 1};
>     vtkSmartPointer<vtkLookupTable> lut =
> vtkSmartPointer<vtkLookupTable>::New();
>     lut->SetRange(range);
>     lut->Build();
>
>     vtkSmartPointer<vtkImageSliceMapper> mapper =
> vtkSmartPointer<vtkImageSliceMapper>::New();
>
>     mapper->SetSliceNumber(4);
>     mapper->SetOrientationToZ();
>     mapper->SetInput(reader->GetOutput());
>
>     vtkSmartPointer<vtkImageSlice> slice =
> vtkSmartPointer<vtkImageSlice>::New();
>     slice->SetMapper(mapper);
>     slice->GetProperty()->SetLookupTable(lut);
>     slice->GetProperty()->SetUseLookupTableScalarRange(1);
>
>     vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
>     ren->AddActor(slice);
>
>     vtkSmartPointer<vtkScalarBarActor> scalarBar =
> vtkSmartPointer<vtkScalarBarActor>::New();
>     scalarBar->SetLookupTable(lut);
>     ren->AddActor2D(scalarBar);
>
>     vtkSmartPointer<vtkRenderWindow> wren =
> vtkSmartPointer<vtkRenderWindow>::New();
>     wren->AddRenderer(ren);
>     wren->SetSize(600, 800);
>
>     vtkSmartPointer<vtkRenderWindowInteractor> iren =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
>     iren->SetRenderWindow(wren);
>
>     iren->Initialize();
>     iren->Start();
>
> ---
>
> I'd like to get the same slice image as one of Paraview with this sample
> code. Could any one tell me where and how i will modify ?
>
> Thanks.
>
> Van.
>
>
>
>
>
> 2011/6/27 David Gobbi <david.gobbi at gmail.com>
>
>> I'm pleased to announce that I have finally completed my work on several
>> new image rendering classes for VTK.  They are in the VTK git development
>> tree, and a few of you have already tried them out (if you are one of those
>> people, note that several feature and performance enhancements were added
>> last week).  More info can be found at the following wiki page:
>>
>> http://www.vtk.org/Wiki/VTK/Image_Rendering_Classes
>>
>> In brief, these classes replace vtkImageActor and provide a much higher
>> level of functionality.  They are new VTK actor and mapper classes
>> specifically meant for image viewing.  What they are not: they are not
>> widgets or viewers, although they provide machinery that can be used to
>> write widget and viewer classes.  In other words, they are meant for people
>> who like to roll their own image viewers.
>>
>> The three new classes that I recommend for people to use are the
>> following:
>> vtkImageSlice - the new actor class for images
>> vtkImageResliceMapper - mapper for drawing images for MPR viewers
>> vtkImageProperty - for controlling lookup tables, window/level, opacity,
>> etc
>>
>> Typical use cases:
>>
>> 1) For an MPR viewer, use vtkInteractorStyleImage and set it to your
>> desired view orientation. Then set the following properties in
>> vtkImageResliceMapper:
>> mapper->SliceFacesCameraOn()
>> mapper->SliceAtFocalPointOn()
>> The interactor will then allow you to pan, zoom, window/level, and (in 3D
>> mode) rotate and slice.  See
>> VTK/Examples/ImageProcessing/ImageInteractorReslice.py for an example.
>>
>> 2) For a 3D ortho object, use multiple vtkImageResliceMapper objects, and
>> for each one make a vtkPlane that describes the normal and position of the
>> slice to extract. Then call these methods:
>> mapper->SetSlicePlane(plane)
>> mapper->ResampleToScreenPixelsOff()
>> Turning the "ResampleToScreenPixels" option Off makes rotation faster, so
>> it is recommended when rotations are going to be common operations.
>>  Example: VTK/Rendering/Testing/Cxx/TestImageResliceMapperOffAxis.cxx
>>
>> Features:
>> 1) oblique views (obviously!)
>> 2) nearest-neighbor, linear, and cubic interpolation
>> 3) modify image orientation with respect to world coords by setting
>> vtkImageSlice's UserMatrix
>> 4) fully multi-threaded reslicing and color mapping operations
>> 5) streaming, i.e. only pulls the data needed for rendering
>> 6) works well with very large images (as long as they fit in memory)
>> 7) LOD-style interaction (switches to faster rendering for interaction)
>> 8) blend images by adding multiple vtkImageSlice objects to a
>> vtkImageStack
>> 9) checkerboard images by setting "CheckerboardOn" in the vtkImageProperty
>> 10) thick-slab views (see vtkImageResliceMapper for details)
>> 11) works with vtkCellPicker for picking image voxels as points or cells
>>
>> For large image viewing, on a 4GB computer (64-bit OS X) I've displayed
>> images up to 3GB in size with full interactivity, but YMMV.  As long as the
>> mapper's ResampleToScreenPixels option is On, the mapper will never try to
>> load the full image onto the GPU (which is what causes the vtkImageActor to
>> be slow for large images).  The size of the images that you can display is
>> limited only by main memory, I have displayed stacks of RGB images that are
>> 10000x10000 pixels in size.
>>
>> I do not plan to push these into the VTK 5.8 release (even if Kitware were
>> to give me the go-ahead), because the VTK development tree has diverged too
>> far from the VTK 5.8 release tree.  These new image classes are only
>> possible due to recent improvements that I've made to the picker, lookup
>> table, and image reslice classes and they probably depend on a handful of
>> recent changes made by other people, as well.
>>
>>  - David
>>
>
>
>
> --
> Nam-Van TRAN
> Résidence MAYA - Bât. A2 Studio 32
> 1817 Chemin de Saint Claude
> 06600 Antibes, France
> --
> Mobile: (+33).6.40.12.78.50
> Domicile: (+33).9.51.05.28.02
> Email:  van.trannam (at) gmail.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110715/6d712f0b/attachment.htm>


More information about the vtkusers mailing list