[vtkusers] Displaying multiple images from ITK with VTK 5.0

Brian Eastwood beastwoo at email.unc.edu
Sat Mar 18 22:59:26 EST 2006


Hi All,

I'm relatively new to VTK; I have been using it to visualize images that 
I am processing in ITK, using wxWidgets as my GUI toolkit.  With the 
latest release (VTK 5.0), the pipeline I had set up stopped 
working--after I display one image, I can never display another image 
again.  Here are the components I put together:
....
    // from the class def
    typedef itk::Image<float, 2> InputImageType;
    typedef itk::Image<unsigned char, 2> DisplayImageType;
    typedef itk::RescaleIntensityImageFilter<InputImageType, 
DisplayImageType> RescalerType;
    typedef itk::ImageToVTKImageFilter<DisplayImageType> ConverterType;

    RescalerType::Pointer rescaler; // changes pixel type to unsigned 
char and stretches intensity
    ConverterType::Pointer converter; // converts ITK data into VTK data
    vtkImageFlip* flipper; // I think ITK and VTK use different y-axis 
conventions
    vtkImageActor* actor;
    vtkRenderer* renderer;
    vtkInteractorStyle* style;
...

I set them up as follows:
...
    // from an initialization method
    this->rescaler = RescalerType::New();
    this->converter = ConverterType::New();
    this->flipper = vtkImageFlip::New();
    this->actor = vtkImageActor::New();
    this->renderer = vtkRenderer::New();
    this->style = vtkInteractorStyleImage::New(); // restricts motion to 
xy plane

    // Rescale intensities for max contrast on 8-bit displays
    this->rescaler->SetOutputMinimum(0);
    this->rescaler->SetOutputMaximum(255);
    this->flipper->SetFilteredAxis(1); // flip the y axis.

    // Assemble the pipeline.
    this->converter->SetInput(this->rescaler->GetOutput());
    this->flipper->SetInput(this->converter->GetOutput());
    this->actor->SetInput(this->flipper->GetOutput());
    this->renderer->AddActor(this->actor);
    // I'm using wxVTKRenderWindowInteractor
    
this->GetVtkInteractor()->GetRenderWindow()->AddRenderer(this->renderer);
    this->GetVtkInteractor()->SetInteractorStyle(this->style);

And when I get new image data to display:
...
    // from SetImage(InputImageType::Pointer image)
    // Set the image data in the pipeline
    this->rescaler->SetInput(image);

    // Removing the existing actor and creating a new one
    // ensures we see the whole image if the new image is a
    // different size from the old one.  But, we still
    // maintain the image transforms (zoom and pan) from the
    // old view.
    this->renderer->RemoveActor(this->actor);
    this->actor->Delete();
    this->actor = vtkImageActor::New();
    this->actor->SetInput(this->flipper->GetOutput());
    this->renderer->AddActor(this->actor);

    this->GetVtkInteractor()->GetRenderWindow()->Render();

Again, this seemed to work fine in the previous versions of VTK.  I've 
tried calling Update() on all the components to see if I had to force 
them to see changes, but that didn't help.  I think I could rebuild the 
entire pipeline and get the images to update, but that seems to defeat 
the purpose of a pipeline.  Has something changed so that my pipeline is 
no longer updating properly?

Thanks,
Brian Eastwood




More information about the vtkusers mailing list