[Insight-developers] reinterpret_cast question

Miller, James V (Research) millerjv at crd . ge . com
Fri, 27 Jun 2003 11:46:57 -0400


I can't comment on the reinterpret_cast part but 
I would worry about the use of GetPixel().  Since
GetPixel() returns by value, you are taking the 
address of a temporary variable, running reinterpret_cast
on that address and then assigning it to as a reference
to a FixedArray.  

I would guess that manipulating the address and 
bit pattern of a temporary variable is not a robust thing
to do.



> -----Original Message-----
> From: Jisung Kim [mailto:bahrahm at yahoo . com]
> Sent: Friday, June 27, 2003 10:51 AM
> To: insight-dev-list
> Subject: [Insight-developers] reinterpret_cast question
> 
> 
> 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
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk . org
> http://www . itk . org/mailman/listinfo/insight-developers
>