42 #include "itkConfigure.h"
43 #include "ITKCommonExport.h"
55 #include <type_traits>
81 #define ITK_NOOP_STATEMENT static_assert(true, "")
92 #define ITK_MACROEND_NOOP_STATEMENT ITK_NOOP_STATEMENT
99 #define ITK_PRAGMA(x) _Pragma(#x)
106 #if defined(__GNUC__)
107 # define ITK_GCC_PRAGMA_PUSH ITK_PRAGMA(GCC diagnostic push)
108 # define ITK_GCC_PRAGMA_POP ITK_PRAGMA(GCC diagnostic pop)
109 # define ITK_GCC_SUPPRESS_Wfloat_equal ITK_PRAGMA(GCC diagnostic ignored "-Wfloat-equal")
110 # define ITK_GCC_SUPPRESS_Wformat_nonliteral ITK_PRAGMA(GCC diagnostic ignored "-Wformat-nonliteral")
111 # define ITK_GCC_SUPPRESS_Warray_bounds ITK_PRAGMA(GCC diagnostic ignored "-Warray-bounds")
113 # define ITK_GCC_PRAGMA_PUSH
114 # define ITK_GCC_PRAGMA_POP
115 # define ITK_GCC_SUPPRESS_Wfloat_equal
116 # define ITK_GCC_SUPPRESS_Wformat_nonliteral
117 # define ITK_GCC_SUPPRESS_Warray_bounds
121 #if defined(__clang__) && defined(__has_warning)
122 # define ITK_CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
123 # define ITK_CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
124 # define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant \
125 ITK_PRAGMA(clang diagnostic ignored "-Wzero-as-null-pointer-constant")
127 # define ITK_CLANG_PRAGMA_PUSH
128 # define ITK_CLANG_PRAGMA_POP
129 # define ITK_CLANG_SUPPRESS_Wzero_as_null_pointer_constant
134 #define CLANG_PRAGMA_PUSH ITK_CLANG_PRAGMA_PUSH
135 #define CLANG_PRAGMA_POP ITK_CLANG_PRAGMA_POP
136 #define CLANG_SUPPRESS_Wfloat_equal ITK_GCC_SUPPRESS_Wfloat_equal
138 #if !defined(ITK_LEGACY_REMOVE)
140 # define CLANG_SUPPRESS_Wcpp14_extensions \
141 [[deprecated("Remove deprecated CLANG_SUPPRESS_Wcpp14_extensions c++14 warning suppression")]] void * \
142 CLANG_SUPPRESS_Wcpp14_extensions = nullptr;
146 #if defined(__INTEL_COMPILER)
147 # define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
148 # define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
149 # define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
151 # define INTEL_PRAGMA_WARN_PUSH
152 # define INTEL_PRAGMA_WARN_POP
153 # define INTEL_SUPPRESS_warning_1292
164 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
165 # define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
166 # define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
167 # define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
169 # define ITK_GCC_PRAGMA_DIAG(x)
170 # define ITK_GCC_PRAGMA_DIAG_PUSH()
171 # define ITK_GCC_PRAGMA_DIAG_POP()
178 #if defined(_MSC_VER) && (_MSC_VER < 1920)
179 # error "MSVC versions before Visual Studio 2019 are not supported"
181 #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
182 # error "SUNPro C++ < 5.14.0 is not supported"
184 #if defined(__CYGWIN__)
185 # error "The Cygwin compiler is not supported"
187 #if defined(__BORLANDC__)
188 # error "The Borland C compiler is not supported"
190 #if defined(__MWERKS__)
191 # error "The MetroWerks compiler is not supported"
193 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (__GNUC__ < 7)
194 # error "GCC < 7 is not supported"
200 # error "The SGI compiler is not supported"
202 #if defined(__APPLE__)
203 # if defined(__clang__) && (__cplusplus < 201703L)
204 # error "Apple LLVM compiling with a standard less than C++17 is not supported"
206 #elif defined(__clang__) && (__clang_major__ < 5)
207 # error "Clang < 5 is not supported"
209 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1910)
210 # error "Intel C++ < 19.1 is not supported4"
214 #if defined(_WIN32) || defined(WIN32)
215 # define ITK_ABI_IMPORT __declspec(dllimport)
216 # define ITK_ABI_EXPORT __declspec(dllexport)
217 # define ITK_ABI_HIDDEN
220 # define ITK_ABI_IMPORT __attribute__((visibility("default")))
221 # define ITK_ABI_EXPORT __attribute__((visibility("default")))
222 # define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
224 # define ITK_ABI_IMPORT
225 # define ITK_ABI_EXPORT
226 # define ITK_ABI_HIDDEN
231 #ifndef ITK_TEMPLATE_EXPORT
232 # ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
233 # define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
235 # define ITK_TEMPLATE_EXPORT
240 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
241 # define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
243 # define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
246 #ifndef ITK_FORWARD_EXPORT
248 # if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
249 defined(USE_COMPILER_HIDDEN_VISIBILITY)
250 # define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
252 # define ITK_FORWARD_EXPORT
277 #define itkNewMacro(x) \
278 itkSimpleNewMacro(x); \
279 itkCreateAnotherMacro(x); \
281 ITK_MACROEND_NOOP_STATEMENT
284 #define itkSimpleNewMacro(x) \
285 static Pointer New() \
287 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
288 if (smartPtr == nullptr) \
290 smartPtr = new x(); \
292 smartPtr->UnRegister(); \
295 ITK_MACROEND_NOOP_STATEMENT
297 #define itkCreateAnotherMacro(x) \
298 ::itk::LightObject::Pointer CreateAnother() const override { return x::New().GetPointer(); } \
299 ITK_MACROEND_NOOP_STATEMENT
301 #define itkCloneMacro(x) \
302 Pointer Clone() const \
304 Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
307 ITK_MACROEND_NOOP_STATEMENT
312 #define itkFactoryOnlyNewMacro(x) \
313 itkSimpleFactoryOnlyNewMacro(x); \
314 itkCreateAnotherMacro(x); \
316 ITK_MACROEND_NOOP_STATEMENT
319 #define itkSimpleFactoryOnlyNewMacro(x) \
320 static auto New()->Pointer \
322 Pointer smartPtr = ::itk::ObjectFactory<x>::Create(); \
323 if (smartPtr == nullptr) \
325 itkSpecializedMessageExceptionMacro(ExceptionObject, \
326 "Object factory failed to instantiate " << typeid(x).name()); \
328 smartPtr->UnRegister(); \
331 ITK_MACROEND_NOOP_STATEMENT
345 #define itkFactorylessNewMacro(x) \
346 static Pointer New() \
348 x * rawPtr = new x(); \
349 Pointer smartPtr = rawPtr; \
350 rawPtr->UnRegister(); \
353 itkCreateAnotherMacro(x); \
354 ITK_MACROEND_NOOP_STATEMENT
366 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
367 TypeName(const TypeName &) = delete; \
368 TypeName & operator=(const TypeName &) = delete; \
369 TypeName(TypeName &&) = delete; \
370 TypeName & operator=(TypeName &&) = delete
372 #if !defined(ITK_LEGACY_REMOVE)
373 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
375 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
376 static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
387 #define ITK_DEFAULT_COPY_AND_MOVE(TypeName) \
388 TypeName(const TypeName &) = default; \
389 TypeName & operator=(const TypeName &) = default; \
390 TypeName(TypeName &&) = default; \
391 TypeName & operator=(TypeName &&) = default
399 #if __cplusplus >= 202002L
400 # define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
406 #ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
409 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
413 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
414 bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
415 ITK_MACROEND_NOOP_STATEMENT
420 #define itkInternalGetNameOfClassImplementationMacro(thisClass) \
422 static_assert(std::is_same_v<thisClass, std::remove_const_t<std::remove_reference_t<decltype(*this)>>>, \
423 "The macro argument `" #thisClass \
424 "` appears incorrect! It should correspond with the name of this class!"); \
427 ITK_MACROEND_NOOP_STATEMENT
433 #define itkVirtualGetNameOfClassMacro(thisClass) \
434 virtual const char * GetNameOfClass() const itkInternalGetNameOfClassImplementationMacro(thisClass)
436 #define itkOverrideGetNameOfClassMacro(thisClass) \
437 const char * GetNameOfClass() const override itkInternalGetNameOfClassImplementationMacro(thisClass)
439 #ifdef ITK_FUTURE_LEGACY_REMOVE
440 # define itkTypeMacro(thisClass, superclass) \
441 static_assert(false, \
442 "In a future revision of ITK, the macro `itkTypeMacro(thisClass, superclass)` will be removed. " \
443 "Please call `itkOverrideGetNameOfClassMacro(thisClass)` instead!")
444 # define itkTypeMacroNoParent(thisClass) \
445 static_assert(false, \
446 "In a future revision of ITK, the macro `itkTypeMacroNoParent(thisClass)` will be removed. " \
447 "Please call `itkVirtualGetNameOfClassMacro(thisClass)` instead!")
453 # define itkTypeMacro(thisClass, superclass) itkOverrideGetNameOfClassMacro(thisClass)
454 # define itkTypeMacroNoParent(thisClass) itkVirtualGetNameOfClassMacro(thisClass)
466 extern ITKCommon_EXPORT
void
467 OutputWindowDisplayText(
const char *);
470 extern ITKCommon_EXPORT
void
471 OutputWindowDisplayErrorText(
const char *);
473 extern ITKCommon_EXPORT
void
474 OutputWindowDisplayWarningText(
const char *);
476 extern ITKCommon_EXPORT
void
477 OutputWindowDisplayGenericOutputText(
const char *);
479 extern ITKCommon_EXPORT
void
480 OutputWindowDisplayDebugText(
const char *);
490 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
491 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
493 # define itkDebugMacro(x) \
495 using namespace ::itk::print_helper; \
496 if (this->GetDebug() && ::itk::Object::GetGlobalWarningDisplay()) \
498 std::ostringstream itkmsg; \
499 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << '\n' \
500 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
501 ::itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
504 ITK_MACROEND_NOOP_STATEMENT
507 # define itkDebugStatement(x) x
514 #define itkWarningMacro(x) \
516 if (::itk::Object::GetGlobalWarningDisplay()) \
518 std::ostringstream itkmsg; \
519 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << '\n' \
520 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
521 ::itk::OutputWindowDisplayWarningText(itkmsg.str().c_str()); \
524 ITK_MACROEND_NOOP_STATEMENT
528 #define itkWarningStatement(x) x
530 #if defined(ITK_CPP_FUNCTION)
531 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
532 # define ITK_LOCATION __FUNCSIG__
533 # elif defined(__GNUC__)
534 # define ITK_LOCATION __PRETTY_FUNCTION__
536 # define ITK_LOCATION __FUNCTION__
539 # define ITK_LOCATION "unknown"
542 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
545 class newexcp : public parentexcp \
549 static constexpr const char * const default_exception_message = whatmessage; \
551 using parentexcp::parentexcp; \
552 itkOverrideGetNameOfClassMacro(newexcp); \
555 ITK_MACROEND_NOOP_STATEMENT
558 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
560 std::ostringstream exceptionDescriptionOutputStringStream; \
561 exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
562 throw ::itk::ExceptionType( \
563 std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
565 ITK_MACROEND_NOOP_STATEMENT
567 #define itkSpecializedExceptionMacro(ExceptionType) \
568 itkSpecializedMessageExceptionMacro(ExceptionType, << ::itk::ExceptionType::default_exception_message)
573 #define itkExceptionMacro(x) \
574 itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
576 #define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
578 #define itkGenericOutputMacro(x) \
580 if (::itk::Object::GetGlobalWarningDisplay()) \
582 std::ostringstream itkmsg; \
583 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
584 ::itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
587 ITK_MACROEND_NOOP_STATEMENT
592 #define itkLogMacro(x, y) \
594 if (this->GetLogger()) \
596 this->GetLogger()->Write(::itk::LoggerBase::x, y); \
599 ITK_MACROEND_NOOP_STATEMENT
601 #define itkLogMacroStatic(obj, x, y) \
603 if (obj->GetLogger()) \
605 obj->GetLogger()->Write(::itk::LoggerBase::x, y); \
608 ITK_MACROEND_NOOP_STATEMENT
639 #if defined(ITK_LEGACY_REMOVE)
640 # define itkLegacyMacro(method)
642 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
644 # define itkLegacyMacro(method) method
647 # define itkLegacyMacro(method) [[deprecated]] method
673 #if defined(ITK_LEGACY_SILENT)
674 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
675 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
676 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
677 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
679 # define itkLegacyBodyMacro(method, version) \
680 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
681 # define itkLegacyReplaceBodyMacro(method, version, replace) \
682 itkWarningMacro(#method " was deprecated for ITK " #version \
683 " and will be removed in a future version. Use " #replace " instead.")
684 # define itkGenericLegacyBodyMacro(method, version) \
685 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
686 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
687 itkGenericOutputMacro(#method " was deprecated for ITK " #version \
688 " and will be removed in a future version. Use " #replace " instead.")
695 #define ITK_CACHE_LINE_ALIGNMENT 64
703 #define itkPadStruct(mincachesize, oldtype, newtype) \
704 struct newtype : public oldtype \
706 char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
713 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
714 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
715 #elif defined(_MSC_VER)
716 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
718 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
721 #if defined(ITK_FUTURE_LEGACY_REMOVE)
744 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
745 #else // LEGACY_REMOVE
746 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
762 #define itkForLoopAssignmentMacro( \
763 DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
764 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
766 DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
768 ITK_MACROEND_NOOP_STATEMENT
779 #define itkForLoopRoundingAndAssignmentMacro( \
780 DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
781 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
783 DestinationArray[i] = ::itk::Math::Round<DestinationElementType>(SourceArray[i]); \
785 ITK_MACROEND_NOOP_STATEMENT
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)); \
890 ITK_GCC_PRAGMA_PUSH \
891 ITK_GCC_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); \
1001 ITK_GCC_PRAGMA_PUSH \
1002 ITK_GCC_SUPPRESS_Wfloat_equal \
1003 if (this->m_##name != _arg) \
1005 this->m_##name = std::move(_arg); \
1008 ITK_GCC_PRAGMA_POP \
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); \
1103 ITK_GCC_PRAGMA_PUSH \
1104 ITK_GCC_SUPPRESS_Wfloat_equal \
1105 if (this->m_##name != temp_extrema) \
1107 this->m_##name = temp_extrema; \
1110 ITK_GCC_PRAGMA_POP \
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."); \
1175 ITK_MACROEND_NOOP_STATEMENT
1177 # define itkGetModifiableObjectMacro(name, type) \
1178 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1179 itkGetConstObjectMacro(name, type)
1181 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1184 # define itkGetObjectMacro(name, type) \
1185 virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1186 ITK_MACROEND_NOOP_STATEMENT
1187 # define itkGetModifiableObjectMacro(name, type) \
1188 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1189 itkGetConstObjectMacro(name, type); \
1190 itkGetObjectMacro(name, type)
1191 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1200 #define itkGetConstReferenceObjectMacro(name, type) \
1201 virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1202 ITK_MACROEND_NOOP_STATEMENT
1207 #define itkSetConstObjectMacro(name, type) \
1208 virtual void Set##name(const type * _arg) \
1210 itkDebugMacro("setting " << #name " to " << _arg); \
1211 if (this->m_##name != _arg) \
1213 this->m_##name = _arg; \
1217 ITK_MACROEND_NOOP_STATEMENT
1222 #define itkBooleanMacro(name) \
1223 virtual void name##On() { this->Set##name(true); } \
1224 virtual void name##Off() { this->Set##name(false); } \
1225 ITK_MACROEND_NOOP_STATEMENT
1232 #define itkSetVectorMacro(name, type, count) \
1233 virtual void Set##name(type data[]) \
1236 for (i = 0; i < count; ++i) \
1238 ITK_GCC_PRAGMA_PUSH \
1239 ITK_GCC_SUPPRESS_Wfloat_equal \
1240 if (data[i] != this->m_##name[i]) \
1244 ITK_GCC_PRAGMA_POP \
1249 for (i = 0; i < count; ++i) \
1251 this->m_##name[i] = data[i]; \
1255 ITK_MACROEND_NOOP_STATEMENT
1261 #define itkGetVectorMacro(name, type, count) \
1262 virtual type * Get##name() const { return this->m_##name; } \
1263 ITK_MACROEND_NOOP_STATEMENT
1269 #define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1276 #define itkGPUKernelMacro(kernel) \
1280 ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1281 kernel() = delete; \
1282 ~kernel() = delete; \
1283 static const char * GetOpenCLSource(); \
1287 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1288 static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); } \
1289 ITK_MACROEND_NOOP_STATEMENT
1293 #define itkPrintSelfObjectMacro(name) \
1294 if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1296 os << indent << #name << ": (null)" << std::endl; \
1300 os << indent << #name << ": " << std::endl; \
1301 this->m_##name->Print(os, indent.GetNextIndent()); \
1303 ITK_MACROEND_NOOP_STATEMENT
1308 #define itkPrintSelfBooleanMacro(name) \
1309 os << indent << #name << ": " << (this->m_##name ? "On" : "Off") << std::endl; \
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
1373 #define itkExceptionObject_h
1375 #undef itkExceptionObject_h
1384 template <
typename TTarget,
typename TSource>
1386 itkDynamicCastInDebugMode(TSource x)
1393 TTarget rval = dynamic_cast<TTarget>(x);
1394 if (rval ==
nullptr)
1396 itkGenericExceptionMacro(
"Failed dynamic cast to " <<
typeid(TTarget).name()
1397 <<
" object type = " << x->GetNameOfClass());
1401 return static_cast<TTarget>(x);
1406 #if __cplusplus >= 202002L
1407 # define ITK_NODISCARD(message) [[nodiscard(message)]]
1409 # define ITK_NODISCARD(message) [[nodiscard]]
1414 #if defined(ITK_LEGACY_REMOVE)
1415 # define itkExposeEnumValue(name) \
1416 static_assert(false, "ERROR: Replace static_cast<int>(name) with with proper enumeration instead of integer")
1418 # define ITK_NOEXCEPT_OR_THROW static_assert(false, "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT")
1420 # define ITK_DELETE_FUNCTION static_assert(false, "ERROR: ITK_DELETE_FUNCTION must be replaced with `= delete`"
1421 # define ITK_CONSTEXPR_FUNC static_assert(false, "ERROR: ITK_CONSTEXPR_FUNC must be replaced with 'constexpr'")
1422 # define ITK_CONSTEXPR_VAR static_assert(false, "ERROR: ITK_CONSTEXPR_VAR must be replaced with 'constexpr'")
1424 # define ITK_FALLTHROUGH static_assert(false, "ERROR: ITK_FALLTHROUGH must be replaced with '[[fallthrough]]'")
1427 # define ITK_ALIGNAS static_assert(false, "ERROR: ITK_ALIGNAS must be replaced with 'alignas'")
1428 # define ITK_ALIGNOF static_assert(false, "ERROR: ITK_ALIGNOF must be replaced with 'alignof'")
1429 # define ITK_DEPRECATED static_assert(false, "ERROR: ITK_DEPRECATED must be replaced with '[[deprecated]]'")
1430 # define ITK_DEPRECATED_MSG \
1431 static_assert(false, "ERROR: ITK_DEPRECATED_MSG must be replaced with '[[deprecated(MSG)]]'")
1432 # define ITK_CONSTEXPR static_assert(false, "ERROR: ITK_CONSTEXPR must be replaced with 'constexpr'")
1433 # define ITK_DELETED_FUNCTION static_assert(false, "ERROR: ITK_DELETED_FUNCTION must be replaced with '= delete'")
1434 # define ITK_EXTERN_TEMPLATE static_assert(false, "ERROR: ITK_EXTERN_TEMPLATE must be replaced with 'extern'")
1435 # define ITK_FINAL static_assert(false, "ERROR: ITK_FINAL must be replaced with 'final'")
1436 # define ITK_NOEXCEPT static_assert(false, "ERROR: ITK_NOEXCEPT must be replaced with 'noexcept'")
1437 # define ITK_NOEXCEPT_EXPR static_assert(false, "ERROR: ITK_NOEXCEPT_EXPR must be replaced with 'noexcept'")
1438 # define ITK_NULLPTR static_assert(false, "ERROR: ITK_NULLPTR must be replaced with 'nullptr'")
1439 # define ITK_OVERRIDE static_assert(false, "ERROR: ITK_OVERRIDE must be replaced with 'override'")
1440 # define ITK_STATIC_ASSERT static_assert(false, "ERROR: ITK_STATIC_ASSERT must be replaced with 'static_assert'")
1441 # define ITK_STATIC_ASSERT_MSG \
1442 static_assert(false, "ERROR: ITK_STATIC_ASSERT_MSG must be replaced with 'static_assert'")
1443 # define ITK_THREAD_LOCAL static_assert(false, "ERROR: ITK_THREAD_LOCAL must be replaced with 'thread_local'")
1446 # define ITKv5_CONST static_assert(false, "ERROR: ITKv5_CONST must be replaced with 'const'")
1448 # define ITK_ITERATOR_VIRTUAL static_assert(false, "ERROR: ITK_ITERATOR_VIRTUAL must be removed'")
1449 # define ITK_ITERATOR_OVERRIDE static_assert(false, "ERROR: ITK_ITERATOR_OVERRIDE must be removed")
1450 # define ITK_ITERATOR_FINAL static_assert(false, "ERROR: ITK_ITERATOR_FINAL must be removed")
1459 # define itkExposeEnumValue(name) static_cast<int>(name)
1462 # define ITK_NOEXCEPT_OR_THROW ITK_NOEXCEPT
1464 # define ITK_FALLTHROUGH [[fallthrough]]
1466 # define ITK_DELETE_FUNCTION = delete
1468 # define ITK_CONSTEXPR_FUNC constexpr
1469 # define ITK_CONSTEXPR_VAR constexpr
1472 # define ITK_ALIGNAS(X) alignas(X)
1473 # define ITK_ALIGNOF(X) alignof(X)
1474 # define ITK_DEPRECATED [[deprecated]]
1475 # define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1476 # define ITK_CONSTEXPR constexpr
1477 # define ITK_DELETED_FUNCTION = delete
1478 # define ITK_EXTERN_TEMPLATE extern
1479 # define ITK_FINAL final
1480 # define ITK_NOEXCEPT noexcept
1481 # define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1482 # define ITK_NULLPTR nullptr
1483 # define ITK_OVERRIDE override
1484 # define ITK_STATIC_ASSERT(X) static_assert(X, # X)
1485 # define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1486 # define ITK_THREAD_LOCAL thread_local
1489 # define ITKv5_CONST const
1491 # define ITK_ITERATOR_VIRTUAL
1492 # define ITK_ITERATOR_OVERRIDE
1493 # define ITK_ITERATOR_FINAL
1496 #endif // itkMacro_h