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)
270 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
272 # define ITK_FALLTHROUGH __attribute__((fallthrough))
274 #elif defined(__has_warning)
275 # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
276 # define ITK_FALLTHROUGH [[clang::fallthrough]]
280 #ifndef ITK_FALLTHROUGH
281 # define ITK_FALLTHROUGH ((void)0)
304 #define itkNewMacro(x) \
305 itkSimpleNewMacro(x); \
306 itkCreateAnotherMacro(x); \
308 ITK_MACROEND_NOOP_STATEMENT
311 #define itkSimpleNewMacro(x) \
312 static Pointer New() \
314 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
315 if (smartPtr == nullptr) \
317 smartPtr = new x(); \
319 smartPtr->UnRegister(); \
322 ITK_MACROEND_NOOP_STATEMENT
324 #define itkCreateAnotherMacro(x) \
325 ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
326 ITK_MACROEND_NOOP_STATEMENT
328 #define itkCloneMacro(x) \
329 Pointer Clone() const \
331 Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
334 ITK_MACROEND_NOOP_STATEMENT
339 #define itkFactoryOnlyNewMacro(x) \
340 itkSimpleFactoryOnlyNewMacro(x); \
341 itkCreateAnotherMacro(x); \
343 ITK_MACROEND_NOOP_STATEMENT
346 #define itkSimpleFactoryOnlyNewMacro(x) \
347 static auto New()->Pointer \
349 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
350 if (smartPtr == nullptr) \
352 itkSpecializedMessageExceptionMacro(ExceptionObject, \
353 "Object factory failed to instantiate " << typeid(x).name()); \
355 smartPtr->UnRegister(); \
358 ITK_MACROEND_NOOP_STATEMENT
372 #define itkFactorylessNewMacro(x) \
373 static Pointer New() \
375 x * rawPtr = new x(); \
376 Pointer smartPtr = rawPtr; \
377 rawPtr->UnRegister(); \
380 itkCreateAnotherMacro(x); \
381 ITK_MACROEND_NOOP_STATEMENT
393 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
394 TypeName(const TypeName &) = delete; \
395 TypeName & operator=(const TypeName &) = delete; \
396 TypeName(TypeName &&) = delete; \
397 TypeName & operator=(TypeName &&) = delete
399 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
400 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
402 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
403 static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
411 #if __cplusplus >= 202002L
412 # define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
418 #ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
421 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
425 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
426 bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
427 ITK_MACROEND_NOOP_STATEMENT
432 #define itkInternalGetNameOfClassImplementationMacro(thisClass) \
434 static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
435 "The macro argument `" #thisClass \
436 "` appears incorrect! It should correspond with the name of this class!"); \
439 ITK_MACROEND_NOOP_STATEMENT
445 #define itkVirtualGetNameOfClassMacro(thisClass) \
446 virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
448 #define itkOverrideGetNameOfClassMacro(thisClass) \
449 const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
451 #ifdef ITK_FUTURE_LEGACY_REMOVE
452 # define itkTypeMacro(thisClass, superclass) \
453 static_assert(false, \
454 "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
455 "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
456 # define itkTypeMacroNoParent(thisClass) \
457 static_assert(false, \
458 "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
459 "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
465 # define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
466 # define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
478 extern ITKCommon_EXPORT
void
479 OutputWindowDisplayText(
const char *);
482 extern ITKCommon_EXPORT
void
483 OutputWindowDisplayErrorText(
const char *);
485 extern ITKCommon_EXPORT
void
486 OutputWindowDisplayWarningText(
const char *);
488 extern ITKCommon_EXPORT
void
489 OutputWindowDisplayGenericOutputText(
const char *);
491 extern ITKCommon_EXPORT
void
492 OutputWindowDisplayDebugText(
const char *);
502 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
503 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
505 # define itkDebugMacro(x) \
508 using namespace ::itk::print_helper; \
509 if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
511 std::ostringstream itkmsg; \
512 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << '\n' \
513 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
514 ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
521 # define itkDebugStatement(x) x
527 #define itkWarningMacro(x) \
530 if (::itk::Object::GetGlobalWarningDisplay()) \
532 std::ostringstream itkmsg; \
533 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << '\n' \
534 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
535 ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
540 #define itkWarningStatement(x) x
542 #if defined(ITK_CPP_FUNCTION)
543 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
544 # define ITK_LOCATION __FUNCSIG__
545 # elif defined(__GNUC__)
546 # define ITK_LOCATION __PRETTY_FUNCTION__
548 # define ITK_LOCATION __FUNCTION__
551 # define ITK_LOCATION "unknown"
554 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
557 class newexcp : public parentexcp \
561 static constexpr const char * const default_exception_message = whatmessage; \
563 using parentexcp::parentexcp; \
564 itkOverrideGetNameOfClassMacro(newexcp); \
567 ITK_MACROEND_NOOP_STATEMENT
570 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
572 std::ostringstream exceptionDescriptionOutputStringStream; \
573 exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
574 throw ::itk::ExceptionType( \
575 std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
577 ITK_MACROEND_NOOP_STATEMENT
579 #define itkSpecializedExceptionMacro(ExceptionType) \
580 itkSpecializedMessageExceptionMacro(ExceptionType, << ::itk::ExceptionType::default_exception_message)
585 #define itkExceptionMacro(x) \
586 itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
588 #define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
590 #define itkGenericOutputMacro(x) \
592 if (::itk::Object::GetGlobalWarningDisplay()) \
594 std::ostringstream itkmsg; \
595 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
596 ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
599 ITK_MACROEND_NOOP_STATEMENT
604 #define itkLogMacro(x, y) \
606 if (this->GetLogger()) \
608 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
611 ITK_MACROEND_NOOP_STATEMENT
613 #define itkLogMacroStatic(obj, x, y) \
615 if (obj->GetLogger()) \
617 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
620 ITK_MACROEND_NOOP_STATEMENT
651 #if defined(ITK_LEGACY_REMOVE)
652 # define itkLegacyMacro(method)
654 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
656 # define itkLegacyMacro(method) method
659 # define itkLegacyMacro(method) [[deprecated]] method
685 #if defined(ITK_LEGACY_SILENT)
686 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
687 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
688 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
689 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
691 # define itkLegacyBodyMacro(method, version) \
692 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
693 # define itkLegacyReplaceBodyMacro(method, version, replace) \
694 itkWarningMacro(#method " was deprecated for ITK " #version \
695 " and will be removed in a future version. Use " #replace " instead.")
696 # define itkGenericLegacyBodyMacro(method, version) \
697 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
698 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
699 itkGenericOutputMacro(#method " was deprecated for ITK " #version \
700 " and will be removed in a future version. Use " #replace " instead.")
707 #define ITK_CACHE_LINE_ALIGNMENT 64
715 #define itkPadStruct(mincachesize, oldtype, newtype) \
716 struct newtype : public oldtype \
718 char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
725 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
726 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
727 #elif defined(_MSC_VER)
728 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
730 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
733 #if defined(ITK_FUTURE_LEGACY_REMOVE)
756 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
757 #else // LEGACY_REMOVE
758 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
774 #define itkForLoopAssignmentMacro( \
775 DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
776 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
778 DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
790 #define itkForLoopRoundingAndAssignmentMacro( \
791 DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
792 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
794 DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
799 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
802 # define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
804 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
808 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
811 #define itkAssertOrThrowMacro(test, message) \
814 std::ostringstream msgstr; \
816 itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
818 ITK_MACROEND_NOOP_STATEMENT
820 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
821 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
823 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
833 #ifdef ITK_FUTURE_LEGACY_REMOVE
834 # define itkStaticConstMacro(name, type, value) \
835 "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
836 # define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
852 # define itkStaticConstMacro(name, type, value) static constexpr type name = value
854 # define itkGetStaticConstMacro(name) (Self::name)
858 #define itkSetInputMacro(name, type) \
859 virtual void Set##name(const type * _arg) \
861 itkDebugMacro("setting input " #name " to " << _arg); \
862 if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
864 this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
868 ITK_MACROEND_NOOP_STATEMENT
872 #define itkGetInputMacro(name, type) \
873 virtual const type * Get##name() const \
875 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
876 return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
878 ITK_MACROEND_NOOP_STATEMENT
883 #define itkSetDecoratedInputMacro(name, type) \
884 virtual void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) \
886 itkDebugMacro("setting input " #name " to " << _arg); \
887 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
889 this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
893 virtual void Set##name(const SimpleDataObjectDecorator<type> * _arg) { this->Set##name##Input(_arg); } \
894 virtual void Set##name(const type & _arg) \
896 using DecoratorType = SimpleDataObjectDecorator<type>; \
897 itkDebugMacro("setting input " #name " to " << _arg); \
898 const DecoratorType * oldInput = \
899 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
901 CLANG_SUPPRESS_Wfloat_equal \
902 if (oldInput && oldInput->Get() == _arg) \
907 auto newInput = DecoratorType::New(); \
908 newInput->Set(_arg); \
909 this->Set##name##Input(newInput); \
911 ITK_MACROEND_NOOP_STATEMENT
916 #define itkGetDecoratedInputMacro(name, type) \
917 virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
919 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
920 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
922 virtual const type & Get##name() const \
924 itkDebugMacro("Getting input " #name); \
925 using DecoratorType = SimpleDataObjectDecorator<type>; \
926 const DecoratorType * input = \
927 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
928 if (input == nullptr) \
930 itkExceptionMacro("input" #name " is not set"); \
932 return input->Get(); \
934 ITK_MACROEND_NOOP_STATEMENT
939 #define itkSetGetDecoratedInputMacro(name, type) \
940 itkSetDecoratedInputMacro(name, type); \
941 itkGetDecoratedInputMacro(name, type)
947 #define itkSetDecoratedObjectInputMacro(name, type) \
948 virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
950 itkDebugMacro("setting input " #name " to " << _arg); \
951 if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
953 this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
957 virtual void Set##name(const type * _arg) \
959 using DecoratorType = DataObjectDecorator<type>; \
960 itkDebugMacro("setting input " #name " to " << _arg); \
961 const DecoratorType * oldInput = \
962 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
963 if (oldInput && oldInput->Get() == _arg) \
967 auto newInput = DecoratorType::New(); \
968 newInput->Set(_arg); \
969 this->Set##name##Input(newInput); \
971 ITK_MACROEND_NOOP_STATEMENT
978 #define itkGetDecoratedObjectInputMacro(name, type) \
979 virtual const DataObjectDecorator<type> * Get##name##Input() const \
981 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
982 return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
984 virtual const type * Get##name() const \
986 itkDebugMacro("Getting input " #name); \
987 using DecoratorType = DataObjectDecorator<type>; \
988 const DecoratorType * input = \
989 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
990 if (input == nullptr) \
994 return input->Get(); \
996 ITK_MACROEND_NOOP_STATEMENT
1001 #define itkSetGetDecoratedObjectInputMacro(name, type) \
1002 itkSetDecoratedObjectInputMacro(name, type); \
1003 itkGetDecoratedObjectInputMacro(name, type)
1007 #define itkSetMacro(name, type) \
1008 virtual void Set##name(type _arg) \
1010 itkDebugMacro("setting " #name " to " << _arg); \
1012 CLANG_SUPPRESS_Wfloat_equal \
1013 if (this->m_##name != _arg) \
1015 this->m_##name = std::move(_arg); \
1020 ITK_MACROEND_NOOP_STATEMENT
1024 #define itkGetMacro(name, type) \
1025 virtual type Get##name() { return this->m_##name; } \
1026 ITK_MACROEND_NOOP_STATEMENT
1032 #define itkGetConstMacro(name, type) \
1033 virtual type Get##name() const { return this->m_##name; } \
1034 ITK_MACROEND_NOOP_STATEMENT
1041 #define itkGetConstReferenceMacro(name, type) \
1042 virtual const type & Get##name() const { return this->m_##name; } \
1043 ITK_MACROEND_NOOP_STATEMENT
1050 #define itkSetEnumMacro(name, type) \
1051 virtual void Set##name(const type _arg) \
1053 itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1054 if (this->m_##name != _arg) \
1056 this->m_##name = _arg; \
1060 ITK_MACROEND_NOOP_STATEMENT
1067 #define itkGetEnumMacro(name, type) \
1068 virtual type Get##name() const { return this->m_##name; } \
1069 ITK_MACROEND_NOOP_STATEMENT
1075 #define itkSetStringMacro(name) \
1076 virtual void Set##name(const char * _arg) \
1078 if (_arg && (_arg == this->m_##name)) \
1084 this->m_##name = _arg; \
1088 this->m_##name = ""; \
1092 virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1093 ITK_MACROEND_NOOP_STATEMENT
1100 #define itkGetStringMacro(name) \
1101 virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1102 ITK_MACROEND_NOOP_STATEMENT
1108 #define itkSetClampMacro(name, type, min, max) \
1109 virtual void Set##name(type _arg) \
1111 const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1112 itkDebugMacro("setting " << #name " to " << _arg); \
1114 CLANG_SUPPRESS_Wfloat_equal \
1115 if (this->m_##name != temp_extrema) \
1117 this->m_##name = temp_extrema; \
1122 ITK_MACROEND_NOOP_STATEMENT
1130 #define itkSetObjectMacro(name, type) \
1131 virtual void Set##name(type * _arg) \
1133 itkDebugMacro("setting " << #name " to " << _arg); \
1134 if (this->m_##name != _arg) \
1136 this->m_##name = _arg; \
1140 ITK_MACROEND_NOOP_STATEMENT
1169 #define itkGetConstObjectMacro(name, type) \
1170 virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1171 ITK_MACROEND_NOOP_STATEMENT
1174 #if defined(ITK_FUTURE_LEGACY_REMOVE)
1180 # define itkGetObjectMacro(name, type) \
1181 virtual type * Get##name() \
1183 purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1186 # define itkGetModifiableObjectMacro(name, type) \
1187 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1188 itkGetConstObjectMacro(name, type)
1190 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1193 # define itkGetObjectMacro(name, type) \
1194 virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1195 ITK_MACROEND_NOOP_STATEMENT
1196 # define itkGetModifiableObjectMacro(name, type) \
1197 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1198 itkGetConstObjectMacro(name, type); \
1199 itkGetObjectMacro(name, type)
1200 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1209 #define itkGetConstReferenceObjectMacro(name, type) \
1210 virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1211 ITK_MACROEND_NOOP_STATEMENT
1216 #define itkSetConstObjectMacro(name, type) \
1217 virtual void Set##name(const type * _arg) \
1219 itkDebugMacro("setting " << #name " to " << _arg); \
1220 if (this->m_##name != _arg) \
1222 this->m_##name = _arg; \
1226 ITK_MACROEND_NOOP_STATEMENT
1231 #define itkBooleanMacro(name) \
1232 virtual void name##On() { this->Set##name(true); } \
1233 virtual void name##Off() { this->Set##name(false); }
1240 #define itkSetVectorMacro(name, type, count) \
1241 virtual void Set##name(type data[]) \
1244 for (i = 0; i < count; ++i) \
1247 CLANG_SUPPRESS_Wfloat_equal \
1248 if (data[i] != this->m_##name[i]) \
1257 for (i = 0; i < count; ++i) \
1259 this->m_##name[i] = data[i]; \
1263 ITK_MACROEND_NOOP_STATEMENT
1269 #define itkGetVectorMacro(name, type, count) \
1270 virtual type * Get##name() const { return this->m_##name; } \
1271 ITK_MACROEND_NOOP_STATEMENT
1277 #define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1284 #define itkGPUKernelMacro(kernel) \
1288 ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1289 kernel() = delete; \
1290 ~kernel() = delete; \
1291 static const char * GetOpenCLSource(); \
1295 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1296 static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); }
1300 #define itkPrintSelfObjectMacro(name) \
1301 if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1303 os << indent << #name << ": (null)" << std::endl; \
1307 os << indent << #name << ": " << std::endl; \
1308 this->m_##name->Print(os, indent.GetNextIndent()); \
1310 ITK_MACROEND_NOOP_STATEMENT
1314 #define itkSetDecoratedOutputMacro(name, type) \
1315 virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1317 itkDebugMacro("setting output " #name " to " << _arg); \
1318 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1320 this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1324 virtual void Set##name(const type & _arg) \
1326 using DecoratorType = SimpleDataObjectDecorator<type>; \
1327 itkDebugMacro("setting output " #name " to " << _arg); \
1328 DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1331 if (output->Get() == _arg) \
1337 output->Set(_arg); \
1342 auto newOutput = DecoratorType::New(); \
1343 newOutput->Set(_arg); \
1344 this->Set##name##Output(newOutput); \
1347 ITK_MACROEND_NOOP_STATEMENT
1351 #define itkGetDecoratedOutputMacro(name, type) \
1352 virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1354 itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1355 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1357 virtual const type & Get##name() const \
1359 itkDebugMacro("Getting output " #name); \
1360 using DecoratorType = SimpleDataObjectDecorator<type>; \
1361 const DecoratorType * output = \
1362 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1363 if (output == nullptr) \
1365 itkExceptionMacro("output" #name " is not set"); \
1367 return output->Get(); \
1369 ITK_MACROEND_NOOP_STATEMENT
1382 #if defined(ITKV4_COMPATIBILITY)
1383 # define ITK_ITERATOR_VIRTUAL virtual
1384 # define ITK_ITERATOR_OVERRIDE override
1385 # define ITK_ITERATOR_FINAL
1386 #elif !defined(ITK_LEGACY_REMOVE)
1387 # define ITK_ITERATOR_VIRTUAL virtual
1388 # define ITK_ITERATOR_OVERRIDE override
1389 # define ITK_ITERATOR_FINAL final
1391 # define ITK_ITERATOR_VIRTUAL
1392 # define ITK_ITERATOR_OVERRIDE
1393 # define ITK_ITERATOR_FINAL
1396 #if defined(ITKV4_COMPATIBILITY)
1398 # define ITKv5_CONST
1401 # define ITKv5_CONST const
1404 #define itkExceptionObject_h
1406 #undef itkExceptionObject_h
1415 template <
typename TTarget,
typename TSource>
1417 itkDynamicCastInDebugMode(TSource x)
1424 TTarget rval = dynamic_cast<TTarget>(x);
1425 if (rval ==
nullptr)
1427 itkGenericExceptionMacro(
"Failed dynamic cast to " <<
typeid(TTarget).name()
1428 <<
" object type = " << x->GetNameOfClass());
1432 return static_cast<TTarget>(x);
1437 #ifdef ITK_LEGACY_REMOVE
1438 # if __cplusplus >= 202002L
1439 # define ITK_NODISCARD(message) [[nodiscard(message)]]
1441 # define ITK_NODISCARD(message) [[nodiscard]]
1444 # define ITK_NODISCARD(message)
1448 #define ITK_ALIGNAS(X) alignas(X)
1449 #define ITK_ALIGNOF(X) alignof(X)
1450 #define ITK_DEPRECATED [[deprecated]]
1451 #define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1452 #define ITK_CONSTEXPR constexpr
1453 #define ITK_DELETED_FUNCTION = delete
1454 #define ITK_EXTERN_TEMPLATE extern
1455 #define ITK_FINAL final
1456 #define ITK_NOEXCEPT noexcept
1457 #define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1458 #define ITK_NULLPTR nullptr
1459 #define ITK_OVERRIDE override
1460 #define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1461 #define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1462 #define ITK_THREAD_LOCAL thread_local
1464 #endif // end of itkMacro.h