19 #ifndef itkMeshConvertPixelTraits_h
20 #define itkMeshConvertPixelTraits_h
44 template<
typename PixelType>
53 {
return PixelType::GetNumberOfComponents();}
56 {
return PixelType::GetNumberOfComponents();}
60 {
return pixel.GetNthComponent(c); }
64 { pixel.SetNthComponent(c, v); }
68 {
return pixel.GetScalarValue(); }
72 #define ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(type) \
74 class MeshConvertPixelTraits<type> \
77 typedef type ComponentType; \
78 static unsigned int GetNumberOfComponents() \
82 static unsigned int GetNumberOfComponents(const type& itkNotUsed(pixel))\
86 static ComponentType GetNthComponent(int itkNotUsed(c), const type& pixel)\
90 static void SetNthComponent(int , type& pixel, const ComponentType& v) \
94 static type GetScalarValue(const type& pixel) \
113 #undef ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL
119 #define ITK_MESH_DEFAULTCONVERTTRAITS_OFFSET_TYPE(dimension) \
121 class MeshConvertPixelTraits< Offset<dimension> > \
124 typedef Offset<dimension> TargetType; \
125 typedef TargetType::OffsetValueType ComponentType; \
126 static unsigned int GetNumberOfComponents() \
130 static unsigned int GetNumberOfComponents(const TargetType& itkNotUsed(pixel)) \
134 static ComponentType GetNthComponent(int c, const TargetType& pixel) \
138 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
142 static ComponentType GetScalarValue(const TargetType& pixel) \
160 #define ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(type,componenttype, dimension) \
162 class MeshConvertPixelTraits< type< componenttype, dimension> > \
165 typedef type< componenttype, dimension > TargetType; \
166 typedef componenttype ComponentType; \
167 static unsigned int GetNumberOfComponents() \
171 static unsigned int GetNumberOfComponents(const TargetType& itkNotUsed(pixel)) \
175 static ComponentType GetNthComponent(int c, const TargetType& pixel) \
179 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
183 static ComponentType GetScalarValue(const TargetType& pixel) \
195 #define ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, Type) \
196 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,1) \
197 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,2) \
198 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,3) \
199 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,4) \
200 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,5) \
201 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,6)
203 #define ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(ArrayType) \
204 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, char); \
205 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, signed char); \
206 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned char); \
207 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, short); \
208 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned short); \
209 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, int); \
210 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned int); \
211 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, long); \
212 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned long); \
213 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, float); \
214 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, double);
231 #define ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(type,componenttype,rows,cols) \
233 class MeshConvertPixelTraits< type< componenttype, rows, cols > > \
236 typedef type< componenttype, rows, cols > TargetType; \
237 typedef componenttype ComponentType; \
238 static unsigned int GetNumberOfComponents() \
240 return rows * cols; \
242 static unsigned int GetNumberOfComponents(const TargetType& itkNotUsed(pixel)) \
244 return rows * cols; \
246 static ComponentType GetNthComponent(int c, const TargetType& pixel) \
248 const unsigned int row = c / cols; \
249 const unsigned int col = c % cols; \
250 return pixel[row][col]; \
252 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
254 const unsigned int row = i / cols; \
255 const unsigned int col = i % cols; \
256 pixel[row][col] = v; \
258 static ComponentType GetScalarValue(const TargetType& pixel) \
260 return pixel[0][0]; \
269 #define ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, Type) \
270 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,1,1) \
271 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,2,2) \
272 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,3,3) \
273 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,4,4) \
274 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,5,5) \
275 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,6,6)
277 #define ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_TYPES_MACRO(ArrayType) \
278 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, char); \
279 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, signed char); \
280 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned char); \
281 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, short); \
282 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned short); \
283 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, int); \
284 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned int); \
285 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, long); \
286 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned long); \
287 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, float); \
288 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, double);
305 #define ITK_MESH_DEFAULTCONVERTTRAITS_COMPLEX_TYPE( componenttype ) \
307 class MeshConvertPixelTraits< ::std::complex< componenttype > > \
310 typedef ::std::complex< componenttype> TargetType; \
311 typedef componenttype ComponentType; \
312 static unsigned int GetNumberOfComponents() \
316 static unsigned int GetNumberOfComponents(const TargetType & itkNotUsed(pixel)) \
320 static ComponentType GetNthComponent(int i, TargetType & pixel) \
324 return pixel.imag(); \
328 return pixel.real(); \
331 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
335 pixel = TargetType( v, pixel.imag() ); \
339 pixel = TargetType( pixel.real(), v ); \
342 static ComponentType GetScalarValue(const TargetType& pixel) \
344 return std::norm(pixel); \
351 #define ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(type,componenttype) \
353 class MeshConvertPixelTraits< type< componenttype> > \
356 typedef type< componenttype > TargetType; \
357 typedef componenttype ComponentType; \
358 static unsigned int GetNumberOfComponents() \
362 static unsigned int GetNumberOfComponents(const TargetType& pixel) \
364 return pixel.Size(); \
366 static ComponentType GetNthComponent(int c, const TargetType& pixel) \
370 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
374 static ComponentType GetScalarValue(const TargetType& pixel) \
380 #define ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE_ALL_TYPES_MACRO(ArrayType) \
381 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, char); \
382 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, signed char); \
383 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, unsigned char); \
384 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, short); \
385 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, unsigned short); \
386 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, int); \
387 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, unsigned int); \
388 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, long); \
389 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, unsigned long); \
390 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, float); \
391 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, double);
static unsigned int GetNumberOfComponents(const PixelType &)
Traits class used to by ConvertPixels to convert blocks of pixels.
ITK_MESH_DEFAULTCONVERTTRAITS_COMPLEX_TYPE(float)
#define ITK_MESH_DEFAULTCONVERTTRAITS_OFFSET_TYPE(dimension)
ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE_ALL_TYPES_MACRO(Array)
static ComponentType GetNthComponent(int c, const PixelType &pixel)
ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(Vector)
static void SetNthComponent(int c, PixelType &pixel, const ComponentType &v)
ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_TYPES_MACRO(Matrix)
static ComponentType GetScalarValue(const PixelType &pixel)
static unsigned int GetNumberOfComponents()
PixelType::ComponentType ComponentType
#define ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(type)