Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkPixelTypeList.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 #include <stdexcept>
18 
19 namespace mitk
20 {
21  struct EmptyType
22  {
23  };
24 
25  template <typename T0 = EmptyType,
26  typename T1 = EmptyType,
27  typename T2 = EmptyType,
28  typename T3 = EmptyType,
29  typename T4 = EmptyType,
30  typename T5 = EmptyType,
31  typename T6 = EmptyType,
32  typename T7 = EmptyType,
33  typename T8 = EmptyType,
34  typename T9 = EmptyType>
35  struct PixelTypeList;
36 
37  template <typename T0,
38  typename T1,
39  typename T2,
40  typename T3,
41  typename T4,
42  typename T5,
43  typename T6,
44  typename T7,
45  typename T8,
46  typename T9>
47  struct PixelTypeList
48  {
49  typedef T0 head;
51  enum
52  {
54  };
55  };
56 
57  template <>
59  EmptyType,
60  EmptyType,
61  EmptyType,
62  EmptyType,
63  EmptyType,
64  EmptyType,
65  EmptyType,
66  EmptyType,
67  EmptyType>
68  {
69  enum
70  {
71  length = 0
72  };
73  };
74 
75  template <typename TypeList>
77  {
78  enum
79  {
80  value = TypeList::length
81  };
82  };
83 
84  template <typename TypeList,
85  int Index, // requested element index
86  int Step = 0, // current recusion step
87  bool Stop = (Index == Step), // stop recusion flag
88  bool OutOfRange = PixelTypeLength<TypeList>::value == 0 // out of range flag
89  >
90  struct GetPixelType
91  {
93  };
94 
95  //"out of range" specialization
96  template <typename TypeList, int Index, int Step, bool Stop>
98  {
99  // if OutOfRange is 'true' the 'type' is undefined
100  // so we'll get a compile-time error
101  };
102 
103  //"element found" specialization
104  template <typename TypeList, int Index, int Step, bool OutOfRange>
106  {
107  // the index is equal to the recursion step
108  // so the result type is the head of the Typlist and stop!
109  typedef typename TypeList::head type;
110  };
111 
113  // run-time type switch
114  template <typename TypeList, int Index = 0, bool Stop = (Index == PixelTypeLength<TypeList>::value)>
116 
117  template <typename TypeList, int Index, bool Stop>
118  struct PixelTypeSwitch
119  {
120  template <typename F>
121  bool operator()(int i, F &f)
122  {
123  if (i == Index)
124  {
125  return f.operator()<typename GetPixelType<TypeList, Index>::type>();
126  }
127  else
128  {
130  return next(i, f);
131  }
132  }
133  };
134 
135  template <typename TypeList, int Index>
136  struct PixelTypeSwitch<TypeList, Index, true>
137  {
138  template <typename F>
139  bool operator()(int, F &)
140  {
141  throw std::out_of_range("Index out of range");
142  }
143  };
144 
145  template <typename X, int VDimension, typename T1 = EmptyType, typename T2 = EmptyType, typename T3 = EmptyType>
147  {
148  typedef void (*CallBack)(T1, T2, T3);
149 
151  X *cl, CallBack callBack, const mitk::Image *mitkImage, T1 t1 = T1(), T2 t2 = T2(), T3 t3 = T3())
152  : cl(cl), callBack(callBack), mitkImage(mitkImage), pixelType(mitkImage->GetPixelType()), t1(t1), t2(t2), t3(t3)
153  {
154  }
155 
156  template <typename PixelType>
157  bool operator()()
158  {
159  if (pixelType != typeid(PixelType))
160  return false;
161  if (mitkImage->GetDimension() != VDimension)
162  return false;
163 
164  const_cast<mitk::Image *>(mitkImage)->Update();
165 
166  typedef itk::Image<PixelType, VDimension> ImageType;
167  typedef mitk::ImageToItk<ImageType> ImageToItkType;
169  imagetoitk->SetInput(mitkImage);
170  imagetoitk->Update();
171  cl->*callBack(imagetoitk->GetOutput(), t1, t2, t3);
172  return true;
173  }
174 
175  private:
176  X *cl;
177  CallBack callBack;
178 
179  const mitk::Image *mitkImage;
180  const mitk::PixelType &pixelType;
181  T1 t1;
182  T2 t2;
183  T3 t3;
184  };
185 
186 } // namespace mitk
PixelTypeList< T1, T2, T3, T4, T5, T6, T7, T8, T9 > tail
static void Update(vtkPolyData *)
Definition: mitkSurface.cpp:35
DataCollection - Class to facilitate loading/accessing structured data.
bool operator()(int i, F &f)
map::core::discrete::Elements< 3 >::InternalImageType ImageType
GetPixelType< typename TypeList::tail, Index, Step+1 >::type type
Image class for storing images.
Definition: mitkImage.h:76
AccessItkImageFunctor(X *cl, CallBack callBack, const mitk::Image *mitkImage, T1 t1=T1(), T2 t2=T2(), T3 t3=T3())
unsigned int GetDimension() const
Get dimension of the image.
Definition: mitkImage.cpp:110
void(* CallBack)(T1, T2, T3)
Class for defining the data type of pixels.
Definition: mitkPixelType.h:55
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.