From d0f40877c92a5bbfc92baee53e3f4abc14beb130 Mon Sep 17 00:00:00 2001 From: Julien Malik <julien.malik@c-s.fr> Date: Tue, 25 Feb 2014 14:06:05 +0100 Subject: [PATCH] ENH: clarify comment for DefaultConvertPixelTraits< complex > and fix style --- Code/IO/otbDefaultConvertPixelTraits.h | 74 ++++++++++++++------------ 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/Code/IO/otbDefaultConvertPixelTraits.h b/Code/IO/otbDefaultConvertPixelTraits.h index 5b6c4b9a98..688e3c4cfa 100644 --- a/Code/IO/otbDefaultConvertPixelTraits.h +++ b/Code/IO/otbDefaultConvertPixelTraits.h @@ -275,40 +275,46 @@ public: \ // Default traits for the pixel types deriving from std::complex<> // -#define OTB_DEFAULTCONVERTTRAITS_COMPLEX_TYPE( componenttype ) \ -template<> \ -class DefaultConvertPixelTraits< ::std::complex< componenttype > > \ -{ \ -public: \ - typedef ::std::complex< componenttype> TargetType; \ - typedef componenttype ComponentType; \ - static unsigned int GetNumberOfComponents() \ - { \ - return 2; \ - } \ - static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \ - { \ - if( i == 0 ) \ - { \ - pixel = TargetType( v, pixel.imag() ); \ - } \ - else \ - { \ - pixel = TargetType( pixel.real(), v ); \ - } \ - } \ - static void SetNthComponent(int , TargetType & pixel, const TargetType& v) \ - { \ - pixel = v; \ - } \ - static ComponentType GetScalarValue(const TargetType& pixel) \ - { \ - /*issue with std::norm on Mac OS X Mavericks*/ \ - /*return std::norm(pixel); */ \ - return static_cast<ComponentType>( pixel.real()*pixel.real() \ - +pixel.imag()*pixel.imag() ); \ - } \ -}; \ +#define OTB_DEFAULTCONVERTTRAITS_COMPLEX_TYPE( componenttype ) \ +template<> \ +class DefaultConvertPixelTraits< ::std::complex< componenttype > > \ +{ \ +public: \ + typedef ::std::complex< componenttype> TargetType; \ + typedef componenttype ComponentType; \ + static unsigned int GetNumberOfComponents() \ + { \ + return 2; \ + } \ + static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \ + { \ + if( i == 0 ) \ + { \ + pixel = TargetType( v, pixel.imag() ); \ + } \ + else \ + { \ + pixel = TargetType( pixel.real(), v ); \ + } \ + } \ + static void SetNthComponent(int , TargetType & pixel, const TargetType& v) \ + { \ + pixel = v; \ + } \ + static ComponentType GetScalarValue(const TargetType& pixel) \ + { \ + /* \ + * This seems to be dead code, since the complex to scalar \ + * conversion is done by ConvertPixelBuffer \ + * \ + * Historically, it was returning std::norm, which causes \ + * compilation error on MacOSX 10.9. \ + * Now returns the equivalent implementation of std::norm. \ + */ \ + return static_cast<ComponentType>( pixel.real()*pixel.real() \ + + pixel.imag()*pixel.imag() ); \ + } \ +}; \ OTB_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(float); OTB_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(double); -- GitLab