00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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(unsigned char)
00091 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(unsigned short)
00092 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(long)
00093 ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(unsigned long)
00094
00095 #undef ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL
00096
00097
00098
00099
00100
00101
00102
00103
00104 #define ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(dimension) \
00105 template<> \
00106 class DefaultConvertPixelTraits< Offset<dimension> > \
00107 { \
00108 public: \
00109 typedef Offset<dimension> TargetType; \
00110 typedef TargetType::OffsetValueType ComponentType; \
00111 static unsigned int GetNumberOfComponents() \
00112 { \
00113 return dimension; \
00114 } \
00115 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
00116 { \
00117 pixel[i] = v; \
00118 } \
00119 static ComponentType GetScalarValue(const TargetType& pixel) \
00120 { \
00121 return pixel[0]; \
00122 } \
00123 }; \
00124
00125
00126
00127 ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(1)
00128 ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(2)
00129 ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(3)
00130 ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(4)
00131 ITK_DEFAULTCONVERTTRAITS_OFFSET_TYPE(5)
00132
00133
00134
00135
00136
00137
00138
00139
00140 #define ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(type,componenttype, dimension) \
00141 template<> \
00142 class DefaultConvertPixelTraits< type< componenttype, dimension> > \
00143 { \
00144 public: \
00145 typedef type< componenttype, dimension > TargetType; \
00146 typedef componenttype ComponentType; \
00147 static unsigned int GetNumberOfComponents() \
00148 { \
00149 return dimension; \
00150 } \
00151 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
00152 { \
00153 pixel[i] = v; \
00154 } \
00155 static ComponentType GetScalarValue(const TargetType& pixel) \
00156 { \
00157 return pixel[0]; \
00158 } \
00159 }; \
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 #define ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, Type) \
00172 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,1) \
00173 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,2) \
00174 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,3) \
00175 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,4) \
00176 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,5) \
00177 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,6)
00178
00179 #define ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(ArrayType) \
00180 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, char); \
00181 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned char); \
00182 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, short); \
00183 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned short); \
00184 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, int); \
00185 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned int); \
00186 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, long); \
00187 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned long); \
00188 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, float); \
00189 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, double);
00190
00191 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(Vector);
00192 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(CovariantVector);
00193 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(Point);
00194 ITK_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(FixedArray);
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 #define ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE( componenttype ) \
00209 template<> \
00210 class DefaultConvertPixelTraits< ::std::complex< componenttype > > \
00211 { \
00212 public: \
00213 typedef ::std::complex< componenttype> TargetType; \
00214 typedef componenttype ComponentType; \
00215 static unsigned int GetNumberOfComponents() \
00216 { \
00217 return 2; \
00218 } \
00219 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
00220 { \
00221 if( i == 0 ) \
00222 { \
00223 pixel = TargetType( v, pixel.imag() ); \
00224 } \
00225 else \
00226 { \
00227 pixel = TargetType( pixel.real(), v ); \
00228 } \
00229 } \
00230 static ComponentType GetScalarValue(const TargetType& pixel) \
00231 { \
00232 return std::norm(pixel); \
00233 } \
00234 }; \
00235
00236 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(float);
00237 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(double);
00238 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed int);
00239 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned int);
00240 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed char);
00241 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned char);
00242 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(signed long);
00243 ITK_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(unsigned long);
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 }
00255
00256
00257 #endif