<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
Hi all,<br><br>I'm trying to visualize a DICOM series of files with VTK but when the volume is rendered everything is wrapped within a big black box.<br><br>This is what I get: <a href="http://img64.imageshack.us/img64/3506/visualize.png">http://img64.imageshack.us/img64/3506/visualize.png</a><br><br>And the volume I should be getting is inside it.<br><br>Can someone tell me what I'm doing wrong please? Or give some advice to fix this problem?<br><br><br>Below is my code, which is a combination of "InsightToolkit\Examples\IO\DicomSeriesReadImageWrite2.cxx" and "InsightApplications\Auxiliary\vtk\itkReadITKImageShowVTK.cxx" with some adjustments.<br><br>-------------------------------------------------------------------------<br><br>#include "itkOrientedImage.h"<br>#include "itkGDCMImageIO.h"<br>#include "itkGDCMSeriesFileNames.h"<br>#include "itkImageSeriesReader.h"<br>#include "itkImageFileWriter.h"<br><br>#include "itkCommand.h"<br>#include "itkImage.h"<br>#include "itkVTKImageExport.h"<br>#include "itkVTKImageImport.h"<br>#include "itkCurvatureFlowImageFilter.h"<br>#include "itkCastImageFilter.h"<br>#include "itkRGBPixel.h"<br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>#include "vtkImageData.h"<br><br>#include "vtkImageImport.h"<br>#include "vtkImageExport.h"<br>#include "vtkImageActor.h"<br>#include "vtkRenderer.h"<br>#include "vtkRenderWindow.h"<br>#include "vtkRenderWindowInteractor.h"<br>#include "vtkInteractorStyleImage.h" <br>#include "vtkPiecewiseFunction.h"<br>#include "vtkColorTransferFunction.h"<br>#include "vtkVolumeProperty.h"<br>#include "vtkVolumeTextureMapper3D.h"<br>#include "vtkFixedPointVolumeRayCastMapper.h"<br>#include "vtkSmartPointer.h"<br><br>template <typename ITK_Exporter, typename VTK_Importer><br>void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)<br>{<br> importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());<br> importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());<br> importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());<br> importer->SetSpacingCallback(exporter->GetSpacingCallback());<br> importer->SetOriginCallback(exporter->GetOriginCallback());<br> importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());<br> importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());<br> importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());<br> importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());<br> importer->SetDataExtentCallback(exporter->GetDataExtentCallback());<br> importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());<br> importer->SetCallbackUserData(exporter->GetCallbackUserData());<br>}<br><br>template <typename VTK_Exporter, typename ITK_Importer><br>void ConnectPipelines(VTK_Exporter* exporter, ITK_Importer importer)<br>{<br> importer->SetUpdateInformationCallback(exporter->GetUpdateInformationCallback());<br> importer->SetPipelineModifiedCallback(exporter->GetPipelineModifiedCallback());<br> importer->SetWholeExtentCallback(exporter->GetWholeExtentCallback());<br> importer->SetSpacingCallback(exporter->GetSpacingCallback());<br> importer->SetOriginCallback(exporter->GetOriginCallback());<br> importer->SetScalarTypeCallback(exporter->GetScalarTypeCallback());<br> importer->SetNumberOfComponentsCallback(exporter->GetNumberOfComponentsCallback());<br> importer->SetPropagateUpdateExtentCallback(exporter->GetPropagateUpdateExtentCallback());<br> importer->SetUpdateDataCallback(exporter->GetUpdateDataCallback());<br> importer->SetDataExtentCallback(exporter->GetDataExtentCallback());<br> importer->SetBufferPointerCallback(exporter->GetBufferPointerCallback());<br> importer->SetCallbackUserData(exporter->GetCallbackUserData());<br>}<br><br>void visualize(std::string dcm)<br>{ <br><br> typedef itk::RGBPixel< signed short > PixelType;<br> const unsigned int Dimension = 3;<br><br> typedef itk::OrientedImage< PixelType, 3 > ImageType;<br><br> typedef itk::ImageSeriesReader< ImageType > ReaderType;<br> ReaderType::Pointer reader = ReaderType::New();<br><br> typedef itk::GDCMImageIO ImageIOType;<br> ImageIOType::Pointer dicomIO = ImageIOType::New();<br><br> reader->SetImageIO( dicomIO );<br><br> typedef itk::GDCMSeriesFileNames NamesGeneratorType;<br> NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();<br><br> nameGenerator->SetUseSeriesDetails( true );<br> nameGenerator->AddSeriesRestriction("0008|0021" );<br><br> nameGenerator->SetDirectory(directoryPath);<br> <br> try{<br> std::cout << std::endl << "The directory: " << std::endl;<br> std::cout << std::endl << directoryPath << std::endl << std::endl;<br> std::cout << "Contains the following DICOM Series: ";<br> std::cout << std::endl << std::endl;<br><br> typedef std::vector< std::string > SeriesIdContainer;<br><br> const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();<br> <br> SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();<br> SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();<br> while( seriesItr != seriesEnd ) {<br> std::cout << seriesItr->c_str() << std::endl;<br> seriesItr++;<br> }<br><br> std::string seriesIdentifier;<br> seriesIdentifier = seriesUID.begin()->c_str();<br> <br> std::cout << std::endl << std::endl;<br> std::cout << "Now reading series: " << std::endl << std::endl;<br> std::cout << seriesIdentifier << std::endl;<br> std::cout << std::endl << std::endl;<br><br> typedef std::vector< std::string > FileNamesContainer;<br> FileNamesContainer fileNames;<br><br> fileNames = nameGenerator->GetFileNames( seriesIdentifier );<br><br> FileNamesContainer::const_iterator iterator = fileNames.begin();<br> FileNamesContainer::const_iterator final = fileNames.end();<br> while( iterator != final )<br> {<br> std::cout << iterator->c_str() << std::endl;<br> iterator++;<br> }<br><br>reader->SetFileNames( fileNames ); <br><br> try<br> {<br> reader->Update();<br> }<br> catch (itk::ExceptionObject &ex)<br> {<br> std::cout << ex << std::endl;<br> return EXIT_FAILURE;<br> }<br><br> }<br>catch (itk::ExceptionObject &ex)<br> {<br> std::cout << ex << std::endl;<br> return EXIT_FAILURE;<br> }<br><br><br>typedef itk::VTKImageExport< ImageType > ExportFilterType;<br>ExportFilterType::Pointer itkExporter = ExportFilterType::New(); <br><br>itkExporter->SetInput( reader->GetOutput() );<br> <br>vtkImageImport* vtkImporter = vtkImageImport::New(); <br>ConnectPipelines(itkExporter, vtkImporter);<br><br>typedef itk::VTKImageImport< ImageType > ImportFilterType;<br>ImportFilterType::Pointer itkImporter = ImportFilterType::New();<br><br>vtkImageExport* vtkExporter = vtkImageExport::New(); <br>ConnectPipelines(vtkExporter, itkImporter);<br> <br>vtkExporter->SetInput( vtkImporter->GetOutput() );<br> <br> <br>vtkPiecewiseFunction* opacityTransferFunction = vtkPiecewiseFunction::New();<br>opacityTransferFunction->AddPoint(0, 0.00);<br>opacityTransferFunction->AddPoint(500, 0.15);<br>opacityTransferFunction->AddPoint(1000, 0.15);<br>opacityTransferFunction->AddPoint(1150, 0.85);<br><br>vtkColorTransferFunction* colorTransferFunction = vtkColorTransferFunction::New(); <br>colorTransferFunction->AddRGBPoint(0, 0.0, 0.0, 0.0);<br>colorTransferFunction->AddRGBPoint(500, 1.0, 0.5, 0.3);<br>colorTransferFunction->AddRGBPoint(1000, 1.0, 0.5, 0.3);<br>colorTransferFunction->AddRGBPoint(1150, 1.0, 1.0, 0.9);<br> <br>vtkVolume* volume = vtkVolume::New();<br>vtkVolumeProperty* volumeProperty = vtkVolumeProperty::New(); <br> vtkFixedPointVolumeRayCastMapper* volumeMapperSoftware = vtkFixedPointVolumeRayCastMapper::New();<br><br>volumeProperty->SetScalarOpacity(opacityTransferFunction);<br>volumeProperty->SetColor(colorTransferFunction);<br>volumeProperty->SetInterpolationTypeToLinear();<br>volumeProperty->ShadeOff();<br>volume->SetProperty(volumeProperty); <br><br>volumeMapperSoftware->SetInput(vtkImporter->GetOutput());<br>volumeMapperSoftware->SetSampleDistance(1.0);<br>volume->SetMapper(volumeMapperSoftware);<br><br>vtkInteractorStyleTrackballCamera * interactorStyle = vtkInteractorStyleTrackballCamera::New();<br><br>vtkRenderer* renderer = vtkRenderer::New();<br>vtkRenderWindow* renWin = vtkRenderWindow::New();<br>vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();<br> <br> renWin->SetSize(500, 500);<br> renWin->AddRenderer(renderer);<br> iren->SetRenderWindow(renWin);<br> iren->SetInteractorStyle(interactorStyle);<br><br> renderer->AddVolume(volume);<br><br> renderer->SetBackground(0.5, 0.5, 0.5);<br><br> renWin->Render();<br> iren->Start();<br><br> vtkImporter->Delete();<br> vtkExporter->Delete();<br> renWin->Delete();<br> renderer->Delete();<br> iren->Delete();<br>}<br><br>int main(int argc, char * argv [] )<br>{ <br> if( argc < 2 )<br> {<br> std::cerr << "Usage: " << argv[0] << " path to DICOM series" << std::endl;<br> return 1;<br> }<br><br> visualize(argv[1]);<br><br> return 0;<br>}                                            </body>
</html>