/
elxMacro.h
305 lines (293 loc) · 9.97 KB
/
elxMacro.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*=========================================================================
*
* Copyright UMC Utrecht 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.
*
*=========================================================================*/
#ifndef __elxMacro_h
#define __elxMacro_h
/** This include is only used to get rid of a MSVS compiler warning
* when using std::copy. The warning is like:
* 'conversion' conversion from 'type1' to 'type2', possible loss of data
* To solve it ITK recommends to include itkMacro.h before <algorithm> or
* any other stl header. In elastix we try to make sure that elxIncludes.h
* is included before anything else, which includes elxMacro.h, which now
* includes itkWin32Header.h.
*/
#include "itkWin32Header.h"
/**
* Macro for installing support new components
* (like a new metric, interpolator, or transform).
* Must be invoked in the .cxx file of the component,
* after declaration of the class.
*
* Example of usage:
*
* \code
* // elxMyMetric.h //
* #include "elxMetricBase.h"
* #include "itkMattesMutualInformationImageToImageMetric.h"
*
* namespace elastix {
*
* template <class TElastix>
* class MyMetric : public MetricBase<TElastix>,
* public itk::MattesMutualInformationImageToImageMetric
* < MetricBase<TElastix>::FixedImageType
* MetricBase<TElastix>::MovingImageType >
* {
* typedef MyMetric Self;
* itkNewMacro( Self ); //needed for the elxInstallMacro
* elxClassNameMacro("MattesMutualInformation"); //also needed
* .......
* };
*
* } // end namespace elastix
* \endcode
*
* \code
* // elxMyMetric.hxx //
* // Definitions of the methods of the MyMetric class template
* \endcode
*
* \code
* // elxMyMetric.cxx //
* #include elxMyMetric.h
* elxInstallMacro(MyMetric);
*
* // CMakeLists.txt //
* ADD_ELXCOMPONENT( MyMetric
* elxMyMetric.h
* elxMyMetric.hxx
* elxMyMetric.cxx
* [<any other source files needed>] )
* \endcode
*
* The class to be installed should inherit from the appropriate base class.
* (elx::MetricBase, elx::TransformBase etc,) and from a specific itk object.
*
* IMPORTANT: only one template argument <class TElastix> is allowed. Not more,
* not less.
*
* Details: a function "int _classname##InstallComponent( _cdb )" is defined.
* In this function a template is defined, _classname##_install<VIndex>.
* It contains the ElastixTypedef<VIndex>, and recursive function DO(cdb).
* DO installs the component for all defined ElastixTypedefs (so for all
* supported image types).
*
*/
#define elxInstallMacro( _classname ) \
template< ::elx::ComponentDatabase::IndexType VIndex > \
class _classname##_install \
{ \
public: \
typedef typename::elx::ElastixTypedef< VIndex >::ElastixType ElastixType; \
typedef::elx::ComponentDatabase::ComponentDescriptionType ComponentDescriptionType; \
static int DO( ::elx::ComponentDatabase * cdb ) \
{ \
ComponentDescriptionType name = ::elx::_classname< ElastixType >::elxGetClassNameStatic(); \
int dummy = ::elx::InstallFunctions< ::elx::_classname< ElastixType > >::InstallComponent( name, VIndex, cdb ); \
if( ::elx::ElastixTypedef< VIndex + 1 >::Defined() ) \
{ return _classname##_install< VIndex + 1 >::DO( cdb ); } \
return dummy; \
} \
}; \
template< > \
class _classname##_install< ::elx::NrOfSupportedImageTypes + 1 > \
{ \
public: \
typedef::elx::ComponentDatabase::ComponentDescriptionType ComponentDescriptionType; \
static int DO( ::elx::ComponentDatabase * /** cdb */ ) \
{ return 0; } \
}; \
extern "C" int _classname##InstallComponent( \
::elx::ComponentDatabase * _cdb ) \
{ \
int _InstallDummy##_classname = _classname##_install< 1 >::DO( _cdb ); \
return _InstallDummy##_classname; \
} //ignore semicolon
/**
* elxInstallComponentFunctionDeclarationMacro
*
* Usage example:
* elxInstallComponentFunctionDeclarationMacro( BSplineTransform );
*
* This macro declares the function implemented by
* the elxInstallMacro. This macro is used by the
* CMake generated file
* elxInstallComponentFunctionDeclarations.h
* only.
*
* Details: the declaration of InstallComponent function defined
* by elxInstallMacro is simply repeated.
*
* See also elxInstallAllComponents.h.
*/
#define elxInstallComponentFunctionDeclarationMacro( _classname ) \
extern "C" int _classname##InstallComponent( \
::elx::ComponentDatabase * _cdb )
/**
* elxInstallComponentFunctionCallMacro
*
* Usage example:
* elxInstallComponentFunctionCallMacro( BSplineTransform );
*
* This macro calls the function implemented by
* the elxInstallMacro. This macro is used by the
* CMake generated file
* elxInstallComponentFunctionCalls.h
* only.
*
* Details: the InstallComponent function defined
* by elxInstallMacro is called.
*
* See also elxInstallAllComponents.h.
*/
#define elxInstallComponentFunctionCallMacro( _classname ) \
ret |= _classname##InstallComponent( _cdb )
/**
* elxPrepareImageTypeSupportMacro
* To be called once, before the elxSupportImageTypeMacro()
*
* IMPORTANT: the macro must be invoked in namespace elastix!
*/
#define elxPrepareImageTypeSupportMacro() \
template< ::elx::ComponentDatabase::IndexType VIndex > \
/**unsigned int*/ \
class ElastixTypedef \
{ \
public: \
/** In the specialisations of this template class */ \
/** this typedef will make sense */ \
typedef::itk::Object ElastixType; \
typedef::elx::ComponentDatabase::PixelTypeDescriptionType PixelTypeString; \
static PixelTypeString fPixelTypeAsString( void ) \
{ return PixelTypeString( "" ); } \
static PixelTypeString mPixelTypeAsString( void ) \
{ return PixelTypeString( "" ); } \
static unsigned int fDim( void ) \
{ return 0; } \
static unsigned int mDim( void ) \
{ return 0; } \
/** In the specialisations of this template class*/ \
/** this function will return 'true' */ \
static bool Defined( void ) \
{ return false; } \
}
/**
* Macro for installing support for new ImageTypes.
* Used in elxSupportedImageTypes.cxx .
*
* Example of usage:
*
* namespace elastix {
* elxSupportedImageTypeMacro(unsigned short, 2, float, 3, 1);
* elxSupportedImageTypeMacro(unsigned short, 3, float, 3, 2);
* etc.
* } //end namespace elastix
*
* The first line adds support for the following combination of ImageTypes:
* fixedImage: 2D unsigned short
* movingImage 3D float
* The Index (last argument) of this combination of ImageTypes is 1.
*
* The Index should not be 0. This value is reserved for errormessages.
* Besides, duplicate indices are not allowed.
*
* IMPORTANT: the macro must be invoked in namespace elastix!
*
* Details: the macro adds a class template specialization for the class
* ElastixTypedef<VIndex>.
*
*/
#define elxSupportedImageTypeMacro( _fPixelType, _fDim, _mPixelType, _mDim, _VIndex ) \
template< > \
class ElastixTypedef< _VIndex > \
{ \
public: \
typedef::itk::Image< _fPixelType, _fDim > FixedImageType; \
typedef::itk::Image< _mPixelType, _mDim > MovingImageType; \
typedef::elx::ElastixTemplate< FixedImageType, MovingImageType > ElastixType; \
typedef::elx::ComponentDatabase::PixelTypeDescriptionType PixelTypeString; \
static PixelTypeString fPixelTypeAsString( void ) \
{ return PixelTypeString( #_fPixelType ); } \
static PixelTypeString mPixelTypeAsString( void ) \
{ return PixelTypeString( #_mPixelType ); } \
static unsigned int fDim( void ) \
{ return _fDim; } \
static unsigned int mDim( void ) \
{ return _mDim; } \
static bool Defined( void ) \
{ return true; } \
}
/**
* elxClassNameMacro(_name)
*
* Example of usage:
*
* class MyMetric
* {
* public:
* elxClassNameMacro("MyFirstMetric");
* }
*
* This macro defines two functions.
*
* static const char * elxGetClassNameStatic(void){return _name;}
* virtual const char * elxGetClassName(void){return _name;}
*
* Use this macro in every component that will be installed in the
* ComponentDatabase, using "elxInstallMacro".
*/
#define elxClassNameMacro( _name ) \
static const char * elxGetClassNameStatic( void ) { return _name; } \
virtual const char * elxGetClassName( void ) const { return _name; }
/**
* elxout
*
* This macro replaces 'elxout' by 'xl::xout["standard"]'.
* This simplifies writing messages to screen and logfile.
*
* NB: for error and warning messages, for writing to the
* transformparameterfile etc. do not use elxout, but
* xout["{error, warning, etc}"].
*
*/
#define elxout ::xl::xout[ "standard" ]
/********************************************************************************
* *
* Dll export *
* *
********************************************************************************/
// Note: Consumers of the DLL must define the symbol _ELASTIX_USE_SHARED_LIBRARY.
// No such symbol is required for users of the static library.
//
#if ( defined( _WIN32 ) || defined( WIN32 ) )
# ifdef _ELASTIX_USE_SHARED_LIBRARY
# ifdef elastix_EXPORTS
# define ELASTIXLIB_API __declspec( dllexport )
# else
# define ELASTIXLIB_API __declspec( dllimport )
# endif
# else
# define ELASTIXLIB_API
# endif
#else
# if ( __GNUC__ >= 4 || defined( __clang__ ) )
# define ELASTIXLIB_API __attribute__ ( ( visibility( "default" ) ) )
# else
# define ELASTIXLIB_API
# endif
#endif
#endif // end #ifndef __elxMacro_h