[vtkusers] Building a volume out of DICOM images

David Gobbi david.gobbi at gmail.com
Wed Jul 14 16:37:20 EDT 2010


Hi Steve,

The reader's SetDataScalarTypeTo...() methods are used to tell the
reader what the data type _is_, it can't change the data from one type
to another.  These methods are meant to be used when the reader has to
deal with raw data (specifically, when the superclass vtkImageReader
has to deal with raw data, the vtkDICOMImageReader gets the data type
information from the DICOM header).

You need to use vtkImageShiftScale to convert the "signed short" data
into "unsigned short".  The lowest value in a "signed short" CT file
is usually around -1000, so a Shift of 1000 is usually needed when
converting to unsigned, but you will need to check the actual range of
data values stored in the file to be sure.

  David


On Wed, Jul 14, 2010 at 2:13 PM, Steven Chall <stevec at renci.org> wrote:
> 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
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>



More information about the vtkusers mailing list