Medical Imaging Interaction Toolkit  2025.12.02
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
#define DEFINE_TYPE_PRIMITIVE(_TYPEIN)
Provides a partial specialization for the.
Find image slices visible on a given plane.
itk::IOPixelEnum itkIOPixelType
static const int PixelUserType
static const int PixelComponentUserType
itk::IOComponentEnum itkIOComponentType
Object for compile-time resolving of the number of components for given type.
static const size_t Size
Compile time resolving of the type of a component.
PixelTypeTrait< isPrimitiveType< T >::value, T >::ValueType ComponentType
itk::Image< TPixelType, VDimension > ImageType
static const bool IsVectorImage
Object for compile-time translation of a composite pixel type into an itk::ImageIOBase::IOPixelType i...
static const itkIOPixelType IOCompositeType
static const itk::IOComponentEnum value
Object for compile-time translation of a pixel type into an itk::ImageIOBase::IOPixelType information...
static const itkIOComponentType IOComponentType
static const itkIOPixelType IOPixelType
Compile-time trait for resolving the ValueType from an ItkImageType.
This is an implementation of a type trait to provide a compile-time check for PixelType used in the i...
static const bool value