[vtkusers] How to cast vtkImageData from signed to unsigned?

list at kobenetz.de list at kobenetz.de
Fri Apr 20 04:52:35 EDT 2007


Hi, I'm trying to volume render a set of DICOM files.

I was able to open a single file with vtkDICOMImageReader
(Using SetFileName) and display the content without Problems.


Then I wanted to display the whole volume using
vtkDICOMImageReader::SetDirectoryName, but I got the following runtime error:

----
ERROR: In ..\..\SRC\VolumeRendering\vtkVolumeRayCastMapper.cxx, line 326
vtkVolumeRayCastMapper (035BBD08): Cannot volume render data of type
short, only unsigned char or unsigned short.
----


I tried to convert the signed data to unsigned using vtkImageCast:


----
vtkDICOMImageReader *dicomReader = vtkDICOMImageReader::New();
dicomReader->SetDirectoryName( HOLZKLOTZ_VERZEICHNIS );

vtkImageCast *imageCast = vtkImageCast::New();
imageCast->SetInput( dicomReader->GetOutput() );  // ERROR HERE
imageCast->SetOutputScalarTypeToUnsignedShort();

vtkVolumeRayCastMapper *mapper = vtkVolumeRayCastMapper::New();
mapper->SetInput( imageCast->GetOutput() );
----

The code doesn't compile, because vtkImageCast::SetInput only
accepts a vtkDataObject and the vtkDICOMImageReader only gives
me a vtkImageData object.

How can I 'convert' the signed ImageData to unsigned ImageData?

Thanks,

Christoph



More information about the vtkusers mailing list