<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 &lt;typename ITK_Exporter, typename VTK_Importer&gt;<br>void ConnectPipelines(ITK_Exporter exporter, VTK_Importer* importer)<br>{<br>&nbsp; importer-&gt;SetUpdateInformationCallback(exporter-&gt;GetUpdateInformationCallback());<br>&nbsp; importer-&gt;SetPipelineModifiedCallback(exporter-&gt;GetPipelineModifiedCallback());<br>&nbsp; importer-&gt;SetWholeExtentCallback(exporter-&gt;GetWholeExtentCallback());<br>&nbsp; importer-&gt;SetSpacingCallback(exporter-&gt;GetSpacingCallback());<br>&nbsp; importer-&gt;SetOriginCallback(exporter-&gt;GetOriginCallback());<br>&nbsp; importer-&gt;SetScalarTypeCallback(exporter-&gt;GetScalarTypeCallback());<br>&nbsp; importer-&gt;SetNumberOfComponentsCallback(exporter-&gt;GetNumberOfComponentsCallback());<br>&nbsp; importer-&gt;SetPropagateUpdateExtentCallback(exporter-&gt;GetPropagateUpdateExtentCallback());<br>&nbsp; importer-&gt;SetUpdateDataCallback(exporter-&gt;GetUpdateDataCallback());<br>&nbsp; importer-&gt;SetDataExtentCallback(exporter-&gt;GetDataExtentCallback());<br>&nbsp; importer-&gt;SetBufferPointerCallback(exporter-&gt;GetBufferPointerCallback());<br>&nbsp; importer-&gt;SetCallbackUserData(exporter-&gt;GetCallbackUserData());<br>}<br><br>template &lt;typename VTK_Exporter, typename ITK_Importer&gt;<br>void ConnectPipelines(VTK_Exporter* exporter, ITK_Importer importer)<br>{<br>&nbsp; importer-&gt;SetUpdateInformationCallback(exporter-&gt;GetUpdateInformationCallback());<br>&nbsp; importer-&gt;SetPipelineModifiedCallback(exporter-&gt;GetPipelineModifiedCallback());<br>&nbsp; importer-&gt;SetWholeExtentCallback(exporter-&gt;GetWholeExtentCallback());<br>&nbsp; importer-&gt;SetSpacingCallback(exporter-&gt;GetSpacingCallback());<br>&nbsp; importer-&gt;SetOriginCallback(exporter-&gt;GetOriginCallback());<br>&nbsp; importer-&gt;SetScalarTypeCallback(exporter-&gt;GetScalarTypeCallback());<br>&nbsp; importer-&gt;SetNumberOfComponentsCallback(exporter-&gt;GetNumberOfComponentsCallback());<br>&nbsp; importer-&gt;SetPropagateUpdateExtentCallback(exporter-&gt;GetPropagateUpdateExtentCallback());<br>&nbsp; importer-&gt;SetUpdateDataCallback(exporter-&gt;GetUpdateDataCallback());<br>&nbsp; importer-&gt;SetDataExtentCallback(exporter-&gt;GetDataExtentCallback());<br>&nbsp; importer-&gt;SetBufferPointerCallback(exporter-&gt;GetBufferPointerCallback());<br>&nbsp; importer-&gt;SetCallbackUserData(exporter-&gt;GetCallbackUserData());<br>}<br><br>void visualize(std::string dcm)<br>{ <br><br>&nbsp;typedef itk::RGBPixel&lt; signed short &gt; PixelType;<br>&nbsp;const unsigned int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dimension = 3;<br><br>&nbsp;typedef itk::OrientedImage&lt; PixelType, 3 &gt; ImageType;<br><br>&nbsp;typedef itk::ImageSeriesReader&lt; ImageType &gt; ReaderType;<br>&nbsp;ReaderType::Pointer reader = ReaderType::New();<br><br>&nbsp;typedef itk::GDCMImageIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageIOType;<br>&nbsp;ImageIOType::Pointer dicomIO = ImageIOType::New();<br><br>&nbsp;reader-&gt;SetImageIO( dicomIO );<br><br>&nbsp;typedef itk::GDCMSeriesFileNames NamesGeneratorType;<br>&nbsp;NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();<br><br>&nbsp;nameGenerator-&gt;SetUseSeriesDetails( true );<br>&nbsp;nameGenerator-&gt;AddSeriesRestriction("0008|0021" );<br><br>&nbsp;nameGenerator-&gt;SetDirectory(directoryPath);<br>&nbsp;<br>&nbsp;try{<br>&nbsp; &nbsp;&nbsp; std::cout &lt;&lt; std::endl &lt;&lt; "The directory: " &lt;&lt; std::endl;<br>&nbsp;&nbsp; &nbsp; std::cout &lt;&lt; std::endl &lt;&lt; directoryPath &lt;&lt; std::endl &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Contains the following DICOM Series: ";<br>&nbsp; &nbsp;&nbsp; std::cout &lt;&lt; std::endl &lt;&lt; std::endl;<br><br>&nbsp; &nbsp;&nbsp; typedef std::vector&lt; std::string &gt;&nbsp;&nbsp;&nbsp; SeriesIdContainer;<br><br>&nbsp; &nbsp;&nbsp; const SeriesIdContainer &amp; seriesUID = nameGenerator-&gt;GetSeriesUIDs();<br>&nbsp;<br>&nbsp; &nbsp;&nbsp; SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();<br>&nbsp;&nbsp; &nbsp; SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();<br>&nbsp;&nbsp;&nbsp;&nbsp; while( seriesItr != seriesEnd ) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; std::cout &lt;&lt; seriesItr-&gt;c_str() &lt;&lt; std::endl;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; seriesItr++;<br>&nbsp; &nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; std::string seriesIdentifier;<br>&nbsp;&nbsp;&nbsp; seriesIdentifier = seriesUID.begin()-&gt;c_str();<br>&nbsp;<br>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; std::endl &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Now reading series: " &lt;&lt; std::endl &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; seriesIdentifier &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; std::endl &lt;&lt; std::endl;<br><br>&nbsp;&nbsp;&nbsp; typedef std::vector&lt; std::string &gt;&nbsp;&nbsp; FileNamesContainer;<br>&nbsp;&nbsp;&nbsp; FileNamesContainer fileNames;<br><br>&nbsp;&nbsp;&nbsp; fileNames = nameGenerator-&gt;GetFileNames( seriesIdentifier );<br><br>&nbsp;&nbsp; &nbsp;FileNamesContainer::const_iterator iterator = fileNames.begin();<br>&nbsp;&nbsp;&nbsp; FileNamesContainer::const_iterator final = fileNames.end();<br>&nbsp;&nbsp;&nbsp; while( iterator != final )<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; iterator-&gt;c_str() &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iterator++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>reader-&gt;SetFileNames( fileNames ); &nbsp;<br><br>&nbsp;try<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reader-&gt;Update();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; catch (itk::ExceptionObject &amp;ex)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; ex &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return EXIT_FAILURE;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;}<br>catch (itk::ExceptionObject &amp;ex)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; ex &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; return EXIT_FAILURE;<br>&nbsp;&nbsp;&nbsp; }<br><br><br>typedef itk::VTKImageExport&lt; ImageType &gt; ExportFilterType;<br>ExportFilterType::Pointer itkExporter = ExportFilterType::New(); <br><br>itkExporter-&gt;SetInput( reader-&gt;GetOutput() );<br>&nbsp;<br>vtkImageImport* vtkImporter = vtkImageImport::New(); &nbsp;<br>ConnectPipelines(itkExporter, vtkImporter);<br><br>typedef itk::VTKImageImport&lt; ImageType &gt; ImportFilterType;<br>ImportFilterType::Pointer itkImporter = ImportFilterType::New();<br><br>vtkImageExport* vtkExporter = vtkImageExport::New(); &nbsp;<br>ConnectPipelines(vtkExporter, itkImporter);<br>&nbsp;&nbsp; &nbsp;<br>vtkExporter-&gt;SetInput( vtkImporter-&gt;GetOutput() );<br>&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp; &nbsp;<br>vtkPiecewiseFunction* opacityTransferFunction = vtkPiecewiseFunction::New();<br>opacityTransferFunction-&gt;AddPoint(0,&nbsp;&nbsp;&nbsp; 0.00);<br>opacityTransferFunction-&gt;AddPoint(500,&nbsp; 0.15);<br>opacityTransferFunction-&gt;AddPoint(1000, 0.15);<br>opacityTransferFunction-&gt;AddPoint(1150, 0.85);<br><br>vtkColorTransferFunction* colorTransferFunction = vtkColorTransferFunction::New(); <br>colorTransferFunction-&gt;AddRGBPoint(0,&nbsp;&nbsp;&nbsp; 0.0, 0.0, 0.0);<br>colorTransferFunction-&gt;AddRGBPoint(500,&nbsp; 1.0, 0.5, 0.3);<br>colorTransferFunction-&gt;AddRGBPoint(1000, 1.0, 0.5, 0.3);<br>colorTransferFunction-&gt;AddRGBPoint(1150, 1.0, 1.0, 0.9);<br>&nbsp;<br>vtkVolume* volume = vtkVolume::New();<br>vtkVolumeProperty* volumeProperty = vtkVolumeProperty::New(); <br>&nbsp;&nbsp;&nbsp; vtkFixedPointVolumeRayCastMapper* volumeMapperSoftware = vtkFixedPointVolumeRayCastMapper::New();<br><br>volumeProperty-&gt;SetScalarOpacity(opacityTransferFunction);<br>volumeProperty-&gt;SetColor(colorTransferFunction);<br>volumeProperty-&gt;SetInterpolationTypeToLinear();<br>volumeProperty-&gt;ShadeOff();<br>volume-&gt;SetProperty(volumeProperty); <br><br>volumeMapperSoftware-&gt;SetInput(vtkImporter-&gt;GetOutput());<br>volumeMapperSoftware-&gt;SetSampleDistance(1.0);<br>volume-&gt;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>&nbsp;&nbsp; &nbsp;<br>&nbsp; renWin-&gt;SetSize(500, 500);<br>&nbsp; renWin-&gt;AddRenderer(renderer);<br>&nbsp; iren-&gt;SetRenderWindow(renWin);<br>&nbsp; iren-&gt;SetInteractorStyle(interactorStyle);<br><br>&nbsp; renderer-&gt;AddVolume(volume);<br><br>&nbsp; renderer-&gt;SetBackground(0.5, 0.5, 0.5);<br><br>&nbsp; renWin-&gt;Render();<br>&nbsp; iren-&gt;Start();<br><br>&nbsp; vtkImporter-&gt;Delete();<br>&nbsp; vtkExporter-&gt;Delete();<br>&nbsp; renWin-&gt;Delete();<br>&nbsp; renderer-&gt;Delete();<br>&nbsp; iren-&gt;Delete();<br>}<br><br>int main(int argc, char * argv [] )<br>{ &nbsp;<br>&nbsp;&nbsp; &nbsp;if( argc &lt; 2 )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; "Usage: " &lt;&lt; argv[0] &lt;&lt; " path to DICOM series" &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; return 1;<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; visualize(argv[1]);<br><br>&nbsp;&nbsp;&nbsp; return 0;<br>}                                               </body>
</html>