Medical Imaging Interaction Toolkit  2018.4.99-701c8286
Medical Imaging Interaction Toolkit
mitkPixelTypeTraits.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef PIXELTYPETRAITS_H
14 #define PIXELTYPETRAITS_H
15 
16 #include <itkDiffusionTensor3D.h>
17 #include <itkImage.h>
18 #include <itkImageIOBase.h>
19 #include <itkRGBAPixel.h>
20 #include <itkRGBPixel.h>
21 #include <itkVectorImage.h>
22 
30 namespace itk
31 {
33  template <typename TValueType>
35 }
36 
37 #define MITK_PIXEL_COMPONENT_TYPE(type, ctype, name) \
38  template <> \
39  struct mitk::MapPixelComponentType<type> \
40  { \
41  static const int value = ctype; \
42  } template <> \
43  std::string mitk::PixelComponentTypeToString() \
44  { \
45  return name; \
46  }
47 
48 namespace mitk
49 {
50  static const int PixelUserType = itk::ImageIOBase::MATRIX + 1;
51  static const int PixelComponentUserType = itk::ImageIOBase::DOUBLE + 1;
52 
58  template <typename T>
60  {
61  static const int value = itk::ImageIOBase::MapPixelType<T>::CType;
62  };
63 
68  template <typename T>
70  {
71  static const bool value = false;
72  };
73 
75 #define DEFINE_TYPE_PRIMITIVE(_TYPEIN) \
76  template <> \
77  struct isPrimitiveType<_TYPEIN> \
78  { \
79  static const bool value = true; \
80  }
81 
83  DEFINE_TYPE_PRIMITIVE(unsigned char);
87  DEFINE_TYPE_PRIMITIVE(signed char);
89  DEFINE_TYPE_PRIMITIVE(unsigned short);
93  DEFINE_TYPE_PRIMITIVE(unsigned int);
99  DEFINE_TYPE_PRIMITIVE(long unsigned int);
104 
105  template <typename TPixelType, unsigned int VDimension = 0>
107  {
108  typedef itk::Image<TPixelType, VDimension> ImageType;
109  static const bool IsVectorImage = false;
110  };
111 
112  template <typename TPixelType, unsigned int VDimension>
113  struct ImageTypeTrait<itk::VariableLengthVector<TPixelType>, VDimension>
114  {
115  typedef itk::VectorImage<TPixelType, VDimension> ImageType;
116  static const bool IsVectorImage = true;
117  };
118 
119  template <typename T>
120  struct ImageTypeTrait<T, 0>
121  {
122  typedef T ImageType;
123  static const bool IsVectorImage = false;
124  };
125 
126  template <typename TPixelType, unsigned int VDimension>
127  struct ImageTypeTrait<itk::VectorImage<TPixelType, VDimension>, 0>
128  {
129  typedef itk::VectorImage<TPixelType, VDimension> ImageType;
130  static const bool IsVectorImage = true;
131  };
132 
134  template <bool flag, typename T>
136  {
137  typedef T ValueType;
138  };
139 
144  template <typename T>
145  struct PixelTypeTrait<false, T>
146  {
147  typedef typename T::ValueType ValueType;
148  };
149 
151  template <typename T>
153  {
155  };
156 
161  template <bool V, typename T>
163  {
164  static const size_t Size = 1;
165  };
166 
168  template <typename T>
169  struct ComponentsTrait<false, T>
170  {
171  static const size_t Size = T::ValueType::Length;
172  };
173 
174  typedef itk::ImageIOBase::IOPixelType itkIOPixelType;
175 
184  template <class T>
186  {
187  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::UNKNOWNPIXELTYPE;
188  };
189 
190  //------------------------
191  // Partial template specialization for fixed-length types
192  //------------------------
193 
194  template <class C>
195  struct MapCompositePixelType<itk::RGBPixel<C>>
196  {
197  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::RGB;
198  };
199 
200  template <class C>
201  struct MapCompositePixelType<itk::RGBAPixel<C>>
202  {
203  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::RGBA;
204  };
205 
206  template <class C>
207  struct MapCompositePixelType<itk::DiffusionTensor3D<C>>
208  {
209  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::DIFFUSIONTENSOR3D;
210  };
211 
212  template <class C>
213  struct MapCompositePixelType<itk::VariableLengthVector<C>>
214  {
215  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::VECTOR;
216  };
217 
218  //------------------------
219  // Partial template specialization for variable-length types
220  //------------------------
221  template <class C, unsigned int N>
223  {
224  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::VECTOR;
225  };
226 
227  template <class C, unsigned int N>
228  struct MapCompositePixelType<itk::FixedArray<C, N>>
229  {
230  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::COVARIANTVECTOR;
231  };
232 
233  template <class C, unsigned int N>
234  struct MapCompositePixelType<itk::CovariantVector<C, N>>
235  {
236  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::COVARIANTVECTOR;
237  };
238 
239  template <class C, unsigned int N>
241  {
242  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::MATRIX;
243  };
244 
254  template <class T, bool Primitive>
256  {
257  static const itkIOPixelType IOPixelType = MapCompositePixelType<T>::IOCompositeType;
258  static const int IOComponentType = MapPixelComponentType<typename GetComponentType<T>::ComponentType>::value;
259  };
260 
262  template <class T>
263  struct MapPixelType<T, true>
264  {
265  static const itkIOPixelType IOPixelType = itk::ImageIOBase::SCALAR;
266  static const int IOComponentType = MapPixelComponentType<T>::value;
267  };
268 
269 } // end namespace mitk
270 
271 #endif // PIXELTYPETRAITS_H
PixelTypeTrait< isPrimitiveType< T >::value, T >::ValueType ComponentType
DataCollection - Class to facilitate loading/accessing structured data.
itk::ImageIOBase::IOPixelType itkIOPixelType
static const int PixelComponentUserType
Object for compile-time translation of a composite pixel type into an itk::ImageIOBase::IOPixelType i...
itk::Image< TPixelType, VDimension > ImageType
Object for compile-time resolving of the number of components for given type.
ValueType
Type of the value held by a Value object.
Definition: jsoncpp.h:345
#define DEFINE_TYPE_PRIMITIVE(_TYPEIN)
Provides a partial specialization for the.
This is an implementation of a type trait to provide a compile-time check for PixelType used in the i...
Compile time resolving of the type of a component.
Compile-time trait for resolving the ValueType from an ItkImageType.
Object for compile-time translation of a pixel type into an itk::ImageIOBase::IOPixelType information...
static const int PixelUserType