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: 2007/03/22 14:28:48 $
00007   Version:   $Revision: 1.19 $
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   
00039 template<typename PixelType>
00040 class DefaultConvertPixelTraits
00041 {
00042 public:
00044   typedef typename PixelType::ComponentType ComponentType;
00045 
00047   static unsigned int GetNumberOfComponents() 
00048   { return PixelType::GetNumberOfComponents();}
00049 
00051   static ComponentType GetNthComponent(int c, const PixelType& pixel) 
00052   { return pixel.GetNthComponent(c); }
00053 
00055   static void SetNthComponent(int c, PixelType& pixel, const ComponentType& v) 
00056   { pixel.SetNthComponent(c, v); }
00057 
00059   static ComponentType GetScalarValue(const PixelType& pixel)
00060   { return pixel.GetScalarValue(); }
00061 
00062 };
00063 
00064 #define ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(type)                    \
00065 template<>                                                               \
00066 class DefaultConvertPixelTraits<type>                                    \
00067 {                                                                        \
00068 public:                                                                  \
00069   typedef type ComponentType;                                            \
00070   static unsigned int GetNumberOfComponents()                            \
00071     {                                                                    \
00072       return 1;                                                          \
00073     }                                                                    \
00074   static void SetNthComponent(int , type& pixel, const ComponentType& v) \
00075     {                                                                    \
00076       pixel = v;                                                         \
00077     }                                                                    \
00078   static type GetScalarValue(const type& pixel)                          \
00079     {                                                                    \
00080       return pixel;                                                      \
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 //  Default traits for the Offset<> pixel type
00101 //
00102 
00103 #define ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(dimension)                  \
00104 template<>                                                               \
00105 class DefaultConvertPixelTraits< Offset<dimension> >                     \
00106 {                                                                        \
00107 public:                                                                  \
00108   typedef Offset<dimension>  TargetType;                                 \
00109   typedef TargetType::OffsetValueType  ComponentType;                    \
00110   static unsigned int GetNumberOfComponents()                            \
00111     {                                                                    \
00112       return dimension;                                                  \
00113     }                                                                    \
00114   static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v)   \
00115     {                                                                    \
00116       pixel[i] = v;                                                      \
00117     }                                                                    \
00118   static ComponentType GetScalarValue(const TargetType& pixel)           \
00119     {                                                                    \
00120       return pixel[0];                                                   \
00121     }                                                                    \
00122 };                                                                       \
00123 
00124 
00125 // Define traits for Offset<> from dimensions 1 to 5
00126   ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(1)
00127   ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(2)
00128   ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(3)
00129   ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(4)
00130   ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(5)
00131 
00132 //
00133 //  Default traits for the pixel types deriving from FixedArray<>
00134 //
00135 
00136 #define ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(type,componenttype, dimension) \
00137 template<>                                                               \
00138 class DefaultConvertPixelTraits< type< componenttype, dimension> >       \
00139 {                                                                        \
00140 public:                                                                  \
00141   typedef type< componenttype, dimension >  TargetType;                  \
00142   typedef componenttype                     ComponentType;               \
00143   static unsigned int GetNumberOfComponents()                            \
00144     {                                                                    \
00145       return dimension;                                                  \
00146     }                                                                    \
00147   static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v)   \
00148     {                                                                    \
00149       pixel[i] = v;                                                      \
00150     }                                                                    \
00151   static ComponentType GetScalarValue(const TargetType& pixel)           \
00152     {                                                                    \
00153       return pixel[0];                                                   \
00154     }                                                                    \
00155 };                                                                       \
00156 
00157 //
00158 //
00159 // Define traits for Classed deriving from FixedArray from dimensions 1 to 6
00160 // These classes include: Vector, CovariantVector and Point.
00161 //
00162 //
00163 #define ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, Type) \
00164   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,1) \
00165   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,2) \
00166   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,3) \
00167   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,4) \
00168   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,5) \
00169   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,6)
00170 
00171 #define ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(ArrayType) \
00172   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, char); \
00173   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, signed char); \
00174   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned char); \
00175   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, short); \
00176   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned short); \
00177   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, int); \
00178   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned int); \
00179   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, long); \
00180   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned long); \
00181   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, float); \
00182   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, double);
00183 
00184   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(Vector);
00185   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(CovariantVector);
00186   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(Point);
00187   ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(FixedArray);
00188 
00189 //
00190 //  End of Traits for the classes deriving from FixedArray.
00191 //
00192 //
00193 
00194 //
00195 //  Default traits for the pixel types deriving from std::complex<>
00196 //
00197 
00198 #define ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE( componenttype ) \
00199 template<>                                                               \
00200 class DefaultConvertPixelTraits< ::std::complex< componenttype > >       \
00201 {                                                                        \
00202 public:                                                                  \
00203   typedef ::std::complex< componenttype>  TargetType;                    \
00204   typedef componenttype                     ComponentType;               \
00205   static unsigned int GetNumberOfComponents()                            \
00206     {                                                                    \
00207     return 2;                                                  \
00208     }                                                                    \
00209   static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v)   \
00210     {                                                                    \
00211     if( i == 0 )                                                            \
00212       {                                                                  \
00213       pixel = TargetType( v, pixel.imag() );                           \
00214       }                                                                  \
00215     else                                                                 \
00216       {                                                                  \
00217       pixel = TargetType( pixel.real(), v );                           \
00218       }                                                                  \
00219     }                                                                    \
00220   static ComponentType GetScalarValue(const TargetType& pixel)           \
00221     {                                                                    \
00222     return std::norm(pixel);                                             \
00223     }                                                                    \
00224 };                                                                       \
00225 
00226 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(float);
00227 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(double);
00228 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed int);
00229 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned int);
00230 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed char);
00231 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned char);
00232 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed long);
00233 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned long);
00234 
00235 //
00236 //  End of Traits for the classes deriving from std::complex.
00237 //
00238 //
00239   
00240 } // end namespace itk
00241 #endif
00242 

Generated at Sun Sep 23 12:20:47 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000