19 #ifndef __itkMeshConvertPixelTraits_h
20 #define __itkMeshConvertPixelTraits_h
21 #include "ITKIOMeshExport.h"
45 template<
typename PixelType>
54 {
return PixelType::GetNumberOfComponents();}
57 {
return PixelType::GetNumberOfComponents();}
61 {
return pixel.GetNthComponent(c); }
65 { pixel.SetNthComponent(c, v); }
69 {
return pixel.GetScalarValue(); }
73 #define ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL(type) \
75 class MeshConvertPixelTraits<type> \
78 typedef type ComponentType; \
79 static unsigned int GetNumberOfComponents() \
83 static unsigned int GetNumberOfComponents(const type& itkNotUsed(pixel))\
87 static ComponentType GetNthComponent(int itkNotUsed(c), const type& pixel)\
91 static void SetNthComponent(int , type& pixel, const ComponentType& v) \
95 static type GetScalarValue(const type& pixel) \
114 #undef ITK_DEFAULTCONVERTTRAITS_NATIVE_SPECIAL
120 #define ITK_MESH_DEFAULTCONVERTTRAITS_OFFSET_TYPE(dimension) \
122 class MeshConvertPixelTraits< Offset<dimension> > \
125 typedef Offset<dimension> TargetType; \
126 typedef TargetType::OffsetValueType ComponentType; \
127 static unsigned int GetNumberOfComponents() \
131 static unsigned int GetNumberOfComponents(const TargetType& itkNotUsed(pixel)) \
135 static ComponentType GetNthComponent(int c, const TargetType& pixel) \
139 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
143 static ComponentType GetScalarValue(const TargetType& pixel) \
161 #define ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(type,componenttype, dimension) \
163 class MeshConvertPixelTraits< type< componenttype, dimension> > \
166 typedef type< componenttype, dimension > TargetType; \
167 typedef componenttype ComponentType; \
168 static unsigned int GetNumberOfComponents() \
172 static unsigned int GetNumberOfComponents(const TargetType& itkNotUsed(pixel)) \
176 static ComponentType GetNthComponent(int c, const TargetType& pixel) \
180 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
184 static ComponentType GetScalarValue(const TargetType& pixel) \
196 #define ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, Type) \
197 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,1) \
198 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,2) \
199 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,3) \
200 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,4) \
201 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,5) \
202 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE(ArrayType,Type,6)
204 #define ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_TYPES_MACRO(ArrayType) \
205 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, char); \
206 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, signed char); \
207 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned char); \
208 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, short); \
209 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned short); \
210 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, int); \
211 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned int); \
212 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, long); \
213 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, unsigned long); \
214 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, float); \
215 ITK_MESH_DEFAULTCONVERTTRAITS_FIXEDARRAY_TYPE_ALL_MACRO(ArrayType, double);
232 #define ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(type,componenttype,rows,cols) \
234 class MeshConvertPixelTraits< type< componenttype, rows, cols > > \
237 typedef type< componenttype, rows, cols > TargetType; \
238 typedef componenttype ComponentType; \
239 static unsigned int GetNumberOfComponents() \
241 return rows * cols; \
243 static unsigned int GetNumberOfComponents(const TargetType& itkNotUsed(pixel)) \
245 return rows * cols; \
247 static ComponentType GetNthComponent(int c, const TargetType& pixel) \
249 const unsigned int row = c / cols; \
250 const unsigned int col = c % cols; \
251 return pixel[row][col]; \
253 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
255 const unsigned int row = i / cols; \
256 const unsigned int col = i % cols; \
257 pixel[row][col] = v; \
259 static ComponentType GetScalarValue(const TargetType& pixel) \
261 return pixel[0][0]; \
270 #define ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, Type) \
271 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,1,1) \
272 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,2,2) \
273 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,3,3) \
274 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,4,4) \
275 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,5,5) \
276 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE(ArrayType,Type,6,6)
278 #define ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_TYPES_MACRO(ArrayType) \
279 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, char); \
280 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, signed char); \
281 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned char); \
282 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, short); \
283 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned short); \
284 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, int); \
285 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned int); \
286 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, long); \
287 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, unsigned long); \
288 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, float); \
289 ITK_MESH_DEFAULTCONVERTTRAITS_MATRIX_TYPE_ALL_MACRO(ArrayType, double);
306 #define ITK_MESH_DEFAULTCONVERTTRAITS_COMPLEX_TYPE( componenttype ) \
308 class MeshConvertPixelTraits< ::std::complex< componenttype > > \
311 typedef ::std::complex< componenttype> TargetType; \
312 typedef componenttype ComponentType; \
313 static unsigned int GetNumberOfComponents() \
317 static unsigned int GetNumberOfComponents(const TargetType & itkNotUsed(pixel)) \
321 static ComponentType GetNthComponent(int i, TargetType & pixel) \
325 return pixel.imag(); \
329 return pixel.real(); \
332 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
336 pixel = TargetType( v, pixel.imag() ); \
340 pixel = TargetType( pixel.real(), v ); \
343 static ComponentType GetScalarValue(const TargetType& pixel) \
345 return std::norm(pixel); \
352 #define ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(type,componenttype) \
354 class MeshConvertPixelTraits< type< componenttype> > \
357 typedef type< componenttype > TargetType; \
358 typedef componenttype ComponentType; \
359 static unsigned int GetNumberOfComponents() \
363 static unsigned int GetNumberOfComponents(const TargetType& pixel) \
365 return pixel.Size(); \
367 static ComponentType GetNthComponent(int c, const TargetType& pixel) \
371 static void SetNthComponent(int i, TargetType & pixel, const ComponentType& v) \
375 static ComponentType GetScalarValue(const TargetType& pixel) \
381 #define ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE_ALL_TYPES_MACRO(ArrayType) \
382 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, char); \
383 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, signed char); \
384 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, unsigned char); \
385 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, short); \
386 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, unsigned short); \
387 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, int); \
388 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, unsigned int); \
389 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, long); \
390 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, unsigned long); \
391 ITK_MESH_DEFAULTCONVERTTRAITS_ARRAY_TYPE(ArrayType, float); \
392 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)