[Insight-users] Reading a Dicom Series and visualizing it in vtk
Luis Ibanez
luis.ibanez at kitware.com
Tue Apr 1 20:15:05 EDT 2008
Hi Polys_poly,
Please do the following:
a) After reading in the DICOM image,
call Print(std::cout) on the image,
in order to verify if the image was read
correctly. You will be able to verify
parameters such as origin, spacing,
orientation and number of pixels
b) After converting the ITK image to vtkImageData,
also call Print(std::cout) on the vtkImageData.
In this way you will verify whether the conversion
was successful or not, by looking at origin, spacing
and number of pixels.
Please post to the mailing list the output that you
get from (a) and (b) above,
Thanks,
Luis
----------------------------
polys_poly at hotmail.com wrote:
> 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. 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.
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list