Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef PIXELTYPETRAITS_H
18 #define PIXELTYPETRAITS_H
19 
20 #include <itkDiffusionTensor3D.h>
21 #include <itkImage.h>
22 #include <itkImageIOBase.h>
23 #include <itkRGBAPixel.h>
24 #include <itkRGBPixel.h>
25 #include <itkVectorImage.h>
26 
34 namespace itk
35 {
37  template <typename TValueType>
39 }
40 
41 #define MITK_PIXEL_COMPONENT_TYPE(type, ctype, name) \
42  template <> \
43  struct mitk::MapPixelComponentType<type> \
44  { \
45  static const int value = ctype; \
46  } template <> \
47  std::string mitk::PixelComponentTypeToString() \
48  { \
49  return name; \
50  }
51 
52 namespace mitk
53 {
54  static const int PixelUserType = itk::ImageIOBase::MATRIX + 1;
55  static const int PixelComponentUserType = itk::ImageIOBase::DOUBLE + 1;
56 
62  template <typename T>
64  {
65  static const int value = itk::ImageIOBase::MapPixelType<T>::CType;
66  };
67 
72  template <typename T>
74  {
75  static const bool value = false;
76  };
77 
80 #define DEFINE_TYPE_PRIMITIVE(_TYPEIN) \
81  template <> \
82  struct isPrimitiveType<_TYPEIN> \
83  { \
84  static const bool value = true; \
85  }
86 
88  DEFINE_TYPE_PRIMITIVE(unsigned char);
92  DEFINE_TYPE_PRIMITIVE(signed char);
94  DEFINE_TYPE_PRIMITIVE(unsigned short);
98  DEFINE_TYPE_PRIMITIVE(unsigned int);
104  DEFINE_TYPE_PRIMITIVE(long unsigned int);
109 
110  template <typename TPixelType, unsigned int VDimension = 0>
112  {
113  typedef itk::Image<TPixelType, VDimension> ImageType;
114  static const bool IsVectorImage = false;
115  };
116 
117  template <typename TPixelType, unsigned int VDimension>
118  struct ImageTypeTrait<itk::VariableLengthVector<TPixelType>, VDimension>
119  {
120  typedef itk::VectorImage<TPixelType, VDimension> ImageType;
121  static const bool IsVectorImage = true;
122  };
123 
124  template <typename T>
125  struct ImageTypeTrait<T, 0>
126  {
127  typedef T ImageType;
128  static const bool IsVectorImage = false;
129  };
130 
131  template <typename TPixelType, unsigned int VDimension>
132  struct ImageTypeTrait<itk::VectorImage<TPixelType, VDimension>, 0>
133  {
134  typedef itk::VectorImage<TPixelType, VDimension> ImageType;
135  static const bool IsVectorImage = true;
136  };
137 
139  template <bool flag, typename T>
141  {
142  typedef T ValueType;
143  };
144 
149  template <typename T>
150  struct PixelTypeTrait<false, T>
151  {
152  typedef typename T::ValueType ValueType;
153  };
154 
156  template <typename T>
158  {
160  };
161 
166  template <bool V, typename T>
168  {
169  static const size_t Size = 1;
170  };
171 
173  template <typename T>
174  struct ComponentsTrait<false, T>
175  {
176  static const size_t Size = T::ValueType::Length;
177  };
178 
179  typedef itk::ImageIOBase::IOPixelType itkIOPixelType;
180 
189  template <class T>
191  {
192  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::UNKNOWNPIXELTYPE;
193  };
194 
195  //------------------------
196  // Partial template specialization for fixed-length types
197  //------------------------
198 
199  template <class C>
200  struct MapCompositePixelType<itk::RGBPixel<C>>
201  {
202  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::RGB;
203  };
204 
205  template <class C>
206  struct MapCompositePixelType<itk::RGBAPixel<C>>
207  {
208  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::RGBA;
209  };
210 
211  template <class C>
212  struct MapCompositePixelType<itk::DiffusionTensor3D<C>>
213  {
214  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::DIFFUSIONTENSOR3D;
215  };
216 
217  template <class C>
218  struct MapCompositePixelType<itk::VariableLengthVector<C>>
219  {
220  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::VECTOR;
221  };
222 
223  //------------------------
224  // Partial template specialization for variable-length types
225  //------------------------
226  template <class C, unsigned int N>
228  {
229  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::VECTOR;
230  };
231 
232  template <class C, unsigned int N>
233  struct MapCompositePixelType<itk::FixedArray<C, N>>
234  {
235  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::COVARIANTVECTOR;
236  };
237 
238  template <class C, unsigned int N>
239  struct MapCompositePixelType<itk::CovariantVector<C, N>>
240  {
241  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::COVARIANTVECTOR;
242  };
243 
244  template <class C, unsigned int N>
246  {
247  static const itkIOPixelType IOCompositeType = itk::ImageIOBase::MATRIX;
248  };
249 
259  template <class T, bool Primitive>
261  {
264  };
265 
267  template <class T>
268  struct MapPixelType<T, true>
269  {
270  static const itkIOPixelType IOPixelType = itk::ImageIOBase::SCALAR;
272  };
273 
274 } // end namespace mitk
275 
276 #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
static const itkIOPixelType IOCompositeType
Object for compile-time resolving of the number of components for given type.
static const bool IsVectorImage
ValueType
Type of the value held by a Value object.
Definition: jsoncpp.h:345
static const int IOComponentType
static const bool value
#define DEFINE_TYPE_PRIMITIVE(_TYPEIN)
static const itkIOPixelType IOPixelType
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 vcl_size_t Size
static const int PixelUserType