[vtkusers] Reading DICOM using vtkImageActor

David Gobbi david.gobbi at gmail.com
Tue Mar 4 13:44:54 EST 2014


Hi Sam,

There are a couple issues here.  First, the mapper for vtkImageActor
is vtkImageSliceMapper, not vtkImageMapper.  The vtkImageMapper is not
compatible with vtkImageActor.  Second, the mapper is created is
created by the vtkImageActor, so to get the mapper, you should do
this:

vtkImageSliceMapper *mapper = actor->GetMapper();

Then, you should be able to use mapper->SetSliceNumber(n) to set the
slice.  See the documentation for vtkImageSliceMapper for more
information.

Also, at least on my computer, the fonts in your emails are tiny and
almost impossible to read... please either fix the fonts, or just send
your emails as plain text.

  David




On Tue, Mar 4, 2014 at 11:29 AM, Sam Raby <rabysam28 at gmail.com> wrote:
> I learnt that this seems to be a bug as reported here:
>
> http://www.paraview.org/Bug/bug_relationship_graph.php?bug_id=3661&graph=dependency
>
> From the link, I figured we can get around this issue by using
> GetDisplayExtent. So the following code works:
>
>
>     // DICOM Reader
>
>     vtkSmartPointer<vtkDICOMImageReader> reader =
> vtkSmartPointer<vtkDICOMImageReader>::New();
>
>     reader->SetDirectoryName("/home/Images/DICOM");
>
>     reader->Update();
>
>
>     // Mapper
>
>     vtkSmartPointer<vtkImageMapper> imageMapper =
> vtkSmartPointer<vtkImageMapper>::New();
>
>     imageMapper->SetInputData(reader->GetOutput());
>
>     imageMapper->SetZSlice(12); // does not work.
>
>
>     // Actor
>
> vtkSmartPointer<vtkImageActor> mapActor =
> vtkSmartPointer<vtkImageActor>::New();
>
>     mapActor->SetInputData(imageMapper->GetInput());
>
>     mapActor->SetZSlice(12); // this also does not work.
>
>
>
> On Tue, Mar 4, 2014 at 11:10 AM, Sam Raby <rabysam28 at gmail.com> wrote:
>>
>> Hi,
>>
>> I am trying to read DICOM series using vtkImageActor. (Note: I know I can
>> read them easily by vtkImageViewer2, however it is not suitable for my
>> application).
>>
>> The problem is when I use SetZSlice, it does not update the slice and it
>> always shows the first slice of DICOM. I call SetZSlice in both
>> vtkImageActor and vtkImageMapper but it does not change the slice.
>>
>> Thanks for any tips, and here is my simple code:
>>
>>     // DICOM Reader
>>
>>     vtkSmartPointer<vtkDICOMImageReader> reader =
>> vtkSmartPointer<vtkDICOMImageReader>::New();
>>
>>     reader->SetDirectoryName("/home/Images/DICOM");
>>
>>     reader->Update();
>>
>>
>>     // Mapper
>>
>>     vtkSmartPointer<vtkImageMapper> imageMapper =
>> vtkSmartPointer<vtkImageMapper>::New();
>>
>>     imageMapper->SetInputData(reader->GetOutput());
>>
>>     imageMapper->SetZSlice(12); // does not work.
>>
>>
>>     // Actor
>>
>> vtkSmartPointer<vtkImageActor> mapActor =
>> vtkSmartPointer<vtkImageActor>::New();
>>
>>     mapActor->SetInputData(imageMapper->GetInput());
>>
>>     mapActor->SetZSlice(12); // this also does not work.
>>
>>
>>     // Visualization
>>
>>     vtkRenderer *ren=vtkRenderer::New();
>>
>>     ren->AddActor(mapActor);
>>
>>     ren->ResetCamera();
>>
>>
>>     vtkSmartPointer<vtkRenderWindow> renderWindow =
>> vtkSmartPointer<vtkRenderWindow>::New();
>>
>>     renderWindow->AddRenderer(ren);
>>
>>
>>     vtkSmartPointer<vtkRenderWindowInteractor> iren =
>> vtkSmartPointer<vtkRenderWindowInteractor>::New();
>>
>>     iren->SetRenderWindow(renderWindow);
>>
>>     iren->Start();


More information about the vtkusers mailing list