[vtkusers] Building a volume out of DICOM images

Steven Chall stevec at renci.org
Wed Jul 14 16:13:47 EDT 2010


Based on http://public.kitware.com/cgi-bin/viewcvs.cgi/*checkout*/Examples/VolumeRendering/Cxx/GPURenderDemo.cxx?root=VTK&content-type=text/plain, I've written a little app to display a volume constructed from a directory of DICOM files of CT data.  I'm having no problem displaying individual image files, but when I try to see the volume, it's a different story.  Here are what I believe are the germane C++ code fragments:

...
  vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
  reader->SetDirectoryName("C:\\Documents and Settings\\Steve Chall\\My Documents\\IMRT\\CT");
  reader->Update();
  int dataScalarType = reader->GetDataScalarType();
  reader->SetDataScalarTypeToUnsignedShort();
  reader->GetOutput()->SetScalarTypeToUnsignedInt();
...
  vtkVolume *volume = vtkVolume::New();
  vtkVolumeRayCastMapper *mapper = vtkVolumeRayCastMapper::New();
...
  renderer->AddVolume( volume );
  renderer->ResetCamera();
...

It builds and runs, but instead of displaying the volume I get the following message:

ERROR: In ..\..\VTK\VolumeRendering\vtkVolumeRayCastMapper.cxx, line 327
vtkVolumeRayCastMapper (01F111C8): Cannot volume render data of type short, only unsigned char or unsigned short.

I'd expect the call to
reader->SetDataScalarTypeToUnsignedShort();
to do just that, and when I step through it in the debugger it does indeed get called and does everything I'd expect except the reader's DataScalarType value never changes (down where the assignment should occur, in vtkImageReader2::SetDataScalarType(int type)) from 4 (VTK_SHORT) to 5 (VTK_UNSIGNED_SHORT).

Finally, here's the method comment for void vtkImageReader2::SetDataScalarType(int type):

// Set the data type of pixels in the file.
// If you want the output scalar type to have a different value, set it
// after this method is called.

And that's what I thought
reader->GetOutput()->SetScalarTypeToUnsignedInt();
would do.  But no, it's still VTK_SHORT.

I'd appreciate any suggestions y'all might have.  I'm running VTK 5.4.2 with Visual C++ 2008 in WinXP SP3.  Thanks.

-Steve Chall
 Senior Research Software Developer
 Renaissance Computing Institute (RENCI)
 Phone: 919-681-9639
 Email: stevec at renci.org

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


More information about the vtkusers mailing list