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: 2008/01/21 18:30:58 $
00007   Version:   $Revision: 1.20 $
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 //
00196 //  Default traits for the pixel types deriving from Matrix<>
00197 //
00198 
00199 #define ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE(type,componenttype,rows,cols) \
00200 template<>                                                               \
00201 class DefaultConvertPixelTraits< type< componenttype, rows, cols > >     \
00202 {                                                                        \
00203 public:                                                                  \
00204   typedef type< componenttype, rows, cols >  TargetType;                 \
00205   typedef componenttype                     ComponentType;               \
00206   static unsigned int GetNumberOfComponents()                            \
00207     {                                                                    \
00208       return rows * cols;                                                \
00209     }                                                                    \
00210   static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v)   \
00211     {                                                                    \
00212       const unsigned int row = i / cols;                                 \
00213       const unsigned int col = i % cols;                                 \
00214       pixel[row][col] = v;                                               \
00215     }                                                                    \
00216   static ComponentType GetScalarValue(const TargetType& pixel)           \
00217     {                                                                    \
00218       return pixel[0][0];                                                \
00219     }                                                                    \
00220 };                                                                       \
00221 
00222 //
00223 //
00224 // Define traits for Classed deriving from Matrix from dimensions 1 to 6
00225 //
00226 //
00227 #define ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, Type) \
00228   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,1,1) \
00229   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,2,2) \
00230   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,3,3) \
00231   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,4,4) \
00232   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,5,5) \
00233   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,6,6)
00234 
00235 #define ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_TYPES_MACRO(ArrayType) \
00236   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, char); \
00237   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, signed char); \
00238   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned char); \
00239   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, short); \
00240   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned short); \
00241   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, int); \
00242   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned int); \
00243   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, long); \
00244   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned long); \
00245   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, float); \
00246   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, double);
00247 
00248 //
00249 // Add here other classes that derive from Matrix or that have the same API
00250 //
00251   ITK_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_TYPES_MACRO(Matrix);
00252 
00253 //
00254 //  End of Traits for the classes deriving from Matrix.
00255 //
00256 //
00257 
00258 
00259 //
00260 //  Default traits for the pixel types deriving from std::complex<>
00261 //
00262 
00263 #define ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE( componenttype ) \
00264 template<>                                                               \
00265 class DefaultConvertPixelTraits< ::std::complex< componenttype > >       \
00266 {                                                                        \
00267 public:                                                                  \
00268   typedef ::std::complex< componenttype>  TargetType;                    \
00269   typedef componenttype                     ComponentType;               \
00270   static unsigned int GetNumberOfComponents()                            \
00271     {                                                                    \
00272     return 2;                                                  \
00273     }                                                                    \
00274   static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v)   \
00275     {                                                                    \
00276     if( i == 0 )                                                            \
00277       {                                                                  \
00278       pixel = TargetType( v, pixel.imag() );                           \
00279       }                                                                  \
00280     else                                                                 \
00281       {                                                                  \
00282       pixel = TargetType( pixel.real(), v );                           \
00283       }                                                                  \
00284     }                                                                    \
00285   static ComponentType GetScalarValue(const TargetType& pixel)           \
00286     {                                                                    \
00287     return std::norm(pixel);                                             \
00288     }                                                                    \
00289 };                                                                       \
00290 
00291 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(float);
00292 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(double);
00293 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed int);
00294 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned int);
00295 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed char);
00296 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned char);
00297 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed long);
00298 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned long);
00299 
00300 //
00301 //  End of Traits for the classes deriving from std::complex.
00302 //
00303 //
00304   
00305 } // end namespace itk
00306 #endif
00307 

Generated at Tue Jul 29 19:43:56 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000