[vtkusers] Using ImagePlaneWidget to display 3D Images

Imre Goretzki goretzki.imre at gmail.com
Sat Nov 28 09:42:26 EST 2015


Hey guys

I have some trouble displaying a 3D Image (multipaged tif) via VTK. My 
Setup:

grayscale image (520x520x47)
Single slice (1 to 47) is an image (520x520)
reading via ITK works great, I even can display 2D images using the 
ImageToVTKImageFilter

Now the problem:

I tried to connect the ITK image with VTK to visualize the image. I use 
the ImageToVTKImageFilter to connect ITK with VTK. Displaying 2D images 
(a single slice of the whole image) works, but i dont know how to 
display the 3D volume.

For reference, I tried to change these examples to work with the 
connector type:
http://itk.org/Wiki/ITK/Examples/ImageProcessing/MinimumMaximumImageCalculator
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Widgets/ImagePlaneWidget

My code:

void MainWindow::displayOriginalImage(PointerImage3D img)
{
     typedef itk::ImageToVTKImageFilter<Image3DType> TemplatedConnectorType;
     TemplatedConnectorType::Pointer con = TemplatedConnectorType::New();
     con->SetInput(img);
     cout <<  "1" << endl;
//    vtkSmartPointer<vtkPolyDataMapper> mapper = 
vtkSmartPointer<vtkPolyDataMapper>::New();
     cout <<  "2" << endl;
     vtkSmartPointer<vtkImageActor> actor = 
vtkSmartPointer<vtkImageActor>::New();
     try {
         con->Update();
     } catch (itk::ExceptionObject &e)
     {
         cerr << e << endl;
     }
     actor->GetMapper()->SetInputData(con->GetOutput());
     cout <<  "3" << endl;
//    mapper->SetInputConnection(con->GetOutputPort());
     cout <<  "4" << endl;
//    actor->SetMapper(mapper);


     vtkSmartPointer<vtkRenderer> renderer = 
vtkSmartPointer<vtkRenderer>::New();
     vtkSmartPointer<vtkRenderWindow> wnd = 
vtkSmartPointer<vtkRenderWindow>::New();
     wnd->AddRenderer(renderer);
     renderer->AddActor(actor);

     vtkSmartPointer<vtkRenderWindowInteractor> wndInteractor = 
vtkSmartPointer<vtkRenderWindowInteractor>::New();
     wndInteractor->SetRenderWindow(wnd);
     vtkSmartPointer<vtkInteractorStyleImage> styler = 
vtkSmartPointer<vtkInteractorStyleImage>::New();
     wndInteractor->SetInteractorStyle(styler);

     vtkSmartPointer<vtkImagePlaneWidget> planeWidget = 
vtkSmartPointer<vtkImagePlaneWidget>::New();
     cout << "5" << endl;
     planeWidget->SetInputData(con->GetOutput());
     cout << "6" << endl;
     planeWidget->SetInteractor(wndInteractor);

     double origin[3] = {0,1,0};
     planeWidget->SetOrigin(origin);
     planeWidget->UpdatePlacement();

//    renderer->ResetCamera();
     wnd->Render();

     wndInteractor->Initialize();
     wnd->Render();
     cout << "7" << endl;
     planeWidget->On();
     cout << "8" << endl;
     wndInteractor->Start();
}

If I do this, all I get is a white image. May to tell me, what I'm doing 
wrong?

In case that you wonder, why I print out the numbers:

Between 1 and 2:
If I enable this, the compiler says that the line between 3 and 4 is a 
invalid use of the mapper.

Between 7 and 8:
I have to set the input data or connection (between 5 and 6) in order to 
make the planeWidget->On() work (the widget tries to access indices that 
do not exist, because there is no connection or data, that is what I guess)

Thank you,
Imre



More information about the vtkusers mailing list