42 #include "itkConfigure.h"
43 #include "ITKCommonExport.h"
55 #include <type_traits>
81 #define ITK_NOOP_STATEMENT static_assert(true, "")
84 #if defined(ITK_FUTURE_LEGACY_REMOVE)
86 # define ITK_MACROEND_NOOP_STATEMENT ITK_NOOP_STATEMENT
92 # define ITK_MACROEND_NOOP_STATEMENT
100 #define ITK_PRAGMA(x) _Pragma(#x)
106 #if defined(__clang__) && defined(__has_warning)
107 # define CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
108 # define CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
109 # if __has_warning("-Wfloat-equal")
110 # define CLANG_SUPPRESS_Wfloat_equal ITK_PRAGMA(clang diagnostic ignored "-Wfloat-equal")
112 # define CLANG_SUPPRESS_Wfloat_equal
114 # if __has_warning("-Wc++14-extensions")
115 # define CLANG_SUPPRESS_Wcpp14_extensions ITK_PRAGMA(clang diagnostic ignored "-Wc++14-extensions")
117 # define CLANG_SUPPRESS_Wcpp14_extensions
120 # define CLANG_PRAGMA_PUSH
121 # define CLANG_PRAGMA_POP
122 # define CLANG_SUPPRESS_Wfloat_equal
123 # define CLANG_SUPPRESS_Wcpp14_extensions
127 #if defined(__INTEL_COMPILER)
128 # define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
129 # define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
130 # define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
132 # define INTEL_PRAGMA_WARN_PUSH
133 # define INTEL_PRAGMA_WARN_POP
134 # define INTEL_SUPPRESS_warning_1292
145 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
146 # define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
147 # define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
148 # define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
150 # define ITK_GCC_PRAGMA_DIAG(x)
151 # define ITK_GCC_PRAGMA_DIAG_PUSH()
152 # define ITK_GCC_PRAGMA_DIAG_POP()
159 #if defined(_MSC_VER) && (_MSC_VER < 1920)
160 # error "MSVC versions before Visual Studio 2019 are not supported under ITKv5.4"
162 #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
163 # error "SUNPro C++ < 5.14.0 is not supported under ITKv5 and above"
165 #if defined(__CYGWIN__)
166 # error "The Cygwin compiler is not supported in ITKv4 and above"
168 #if defined(__BORLANDC__)
169 # error "The Borland C compiler is not supported in ITKv4 and above"
171 #if defined(__MWERKS__)
172 # error "The MetroWerks compiler is not supported in ITKv4 and above"
174 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 7)
175 # error "GCC < 7 is not supported under ITKv5.4"
181 # error "The SGI compiler is not supported under ITKv4 and above"
183 #if defined(__APPLE__)
184 # if defined(__clang__) && (__cplusplus < 201703L)
185 # error "Apple LLVM compiling with a standard less than C++17 is not supported under ITKv5.4"
187 #elif defined(__clang__) && (__clang_major__ < 5)
188 # error "Clang < 5 is not supported under ITKv5.4"
190 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1910)
191 # error "Intel C++ < 19.1 is not supported under ITKv5.4"
195 #if defined(_WIN32) || defined(WIN32)
196 # define ITK_ABI_IMPORT __declspec(dllimport)
197 # define ITK_ABI_EXPORT __declspec(dllexport)
198 # define ITK_ABI_HIDDEN
201 # define ITK_ABI_IMPORT __attribute__((visibility("default")))
202 # define ITK_ABI_EXPORT __attribute__((visibility("default")))
203 # define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
205 # define ITK_ABI_IMPORT
206 # define ITK_ABI_EXPORT
207 # define ITK_ABI_HIDDEN
212 #ifndef ITK_TEMPLATE_EXPORT
213 # ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
214 # define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
216 # define ITK_TEMPLATE_EXPORT
221 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
222 # define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
224 # define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
227 #ifndef ITK_FORWARD_EXPORT
229 # if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
230 defined(USE_COMPILER_HIDDEN_VISIBILITY)
231 # define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
233 # define ITK_FORWARD_EXPORT
241 #define ITK_NOEXCEPT_OR_THROW error "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT"
243 #if !defined(ITK_LEGACY_REMOVE)
244 # define ITK_DELETE_FUNCTION = delete
246 # define ITK_DELETE_FUNCTION error "Replace ITK_DELETE_FUNCTION with = delete"
253 #if defined(ITK_FUTURE_LEGACY_REMOVE)
254 # define ITK_CONSTEXPR_FUNC "Replace ITK_CONSTEXPR_FUNC with constexpr"
255 # define ITK_CONSTEXPR_VAR "Replace ITK_CONSTEXPR_VAR with constexpr"
257 # define itkExposeEnumValue(name) static_cast<int>(name)
261 # define ITK_CONSTEXPR_FUNC constexpr
262 # define ITK_CONSTEXPR_VAR constexpr
265 # define itkExposeEnumValue(name) static_cast<int>(name)
268 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
269 # define ITK_FALLTHROUGH [[fallthrough]]
271 # define ITK_FALLTHROUGH static_assert(false, "ERROR: ITK_FALLTHROUGH must be replaced with [[fallthrough]]")
294 #define itkNewMacro(x) \
295 itkSimpleNewMacro(x); \
296 itkCreateAnotherMacro(x); \
298 ITK_MACROEND_NOOP_STATEMENT
301 #define itkSimpleNewMacro(x) \
302 static Pointer New() \
304 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
305 if (smartPtr == nullptr) \
307 smartPtr = new x(); \
309 smartPtr->UnRegister(); \
312 ITK_MACROEND_NOOP_STATEMENT
314 #define itkCreateAnotherMacro(x) \
315 ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
316 ITK_MACROEND_NOOP_STATEMENT
318 #define itkCloneMacro(x) \
319 Pointer Clone() const \
321 Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
324 ITK_MACROEND_NOOP_STATEMENT
329 #define itkFactoryOnlyNewMacro(x) \
330 itkSimpleFactoryOnlyNewMacro(x); \
331 itkCreateAnotherMacro(x); \
333 ITK_MACROEND_NOOP_STATEMENT
336 #define itkSimpleFactoryOnlyNewMacro(x) \
337 static auto New()->Pointer \
339 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
340 if (smartPtr == nullptr) \
342 itkSpecializedMessageExceptionMacro(ExceptionObject, \
343 "Object factory failed to instantiate " << typeid(x).name()); \
345 smartPtr->UnRegister(); \
348 ITK_MACROEND_NOOP_STATEMENT
362 #define itkFactorylessNewMacro(x) \
363 static Pointer New() \
365 x * rawPtr = new x(); \
366 Pointer smartPtr = rawPtr; \
367 rawPtr->UnRegister(); \
370 itkCreateAnotherMacro(x); \
371 ITK_MACROEND_NOOP_STATEMENT
383 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
384 TypeName(const TypeName &) = delete; \
385 TypeName & operator=(const TypeName &) = delete; \
386 TypeName(TypeName &&) = delete; \
387 TypeName & operator=(TypeName &&) = delete
389 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
390 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
392 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
393 static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
401 #if __cplusplus >= 202002L
402 # define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
408 #ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
411 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
415 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
416 bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
417 ITK_MACROEND_NOOP_STATEMENT
422 #define itkInternalGetNameOfClassImplementationMacro(thisClass) \
424 static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
425 "The macro argument `" #thisClass \
426 "` appears incorrect! It should correspond with the name of this class!"); \
429 ITK_MACROEND_NOOP_STATEMENT
435 #define itkVirtualGetNameOfClassMacro(thisClass) \
436 virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
438 #define itkOverrideGetNameOfClassMacro(thisClass) \
439 const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
441 #ifdef ITK_FUTURE_LEGACY_REMOVE
442 # define itkTypeMacro(thisClass, superclass) \
443 static_assert(false, \
444 "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
445 "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
446 # define itkTypeMacroNoParent(thisClass) \
447 static_assert(false, \
448 "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
449 "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
455 # define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
456 # define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
468 extern ITKCommon_EXPORT
void
469 OutputWindowDisplayText(
const char *);
472 extern ITKCommon_EXPORT
void
473 OutputWindowDisplayErrorText(
const char *);
475 extern ITKCommon_EXPORT
void
476 OutputWindowDisplayWarningText(
const char *);
478 extern ITKCommon_EXPORT
void
479 OutputWindowDisplayGenericOutputText(
const char *);
481 extern ITKCommon_EXPORT
void
482 OutputWindowDisplayDebugText(
const char *);
492 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
493 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
495 # define itkDebugMacro(x) \
498 using namespace ::itk::print_helper; \
499 if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
501 std::ostringstream itkmsg; \
502 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << '\n' \
503 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
504 ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
511 # define itkDebugStatement(x) x
517 #define itkWarningMacro(x) \
520 if (::itk::Object::GetGlobalWarningDisplay()) \
522 std::ostringstream itkmsg; \
523 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << '\n' \
524 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
525 ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
530 #define itkWarningStatement(x) x
532 #if defined(ITK_CPP_FUNCTION)
533 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
534 # define ITK_LOCATION __FUNCSIG__
535 # elif defined(__GNUC__)
536 # define ITK_LOCATION __PRETTY_FUNCTION__
538 # define ITK_LOCATION __FUNCTION__
541 # define ITK_LOCATION "unknown"
544 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
547 class newexcp : public parentexcp \
551 static constexpr const char * const default_exception_message = whatmessage; \
553 using parentexcp::parentexcp; \
554 itkOverrideGetNameOfClassMacro(newexcp); \
557 ITK_MACROEND_NOOP_STATEMENT
560 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
562 std::ostringstream exceptionDescriptionOutputStringStream; \
563 exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
564 throw ::itk::ExceptionType( \
565 std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
567 ITK_MACROEND_NOOP_STATEMENT
569 #define itkSpecializedExceptionMacro(ExceptionType) \
570 itkSpecializedMessageExceptionMacro(ExceptionType, << ::itk::ExceptionType::default_exception_message)
575 #define itkExceptionMacro(x) \
576 itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
578 #define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
580 #define itkGenericOutputMacro(x) \
582 if (::itk::Object::GetGlobalWarningDisplay()) \
584 std::ostringstream itkmsg; \
585 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
586 ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
589 ITK_MACROEND_NOOP_STATEMENT
594 #define itkLogMacro(x, y) \
596 if (this->GetLogger()) \
598 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
601 ITK_MACROEND_NOOP_STATEMENT
603 #define itkLogMacroStatic(obj, x, y) \
605 if (obj->GetLogger()) \
607 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
610 ITK_MACROEND_NOOP_STATEMENT
641 #if defined(ITK_LEGACY_REMOVE)
642 # define itkLegacyMacro(method)
644 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
646 # define itkLegacyMacro(method) method
649 # define itkLegacyMacro(method) [[deprecated]] method
675 #if defined(ITK_LEGACY_SILENT)
676 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
677 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
678 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
679 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
681 # define itkLegacyBodyMacro(method, version) \
682 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
683 # define itkLegacyReplaceBodyMacro(method, version, replace) \
684 itkWarningMacro(#method " was deprecated for ITK " #version \
685 " and will be removed in a future version. Use " #replace " instead.")
686 # define itkGenericLegacyBodyMacro(method, version) \
687 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
688 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
689 itkGenericOutputMacro(#method " was deprecated for ITK " #version \
690 " and will be removed in a future version. Use " #replace " instead.")
697 #define ITK_CACHE_LINE_ALIGNMENT 64
705 #define itkPadStruct(mincachesize, oldtype, newtype) \
706 struct newtype : public oldtype \
708 char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
715 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
716 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
717 #elif defined(_MSC_VER)
718 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
720 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
723 #if defined(ITK_FUTURE_LEGACY_REMOVE)
746 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
747 #else // LEGACY_REMOVE
748 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
764 #define itkForLoopAssignmentMacro( \
765 DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
766 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
768 DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
780 #define itkForLoopRoundingAndAssignmentMacro( \
781 DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
782 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
784 DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
789 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
792 # define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
794 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
798 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
801 #define itkAssertOrThrowMacro(test, message) \
804 std::ostringstream msgstr; \
806 itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
808 ITK_MACROEND_NOOP_STATEMENT
810 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
811 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
813 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
823 #ifdef ITK_FUTURE_LEGACY_REMOVE
824 # define itkStaticConstMacro(name, type, value) \
825 "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
826 # define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
842 # define itkStaticConstMacro(name, type, value) static constexpr type name = value
844 # define itkGetStaticConstMacro(name) (Self::name)
848 #define itkSetInputMacro(name, type) \
849 virtual void Set##name(const type * _arg) \
851 itkDebugMacro("setting input " #name " to " << _arg); \
852 if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
854 this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
858 ITK_MACROEND_NOOP_STATEMENT
862 #define itkGetInputMacro(name, type) \
863 virtual const type * Get##name() const \
865 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
866 return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
868 ITK_MACROEND_NOOP_STATEMENT
873 #define itkSetDecoratedInputMacro(name, type) \
874 virtual void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) \
876 itkDebugMacro("setting input " #name " to " << _arg); \
877 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
879 this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
883 virtual void Set##name(const SimpleDataObjectDecorator<type> * _arg) { this->Set##name##Input(_arg); } \
884 virtual void Set##name(const type & _arg) \
886 using DecoratorType = SimpleDataObjectDecorator<type>; \
887 itkDebugMacro("setting input " #name " to " << _arg); \
888 const DecoratorType * oldInput = \
889 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
891 CLANG_SUPPRESS_Wfloat_equal \
892 if (oldInput && oldInput->Get() == _arg) \
897 auto newInput = DecoratorType::New(); \
898 newInput->Set(_arg); \
899 this->Set##name##Input(newInput); \
901 ITK_MACROEND_NOOP_STATEMENT
906 #define itkGetDecoratedInputMacro(name, type) \
907 virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
909 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
910 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
912 virtual const type & Get##name() const \
914 itkDebugMacro("Getting input " #name); \
915 using DecoratorType = SimpleDataObjectDecorator<type>; \
916 const DecoratorType * input = \
917 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
918 if (input == nullptr) \
920 itkExceptionMacro("input" #name " is not set"); \
922 return input->Get(); \
924 ITK_MACROEND_NOOP_STATEMENT
929 #define itkSetGetDecoratedInputMacro(name, type) \
930 itkSetDecoratedInputMacro(name, type); \
931 itkGetDecoratedInputMacro(name, type)
937 #define itkSetDecoratedObjectInputMacro(name, type) \
938 virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
940 itkDebugMacro("setting input " #name " to " << _arg); \
941 if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
943 this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
947 virtual void Set##name(const type * _arg) \
949 using DecoratorType = DataObjectDecorator<type>; \
950 itkDebugMacro("setting input " #name " to " << _arg); \
951 const DecoratorType * oldInput = \
952 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
953 if (oldInput && oldInput->Get() == _arg) \
957 auto newInput = DecoratorType::New(); \
958 newInput->Set(_arg); \
959 this->Set##name##Input(newInput); \
961 ITK_MACROEND_NOOP_STATEMENT
968 #define itkGetDecoratedObjectInputMacro(name, type) \
969 virtual const DataObjectDecorator<type> * Get##name##Input() const \
971 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
972 return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
974 virtual const type * Get##name() const \
976 itkDebugMacro("Getting input " #name); \
977 using DecoratorType = DataObjectDecorator<type>; \
978 const DecoratorType * input = \
979 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
980 if (input == nullptr) \
984 return input->Get(); \
986 ITK_MACROEND_NOOP_STATEMENT
991 #define itkSetGetDecoratedObjectInputMacro(name, type) \
992 itkSetDecoratedObjectInputMacro(name, type); \
993 itkGetDecoratedObjectInputMacro(name, type)
997 #define itkSetMacro(name, type) \
998 virtual void Set##name(type _arg) \
1000 itkDebugMacro("setting " #name " to " << _arg); \
1002 CLANG_SUPPRESS_Wfloat_equal \
1003 if (this->m_##name != _arg) \
1005 this->m_##name = std::move(_arg); \
1010 ITK_MACROEND_NOOP_STATEMENT
1014 #define itkGetMacro(name, type) \
1015 virtual type Get##name() { return this->m_##name; } \
1016 ITK_MACROEND_NOOP_STATEMENT
1022 #define itkGetConstMacro(name, type) \
1023 virtual type Get##name() const { return this->m_##name; } \
1024 ITK_MACROEND_NOOP_STATEMENT
1031 #define itkGetConstReferenceMacro(name, type) \
1032 virtual const type & Get##name() const { return this->m_##name; } \
1033 ITK_MACROEND_NOOP_STATEMENT
1040 #define itkSetEnumMacro(name, type) \
1041 virtual void Set##name(const type _arg) \
1043 itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1044 if (this->m_##name != _arg) \
1046 this->m_##name = _arg; \
1050 ITK_MACROEND_NOOP_STATEMENT
1057 #define itkGetEnumMacro(name, type) \
1058 virtual type Get##name() const { return this->m_##name; } \
1059 ITK_MACROEND_NOOP_STATEMENT
1065 #define itkSetStringMacro(name) \
1066 virtual void Set##name(const char * _arg) \
1068 if (_arg && (_arg == this->m_##name)) \
1074 this->m_##name = _arg; \
1078 this->m_##name = ""; \
1082 virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1083 ITK_MACROEND_NOOP_STATEMENT
1090 #define itkGetStringMacro(name) \
1091 virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1092 ITK_MACROEND_NOOP_STATEMENT
1098 #define itkSetClampMacro(name, type, min, max) \
1099 virtual void Set##name(type _arg) \
1101 const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1102 itkDebugMacro("setting " << #name " to " << _arg); \
1104 CLANG_SUPPRESS_Wfloat_equal \
1105 if (this->m_##name != temp_extrema) \
1107 this->m_##name = temp_extrema; \
1112 ITK_MACROEND_NOOP_STATEMENT
1120 #define itkSetObjectMacro(name, type) \
1121 virtual void Set##name(type * _arg) \
1123 itkDebugMacro("setting " << #name " to " << _arg); \
1124 if (this->m_##name != _arg) \
1126 this->m_##name = _arg; \
1130 ITK_MACROEND_NOOP_STATEMENT
1159 #define itkGetConstObjectMacro(name, type) \
1160 virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1161 ITK_MACROEND_NOOP_STATEMENT
1164 #if defined(ITK_FUTURE_LEGACY_REMOVE)
1170 # define itkGetObjectMacro(name, type) \
1171 virtual type * Get##name() \
1173 purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1176 # define itkGetModifiableObjectMacro(name, type) \
1177 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1178 itkGetConstObjectMacro(name, type)
1180 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1183 # define itkGetObjectMacro(name, type) \
1184 virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1185 ITK_MACROEND_NOOP_STATEMENT
1186 # define itkGetModifiableObjectMacro(name, type) \
1187 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1188 itkGetConstObjectMacro(name, type); \
1189 itkGetObjectMacro(name, type)
1190 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1199 #define itkGetConstReferenceObjectMacro(name, type) \
1200 virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1201 ITK_MACROEND_NOOP_STATEMENT
1206 #define itkSetConstObjectMacro(name, type) \
1207 virtual void Set##name(const type * _arg) \
1209 itkDebugMacro("setting " << #name " to " << _arg); \
1210 if (this->m_##name != _arg) \
1212 this->m_##name = _arg; \
1216 ITK_MACROEND_NOOP_STATEMENT
1221 #define itkBooleanMacro(name) \
1222 virtual void name##On() { this->Set##name(true); } \
1223 virtual void name##Off() { this->Set##name(false); }
1230 #define itkSetVectorMacro(name, type, count) \
1231 virtual void Set##name(type data[]) \
1234 for (i = 0; i < count; ++i) \
1237 CLANG_SUPPRESS_Wfloat_equal \
1238 if (data[i] != this->m_##name[i]) \
1247 for (i = 0; i < count; ++i) \
1249 this->m_##name[i] = data[i]; \
1253 ITK_MACROEND_NOOP_STATEMENT
1259 #define itkGetVectorMacro(name, type, count) \
1260 virtual type * Get##name() const { return this->m_##name; } \
1261 ITK_MACROEND_NOOP_STATEMENT
1267 #define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1274 #define itkGPUKernelMacro(kernel) \
1278 ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1279 kernel() = delete; \
1280 ~kernel() = delete; \
1281 static const char * GetOpenCLSource(); \
1285 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1286 static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); }
1290 #define itkPrintSelfObjectMacro(name) \
1291 if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1293 os << indent << #name << ": (null)" << std::endl; \
1297 os << indent << #name << ": " << std::endl; \
1298 this->m_##name->Print(os, indent.GetNextIndent()); \
1300 ITK_MACROEND_NOOP_STATEMENT
1304 #define itkSetDecoratedOutputMacro(name, type) \
1305 virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1307 itkDebugMacro("setting output " #name " to " << _arg); \
1308 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1310 this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1314 virtual void Set##name(const type & _arg) \
1316 using DecoratorType = SimpleDataObjectDecorator<type>; \
1317 itkDebugMacro("setting output " #name " to " << _arg); \
1318 DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1321 if (output->Get() == _arg) \
1327 output->Set(_arg); \
1332 auto newOutput = DecoratorType::New(); \
1333 newOutput->Set(_arg); \
1334 this->Set##name##Output(newOutput); \
1337 ITK_MACROEND_NOOP_STATEMENT
1341 #define itkGetDecoratedOutputMacro(name, type) \
1342 virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1344 itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1345 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1347 virtual const type & Get##name() const \
1349 itkDebugMacro("Getting output " #name); \
1350 using DecoratorType = SimpleDataObjectDecorator<type>; \
1351 const DecoratorType * output = \
1352 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1353 if (output == nullptr) \
1355 itkExceptionMacro("output" #name " is not set"); \
1357 return output->Get(); \
1359 ITK_MACROEND_NOOP_STATEMENT
1372 #if defined(ITKV4_COMPATIBILITY)
1373 # define ITK_ITERATOR_VIRTUAL virtual
1374 # define ITK_ITERATOR_OVERRIDE override
1375 # define ITK_ITERATOR_FINAL
1376 #elif !defined(ITK_LEGACY_REMOVE)
1377 # define ITK_ITERATOR_VIRTUAL virtual
1378 # define ITK_ITERATOR_OVERRIDE override
1379 # define ITK_ITERATOR_FINAL final
1381 # define ITK_ITERATOR_VIRTUAL
1382 # define ITK_ITERATOR_OVERRIDE
1383 # define ITK_ITERATOR_FINAL
1386 #if defined(ITKV4_COMPATIBILITY)
1388 # define ITKv5_CONST
1391 # define ITKv5_CONST const
1394 #define itkExceptionObject_h
1396 #undef itkExceptionObject_h
1405 template <
typename TTarget,
typename TSource>
1407 itkDynamicCastInDebugMode(TSource x)
1414 TTarget rval = dynamic_cast<TTarget>(x);
1415 if (rval ==
nullptr)
1417 itkGenericExceptionMacro(
"Failed dynamic cast to " <<
typeid(TTarget).name()
1418 <<
" object type = " << x->GetNameOfClass());
1422 return static_cast<TTarget>(x);
1427 #ifdef ITK_LEGACY_REMOVE
1428 # if __cplusplus >= 202002L
1429 # define ITK_NODISCARD(message) [[nodiscard(message)]]
1431 # define ITK_NODISCARD(message) [[nodiscard]]
1434 # define ITK_NODISCARD(message)
1438 #define ITK_ALIGNAS(X) alignas(X)
1439 #define ITK_ALIGNOF(X) alignof(X)
1440 #define ITK_DEPRECATED [[deprecated]]
1441 #define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1442 #define ITK_CONSTEXPR constexpr
1443 #define ITK_DELETED_FUNCTION = delete
1444 #define ITK_EXTERN_TEMPLATE extern
1445 #define ITK_FINAL final
1446 #define ITK_NOEXCEPT noexcept
1447 #define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1448 #define ITK_NULLPTR nullptr
1449 #define ITK_OVERRIDE override
1450 #define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1451 #define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1452 #define ITK_THREAD_LOCAL thread_local
1454 #endif // end of itkMacro.h