Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkDefaultConvertPixelTraits.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkDefaultConvertPixelTraits.h,v $
00005   Language:  C++
00006   Date:      $Date: 2006/01/20 18:55:13 $
00007   Version:   $Revision: 1.18 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 
00018 #ifndef __itkDefaultConvertPixelTraits_h
00019 #define __itkDefaultConvertPixelTraits_h
00020 
00021 #include "itkOffset.h"
00022 #include "itkCovariantVector.h"
00023 #include "itkVector.h"
00024 #include "itkPoint.h"
00025 
00026 namespace itk
00027 {
00028   
00038 template<typename PixelType>
00039 class DefaultConvertPixelTraits
00040 {
00041 public:
00043   typedef typename PixelType::ComponentType ComponentType;
00044 
00046   static unsigned int GetNumberOfComponents() 
00047   { return PixelType::GetNumberOfComponents();}
00048 
00050   static ComponentType GetNthComponent(int c, const PixelType& pixel) 
00051   { return pixel.GetNthComponent(c); }
00052 
00054   static void SetNthComponent(int c, PixelType& pixel, const ComponentType& v) 
00055   { pixel.SetNthComponent(c, v); }
00056 
00058   static ComponentType GetScalarValue(const PixelType& pixel)
00059   { return pixel.GetScalarValue(); }
00060 
00061 };
00062 
00063 #define ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(type)                    \
00064 template<>                                                               \
00065 class DefaultConvertPixelTraits<type>                                    \
00066 {                                                                        \
00067 public:                                                                  \
00068   typedef type ComponentType;                                            \
00069   static unsigned int GetNumberOfComponents()                            \
00070     {                                                                    \
00071       return 1;                                                          \
00072     }                                                                    \
00073   static void SetNthComponent(int , type& pixel, const ComponentType& v) \
00074     {                                                                    \
00075       pixel = v;                                                         \
00076     }                                                                    \
00077   static type GetScalarValue(const type& pixel)                          \
00078     {                                                                    \
00079       return pixel;                                                      \
00080     }                                                                    \
00081 };
00082 
00083 
00084   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(float)
00085   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(double)
00086   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(int)
00087   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(char)
00088   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(short)
00089   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(unsigned int)
00090   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(signed char)
00091   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(unsigned char)
00092   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(unsigned short)
00093   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(long)  
00094   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(unsigned long)
00095   ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(bool)
00096 
00097 #undef ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL
00098 
00099 
00100 
00101 
00102 //
00103 //  Default traits for the Offset<> pixel type
00104 //
00105 
00106 #define ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(dimension)                  \
00107 template<>                                                               \
00108 class DefaultConvertPixelTraits< Offset<dimension> >                     \
00109 {                                                                        \
00110 public:                                                                  \
00111   typedef Offset<dimension>  TargetType;                                 \
00112   typedef TargetType::OffsetValueType  ComponentType;                    \
00113   static unsigned int GetNumberOfComponents()                            \
00114     {                                                                    \
00115       return dimension;                                                  \
00116     }                                                                    \
00117   static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v)   \
00118     {                                                                    \
00119       pixel[i] = v;                                                      \
00120     }                                                                    \
00121   static ComponentType GetScalarValue(const TargetType& pixel)           \
00122     {                                                                    \
00123       return pixel[0];                                                   \
00124     }                                                                    \
00125 };                                                                       \
00126 
00127 
00128 // Define traits for Offset<> from dimensions 1 to 5
00129   ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(1)
00130   ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(2)
00131   ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(3)
00132   ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(4)
00133   ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(5)
00134 
00135 
00136 
00137 
00138 //
00139 //  Default traits for the pixel types deriving from FixedArray<>
00140 //
00141 
00142 #define ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(type,componenttype, dimension) \
00143 template<>                                                               \
00144 class DefaultConvertPixelTraits< type< componenttype, dimension> >       \
00145 {                                                                        \
00146 public:                                                                  \
00147   typedef type< componenttype, dimension >  TargetType;                  \
00148   typedef componenttype                     ComponentType;               \
00149   static unsigned int GetNumberOfComponents()                            \
00150     {                                                                    \
00151       return dimension;                                                  \
00152     }                                                                    \
00153   static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v)   \
00154     {                                                                    \
00155       pixel[i] = v;                                                      \
00156     }                                                                    \
00157   static ComponentType GetScalarValue(const TargetType& pixel)           \
00158     {                                                                    \
00159       return pixel[0];                                                   \
00160     }                                                                    \
00161 };                                                                       \
00162 
00163 
00164 
00165 
00166 
00167 //
00168 //
00169 // Define traits for Classed deriving from FixedArray from dimensions 1 to 6
00170 // These classes include: Vector, CovariantVector and Point.
00171 //
00172 //
00173 #define ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, Type) \
00174   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,1) \
00175   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,2) \
00176   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,3) \
00177   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,4) \
00178   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,5) \
00179   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,6)
00180 
00181 #define ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(ArrayType) \
00182   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, char); \
00183   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, signed char); \
00184   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned char); \
00185   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, short); \
00186   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned short); \
00187   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, int); \
00188   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned int); \
00189   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, long); \
00190   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned long); \
00191   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, float); \
00192   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, double);
00193 
00194   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(Vector);
00195   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(CovariantVector);
00196   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(Point);
00197   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(FixedArray);
00198 
00199 //
00200 //  End of Traits for the classes deriving from FixedArray.
00201 //
00202 //
00203 
00204 
00205 
00206 
00207 //
00208 //  Default traits for the pixel types deriving from std::complex<>
00209 //
00210 
00211 #define ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE( componenttype ) \
00212 template<>                                                               \
00213 class DefaultConvertPixelTraits< ::std::complex< componenttype > >       \
00214 {                                                                        \
00215 public:                                                                  \
00216   typedef ::std::complex< componenttype>  TargetType;                    \
00217   typedef componenttype                     ComponentType;               \
00218   static unsigned int GetNumberOfComponents()                            \
00219     {                                                                    \
00220     return 2;                                                  \
00221     }                                                                    \
00222   static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v)   \
00223     {                                                                    \
00224     if( i == 0 )                                                            \
00225       {                                                                  \
00226       pixel = TargetType( v, pixel.imag() );                           \
00227       }                                                                  \
00228     else                                                                 \
00229       {                                                                  \
00230       pixel = TargetType( pixel.real(), v );                           \
00231       }                                                                  \
00232     }                                                                    \
00233   static ComponentType GetScalarValue(const TargetType& pixel)           \
00234     {                                                                    \
00235     return std::norm(pixel);                                             \
00236     }                                                                    \
00237 };                                                                       \
00238 
00239 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(float);
00240 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(double);
00241 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed int);
00242 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned int);
00243 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed char);
00244 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned char);
00245 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed long);
00246 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned long);
00247 
00248 //
00249 //  End of Traits for the classes deriving from std::complex.
00250 //
00251 //
00252 
00253 
00254 
00255 
00256   
00257   } // end namespace itk
00258 
00259 
00260 #endif
00261 

Generated at Mon Mar 12 00:00:57 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000