Medical Imaging Interaction Toolkit  2026.06.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 
34 namespace itk
35 {
37  template <typename TValueType>
39 }
40 
52 #define MITK_PIXEL_COMPONENT_TYPE(type, ctype, name) \
53  template <> \
54  struct mitk::MapPixelComponentType<type> \
55  { \
56  static const int value = ctype; \
57  } template <> \
58  std::string mitk::PixelComponentTypeToString() \
59  { \
60  return name; \
61  }
62 
63 namespace mitk
64 {
66  static const int PixelUserType = static_cast<int>(itk::IOPixelEnum::MATRIX) + 1;
67 
69  static const int PixelComponentUserType = static_cast<int>(itk::IOComponentEnum::DOUBLE) + 1;
70 
76  template <typename T>
78  {
79  static const itk::IOComponentEnum value = itk::ImageIOBase::MapPixelType<T>::CType;
80  };
81 
86  template <typename T>
88  {
89  static const bool value = false;
90  };
91 
93 #define DEFINE_TYPE_PRIMITIVE(_TYPEIN) \
94  template <> \
95  struct isPrimitiveType<_TYPEIN> \
96  { \
97  static const bool value = true; \
98  }
99 
101  DEFINE_TYPE_PRIMITIVE(unsigned char);
105  DEFINE_TYPE_PRIMITIVE(signed char);
107  DEFINE_TYPE_PRIMITIVE(unsigned short);
111  DEFINE_TYPE_PRIMITIVE(unsigned int);
117  DEFINE_TYPE_PRIMITIVE(long unsigned int);
122 
132  template <typename TPixelType, unsigned int VDimension = 0>
134  {
135  typedef itk::Image<TPixelType, VDimension> ImageType;
136  static const bool IsVectorImage = false;
137  };
138 
140  template <typename TPixelType, unsigned int VDimension>
141  struct ImageTypeTrait<itk::VariableLengthVector<TPixelType>, VDimension>
142  {
143  typedef itk::VectorImage<TPixelType, VDimension> ImageType;
144  static const bool IsVectorImage = true;
145  };
146 
148  template <typename T>
149  struct ImageTypeTrait<T, 0>
150  {
151  typedef T ImageType;
152  static const bool IsVectorImage = false;
153  };
154 
156  template <typename TPixelType, unsigned int VDimension>
157  struct ImageTypeTrait<itk::VectorImage<TPixelType, VDimension>, 0>
158  {
159  typedef itk::VectorImage<TPixelType, VDimension> ImageType;
160  static const bool IsVectorImage = true;
161  };
162 
164  template <bool flag, typename T>
166  {
167  typedef T ValueType;
168  };
169 
174  template <typename T>
175  struct PixelTypeTrait<false, T>
176  {
177  typedef typename T::ValueType ValueType;
178  };
179 
181  template <typename T>
183  {
185  };
186 
191  template <bool V, typename T>
193  {
194  static const size_t Size = 1;
195  };
196 
198  template <typename T>
199  struct ComponentsTrait<false, T>
200  {
201  static const size_t Size = T::ValueType::Length;
202  };
203 
205  typedef itk::IOPixelEnum itkIOPixelType;
206 
208  typedef itk::IOComponentEnum itkIOComponentType;
209 
218  template <class T>
220  {
221  static const itkIOPixelType IOCompositeType = itkIOPixelType::UNKNOWNPIXELTYPE;
222  };
223 
224  //------------------------
225  // Partial template specialization for fixed-length types
226  //------------------------
227 
228  template <class C>
229  struct MapCompositePixelType<itk::RGBPixel<C>>
230  {
231  static const itkIOPixelType IOCompositeType = itkIOPixelType::RGB;
232  };
233 
234  template <class C>
235  struct MapCompositePixelType<itk::RGBAPixel<C>>
236  {
237  static const itkIOPixelType IOCompositeType = itkIOPixelType::RGBA;
238  };
239 
240  template <class C>
241  struct MapCompositePixelType<itk::DiffusionTensor3D<C>>
242  {
243  static const itkIOPixelType IOCompositeType = itkIOPixelType::DIFFUSIONTENSOR3D;
244  };
245 
246  template <class C>
247  struct MapCompositePixelType<itk::VariableLengthVector<C>>
248  {
249  static const itkIOPixelType IOCompositeType = itkIOPixelType::VECTOR;
250  };
251 
252  //------------------------
253  // Partial template specialization for variable-length types
254  //------------------------
255  template <class C, unsigned int N>
257  {
258  static const itkIOPixelType IOCompositeType = itkIOPixelType::VECTOR;
259  };
260 
261  template <class C, unsigned int N>
262  struct MapCompositePixelType<itk::FixedArray<C, N>>
263  {
264  static const itkIOPixelType IOCompositeType = itkIOPixelType::COVARIANTVECTOR;
265  };
266 
267  template <class C, unsigned int N>
268  struct MapCompositePixelType<itk::CovariantVector<C, N>>
269  {
270  static const itkIOPixelType IOCompositeType = itkIOPixelType::COVARIANTVECTOR;
271  };
272 
273  template <class C, unsigned int N>
275  {
276  static const itkIOPixelType IOCompositeType = itkIOPixelType::MATRIX;
277  };
278 
288  template <class T, bool Primitive>
290  {
293  };
294 
296  template <class T>
297  struct MapPixelType<T, true>
298  {
299  static const itkIOPixelType IOPixelType = itkIOPixelType::SCALAR;
301  };
302 
303 } // end namespace mitk
304 
305 #endif
MITK matrix type extending itk::Matrix with additional constructors and utility methods.
Definition: mitkMatrix.h:32
MITK vector type extending itk::Vector with additional constructors and conversions.
Definition: mitkVector.h:39
#define DEFINE_TYPE_PRIMITIVE(_TYPEIN)
Provides a partial specialization for the.
Find image slices visible on a given plane.
itk::IOPixelEnum itkIOPixelType
Type alias for the ITK pixel type enumeration.
static const int PixelUserType
Starting integer value for user-defined pixel types (beyond the built-in ITK pixel types).
static const int PixelComponentUserType
Starting integer value for user-defined pixel component types (beyond the built-in ITK component type...
itk::IOComponentEnum itkIOComponentType
Type alias for the ITK component type enumeration.
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
Compile-time trait that maps a pixel type and dimension to the corresponding ITK image type.
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