42 #include "itkConfigure.h"
78 #if defined( _MSC_VER ) && ( _MSC_VER < 1310 )
81 #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC < 0x590 )
82 #error "__SUNPRO_CC < 0x590 not supported under ITKv4"
84 #if defined( __CYGWIN__ )
85 #error "The Cygwin compiler is not supported in ITKv4 and above"
87 #if defined( __BORLANDC__ )
88 #error "The Borland C compiler is not supported in ITKv4 and above"
90 #if defined( __MWERKS__ )
91 #error "The MetroWerks compiler is not supported in ITKv4 and above"
93 #if defined( __GNUC__ ) && ( __GNUC__ < 3 )
94 #error "The __GNUC__ version 2.95 compiler is not supprted under ITKv4 and above"
99 #error "The __sgi compiler is not supprted under ITKv4 and above"
109 #if defined( _WIN32 ) || defined ( WIN32 )
110 #define ITK_ABI_IMPORT __declspec(dllimport)
111 #define ITK_ABI_EXPORT __declspec(dllexport)
112 #define ITK_ABI_HIDDEN
115 #define ITK_ABI_IMPORT __attribute__ ((visibility ("default")))
116 #define ITK_ABI_EXPORT __attribute__ ((visibility ("default")))
117 #define ITK_ABI_HIDDEN __attribute__ ((visibility ("hidden")))
119 #define ITK_ABI_IMPORT
120 #define ITK_ABI_EXPORT
121 #define ITK_ABI_HIDDEN
125 #define ITKCommon_HIDDEN ITK_ABI_HIDDEN
127 #if !defined( ITKSTATIC )
128 #ifdef ITKCommon_EXPORTS
129 #define ITKCommon_EXPORT ITK_ABI_EXPORT
131 #define ITKCommon_EXPORT ITK_ABI_IMPORT
138 #define ITKCommon_EXPORT ITK_ABI_EXPORT
140 #define ITKCommon_EXPORT
147 #define itkStaticConstMacro(name, type, value) enum { name = value }
149 #define itkGetStaticConstMacro(name) (Self::name)
152 #define itkSetInputMacro(name, type) \
153 virtual void Set##name(const type *_arg) \
155 itkDebugMacro("setting input " #name " to " << _arg); \
156 if ( _arg != static_cast< type * >( this->ProcessObject::GetInput(#name) ) ) \
158 this->ProcessObject::SetInput( #name, const_cast< type * >( _arg ) ); \
165 #define itkGetInputMacro(name, type) \
166 virtual const type * Get##name() const \
168 itkDebugMacro( "returning input " << #name " of " \
169 << static_cast< const type * >( this->ProcessObject::GetInput(#name) ) ); \
170 return static_cast< const type * >( this->ProcessObject::GetInput(#name) ); \
175 #define itkSetDecoratedInputMacro(name, type) \
176 virtual void Set##name##Input(const SimpleDataObjectDecorator< type > *_arg) \
178 itkDebugMacro("setting input " #name " to " << _arg); \
179 if ( _arg != static_cast< SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
181 this->ProcessObject::SetInput( #name, const_cast< SimpleDataObjectDecorator< type > * >( _arg ) ); \
185 virtual void Set##name(const type &_arg) \
187 typedef SimpleDataObjectDecorator< type > DecoratorType; \
188 itkDebugMacro("setting input " #name " to " << _arg); \
189 const DecoratorType *oldInput = \
190 static_cast< const DecoratorType * >( \
191 this->ProcessObject::GetInput(#name) ); \
192 if ( oldInput && oldInput->Get() == _arg ) \
196 typename DecoratorType::Pointer newInput = DecoratorType::New(); \
197 newInput->Set(_arg); \
198 this->Set##name##Input(newInput); \
203 #define itkGetDecoratedInputMacro(name, type) \
204 virtual const SimpleDataObjectDecorator< type > * Get##name##Input() const \
206 itkDebugMacro( "returning input " << #name " of " \
207 << static_cast< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ); \
208 return static_cast< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
210 virtual const type & Get##name() const \
212 itkDebugMacro("Getting input " #name); \
213 typedef SimpleDataObjectDecorator< type > DecoratorType; \
214 const DecoratorType *input = \
215 static_cast< const DecoratorType * >( \
216 this->ProcessObject::GetInput(#name) ); \
217 if( input == NULL ) \
219 itkExceptionMacro(<<"input" #name " is not set"); \
221 return input->Get(); \
227 #define itkSetGetDecoratedInputMacro(name, type) \
228 itkSetDecoratedInputMacro(name, type) \
229 itkGetDecoratedInputMacro(name, type)
235 #define itkSetDecoratedObjectInputMacro(name, type) \
236 virtual void Set##name##Input(const DataObjectDecorator< type > *_arg) \
238 itkDebugMacro("setting input " #name " to " << _arg); \
239 if ( _arg != static_cast< DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
241 this->ProcessObject::SetInput( #name, const_cast< DataObjectDecorator< type > * >( _arg ) ); \
245 virtual void Set##name(const type * _arg) \
247 typedef DataObjectDecorator< type > DecoratorType; \
248 itkDebugMacro("setting input " #name " to " << _arg); \
249 const DecoratorType *oldInput = \
250 static_cast< const DecoratorType * >( \
251 this->ProcessObject::GetInput(#name) ); \
252 if ( oldInput && oldInput->Get() == _arg ) \
256 typename DecoratorType::Pointer newInput = DecoratorType::New(); \
257 newInput->Set(_arg); \
258 this->Set##name##Input(newInput); \
266 #define itkGetDecoratedObjectInputMacro(name, type) \
267 virtual const DataObjectDecorator< type > * Get##name##Input() const \
269 itkDebugMacro( "returning input " << #name " of " \
270 << static_cast< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ); \
271 return static_cast< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
273 virtual const type * Get##name() const \
275 itkDebugMacro("Getting input " #name); \
276 typedef DataObjectDecorator< type > DecoratorType; \
277 const DecoratorType *input = \
278 static_cast< const DecoratorType * >( \
279 this->ProcessObject::GetInput(#name) ); \
280 if( input == NULL ) \
282 itkExceptionMacro(<<"input" #name " is not set"); \
284 return input->Get(); \
290 #define itkSetGetDecoratedObjectInputMacro(name, type) \
291 itkSetDecoratedObjectInputMacro(name, type) \
292 itkGetDecoratedObjectInputMacro(name, type)
295 #define itkSetMacro(name, type) \
296 virtual void Set##name (const type _arg) \
298 itkDebugMacro("setting " #name " to " << _arg); \
299 if ( this->m_##name != _arg ) \
301 this->m_##name = _arg; \
308 #define itkGetMacro(name, type) \
309 virtual type Get##name () \
311 return this->m_##name; \
318 #define itkGetConstMacro(name, type) \
319 virtual type Get##name () const \
321 return this->m_##name; \
329 #define itkGetConstReferenceMacro(name, type) \
330 virtual const type &Get##name () const \
332 return this->m_##name; \
340 #define itkSetEnumMacro(name, type) \
341 virtual void Set##name (const type _arg) \
343 itkDebugMacro( "setting " #name " to " << static_cast< long >( _arg ) ); \
344 if ( this->m_##name != _arg ) \
346 this->m_##name = _arg; \
356 #define itkGetEnumMacro(name, type) \
357 virtual type Get##name () const \
359 return this->m_##name; \
366 #define itkSetStringMacro(name) \
367 virtual void Set##name (const char *_arg) \
369 if ( _arg && ( _arg == this->m_##name ) ) { return; } \
372 this->m_##name = _arg; \
376 this->m_##name = ""; \
380 virtual void Set##name (const std::string & _arg) \
382 this->Set##name( _arg.c_str() ); \
390 #define itkGetStringMacro(name) \
391 virtual const char *Get##name () const \
393 return this->m_##name.c_str(); \
399 #define itkSetClampMacro(name, type, min, max) \
400 virtual void Set##name (type _arg) \
402 itkDebugMacro("setting " << #name " to " << _arg); \
403 if ( this->m_##name != ( _arg < min ? min : ( _arg > max ? max : _arg ) ) ) \
405 this->m_##name = ( _arg < min ? min : ( _arg > max ? max : _arg ) ); \
415 #define itkSetObjectMacro(name, type) \
416 virtual void Set##name (type * _arg) \
418 itkDebugMacro("setting " << #name " to " << _arg); \
419 if ( this->m_##name != _arg ) \
421 this->m_##name = _arg; \
429 #define itkGetObjectMacro(name, type) \
430 virtual type * Get##name () \
432 return this->m_##name.GetPointer(); \
439 #define itkSetConstObjectMacro(name, type) \
440 virtual void Set##name (const type * _arg) \
442 itkDebugMacro("setting " << #name " to " << _arg); \
443 if ( this->m_##name != _arg ) \
445 this->m_##name = _arg; \
453 #define itkGetConstObjectMacro(name, type) \
454 virtual const type * Get##name () const \
456 return this->m_##name.GetPointer(); \
461 #define itkGetConstReferenceObjectMacro(name, type) \
462 virtual const typename type::Pointer & Get##name () const \
464 return this->m_##name; \
469 #define itkBooleanMacro(name) \
470 virtual void name##On () \
472 this->Set##name(true); \
474 virtual void name##Off () \
476 this->Set##name(false); \
483 #define itkSetVectorMacro(name, type, count) \
484 virtual void Set##name(type data[]) \
487 for ( i = 0; i < count; i++ ) \
489 if ( data[i] != this->m_##name[i] ) \
497 for ( i = 0; i < count; i++ ) \
499 this->m_##name[i] = data[i]; \
507 #define itkGetVectorMacro(name, type, count) \
508 virtual type * Get##name () const \
510 return this->m_##name; \
516 #define itkGPUKernelClassMacro(kernel) \
517 class ITK_EXPORT kernel \
520 static const char* GetOpenCLSource(); \
524 kernel(const kernel &); \
525 void operator=(const kernel &); \
529 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
530 static const char* GetOpenCLSource() \
532 return kernel::GetOpenCLSource(); \
555 #define itkNewMacro(x) \
556 itkSimpleNewMacro(x) \
557 itkCreateAnotherMacro(x) \
560 #define itkSimpleNewMacro(x) \
561 static Pointer New(void) \
563 Pointer smartPtr = ::itk::ObjectFactory< x >::Create(); \
564 if ( smartPtr.GetPointer() == NULL ) \
568 smartPtr->UnRegister(); \
572 #define itkCreateAnotherMacro(x) \
573 virtual::itk::LightObject::Pointer CreateAnother(void) const \
575 ::itk::LightObject::Pointer smartPtr; \
576 smartPtr = x::New().GetPointer(); \
580 #define itkCloneMacro(x) \
581 Pointer Clone() const \
584 dynamic_cast<x *>(this->InternalClone().GetPointer()); \
604 #define itkFactorylessNewMacro(x) \
605 static Pointer New(void) \
608 x * rawPtr = new x; \
610 rawPtr->UnRegister(); \
613 virtual::itk::LightObject::Pointer CreateAnother(void) const \
615 ::itk::LightObject::Pointer smartPtr; \
616 smartPtr = x::New().GetPointer(); \
623 #define itkTypeMacro(thisClass, superclass) \
624 virtual const char *GetNameOfClass() const \
637 extern ITKCommon_EXPORT
void OutputWindowDisplayText(
const char *);
640 extern ITKCommon_EXPORT
void OutputWindowDisplayErrorText(
const char *);
642 extern ITKCommon_EXPORT
void OutputWindowDisplayWarningText(
const char *);
644 extern ITKCommon_EXPORT
void OutputWindowDisplayGenericOutputText(
const char *);
646 extern ITKCommon_EXPORT
void OutputWindowDisplayDebugText(
const char *);
652 #if defined( NDEBUG )
653 #define itkDebugMacro(x)
654 #define itkDebugStatement(x)
656 #define itkDebugMacro(x) \
658 if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \
660 std::ostringstream itkmsg; \
661 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
662 << this->GetNameOfClass() << " (" << this << "): " x \
664 ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() ); \
671 #define itkDebugStatement(x) x
677 #define itkWarningMacro(x) \
679 if ( ::itk::Object::GetGlobalWarningDisplay() ) \
681 std::ostringstream itkmsg; \
682 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
683 << this->GetNameOfClass() << " (" << this << "): " x \
685 ::itk::OutputWindowDisplayWarningText( itkmsg.str().c_str() ); \
692 #define itkWarningStatement(x) x
694 #if defined( ITK_CPP_FUNCTION )
695 #if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( CABLE_CONFIGURATION ) \
697 #define ITK_LOCATION __FUNCSIG__
698 #elif defined( __GNUC__ )
699 #define ITK_LOCATION __PRETTY_FUNCTION__
701 #define ITK_LOCATION __FUNCTION__
704 #define ITK_LOCATION "unknown"
712 #define itkExceptionMacro(x) \
714 std::ostringstream message; \
715 message << "itk::ERROR: " << this->GetNameOfClass() \
716 << "(" << this << "): " x; \
717 ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
722 #define itkGenericExceptionMacro(x) \
724 std::ostringstream message; \
725 message << "itk::ERROR: " x; \
726 ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
730 #define itkDeclareExceptionMacro(newexcp,parentexcp,whatmessage) \
732 class ITK_EXPORT newexcp : public parentexcp \
735 newexcp( const char *file, unsigned int lineNumber ) : \
736 parentexcp( file, lineNumber ) \
738 this->SetDescription( whatmessage ); \
740 newexcp( const std::string & file, unsigned int lineNumber ) : \
741 parentexcp( file, lineNumber ) \
743 this->SetDescription( whatmessage ); \
745 itkTypeMacro(newexcp, parentexcp); \
749 #define itkSpecializedExceptionMacro(exceptiontype) \
751 ::itk::exceptiontype e_(__FILE__, __LINE__); \
752 e_.SetLocation(ITK_LOCATION); \
756 #define itkSpecializedMessageExceptionMacro(exceptiontype,x) \
758 ::itk::exceptiontype e_(__FILE__, __LINE__); \
759 std::ostringstream message; \
760 message << "itk::ERROR: " x; \
761 e_.SetDescription(message.str().c_str()); \
762 e_.SetLocation(ITK_LOCATION); \
767 #define itkGenericOutputMacro(x) \
769 if ( ::itk::Object::GetGlobalWarningDisplay() ) \
771 std::ostringstream itkmsg; \
772 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
774 ::itk::OutputWindowDisplayGenericOutputText( itkmsg.str().c_str() ); \
781 #define itkLogMacro(x, y) \
783 if ( this->GetLogger() ) \
785 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
789 #define itkLogMacroStatic(obj, x, y) \
791 if ( obj->GetLogger() ) \
793 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
819 #if defined( ITK_LEGACY_REMOVE )
824 #define itkLegacyMacro(method) class itkLegacyMethodRemoved
825 #elif defined( ITK_LEGACY_SILENT ) || defined( ITK_LEGACY_TEST ) || defined( CSWIG )
827 #define itkLegacyMacro(method) method
831 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) )
832 #define itkLegacyMacro(method) method __attribute__( ( deprecated ) )
833 #elif defined( _MSC_VER )
834 #define itkLegacyMacro(method) __declspec(deprecated) method
836 #define itkLegacyMacro(method) method
853 #if defined( ITK_LEGACY_REMOVE ) || defined( ITK_LEGACY_SILENT )
854 #define itkLegacyBodyMacro(method, version)
855 #define itkLegacyReplaceBodyMacro(method, version, replace)
856 #define itkGenericLegacyBodyMacro(method, version)
857 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)
859 #define itkLegacyBodyMacro(method, version) \
860 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
861 #define itkLegacyReplaceBodyMacro(method, version, replace) \
863 #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
865 #define itkGenericLegacyBodyMacro(method, version) \
866 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
867 #define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
868 itkGenericOutputMacro( \
869 #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
873 #if defined ( ITK_LEGACY_REMOVE )
874 #define ITK_TEMPLATE_TXX "error ITK_TEMPLATE_TXX is no longer a supported identifier, you should replace with ITK_MANUAL_INSTANTIATION as a replacement"
876 #define ITK_TEMPLATE_TXX 1
884 #define ITK_CACHE_LINE_ALIGNMENT 64
890 #if defined ( ITK_HAS_CPP11_ALIGNAS )
891 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
892 typedef oldtype newtype alignas(alignment)
893 #elif defined( ITK_HAS_GNU_ATTRIBUTE_ALIGNED )
894 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
895 typedef oldtype newtype __attribute__((aligned(alignment)))
896 #elif defined ( _MSC_VER )
897 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
898 typedef __declspec(align( alignment )) struct oldtype newtype
900 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
901 typedef oldtype newtype
933 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_NULL_STRING )
934 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
936 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_EMPTY_BRACKETS )
937 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
939 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_TEMPLATE_ARGUMENTS )
940 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < T >
946 #if ( defined ( _MSC_VER ) && ( _MSC_VER >= 1600 ) )
947 #ifdef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
948 #undef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
950 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
959 #if defined( __INTEL_COMPILER ) && __INTEL_COMPILER >= 700
960 #define ITK_TEMPLATE_EXTERN 1
961 #elif defined( __GNUC__ ) && __GNUC__ >= 3
962 #define ITK_TEMPLATE_EXTERN 1
963 #elif defined( _MSC_VER )
964 #define ITK_TEMPLATE_EXTERN 1
966 #if !defined( ITK_TEMPLATE_DO_NOT_INSTANTIATE )
967 #define ITK_TEMPLATE_DO_NOT_INSTANTIATE 0
969 #if !defined( ITK_TEMPLATE_EXTERN )
970 #define ITK_TEMPLATE_EXTERN 0
980 #define ITK_TEMPLATE_EXPORT(x) ITK_TEMPLATE_EXPORT_DELAY(x)
981 #define ITK_TEMPLATE_EXPORT_DELAY(x) template ITK_TEMPLATE_##x;
991 #if ITK_TEMPLATE_EXTERN
992 #define ITK_TEMPLATE_IMPORT_DELAY(x) extern template ITK_TEMPLATE_##x;
993 #elif ITK_TEMPLATE_DO_NOT_INSTANTIATE
994 #define ITK_TEMPLATE_IMPORT_DELAY(x) \
995 ITK_TEMPLATE_IMPORT_IMPL(do_not_instantiate ITK_TEMPLATE_##x)
996 #define ITK_TEMPLATE_IMPORT_IMPL(x) _Pragma(#x)
998 #if defined( ITK_TEMPLATE_IMPORT_DELAY )
999 #define ITK_TEMPLATE_IMPORT(x) ITK_TEMPLATE_IMPORT_DELAY(x)
1000 #define ITK_TEMPLATE_IMPORT_WORKS 1
1002 #define ITK_TEMPLATE_IMPORT(x)
1003 #define ITK_TEMPLATE_IMPORT_WORKS 0
1010 #define ITK_EXPORT_ITKCommon(c, x, n) \
1011 ITK_EXPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
1012 #define ITK_IMPORT_ITKCommon(c, x, n) \
1013 ITK_IMPORT_TEMPLATE(ITKCommon_EXPORT, c, x, n)
1028 #define itkForLoopAssignmentMacro(DestinationType, \
1030 DestinationElementType, \
1033 NumberOfIterations) \
1034 for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
1036 DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
1048 #define itkForLoopRoundingAndAssignmentMacro(DestinationType, \
1049 Sourcrnd_halfintup, \
1050 DestinationElementType, \
1053 NumberOfIterations) \
1054 for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
1056 DestinationArray[i] = itk::Math::Round< DestinationElementType >(SourceArray[i]); \
1063 #ifdef _POSIX_SOURCE
1064 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
1066 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
1070 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
1073 #define itkAssertOrThrowMacro(test, message) \
1076 std::ostringstream msgstr; \
1077 msgstr << message; \
1078 itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \
1082 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
1084 #define itkAssertInDebugAndIgnoreInReleaseMacro(X)
1087 #ifdef ITKV3_COMPATIBILITY
1091 #define ITK_TYPENAME typename
1097 template <
typename TTarget,
typename TSource>
1098 TTarget itkDynamicCastInDebugMode(TSource x)
1105 TTarget rval =
dynamic_cast<TTarget
>(x);
1108 itkGenericExceptionMacro(<<
"Failed dynamic cast to "
1109 <<
typeid(TTarget).name()
1110 <<
" object type = "
1111 << x->GetNameOfClass());
1115 return static_cast<TTarget
>(x);
1120 #endif //end of itkMacro.h