[Insight-users] Some Questions on ITK - VTK connection

Markus Weigert m.weigert at fz-juelich.de
Thu Mar 30 07:21:55 EST 2006


Dear all,

I encountered a problem when trying to visualize an Image in VTK which 
was loaded in ITK.
To visualize it, I want to use the VTK - Maximum Intensity Projection.
Therefore, I convert the ITK image to a VTK image with  
ITKImageToVTKImageFilter.
The code for the MIP is taken from a very basic example and should work.
Because I use a fltk GUI, I also use vtkFlRenderWindowInteractor instead 
of vtkRenderWindowInteractor.

The Problem is, that after the image is loaded and send to vtk, nothing
shows up in the render window (which is a classmember of the GUI class) 
and additionally,
if I click in the renderwindow, the application exits, what should not 
happen.

I also noticed, that I can not call renderWindowInteractor->Start() 
because then
an error macro will be executed.
I suppose this is intended because an endless commandloop in Start() 
would stop
the whole application from taking requests.
Perhaps, somebody may look at the following code and help me to find the 
reason for the behavoir.

Thanks  a lot in advance,
Markus


 The vtkFlRenderWindowInteractor and vtkRenderer are initialised in the 
GUI - constructor (because they are members):

    RIP_GUI_Implementation::RIP_GUI_Implementation()   
    {       
            m_3DRenderWindow  = vtkRenderWindow::New();
            m_3DRenderWindowInteractor = vtkFlRenderWindowInteractor::New();
            m_3DRenderWindowInteractor->SetRenderWindow(m_3DRenderWindow);
            m_3DRenderer = vtkRenderer::New();
            m_3DRenderer->SetBackground(0, 0, 0);
            m_3DRenderWindow->AddRenderer(m_3DRenderer);   
            m_3DRenderer->GetActiveCamera()->Zoom( 1.0 );
            m_3DRenderer->GetActiveCamera()->SetPosition(0.0, 0.0, 20.0 );
            m_3DRenderWindowInteractor->Initialize();
    }

Here is the code, which is called after a new image was loaded:

 void RIP_GUI_Implementation::initializeViews(std::string imageRole)
    {
                // here is the relevant part, mostly taken from example 
code:

                typedef itk::Image<unsigned char, 3> vtkImageType;
                typedef itk::RescaleIntensityImageFilter<ImageType> 
RescaleType;
                typedef itk::CastImageFilter<ImageType,vtkImageType> 
CasterType; //cast Image type from short to unsigned char for vtk
 
                RescaleType::Pointer rescaler = RescaleType::New();
                CasterType::Pointer caster = CasterType::New();
                rescaler->SetInput(m_refImage);
                rescaler->SetOutputMinimum(0);
                rescaler->SetOutputMaximum(255);
                caster->SetInput(rescaler->GetOutput());
 
                itk::ImageToVTKImageFilter<vtkImageType>::Pointer 
connector = itk::ImageToVTKImageFilter<vtkImageType>::New();
                connector->GetExporter()->SetInput( caster->GetOutput() );
                connector->GetImporter()->Update();
                connector->GetImporter()->GetOutput()->Print(std::cout);
                caster->Update();
                connector->Update();

               
            // Create transfer mapping scalar value to opacity
            vtkPiecewiseFunction* opacityTransferFunction = 
vtkPiecewiseFunction::New();
            opacityTransferFunction->AddPoint(20, 0.0);
            opacityTransferFunction->AddPoint(255, 0.2);

            // Create transfer mapping scalar value to color
            vtkColorTransferFunction* colorTransferFunction = 
vtkColorTransferFunction::New();
            colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
            colorTransferFunction->AddRGBPoint(64.0, 1.0, 0.0, 0.0);
            colorTransferFunction->AddRGBPoint(128.0, 0.0, 0.0, 1.0);
            colorTransferFunction->AddRGBPoint(192.0, 0.0, 1.0, 0.0);
            colorTransferFunction->AddRGBPoint(255.0, 0.0, 0.2, 0.0);

            // The property describes how the data will look
            vtkVolumeProperty* volumeProperty = vtkVolumeProperty::New();
            volumeProperty->SetColor(colorTransferFunction);
            volumeProperty->SetScalarOpacity(opacityTransferFunction);
            volumeProperty->ShadeOn();
            volumeProperty->SetInterpolationTypeToLinear();

            // The mapper / ray cast function know how to render the data
            vtkVolumeRayCastMIPFunction* MIP = 
vtkVolumeRayCastMIPFunction::New();
            vtkVolumeRayCastMapper* volumeMapper = 
vtkVolumeRayCastMapper::New();
            volumeMapper->SetVolumeRayCastFunction(MIP);
            volumeMapper->SetInput(connector->GetImporter()->GetOutput());

             //Another RayCast - Function
            //vtkVolumeRayCastCompositeFunction* compositeFunction = 
vtkVolumeRayCastCompositeFunction::New();
            //vtkVolumeRayCastMapper* volumeMapper = 
vtkVolumeRayCastMapper::New();
            //volumeMapper->SetVolumeRayCastFunction(compositeFunction);
            //volumeMapper->SetInput(connector->GetOutput());
           

            // The volume holds the mapper and the property and
            // can be used to position/orient the volume
            vtkVolume* volume = vtkVolume::New();
            volume->SetMapper(volumeMapper);
            volumeMapper->Update();
            volume->SetProperty(volumeProperty);

            m_3DRenderer->AddVolume(volume);
            m_3DRenderWindowInteractor->Initialize();
            m_3DRenderWindow->Render();
          .....
    }




More information about the Insight-users mailing list