[Insight-users] Reading a Dicom Series in ITK and visualizing the volume in VTK

polys_poly at hotmail.com polys_poly at hotmail.com
Fri Apr 4 14:52:43 EDT 2008


I have combined the code found in itkReadITKImageShowVTK.cpp file (InsightApplications\Auxiliary\vtk) and the code found in DicomSeriesReadImageWrite2.cpp (InsightToolkit\Examples\IO) to read a DICOM series and visualize it in VTK. My problem is that the volume is not visualized correctly. I believe something's wrong with the opacity. Here is my code. 

this is what i get when i read the dicom series in itk and visualize it in vtk

http://img385.imageshack.us/img385/6632/itkla0.jpg

and this is what i want the volume to look like (reading dicom series and visualizing the volume in vtk)

http://img389.imageshack.us/img389/9425/vtkif8.jpg


template <typename ITK_Exporter, typename VTK_Importer>
void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)
{
  importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
  importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
  importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
  importer->SetSpacingCallback(exporter->GetSpacingCallback());
  importer->SetOriginCallback(exporter->GetOriginCallback());
  importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
  importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
  importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
  importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
  importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
  importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
  importer->SetCallbackUserData(exporter->GetCallbackUserData());
}

/**
 * This function will connect the given vtkImageExport filter to
 * the given itk::VTKImageImport filter.
 */
template <typename VTK_Exporter, typename ITK_Importer>
void ConnectPipelines(VTK_Exporter* exporter, ITK_Importer importer)
{
  importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());
  importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());
  importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());
  importer->SetSpacingCallback(exporter->GetSpacingCallback());
  importer->SetOriginCallback(exporter->GetOriginCallback());
  importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());
  importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());
  importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());
  importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());
  importer->SetDataExtentCallback(exporter->GetDataExtentCallback());
  importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());
  importer->SetCallbackUserData(exporter->GetCallbackUserData());
}

int itkReadDicomSeries (std::string directoryPath)
{ 
 typedef unsigned char    PixelType;
 const unsigned int      Dimension = 3;

 typedef itk::OrientedImage< PixelType, Dimension > ImageType;

 typedef itk::ImageSeriesReader< ImageType > ReaderType;
 ReaderType::Pointer reader = ReaderType::New();

 typedef itk::GDCMImageIO       ImageIOType;
 ImageIOType::Pointer dicomIO = ImageIOType::New();

 reader->SetImageIO( dicomIO );

 typedef itk::GDCMSeriesFileNames NamesGeneratorType;
 NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();

 nameGenerator->SetUseSeriesDetails( true );
 nameGenerator->AddSeriesRestriction("0008|0021" );

 nameGenerator->SetDirectory(directoryPath);
 
 std::cout << std::endl << "The directory: " << std::endl;
 std::cout << std::endl << directoryPath << std::endl << std::endl;
 std::cout << "Contains the following DICOM Series: ";
 std::cout << std::endl << std::endl;

 typedef std::vector< std::string >    SeriesIdContainer;

 const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();

 SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
 SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
 while( seriesItr != seriesEnd ) {
  std::cout << seriesItr->c_str() << std::endl;
  seriesItr++;
 }

    std::string seriesIdentifier;
    seriesIdentifier = seriesUID.begin()->c_str();
 
    std::cout << std::endl << std::endl;
    std::cout << "Now reading series: " << std::endl << std::endl;
    std::cout << seriesIdentifier << std::endl;
    std::cout << std::endl << std::endl;

    typedef std::vector< std::string >   FileNamesContainer;
    FileNamesContainer fileNames;

    fileNames = nameGenerator->GetFileNames( seriesIdentifier );

reader->SetFileNames( fileNames );  
reader->Update();
 
typedef itk::VTKImageExport< ImageType > ExportFilterType;
    ExportFilterType::Pointer itkExporter = ExportFilterType::New(); 

    itkExporter->SetInput( reader->GetOutput() );
 
// Create the vtkImageImport and connect it to the itk::VTKImageExport instance.
    vtkImageImport* vtkImporter = vtkImageImport::New();  
    ConnectPipelines(itkExporter, vtkImporter);
 
vtkPiecewiseFunction* opacityTransferFunction = vtkPiecewiseFunction::New();
    vtkColorTransferFunction* colorTransferFunction = vtkColorTransferFunction::New();  
 
vtkVolume* volume = vtkVolume::New();
vtkVolumeProperty* volumeProperty = vtkVolumeProperty::New(); 
    vtkVolumeTextureMapper3D* volumeMapper = vtkVolumeTextureMapper3D::New();
    vtkFixedPointVolumeRayCastMapper* volumeMapperSoftware = vtkFixedPointVolumeRayCastMapper::New();
 
    volumeProperty->SetScalarOpacity(opacityTransferFunction);
    volumeProperty->SetInterpolationTypeToLinear();
    volumeProperty->ShadeOff(); 
    volume->SetProperty(volumeProperty); 

 volumeMapperSoftware->SetInput(vtkImporter->GetOutput());
 volumeMapperSoftware->SetSampleDistance(1.0);
   volume->SetMapper(volumeMapperSoftware);

    vtkInteractorStyleTrackballCamera * interactorStyle = vtkInteractorStyleTrackballCamera::New();

    // Create a renderer, render window, and render window interactor to display the results.
    vtkRenderer* renderer = vtkRenderer::New();
    vtkRenderWindow* renWin = vtkRenderWindow::New();
    vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
    
    renWin->SetSize(500, 500);
    renWin->AddRenderer(renderer);
    iren->SetRenderWindow(renWin);
    iren->SetInteractorStyle(interactorStyle);
    
    // Add the vtkImageActor to the renderer for display.
     renderer->AddVolume(volume);
    
    // Bring up the render window and begin interaction.
    renWin->Render();
    iren->Start();

 return 0;
}

If anyone has another working example that does what i am trying to do please let me know. I would really appreciate it.

Thanks in advance,
Polys
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080404/1d6fec7d/attachment.htm>


More information about the Insight-users mailing list