[vtkusers] Reading DICOM using vtkImageActor

Sam Raby rabysam28 at gmail.com
Mon Mar 31 12:18:25 EDT 2014


Here is the code without text formatting:

 vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<
vtkDICOMImageReader>::New();
    reader->SetDirectoryName("/home/DICOM_Dir");
    reader->Update();
    vtkSmartPointer<vtkImageActor> imageActor =
vtkSmartPointer<vtkImageActor>::New();
    imageActor->SetInputData(reader->GetOutput());

    imageMapper = vtkImageSliceMapper::SafeDownCast(
imageActor->GetMapper() );
    imageMapper->SetSliceNumber(10);
    vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
    ren->AddActor(imageActor);
    ren->ResetCamera();

    vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
    renWin->AddRenderer(ren);

    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
    vtkSmartPointer<vtkInteractorStyleTrackballCamera> interactorImageStyle
= vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();

    renderWindowInteractor->SetInteractorStyle(interactorImageStyle);
    renWin->SetInteractor(renderWindowInteractor);
    renderWindowInteractor->SetRenderWindow(renWin);
    renderWindowInteractor->Initialize();
    renderWindowInteractor->Start();


On Mon, Mar 31, 2014 at 11:11 AM, Sam Raby <rabysam28 at gmail.com> wrote:

> Hi,
>
> As mentioned, I am reading DICOM using vtkImageActor instead of
> vtkImageReviewer2. I have a simple code below. The problem is that when I
> run the code, the slice does not show up, unless I slightly manipulate the
> window by mouse. Once I touch the window and move the mouse, the slice
> shows up immediately. Would you let me know why this happens?
>
>     vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<
> vtkDICOMImageReader>::New();
>     reader->SetDirectoryName("/home/DICOM_Dir");
>     reader->Update();
>     vtkSmartPointer<vtkImageActor> imageActor = vtkSmartPointer<vtkImageActor>::New();
>     imageActor->SetInputData(reader->GetOutput());
>
>     imageMapper = vtkImageSliceMapper::SafeDownCast( imageActor->GetMapper() );
>     imageMapper->SetSliceNumber(10);
>     vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
>     ren->AddActor(imageActor);
>     ren->ResetCamera();
>
>     vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
>     renWin->AddRenderer(ren);
>
>     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
>     vtkSmartPointer<vtkInteractorStyleTrackballCamera> interactorImageStyle = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
>
>     renderWindowInteractor->SetInteractorStyle(interactorImageStyle);
>     renWin->SetInteractor(renderWindowInteractor);
>     renderWindowInteractor->SetRenderWindow(renWin);
>     renderWindowInteractor->Initialize();
>     renderWindowInteractor->Start();
>
>
> Thanks.
>
> -S
>
>
>
> On Fri, Mar 21, 2014 at 12:57 AM, Sam Raby <rabysam28 at gmail.com> wrote:
>
>> Thanks David. Adding SafeDownCast rectified the error, and I can now
>> change the slice number using vtkImageSliceMapper object.
>>
>> I initially was going to change the slice number through vtkImageActor,
>> but the method that is in charge (i.e. SetZSlice) appeared to be not
>> working, as reported in the past on the link, and hence I thought to
>> change the slice number via its mapper. Thanks for the help!
>>
>> http://www.paraview.org/Bug/bug_relationship_graph.php?
>> bug_id=3661&graph=dependency
>>
>>
>> -S
>>
>>
>> On Wed, Mar 19, 2014 at 2:28 PM, David Gobbi <david.gobbi at gmail.com>wrote:
>>
>>> On Wed, Mar 19, 2014 at 12:59 PM, Sam Raby <rabysam28 at gmail.com> wrote:
>>> > thanks for the feedback. I am following your solution as below:
>>> >
>>> > vtkImageSliceMapper* myMapper = myActor->GetMapper();
>>> > myMapper->SetSliceNumber(sliceNum);
>>> >
>>> > However I am getting the following error:
>>> >
>>> > error: invalid conversion from 'vtkImageMapper3D*' to
>>> 'vtkImageSliceMapper*'
>>> > [-fpermissive]
>>> >
>>> > I was not sure how to address this. Am I missing something here?
>>>
>>> Oops, I guess it needs a cast.
>>>
>>> vtkImageSliceMapper* myMapper =
>>>   vtkImageSliceMapper::SafeDownCast(myActor->GetMapper());
>>>
>>> Perhaps vtkImageActor should have a SetSliceNumber() and
>>> SetOrientation() method itself, instead of these methods being just in
>>> the mapper.
>>>
>>>   David
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140331/dffb0dda/attachment.html>


More information about the vtkusers mailing list