42 #include "itkConfigure.h"
43 #include "ITKCommonExport.h"
79 #if defined( _MSC_VER ) && ( _MSC_VER < 1310 )
82 #if defined( __SUNPRO_CC ) && ( __SUNPRO_CC < 0x590 )
83 #error "__SUNPRO_CC < 0x590 not supported under ITKv4"
85 #if defined( __CYGWIN__ )
86 #error "The Cygwin compiler is not supported in ITKv4 and above"
88 #if defined( __BORLANDC__ )
89 #error "The Borland C compiler is not supported in ITKv4 and above"
91 #if defined( __MWERKS__ )
92 #error "The MetroWerks compiler is not supported in ITKv4 and above"
94 #if defined( __GNUC__ ) && ( __GNUC__ < 3 )
95 #error "The __GNUC__ version 2.95 compiler is not supprted under ITKv4 and above"
100 #error "The __sgi compiler is not supprted under ITKv4 and above"
105 #if defined( _WIN32 ) || defined ( WIN32 )
106 #define ITK_ABI_IMPORT __declspec(dllimport)
107 #define ITK_ABI_EXPORT __declspec(dllexport)
108 #define ITK_ABI_HIDDEN
111 #define ITK_ABI_IMPORT __attribute__ ((visibility ("default")))
112 #define ITK_ABI_EXPORT __attribute__ ((visibility ("default")))
113 #define ITK_ABI_HIDDEN __attribute__ ((visibility ("hidden")))
115 #define ITK_ABI_IMPORT
116 #define ITK_ABI_EXPORT
117 #define ITK_ABI_HIDDEN
121 #if __cplusplus >= 201103L
125 #define ITK_OVERRIDE override
131 #define ITK_NULLPTR nullptr
134 #define ITK_NULLPTR NULL
158 #define itkNewMacro(x) \
159 itkSimpleNewMacro(x) \
160 itkCreateAnotherMacro(x) \
163 #define itkSimpleNewMacro(x) \
164 static Pointer New(void) \
166 Pointer smartPtr = ::itk::ObjectFactory< x >::Create(); \
167 if ( smartPtr.GetPointer() == ITK_NULLPTR ) \
171 smartPtr->UnRegister(); \
175 #define itkCreateAnotherMacro(x) \
176 virtual::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE \
178 ::itk::LightObject::Pointer smartPtr; \
179 smartPtr = x::New().GetPointer(); \
183 #define itkCloneMacro(x) \
184 Pointer Clone() const \
187 dynamic_cast<x *>(this->InternalClone().GetPointer()); \
207 #define itkFactorylessNewMacro(x) \
208 static Pointer New(void) \
211 x * rawPtr = new x; \
213 rawPtr->UnRegister(); \
216 virtual::itk::LightObject::Pointer CreateAnother(void) const ITK_OVERRIDE \
218 ::itk::LightObject::Pointer smartPtr; \
219 smartPtr = x::New().GetPointer(); \
226 #define itkTypeMacro(thisClass, superclass) \
227 virtual const char *GetNameOfClass() const \
240 extern ITKCommon_EXPORT
void OutputWindowDisplayText(
const char *);
243 extern ITKCommon_EXPORT
void OutputWindowDisplayErrorText(
const char *);
245 extern ITKCommon_EXPORT
void OutputWindowDisplayWarningText(
const char *);
247 extern ITKCommon_EXPORT
void OutputWindowDisplayGenericOutputText(
const char *);
249 extern ITKCommon_EXPORT
void OutputWindowDisplayDebugText(
const char *);
255 #if defined( NDEBUG )
256 #define itkDebugMacro(x)
257 #define itkDebugStatement(x)
259 #define itkDebugMacro(x) \
261 if ( this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay() ) \
263 std::ostringstream itkmsg; \
264 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << "\n" \
265 << this->GetNameOfClass() << " (" << this << "): " x \
267 ::itk::OutputWindowDisplayDebugText( itkmsg.str().c_str() ); \
274 #define itkDebugStatement(x) x
280 #define itkWarningMacro(x) \
282 if ( ::itk::Object::GetGlobalWarningDisplay() ) \
284 std::ostringstream itkmsg; \
285 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
286 << this->GetNameOfClass() << " (" << this << "): " x \
288 ::itk::OutputWindowDisplayWarningText( itkmsg.str().c_str() ); \
295 #define itkWarningStatement(x) x
297 #if defined( ITK_CPP_FUNCTION )
298 #if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( CABLE_CONFIGURATION ) \
299 && !defined( __GCCXML__ )
300 #define ITK_LOCATION __FUNCSIG__
301 #elif defined( __GNUC__ )
302 #define ITK_LOCATION __PRETTY_FUNCTION__
304 #define ITK_LOCATION __FUNCTION__
307 #define ITK_LOCATION "unknown"
315 #define itkExceptionMacro(x) \
317 std::ostringstream message; \
318 message << "itk::ERROR: " << this->GetNameOfClass() \
319 << "(" << this << "): " x; \
320 ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
325 #define itkGenericExceptionMacro(x) \
327 std::ostringstream message; \
328 message << "itk::ERROR: " x; \
329 ::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
333 #define itkDeclareExceptionMacro(newexcp,parentexcp,whatmessage) \
335 class newexcp : public parentexcp \
338 newexcp( const char *file, unsigned int lineNumber ) : \
339 parentexcp( file, lineNumber ) \
341 this->SetDescription( whatmessage ); \
343 newexcp( const std::string & file, unsigned int lineNumber ) : \
344 parentexcp( file, lineNumber ) \
346 this->SetDescription( whatmessage ); \
348 itkTypeMacro(newexcp, parentexcp); \
352 #define itkSpecializedExceptionMacro(exceptiontype) \
354 ::itk::exceptiontype e_(__FILE__, __LINE__); \
355 e_.SetLocation(ITK_LOCATION); \
359 #define itkSpecializedMessageExceptionMacro(exceptiontype,x) \
361 ::itk::exceptiontype e_(__FILE__, __LINE__); \
362 std::ostringstream message; \
363 message << "itk::ERROR: " x; \
364 e_.SetDescription(message.str().c_str()); \
365 e_.SetLocation(ITK_LOCATION); \
370 #define itkGenericOutputMacro(x) \
372 if ( ::itk::Object::GetGlobalWarningDisplay() ) \
374 std::ostringstream itkmsg; \
375 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" \
377 ::itk::OutputWindowDisplayGenericOutputText( itkmsg.str().c_str() ); \
384 #define itkLogMacro(x, y) \
386 if ( this->GetLogger() ) \
388 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
392 #define itkLogMacroStatic(obj, x, y) \
394 if ( obj->GetLogger() ) \
396 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
422 #if defined( ITK_LEGACY_REMOVE )
423 #define itkLegacyMacro(method)
424 #elif defined( ITK_LEGACY_SILENT ) || defined( ITK_LEGACY_TEST ) || defined( __GCCXML__ )
426 #define itkLegacyMacro(method) method
430 #if defined( __GNUC__ ) && !defined( __INTEL_COMPILER ) && ( __GNUC__ > 3 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 1 ) )
431 #define itkLegacyMacro(method) method __attribute__( ( deprecated ) )
432 #elif defined( _MSC_VER )
433 #define itkLegacyMacro(method) __declspec(deprecated) method
435 #define itkLegacyMacro(method) method
452 #if defined( ITK_LEGACY_REMOVE ) || defined( ITK_LEGACY_SILENT )
453 #define itkLegacyBodyMacro(method, version)
454 #define itkLegacyReplaceBodyMacro(method, version, replace)
455 #define itkGenericLegacyBodyMacro(method, version)
456 #define itkGenericLegacyReplaceBodyMacro(method, version, replace)
458 #define itkLegacyBodyMacro(method, version) \
459 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
460 #define itkLegacyReplaceBodyMacro(method, version, replace) \
462 #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
464 #define itkGenericLegacyBodyMacro(method, version) \
465 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
466 #define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
467 itkGenericOutputMacro( \
468 #method " was deprecated for ITK " #version " and will be removed in a future version. Use " #replace \
472 #if defined ( ITK_LEGACY_REMOVE )
473 #define ITK_TEMPLATE_TXX "error ITK_TEMPLATE_TXX is no longer a supported identifier, you should replace with ITK_MANUAL_INSTANTIATION as a replacement"
475 #define ITK_TEMPLATE_TXX 1
483 #define ITK_CACHE_LINE_ALIGNMENT 64
491 #define itkPadStruct( mincachesize, oldtype, newtype ) \
492 struct newtype: public oldtype \
494 char _StructPadding[mincachesize - (sizeof(oldtype)%mincachesize) ]; \
501 #if defined ( ITK_HAS_CPP11_ALIGNAS )
502 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
503 typedef oldtype newtype alignas(alignment)
504 #elif defined( ITK_HAS_GNU_ATTRIBUTE_ALIGNED )
505 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
506 typedef oldtype newtype __attribute__((aligned(alignment)))
507 #elif defined ( _MSC_VER )
508 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
509 typedef __declspec(align( alignment )) struct oldtype newtype
511 # define itkAlignedTypedef( alignment, oldtype, newtype ) \
512 typedef oldtype newtype
544 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_NULL_STRING )
545 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
547 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_EMPTY_BRACKETS )
548 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
550 #if defined( ITK_SUPPORTS_TEMPLATED_FRIEND_FUNCTION_WITH_TEMPLATE_ARGUMENTS )
551 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < T >
557 #if ( defined ( _MSC_VER ) && ( _MSC_VER >= 1600 ) )
558 #ifdef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
559 #undef ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT
561 #define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T)
577 #define itkForLoopAssignmentMacro(DestinationType, \
579 DestinationElementType, \
582 NumberOfIterations) \
583 for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
585 DestinationArray[i] = static_cast< DestinationElementType >( SourceArray[i] ); \
597 #define itkForLoopRoundingAndAssignmentMacro(DestinationType, \
598 Sourcrnd_halfintup, \
599 DestinationElementType, \
602 NumberOfIterations) \
603 for ( unsigned int i = 0; i < NumberOfIterations; ++i ) \
605 DestinationArray[i] = itk::Math::Round< DestinationElementType >(SourceArray[i]); \
613 #define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail (msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
615 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
619 #define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
622 #define itkAssertOrThrowMacro(test, message) \
625 std::ostringstream msgstr; \
627 itkAssertInDebugOrThrowInReleaseMacro( msgstr.str().c_str() ); \
631 #define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
633 #define itkAssertInDebugAndIgnoreInReleaseMacro(X)
636 #ifdef ITKV3_COMPATIBILITY
640 #define ITK_TYPENAME typename
646 template <
typename TTarget,
typename TSource>
647 TTarget itkDynamicCastInDebugMode(TSource x)
654 TTarget rval =
dynamic_cast<TTarget
>(x);
657 itkGenericExceptionMacro(<<
"Failed dynamic cast to "
658 <<
typeid(TTarget).name()
660 << x->GetNameOfClass());
664 return static_cast<TTarget
>(x);
677 #define itkStaticConstMacro(name, type, value) enum { name = value }
679 #define itkGetStaticConstMacro(name) (Self::name)
682 #define itkSetInputMacro(name, type) \
683 virtual void Set##name(const type *_arg) \
685 itkDebugMacro("setting input " #name " to " << _arg); \
686 if ( _arg != itkDynamicCastInDebugMode< type * >( this->ProcessObject::GetInput(#name) ) ) \
688 this->ProcessObject::SetInput( #name, const_cast< type * >( _arg ) ); \
695 #define itkGetInputMacro(name, type) \
696 virtual const type * Get##name() const \
698 itkDebugMacro( "returning input " << #name " of " << this->ProcessObject::GetInput(#name) ); \
699 return itkDynamicCastInDebugMode< const type * >( this->ProcessObject::GetInput(#name) ); \
704 #define itkSetDecoratedInputMacro(name, type) \
705 virtual void Set##name##Input(const SimpleDataObjectDecorator< type > *_arg) \
707 itkDebugMacro("setting input " #name " to " << _arg); \
708 if ( _arg != itkDynamicCastInDebugMode< SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
710 this->ProcessObject::SetInput( #name, const_cast< SimpleDataObjectDecorator< type > * >( _arg ) ); \
714 virtual void Set##name(const type &_arg) \
716 typedef SimpleDataObjectDecorator< type > DecoratorType; \
717 itkDebugMacro("setting input " #name " to " << _arg); \
718 const DecoratorType *oldInput = \
719 itkDynamicCastInDebugMode< const DecoratorType * >( \
720 this->ProcessObject::GetInput(#name) ); \
721 if ( oldInput && oldInput->Get() == _arg ) \
725 typename DecoratorType::Pointer newInput = DecoratorType::New(); \
726 newInput->Set(_arg); \
727 this->Set##name##Input(newInput); \
732 #define itkGetDecoratedInputMacro(name, type) \
733 virtual const SimpleDataObjectDecorator< type > * Get##name##Input() const \
735 itkDebugMacro( "returning input " << #name " of " << this->ProcessObject::GetInput(#name) ); \
736 return itkDynamicCastInDebugMode< const SimpleDataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
738 virtual const type & Get##name() const \
740 itkDebugMacro("Getting input " #name); \
741 typedef SimpleDataObjectDecorator< type > DecoratorType; \
742 const DecoratorType *input = \
743 itkDynamicCastInDebugMode< const DecoratorType * >( \
744 this->ProcessObject::GetInput(#name) ); \
745 if( input == ITK_NULLPTR ) \
747 itkExceptionMacro(<<"input" #name " is not set"); \
749 return input->Get(); \
755 #define itkSetGetDecoratedInputMacro(name, type) \
756 itkSetDecoratedInputMacro(name, type) \
757 itkGetDecoratedInputMacro(name, type)
763 #define itkSetDecoratedObjectInputMacro(name, type) \
764 virtual void Set##name##Input(const DataObjectDecorator< type > *_arg) \
766 itkDebugMacro("setting input " #name " to " << _arg); \
767 if ( _arg != itkDynamicCastInDebugMode< DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ) ) \
769 this->ProcessObject::SetInput( #name, const_cast< DataObjectDecorator< type > * >( _arg ) ); \
773 virtual void Set##name(const type * _arg) \
775 typedef DataObjectDecorator< type > DecoratorType; \
776 itkDebugMacro("setting input " #name " to " << _arg); \
777 const DecoratorType *oldInput = \
778 itkDynamicCastInDebugMode< const DecoratorType * >( \
779 this->ProcessObject::GetInput(#name) ); \
780 if ( oldInput && oldInput->Get() == _arg ) \
784 typename DecoratorType::Pointer newInput = DecoratorType::New(); \
785 newInput->Set(_arg); \
786 this->Set##name##Input(newInput); \
794 #define itkGetDecoratedObjectInputMacro(name, type) \
795 virtual const DataObjectDecorator< type > * Get##name##Input() const \
797 itkDebugMacro( "returning input " << #name " of "<< this->ProcessObject::GetInput(#name) ); \
798 return itkDynamicCastInDebugMode< const DataObjectDecorator< type > * >( this->ProcessObject::GetInput(#name) ); \
800 virtual const type * Get##name() const \
802 itkDebugMacro("Getting input " #name); \
803 typedef DataObjectDecorator< type > DecoratorType; \
804 const DecoratorType *input = \
805 itkDynamicCastInDebugMode< const DecoratorType * >( \
806 this->ProcessObject::GetInput(#name) ); \
807 if( input == ITK_NULLPTR ) \
809 return ITK_NULLPTR; \
811 return input->Get(); \
817 #define itkSetGetDecoratedObjectInputMacro(name, type) \
818 itkSetDecoratedObjectInputMacro(name, type) \
819 itkGetDecoratedObjectInputMacro(name, type)
822 #define itkSetMacro(name, type) \
823 virtual void Set##name (const type _arg) \
825 itkDebugMacro("setting " #name " to " << _arg); \
826 if ( this->m_##name != _arg ) \
828 this->m_##name = _arg; \
835 #define itkGetMacro(name, type) \
836 virtual type Get##name () \
838 return this->m_##name; \
845 #define itkGetConstMacro(name, type) \
846 virtual type Get##name () const \
848 return this->m_##name; \
856 #define itkGetConstReferenceMacro(name, type) \
857 virtual const type &Get##name () const \
859 return this->m_##name; \
867 #define itkSetEnumMacro(name, type) \
868 virtual void Set##name (const type _arg) \
870 itkDebugMacro( "setting " #name " to " << static_cast< long >( _arg ) ); \
871 if ( this->m_##name != _arg ) \
873 this->m_##name = _arg; \
883 #define itkGetEnumMacro(name, type) \
884 virtual type Get##name () const \
886 return this->m_##name; \
893 #define itkSetStringMacro(name) \
894 virtual void Set##name (const char *_arg) \
896 if ( _arg && ( _arg == this->m_##name ) ) { return; } \
899 this->m_##name = _arg; \
903 this->m_##name = ""; \
907 virtual void Set##name (const std::string & _arg) \
909 this->Set##name( _arg.c_str() ); \
917 #define itkGetStringMacro(name) \
918 virtual const char *Get##name () const \
920 return this->m_##name.c_str(); \
926 #define itkSetClampMacro(name, type, min, max) \
927 virtual void Set##name (type _arg) \
929 itkDebugMacro("setting " << #name " to " << _arg); \
930 if ( this->m_##name != ( _arg < min ? min : ( _arg > max ? max : _arg ) ) ) \
932 this->m_##name = ( _arg < min ? min : ( _arg > max ? max : _arg ) ); \
942 #define itkSetObjectMacro(name, type) \
943 virtual void Set##name (type * _arg) \
945 itkDebugMacro("setting " << #name " to " << _arg); \
946 if ( this->m_##name != _arg ) \
948 this->m_##name = _arg; \
979 #define itkGetConstObjectMacro(name, type) \
980 virtual const type * Get##name () const \
982 return this->m_##name.GetPointer(); \
986 #if defined ( ITK_FUTURE_LEGACY_REMOVE )
992 # define itkGetObjectMacro(name, type) \
993 virtual type * Get##name () \
995 purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
998 # define itkGetModifiableObjectMacro(name, type) \
999 virtual type * GetModifiable##name () \
1001 return this->m_##name.GetPointer(); \
1003 itkGetConstObjectMacro(name, type)
1005 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1008 # define itkGetObjectMacro(name, type) \
1009 virtual type * Get##name () \
1011 return this->m_##name.GetPointer(); \
1013 # define itkGetModifiableObjectMacro(name, type) \
1014 virtual type * GetModifiable##name () \
1016 return this->m_##name.GetPointer(); \
1018 itkGetConstObjectMacro(name, type) \
1019 itkGetObjectMacro(name, type)
1020 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1029 #define itkGetConstReferenceObjectMacro(name, type) \
1030 virtual const typename type::Pointer & Get##name () const \
1032 return this->m_##name; \
1039 #define itkSetConstObjectMacro(name, type) \
1040 virtual void Set##name (const type * _arg) \
1042 itkDebugMacro("setting " << #name " to " << _arg); \
1043 if ( this->m_##name != _arg ) \
1045 this->m_##name = _arg; \
1053 #define itkBooleanMacro(name) \
1054 virtual void name##On () \
1056 this->Set##name(true); \
1058 virtual void name##Off () \
1060 this->Set##name(false); \
1067 #define itkSetVectorMacro(name, type, count) \
1068 virtual void Set##name(type data[]) \
1071 for ( i = 0; i < count; i++ ) \
1073 if ( data[i] != this->m_##name[i] ) \
1081 for ( i = 0; i < count; i++ ) \
1083 this->m_##name[i] = data[i]; \
1091 #define itkGetVectorMacro(name, type, count) \
1092 virtual type * Get##name () const \
1094 return this->m_##name; \
1100 #define itkGPUKernelClassMacro(kernel) \
1104 static const char* GetOpenCLSource(); \
1107 virtual ~kernel(); \
1108 kernel(const kernel &); \
1109 void operator=(const kernel &); \
1113 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1114 static const char* GetOpenCLSource() \
1116 return kernel::GetOpenCLSource(); \
1121 #define itkPrintSelfObjectMacro(name) \
1122 if (static_cast<const LightObject*>(this->m_##name) == ITK_NULLPTR) \
1124 os << indent << #name << ": (null)" << std::endl; \
1128 os << indent << #name << ": " << std::endl; \
1129 this->m_##name->Print(os,indent.GetNextIndent()); \
1132 #endif //end of itkMacro.h