[Insight-developers] reinterpret_cast question

Jisung Kim bahrahm at yahoo . com
Fri, 27 Jun 2003 07:51:03 -0700 (PDT)


Hi.

I am doing an experiment with reinterpret_cast. The
purpose of the experiment is to see if
"reinterpret_cast"ing scalar pixel (int, chat, double)
to itk::FixedArray< PixelType, 1> works.

I checked in the itkDummyImageToListAdaptorTest in
Testing/Code/Numerics/Statistics. The current
implementation of ImageToListAdaptor class accepts
only images with the pixel types of itk::FixedArray or
its derived classes( itk::Vector, itk::Point,
itk::RBGPixel...). Therefore, images with scalar
pixels have to be converted before using them with
ImageToListAdaptor class.

In the new test program, I forced casting from scalar
pixel to itk::FixedArray< PixelType, 1>. And it worked
on all compilers. The casting works something like
this:

typedef int ScalarPixelType ;
typedef itk::Image< ScalarPixelType, 3 >
ScalarImageType ;
typedef itk::FixedArrray< ScalarPixelType, 1 >
ArrayPixelType ;

...... allocates and fills the scalar image ......

ArrayPixelType& arrayPixel = 
*(reinterpret_cast< ArrayPixelType* >
             ( &(scalarImage->GetPixel(index) ) ) ;

std::cout << arrayPixel[0] << std::endl ;

I'm not familiar with the reinterpret_cast and
wondering if this is legitimate use of it.

Any suggestions?

Thanks,


=====
Jisung Kim
bahrahm at yahoo . com
106 Mason Farm Rd.
129 Radiology Research Lab., CB# 7515
Univ. of North Carolina at Chapel Hill
Chapel Hill, NC 27599-7515

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc . yahoo . com