Medical Imaging Interaction Toolkit  2023.04.00
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 mitkPixelTypeTraits_h
14 #define mitkPixelTypeTraits_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 = static_cast<int>(itk::IOPixelEnum::MATRIX) + 1;
51  static const int PixelComponentUserType = static_cast<int>(itk::IOComponentEnum::DOUBLE) + 1;
52 
58  template <typename T>
60  {
61  static const itk::IOComponentEnum 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::IOPixelEnum itkIOPixelType;
175  typedef itk::IOComponentEnum itkIOComponentType;
176 
185  template <class T>
187  {
188  static const itkIOPixelType IOCompositeType = itkIOPixelType::UNKNOWNPIXELTYPE;
189  };
190 
191  //------------------------
192  // Partial template specialization for fixed-length types
193  //------------------------
194 
195  template <class C>
196  struct MapCompositePixelType<itk::RGBPixel<C>>
197  {
198  static const itkIOPixelType IOCompositeType = itkIOPixelType::RGB;
199  };
200 
201  template <class C>
202  struct MapCompositePixelType<itk::RGBAPixel<C>>
203  {
204  static const itkIOPixelType IOCompositeType = itkIOPixelType::RGBA;
205  };
206 
207  template <class C>
208  struct MapCompositePixelType<itk::DiffusionTensor3D<C>>
209  {
210  static const itkIOPixelType IOCompositeType = itkIOPixelType::DIFFUSIONTENSOR3D;
211  };
212 
213  template <class C>
214  struct MapCompositePixelType<itk::VariableLengthVector<C>>
215  {
216  static const itkIOPixelType IOCompositeType = itkIOPixelType::VECTOR;
217  };
218 
219  //------------------------
220  // Partial template specialization for variable-length types
221  //------------------------
222  template <class C, unsigned int N>
224  {
225  static const itkIOPixelType IOCompositeType = itkIOPixelType::VECTOR;
226  };
227 
228  template <class C, unsigned int N>
229  struct MapCompositePixelType<itk::FixedArray<C, N>>
230  {
231  static const itkIOPixelType IOCompositeType = itkIOPixelType::COVARIANTVECTOR;
232  };
233 
234  template <class C, unsigned int N>
235  struct MapCompositePixelType<itk::CovariantVector<C, N>>
236  {
237  static const itkIOPixelType IOCompositeType = itkIOPixelType::COVARIANTVECTOR;
238  };
239 
240  template <class C, unsigned int N>
242  {
243  static const itkIOPixelType IOCompositeType = itkIOPixelType::MATRIX;
244  };
245 
255  template <class T, bool Primitive>
257  {
260  };
261 
263  template <class T>
264  struct MapPixelType<T, true>
265  {
266  static const itkIOPixelType IOPixelType = itkIOPixelType::SCALAR;
268  };
269 
270 } // end namespace mitk
271 
272 #endif
mitk::ImageTypeTrait< itk::VectorImage< TPixelType, VDimension >, 0 >::ImageType
itk::VectorImage< TPixelType, VDimension > ImageType
Definition: mitkPixelTypeTraits.h:129
mitk::ImageTypeTrait< itk::VariableLengthVector< TPixelType >, VDimension >::ImageType
itk::VectorImage< TPixelType, VDimension > ImageType
Definition: mitkPixelTypeTraits.h:115
mitk::ComponentsTrait
Object for compile-time resolving of the number of components for given type.
Definition: mitkPixelTypeTraits.h:162
mitk::itkIOPixelType
itk::IOPixelEnum itkIOPixelType
Definition: mitkPixelTypeTraits.h:174
mitk::MapPixelType::IOPixelType
static const itkIOPixelType IOPixelType
Definition: mitkPixelTypeTraits.h:258
mitk::PixelTypeTrait
Compile-time trait for resolving the ValueType from an ItkImageType.
Definition: mitkPixelTypeTraits.h:135
mitk::GetComponentType
Compile time resolving of the type of a component.
Definition: mitkPixelTypeTraits.h:152
mitk
DataCollection - Class to facilitate loading/accessing structured data.
Definition: RenderingTests.dox:1
mitk::PixelUserType
static const int PixelUserType
Definition: mitkPixelTypeTraits.h:50
mitk::ImageTypeTrait::ImageType
itk::Image< TPixelType, VDimension > ImageType
Definition: mitkPixelTypeTraits.h:108
mitk::PixelTypeTrait< false, T >::ValueType
T::ValueType ValueType
Definition: mitkPixelTypeTraits.h:147
mitk::isPrimitiveType::value
static const bool value
Definition: mitkPixelTypeTraits.h:71
DEFINE_TYPE_PRIMITIVE
#define DEFINE_TYPE_PRIMITIVE(_TYPEIN)
Provides a partial specialization for the.
Definition: mitkPixelTypeTraits.h:75
mitk::Vector
Definition: mitkVector.h:28
mitk::MapCompositePixelType
Object for compile-time translation of a composite pixel type into an itk::ImageIOBase::IOPixelType i...
Definition: mitkPixelTypeTraits.h:186
mitk::MapCompositePixelType::IOCompositeType
static const itkIOPixelType IOCompositeType
Definition: mitkPixelTypeTraits.h:188
mitk::ComponentsTrait::Size
static const size_t Size
Definition: mitkPixelTypeTraits.h:164
mitk::Matrix
Definition: mitkMatrix.h:25
itk::VariableLengthVector
Definition: mitkPixelTypeTraits.h:34
mitk::PixelComponentUserType
static const int PixelComponentUserType
Definition: mitkPixelTypeTraits.h:51
mitk::PixelTypeTrait::ValueType
T ValueType
Definition: mitkPixelTypeTraits.h:137
mitk::isPrimitiveType
This is an implementation of a type trait to provide a compile-time check for PixelType used in the i...
Definition: mitkPixelTypeTraits.h:69
mitk::ImageTypeTrait::IsVectorImage
static const bool IsVectorImage
Definition: mitkPixelTypeTraits.h:109
mitk::MapPixelComponentType
Definition: mitkPixelTypeTraits.h:59
itk
SET FUNCTIONS.
Definition: itkIntelligentBinaryClosingFilter.h:30
mitk::ImageTypeTrait< T, 0 >::ImageType
T ImageType
Definition: mitkPixelTypeTraits.h:122
mitk::GetComponentType::ComponentType
PixelTypeTrait< isPrimitiveType< T >::value, T >::ValueType ComponentType
Definition: mitkPixelTypeTraits.h:154
mitk::itkIOComponentType
itk::IOComponentEnum itkIOComponentType
Definition: mitkPixelTypeTraits.h:175
mitk::ImageTypeTrait
Definition: mitkPixelTypeTraits.h:106
mitk::MapPixelComponentType::value
static const itk::IOComponentEnum value
Definition: mitkPixelTypeTraits.h:61
mitk::MapPixelType
Object for compile-time translation of a pixel type into an itk::ImageIOBase::IOPixelType information...
Definition: mitkPixelTypeTraits.h:256
mitk::MapPixelType::IOComponentType
static const itkIOComponentType IOComponentType
Definition: mitkPixelTypeTraits.h:259