Hi vtkusers,<br><br>I want to read some DICOM files into one vtkImageData. To read the pixel data from the DICOM files I want to use the DCMTK libraries. The vtkImageData object will contain several DICOM images so I want to load the pixel data into vtkImageData file by file.
<br><br>First I allocate the vtkImageData and then I load the files in a bucle from dcmtk (DicomImage class) to the vtkImageData object. The images are loaded correctly by dcmtk ( I dumped the images in a png file and they're ok ) but when I want to view the images with vtkImageViewer2 they are completely dark, so it seems no data is loaded at all. Following there's the code snippet I use to do that. I also tried to read the pixel data with DcmDataset::findAndGetUint16Array(DCM_PixelData,..) instead of DicomImage, but with no success.
<br><br>Has anyone any suggestions of what I'm probably missing or doing wrong?<br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">// first we allocate the data</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">m_imageDataVTK = vtkImageData::New();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
m_imageDataVTK->SetOrigin( origin );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">m_imageDataVTK->SetSpacing( spacing );</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">m_imageDataVTK->SetDimensions( rows, columns, slices );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">m_imageDataVTK->SetScalarTypeToUnsignedShort(); // the data will be 16 bit
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">m_imageDataVTK->SetNumberOfScalarComponents(1);</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
m_imageDataVTK->AllocateScalars();</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">// now we load all the images</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">int zSlice = 0;</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
foreach( Image *image, m_imageSet )</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
DicomImage *dicomImage = new DicomImage( qPrintable( image->getPath() ) ); // we load a new Image</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if( dicomImage != NULL )
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if( dicomImage->getStatus() == EIS_Normal )
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
dicomImage->setMinMaxWindow();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> if( dicomImage->getOutputData(16) != NULL )</span>
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> // we copy the data in the dcmtk buffer to the vtkImageData one
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> memcpy((unsigned short *)m_imageDataVTK->GetScalarPointer(0,0,zSlice), (unsigned short *)dicomImage->getOutputData(16), dicomImage->getOutputDataSize() );
</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> dicomImage->deleteOutputData();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
m_imageDataVTK->Modified();</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> zSlice++;</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> }</span><br style="font-family: courier new,monospace;"><br>Thanks in advance!<br style="font-family: courier new,monospace;">