selxInterfaceTraits.h 7.11 KB
Newer Older
Floris Berendsen's avatar
Floris Berendsen committed
1
2
/*=========================================================================
 *
3
 *  Copyright Leiden University Medical Center, Erasmus University Medical
Floris Berendsen's avatar
Floris Berendsen committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *  Center and contributors
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0.txt
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *=========================================================================*/

20
21
22
#ifndef InterfaceTraits_h
#define InterfaceTraits_h

23
24
//TODO: note, maybe this functionality shouldn't be called a Trait, since we use a method ::Get(). Is Policy a better name?

25
#include "selxInterfaces.h"
26
//#include <type_traits>
FBerendsen's avatar
FBerendsen committed
27

Floris Berendsen's avatar
Floris Berendsen committed
28
namespace selx
29
{
30
31
32
33
34
  // helper to display type name in static assert error message (required, at least for VC++ 2013)
  template <typename T>
  struct StaticErrorMessageRevealT { enum { False = false }; };
  

35
// Traits to get printable interface name
36
37
38

// In our toolbox for each InterfaceType it is required to implement InterfaceName<InterfaceType>::Get()
// If one omits this, the implementation falls back to the default implementation that provides a compiler error message including the InterfaceType name for which the specialization is missing.
39
template< typename T >
40
41
struct InterfaceName
{
42
  static_assert(StaticErrorMessageRevealT<T>::False, "Please Implement InterfaceName<InterfaceType> for this InterfaceType");
43
44
};

45
46
// The specializations for each type of Interface supported by the toolbox

47
48
template< >
struct InterfaceName< MetricValueInterface >
49
{
50
  static const char * Get()
51
52
53
54
  {
    return "MetricValueInterface";
  }
};
55
56
template< >
struct InterfaceName< MetricDerivativeInterface >
57
{
58
  static const char * Get()
59
60
61
62
  {
    return "MetricDerivativeInterface";
  }
};
63
64
template< >
struct InterfaceName< OptimizerUpdateInterface >
65
{
66
  static const char * Get()
67
68
69
70
71
  {
    return "OptimizerUpdateInterface";
  }
};

72
73
template< >
struct InterfaceName< ConflictinUpdateInterface >
74
{
75
  static const char * Get()
76
77
78
79
80
  {
    return "ConflictinUpdateInterface";
  }
};

81
82
template< >
struct InterfaceName< TransformedImageInterface >
Floris Berendsen's avatar
Floris Berendsen committed
83
{
84
  static const char * Get()
Floris Berendsen's avatar
Floris Berendsen committed
85
86
87
88
89
  {
    return "TransformedImageInterface";
  }
};

Floris Berendsen's avatar
Floris Berendsen committed
90
// InterfaceName<T>::Get() should return "itkImageSourceInterface" no matter over which arguments itkImageSourceInterface is templated
91
92
template< int D, class TPixel >
struct InterfaceName< itkImageInterface< D, TPixel >>
93
{
94
  static const char * Get()
95
96
97
98
99
  {
    return "itkImageInterface";
  }
};

100
101
template< int D, class TPixel >
struct InterfaceName< itkImageFixedInterface< D, TPixel >>
102
{
103
104
105
106
  static const char * Get()
  {
    return "itkImageFixedInterface";
  }
107
};
108

109
110
template< int D >
struct InterfaceName< itkImageDomainFixedInterface< D >>
111
{
112
  static const char * Get()
113
114
115
116
117
  {
    return "itkImageDomainFixedInterface";
  }
};

118
119
template< int D, class TPixel >
struct InterfaceName< itkImageMovingInterface< D, TPixel >>
120
{
121
  static const char * Get()
122
123
124
125
126
  {
    return "itkImageMovingInterface";
  }
};

127
128
template< int D, class TPixel >
struct InterfaceName< DisplacementFieldItkImageSourceInterface< D, TPixel >>
129
{
130
  static const char * Get()
131
132
133
134
135
  {
    return "DisplacementFieldItkImageSourceInterface";
  }
};

136
137
template< int D, class TPixel >
struct InterfaceName< itkMeshInterface< D, TPixel >>
Floris Berendsen's avatar
Floris Berendsen committed
138
{
139
  static const char * Get()
Floris Berendsen's avatar
Floris Berendsen committed
140
141
142
143
  {
    return "itkMeshInterface";
  }
};
144

145
146
template< >
struct InterfaceName< SourceInterface >
147
{
148
  static const char * Get()
149
150
151
152
153
  {
    return "SourceInterface";
  }
};

154
155
template< >
struct InterfaceName< SinkInterface >
156
{
157
  static const char * Get()
158
159
160
161
162
  {
    return "SinkInterface";
  }
};

163
164
template< int D, class TPixel >
struct InterfaceName< itkMetricv4Interface< D, TPixel >>
165
{
166
  static const char * Get()
167
168
169
170
171
  {
    return "itkMetricv4Interface";
  }
};

172
173
template< class InternalComputationValueType >
struct InterfaceName< itkOptimizerv4Interface< InternalComputationValueType >>
174
{
175
  static const char * Get()
176
177
178
179
180
  {
    return "itkOptimizerv4Interface";
  }
};

181
182
template< class InternalComputationValueType, int D >
struct InterfaceName< itkTransformInterface< InternalComputationValueType, D >>
183
{
184
  static const char * Get()
185
186
187
188
189
  {
    return "itkTransformInterface";
  }
};

190
191
template< class F, class M >
struct InterfaceName< elastixTransformParameterObjectInterface< F, M >>
192
{
193
  static const char * Get()
194
195
196
197
198
  {
    return "elastixTransformParameterObjectInterface";
  }
};

199
200
template< >
struct InterfaceName< RegistrationControllerStartInterface >
201
{
202
  static const char * Get()
203
204
205
206
  {
    return "RegistrationControllerStartInterface";
  }
};
207

208
209
template< >
struct InterfaceName< RunRegistrationInterface >
210
{
211
  static const char * Get()
212
213
214
215
216
  {
    return "RunRegistrationInterface";
  }
};

217
218
template< >
struct InterfaceName< AfterRegistrationInterface >
219
{
220
  static const char * Get()
221
222
223
224
  {
    return "AfterRegistrationInterface";
  }
};
225

226
227
template< >
struct InterfaceName< ReconnectTransformInterface >
228
{
229
  static const char * Get()
230
231
232
233
234
  {
    return "ReconnectTransformInterface";
  }
};

235
template< class InternalComputationValueType, int D >
Floris Berendsen's avatar
Floris Berendsen committed
236
struct InterfaceName< itkTransformParametersAdaptorsContainerInterface< InternalComputationValueType, D >>
237
238
239
{
  static const char * Get()
  {
Floris Berendsen's avatar
Floris Berendsen committed
240
    return "itkTransformParametersAdaptorsContainerInterface";
241
242
243
  }
};

244
template< class InternalComputationValueType, int D >
Floris Berendsen's avatar
Floris Berendsen committed
245
struct InterfaceName< itkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerInterface< InternalComputationValueType, D >>
246
247
248
{
  static const char * Get()
  {
Floris Berendsen's avatar
Floris Berendsen committed
249
    return "itkGaussianExponentialDiffeomorphicTransformParametersAdaptorsContainerInterface";
250
251
252
  }
};

253
// partial specialization of InterfaceName
Floris Berendsen's avatar
Floris Berendsen committed
254
// InterfaceName<T>::Get() should return the same name no matter whether T is an acceptor or provider interface.
255
256
template< typename InterfaceType >
struct InterfaceName< InterfaceAcceptor< InterfaceType >>
257
258
{
  static const char * Get()
259
  {
260
    return InterfaceName< InterfaceType >::Get();
261
262
  }
};
263

264
265
266
267
268
269
270
271
//************experimental**********

template< typename T >
struct Properties
{
  //static_assert(StaticErrorMessageRevealT<T>::False, "Please Implement InterfaceProperties<InterfaceType> for this InterfaceType");
  static const std::map<std::string, std::string> Get()
  {
272
    return{ { "NameOfInterface", InterfaceName< T >::Get() } };
273
274
275
276
277
278
279
280
281
282
  }
};

// The specializations for each type of Interface supported by the toolbox

template< int D, class TPixel >
struct Properties< itkImageFixedInterface< D, TPixel >>
{
  static const std::map<std::string, std::string> Get()
  {
283
    return{ { "NameOfInterface", InterfaceName< itkImageFixedInterface< D, TPixel> >::Get() }, { "Dimensionality", "3" }, { "PixelType", "float" } };
284
285
286
287
288
289
290
291
  }
};

template< >
struct Properties< MetricValueInterface >
{
  static const std::map<std::string, std::string> Get()
  {
292
    return{ { "NameOfInterface", "MetricValueInterface" } };
293
294
295
  }
};
} // end namespace selx
296
#endif // #define InterfaceTraits_h