[Insight-users] Problems in rendering 3D volume data in VTK using ITK Image3D type

Luis Ibanez luis.ibanez at kitware.com
Tue, 24 Feb 2004 15:38:33 -0500


Hi Jihoon,

The message is stating that VTK RayCasting
requires your volume to be of pixel type
"unsigned char" or "unsiged short".


You can switch the pixel type of the VTK
image by calling

    connector->GetImporter()->SetDataScalarTypeToUnsignedShort()

This method belongs to the vtkImageImport filter:

   http://www.vtk.org/doc/nightly/html/classvtkImageImport.html

The two methods you may want to use are:

    void SetDataScalarTypeToUnsignedShort ()
    void SetDataScalarTypeToUnsignedChar ()


Regards,


   Luis


---------------------
Jihoon Jeong wrote:

> Hi ! folks,
> 
>  
> 
> Recently, I tried connecting ITK + VTK stuffs.
> 
> I completed successful examples using ITK Image3D type in rendering 2D 
> slices in vtkImageViewer.
> 
> But, I failed to render 3D volumes in VTK using same data. Compile and 
> link has no problem.
> 
>  
> 
> I got following messages from VTK output windows.
> 
>  
> 
> ERROR: In vtkVolumeRayCastMapper.cxx, line 328
> 
> vtkOpenGLVolumeRayCastMapper (01BBB678): Cannot volume render data of 
> type unsigned int, only unsigned char or unsigned short.
> 
>  
> 
> Followings are code snippets.
> 
>  
> 
> #include "itkImageFileReader.h"
> 
> #include "itkImageToVTKImageFilter.h"
> 
>> 
>  
> 
> #include "vtkRenderer.h"
> 
> #include "vtkRenderWindow.h"
> 
>> 
>  
> 
> int main (int argc, char **argv ) {
> 
> typedef itk::Image<unsigned int,3>                  Image3DType;
> 
>   typedef itk::ImageToVTKImageFilter<Image3DType>    ConnectorType;
> 
>  
> 
>   itk::NumericSeriesFileNames::Pointer fileIter = 
> itk::NumericSeriesFileNames::New();
> 
>     fileIter->SetStartIndex(1);
> 
>     fileIter->SetEndIndex(107);
> 
>     fileIter->SetIncrementIndex(1);
> 
>     fileIter->SetSeriesFormat("1%03d.dcm");
> 
>  
> 
>   itk::ImageSeriesReader<Image3DType>::Pointer reader = 
> itk::ImageSeriesReader<Image3DType>::New();
> 
>     reader->SetFileNames(fileIter->GetFileNames());
> 
>  
> 
>   try {
> 
>         reader->Update();
> 
>   }
> 
>   catch (itk::ExceptionObject & err) {
> 
>     std::cout << "ExceptionObject caught !" << std::endl;
> 
>     std::cout << err << std::endl;
> 
>     return -1;
> 
>   }
> 
>  
> 
>   ConnectorType::Pointer connector = ConnectorType::New();
> 
>     connector->SetInput(reader->GetOutput());
> 
>  
> 
>   vtkRenderer* renderer = vtkRenderer::New();
> 
>   vtkRenderWindow* renWin = vtkRenderWindow::New();
> 
>     renWin->AddRenderer(renderer);
> 
>   vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
> 
>     iren->SetRenderWindow(renWin);
> 
>  
> 
>   // Create transfer mapping scalar value to opacity
> 
>   vtkPiecewiseFunction* opacityTransferFunction = 
> vtkPiecewiseFunction::New();
> 
>         opacityTransferFunction->AddPoint(20.0, 0.0);
> 
>         opacityTransferFunction->AddPoint(255.0, 0.2);
> 
>  
> 
>   // The property describes how the data will look
> 
>   vtkVolumeProperty* volumeProperty = vtkVolumeProperty::New();
> 
>     volumeProperty->SetScalarOpacity(opacityTransferFunction);
> 
>     
> 
>   // The mapper / ray cast functions know how to render the data
> 
>   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);
> 
> volume->SetProperty(volumeProperty);
> 
>  
> 
>   renderer->AddProp(volume);
> 
>   renWin->Render();
> 
> iren->Start();
> 
>  
> 
>> 
>  
> 
> Any Idea ?
> 
>  
> 
> Jihoon Jeong
>