[vtkusers] DCMTK and VTK - corrected

Beau Sapach beau.sapach at ualberta.ca
Tue May 15 11:19:55 EDT 2007


Woops, my original reply had Uint8 everywhere which would mean Char or
Unsigned Char scalar type.. Here's the corrected code, Uint16 instead.

 

            //retrieve image dimensions (dimx,dimy,dimz)

            //retrieve pixel spacing (spx,spy,spz)

            //get pixel depth (depth) (DCM_BitsAllocated)

 

            //depth is originally a count of bits, convert to bytes

            depth = depth/8;

 

            //calculate the full size of the scalars

int ByteCount = depth * dimx * dimy;

 

            //make an imagedata object

            vtkImageData * image = vtkImageData::New();

            image->SetOrigin(0,0,0);

            image->SetSpacing(spx,spy,spz);

            image->SetDimensions(dimx,dimy,dimz);

            image->SetScalarTypeToShort();

            image->AllocateScalars();

 

            //get the pointer to the allocated scalar memory from the image

            char * scalar_buf = (char*)image->GetScalarPointer();

 

            //buffer to read scalars into from dicom

            Uint16 * pUint16 = NULL;

 

            //read in the scalars

            dicom->findAndGetUint16Array(DCM_PixelData,pUint16);

 

            //since the Uint16 data gets deleted when the DcmDataset object
is destroyed

            //we have to copy the data into the buffer already allocated by
vtkImageData

            memcpy(scalar_buf,pUint16,ByteCount);

 

________________________________________

From: vtkusers-bounces+beau.sapach=ualberta.ca at vtk.org
[mailto:vtkusers-bounces+beau.sapach=ualberta.ca at vtk.org] On Behalf Of Luca
Pamparana

Sent: Tuesday, May 15, 2007 8:20 AM

To: vtkusers

Subject: [vtkusers] DCMTK and VTK

 

Hi everyone,

 

Does anyone has any examples of reading in a DICOM volume into VTK using
DCMTK?

 

So, I have a list of DICOM files that comprises a volume and I want to
create a vtkImageData out of it. Does anyone know what is the best way to
achieve that? A C++ code snippet would be really nice! 

 

Thanks,

Luca

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070515/bdf14169/attachment.htm>


More information about the vtkusers mailing list