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

polys_poly at hotmail.com polys_poly at hotmail.com
Tue Apr 1 08:34:57 EDT 2008


Hello,

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. I understand that the example in itkReadITKImageShowVTK.cpp is about visualizing an image and not a volume. But i believe i have made the necessary changes needed in order to visualize the volume i want. Here is my code. 
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());

}

int itkReadDicomSeries (std::string directoryPath)

{ 

typedef signed short 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();


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);

volumeMapperSoftware->SetBlendModeToMaximumIntensity();

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);

renderer->SetBackground(0.4392, 0.5020, 0.5647);



// Bring up the render window and begin interaction.

renWin->Render();

iren->Start();

}

I would really appreciate any help. Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080401/ca5227de/attachment.htm>


More information about the Insight-users mailing list