[vtkusers] Building a volume out of DICOM images

Steve Chall stevec at renci.org
Wed Jul 14 17:07:11 EDT 2010


Thanks, David.  That does explain why a Set...() method may not set the
value as I expected.  But it does conflict with my expectation that a
Set...() method would set a value rather than simply telling me what it is.
I guess I misunderstand the rationale behind how the method is named.  At
any rate, you've been very helpful.  Thanks again.

-Steve
  
-----Original Message-----
From: David Gobbi [mailto:david.gobbi at gmail.com] 
Sent: Wednesday, July 14, 2010 4:37 PM
To: Steven Chall
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] Building a volume out of DICOM images

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/VolumeRend
ering/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