42 #include "itkConfigure.h"
43 #include "ITKCommonExport.h"
79 #define ITK_NOOP_STATEMENT static_assert(true, "")
82 #if defined(ITK_FUTURE_LEGACY_REMOVE)
84 # define ITK_MACROEND_NOOP_STATEMENT ITK_NOOP_STATEMENT
90 # define ITK_MACROEND_NOOP_STATEMENT
98 #define ITK_PRAGMA(x) _Pragma(#x)
104 #if defined(__clang__) && defined(__has_warning)
105 # define CLANG_PRAGMA_PUSH ITK_PRAGMA(clang diagnostic push)
106 # define CLANG_PRAGMA_POP ITK_PRAGMA(clang diagnostic pop)
107 # if __has_warning("-Wfloat-equal")
108 # define CLANG_SUPPRESS_Wfloat_equal ITK_PRAGMA(clang diagnostic ignored "-Wfloat-equal")
110 # define CLANG_SUPPRESS_Wfloat_equal
112 # if __has_warning("-Wc++14-extensions")
113 # define CLANG_SUPPRESS_Wcpp14_extensions ITK_PRAGMA(clang diagnostic ignored "-Wc++14-extensions")
115 # define CLANG_SUPPRESS_Wcpp14_extensions
118 # define CLANG_PRAGMA_PUSH
119 # define CLANG_PRAGMA_POP
120 # define CLANG_SUPPRESS_Wfloat_equal
121 # define CLANG_SUPPRESS_Wcpp14_extensions
125 #if defined(__INTEL_COMPILER)
126 # define INTEL_PRAGMA_WARN_PUSH ITK_PRAGMA(warning push)
127 # define INTEL_PRAGMA_WARN_POP ITK_PRAGMA(warning pop)
128 # define INTEL_SUPPRESS_warning_1292 ITK_PRAGMA(warning disable 1292)
130 # define INTEL_PRAGMA_WARN_PUSH
131 # define INTEL_PRAGMA_WARN_POP
132 # define INTEL_SUPPRESS_warning_1292
143 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
144 # define ITK_GCC_PRAGMA_DIAG(x) ITK_PRAGMA(GCC diagnostic x)
145 # define ITK_GCC_PRAGMA_DIAG_PUSH() ITK_GCC_PRAGMA_DIAG(push)
146 # define ITK_GCC_PRAGMA_DIAG_POP() ITK_GCC_PRAGMA_DIAG(pop)
148 # define ITK_GCC_PRAGMA_DIAG(x)
149 # define ITK_GCC_PRAGMA_DIAG_PUSH()
150 # define ITK_GCC_PRAGMA_DIAG_POP()
165 #if defined(_MSC_VER) && (_MSC_VER < 1910)
166 # error "Visual Studio < 2017 is not supported under ITKv5.3"
168 #if defined(__SUNPRO_CC) && (__SUNPRO_CC < 0x5140)
169 # error "SUNPro C++ < 5.14.0 is not supported under ITKv5 and above"
171 #if defined(__CYGWIN__)
172 # error "The Cygwin compiler is not supported in ITKv4 and above"
174 #if defined(__BORLANDC__)
175 # error "The Borland C compiler is not supported in ITKv4 and above"
177 #if defined(__MWERKS__)
178 # error "The MetroWerks compiler is not supported in ITKv4 and above"
180 #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) && \
181 ((__GNUC__ < 5) || ((__GNUC__ == 5) && (__GNUC_MINOR__ < 1)))
182 # error "GCC < 5.1 is not supported under ITKv5.3"
188 # error "The SGI compiler is not supported under ITKv4 and above"
190 #if defined(__APPLE__)
191 # if defined(__clang__) && (__cplusplus < 201402L)
192 # error "Apple LLVM < 5.1 (clang < 3.4) or compiling with a standard less than C++14 is not supported under ITKv5.3"
194 #elif defined(__clang__) && ((__clang_major__ < 3) || ((__clang_major__ == 3) && (__clang_minor__ < 4)))
195 # error "Clang < 3.4 is not supported under ITKv5.3"
197 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER < 1700)
198 # error "Intel C++ < 17.0 is not supported under ITKv5.3"
202 #if defined(_WIN32) || defined(WIN32)
203 # define ITK_ABI_IMPORT __declspec(dllimport)
204 # define ITK_ABI_EXPORT __declspec(dllexport)
205 # define ITK_ABI_HIDDEN
208 # define ITK_ABI_IMPORT __attribute__((visibility("default")))
209 # define ITK_ABI_EXPORT __attribute__((visibility("default")))
210 # define ITK_ABI_HIDDEN __attribute__((visibility("hidden")))
212 # define ITK_ABI_IMPORT
213 # define ITK_ABI_EXPORT
214 # define ITK_ABI_HIDDEN
219 #ifndef ITK_TEMPLATE_EXPORT
220 # ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
221 # define ITK_TEMPLATE_EXPORT __attribute__((visibility("default")))
223 # define ITK_TEMPLATE_EXPORT
228 #ifdef ITK_TEMPLATE_VISIBILITY_DEFAULT
229 # define ITK_FORCE_EXPORT_MACRO(moduleName) __attribute__((visibility("default")))
231 # define ITK_FORCE_EXPORT_MACRO(moduleName) moduleName##_EXPORT
234 #ifndef ITK_FORWARD_EXPORT
236 # if defined(__APPLE__) && defined(ITK_TEMPLATE_VISIBILITY_DEFAULT) && defined(ITK_BUILD_SHARED_LIBS) && \
237 defined(USE_COMPILER_HIDDEN_VISIBILITY)
238 # define ITK_FORWARD_EXPORT __attribute__((visibility("default")))
240 # define ITK_FORWARD_EXPORT
248 #define ITK_NOEXCEPT_OR_THROW error "Replace ITK_NOEXCEPT_OR_THROW with ITK_NOEXCEPT"
250 #if !defined(ITK_LEGACY_REMOVE)
251 # define ITK_DELETE_FUNCTION = delete
253 # define ITK_DELETE_FUNCTION error "Replace ITK_DELETE_FUNCTION with = delete"
260 #if defined(ITK_FUTURE_LEGACY_REMOVE)
261 # define ITK_CONSTEXPR_FUNC "Replace ITK_CONSTEXPR_FUNC with constexpr"
262 # define ITK_CONSTEXPR_VAR "Replace ITK_CONSTEXPR_VAR with constexpr"
264 # define itkExposeEnumValue(name) static_cast<int>(name)
268 # define ITK_CONSTEXPR_FUNC constexpr
269 # define ITK_CONSTEXPR_VAR constexpr
272 # define itkExposeEnumValue(name) static_cast<int>(name)
277 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
279 # define ITK_FALLTHROUGH __attribute__((fallthrough))
281 #elif defined(__has_warning)
282 # if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
283 # define ITK_FALLTHROUGH [[clang::fallthrough]]
287 #ifndef ITK_FALLTHROUGH
288 # define ITK_FALLTHROUGH ((void)0)
311 #define itkNewMacro(x) \
312 itkSimpleNewMacro(x); \
313 itkCreateAnotherMacro(x); \
315 ITK_MACROEND_NOOP_STATEMENT
318 #define itkSimpleNewMacro(x) \
319 static Pointer New() \
321 Pointer smartPtr = itk::ObjectFactory<x>::Create(); \
322 if (smartPtr == nullptr) \
326 smartPtr->UnRegister(); \
329 ITK_MACROEND_NOOP_STATEMENT
331 #define itkCreateAnotherMacro(x) \
332 itk::LightObject::Pointer CreateAnother() const override \
334 itk::LightObject::Pointer smartPtr; \
335 smartPtr = x::New().GetPointer(); \
338 ITK_MACROEND_NOOP_STATEMENT
340 #define itkCloneMacro(x) \
341 Pointer Clone() const \
343 Pointer rval = dynamic_cast<x *>(this->InternalClone().GetPointer()); \
346 ITK_MACROEND_NOOP_STATEMENT
351 #define itkFactoryOnlyNewMacro(x) \
352 itkSimpleFactoryOnlyNewMacro(x); \
353 itkCreateAnotherMacro(x); \
355 ITK_MACROEND_NOOP_STATEMENT
358 #define itkSimpleFactoryOnlyNewMacro(x) \
359 static auto New()->Pointer \
361 Pointer smartPtr = itk::ObjectFactory<x>::Create(); \
362 if (smartPtr == nullptr) \
364 itkSpecializedMessageExceptionMacro(ExceptionObject, \
365 "Object factory failed to instantiate " << typeid(x).name()); \
367 smartPtr->UnRegister(); \
370 ITK_MACROEND_NOOP_STATEMENT
384 #define itkFactorylessNewMacro(x) \
385 static Pointer New() \
388 x * rawPtr = new x; \
390 rawPtr->UnRegister(); \
393 itk::LightObject::Pointer CreateAnother() const override \
395 itk::LightObject::Pointer smartPtr; \
396 smartPtr = x::New().GetPointer(); \
399 ITK_MACROEND_NOOP_STATEMENT
411 #define ITK_DISALLOW_COPY_AND_MOVE(TypeName) \
412 TypeName(const TypeName &) = delete; \
413 TypeName & operator=(const TypeName &) = delete; \
414 TypeName(TypeName &&) = delete; \
415 TypeName & operator=(TypeName &&) = delete
417 #if !defined(ITK_FUTURE_LEGACY_REMOVE)
418 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) ITK_DISALLOW_COPY_AND_MOVE(TypeName)
420 # define ITK_DISALLOW_COPY_AND_ASSIGN(TypeName) \
421 static_assert(false, "Replace deprecated ITK_DISALLOW_COPY_AND_ASSIGN with modern ITK_DISALLOW_COPY_AND_MOVE")
429 #if __cplusplus >= 202002L
430 # define ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
436 #ifdef ITK_EXPERIMENTAL_CXX20_REWRITTEN_UNEQUAL_OPERATOR
439 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) ITK_MACROEND_NOOP_STATEMENT
443 # define ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(TypeName) \
444 bool operator!=(const TypeName & other) const { return !(this->operator==(other)); } \
445 ITK_MACROEND_NOOP_STATEMENT
450 #define itkTypeMacro(thisClass, superclass) \
451 const char * GetNameOfClass() const override { return #thisClass; } \
452 ITK_MACROEND_NOOP_STATEMENT
454 #define itkTypeMacroNoParent(thisClass) \
455 virtual const char * GetNameOfClass() const { return #thisClass; } \
456 ITK_MACROEND_NOOP_STATEMENT
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 *);
489 # define itkDebugMacro(x) ITK_NOOP_STATEMENT
490 # define itkDebugStatement(x) ITK_NOOP_STATEMENT
492 # define itkDebugMacro(x) \
495 if (this->GetDebug() && itk::Object::GetGlobalWarningDisplay()) \
497 std::ostringstream itkmsg; \
498 itkmsg << "Debug: In " __FILE__ ", line " << __LINE__ << '\n' \
499 << this->GetNameOfClass() << " (" << this << "): " x << "\n\n"; \
500 itk::OutputWindowDisplayDebugText(itkmsg.str().c_str()); \
507 # define itkDebugStatement(x) x
513 #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()); \
526 #define itkWarningStatement(x) x
528 #if defined(ITK_CPP_FUNCTION)
529 # if defined(_WIN32) && !defined(__MINGW32__) && !defined(ITK_WRAPPING_PARSER)
530 # define ITK_LOCATION __FUNCSIG__
531 # elif defined(__GNUC__)
532 # define ITK_LOCATION __PRETTY_FUNCTION__
534 # define ITK_LOCATION __FUNCTION__
537 # define ITK_LOCATION "unknown"
540 #define itkDeclareExceptionMacro(newexcp, parentexcp, whatmessage) \
543 class newexcp : public parentexcp \
547 static constexpr const char * const default_exception_message = whatmessage; \
549 using parentexcp::parentexcp; \
550 itkTypeMacro(newexcp, parentexcp); \
553 ITK_MACROEND_NOOP_STATEMENT
556 #define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
558 std::ostringstream exceptionDescriptionOutputStringStream; \
559 exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
560 throw itk::ExceptionType( \
561 std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
563 ITK_MACROEND_NOOP_STATEMENT
565 #define itkSpecializedExceptionMacro(ExceptionType) \
566 itkSpecializedMessageExceptionMacro(ExceptionType, << itk::ExceptionType::default_exception_message)
571 #define itkExceptionMacro(x) \
572 itkSpecializedMessageExceptionMacro(ExceptionObject, << this->GetNameOfClass() << '(' << this << "): " x)
574 #define itkGenericExceptionMacro(x) itkSpecializedMessageExceptionMacro(ExceptionObject, x)
576 #define itkGenericOutputMacro(x) \
578 if (itk::Object::GetGlobalWarningDisplay()) \
580 std::ostringstream itkmsg; \
581 itkmsg << "WARNING: In " __FILE__ ", line " << __LINE__ << "\n" x << "\n\n"; \
582 itk::OutputWindowDisplayGenericOutputText(itkmsg.str().c_str()); \
585 ITK_MACROEND_NOOP_STATEMENT
590 #define itkLogMacro(x, y) \
592 if (this->GetLogger()) \
594 this->GetLogger()->Write(itk::LoggerBase::x, y); \
597 ITK_MACROEND_NOOP_STATEMENT
599 #define itkLogMacroStatic(obj, x, y) \
601 if (obj->GetLogger()) \
603 obj->GetLogger()->Write(itk::LoggerBase::x, y); \
606 ITK_MACROEND_NOOP_STATEMENT
637 #if defined(ITK_LEGACY_REMOVE)
638 # define itkLegacyMacro(method)
640 # if defined(ITK_LEGACY_SILENT) || defined(ITK_LEGACY_TEST)
642 # define itkLegacyMacro(method) method
645 # define itkLegacyMacro(method) [[deprecated]] method
671 #if defined(ITK_LEGACY_SILENT)
672 # define itkLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
673 # define itkLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
674 # define itkGenericLegacyBodyMacro(method, version) ITK_NOOP_STATEMENT
675 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) ITK_NOOP_STATEMENT
677 # define itkLegacyBodyMacro(method, version) \
678 itkWarningMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
679 # define itkLegacyReplaceBodyMacro(method, version, replace) \
680 itkWarningMacro(#method " was deprecated for ITK " #version \
681 " and will be removed in a future version. Use " #replace " instead.")
682 # define itkGenericLegacyBodyMacro(method, version) \
683 itkGenericOutputMacro(#method " was deprecated for ITK " #version " and will be removed in a future version.")
684 # define itkGenericLegacyReplaceBodyMacro(method, version, replace) \
685 itkGenericOutputMacro(#method " was deprecated for ITK " #version \
686 " and will be removed in a future version. Use " #replace " instead.")
693 #define ITK_CACHE_LINE_ALIGNMENT 64
701 #define itkPadStruct(mincachesize, oldtype, newtype) \
702 struct newtype : public oldtype \
704 char _StructPadding[mincachesize - (sizeof(oldtype) % mincachesize)]; \
711 #if defined(ITK_HAS_GNU_ATTRIBUTE_ALIGNED)
712 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype __attribute__((aligned(alignment)))
713 #elif defined(_MSC_VER)
714 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = __declspec(align(alignment)) oldtype
716 # define itkAlignedTypedef(alignment, oldtype, newtype) using newtype = oldtype
719 #if defined(ITK_FUTURE_LEGACY_REMOVE)
742 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) < >
743 #else // LEGACY_REMOVE
744 # define ITK_FRIEND_TEMPLATE_FUNCTION_ARGUMENT(T) "Macro remove use C++11 compliant declaration of "
760 #define itkForLoopAssignmentMacro( \
761 DestinationType, SourceType, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
762 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
764 DestinationArray[i] = static_cast<DestinationElementType>(SourceArray[i]); \
776 #define itkForLoopRoundingAndAssignmentMacro( \
777 DestinationType, Sourcrnd_halfintup, DestinationElementType, DestinationArray, SourceArray, NumberOfIterations) \
778 for (unsigned int i = 0; i < NumberOfIterations; ++i) \
780 DestinationArray[i] = itk::Math::Round<DestinationElementType>(SourceArray[i]); \
785 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
788 # define itkAssertInDebugOrThrowInReleaseMacro(msg) __assert_fail(msg, __FILE__, __LINE__, __ASSERT_FUNCTION);
790 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
794 # define itkAssertInDebugOrThrowInReleaseMacro(msg) itkGenericExceptionMacro(<< msg);
797 #define itkAssertOrThrowMacro(test, message) \
800 std::ostringstream msgstr; \
802 itkAssertInDebugOrThrowInReleaseMacro(msgstr.str().c_str()); \
804 ITK_MACROEND_NOOP_STATEMENT
806 #if !defined(NDEBUG) && !defined(ITK_WRAPPING)
807 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) assert(X)
809 # define itkAssertInDebugAndIgnoreInReleaseMacro(X) ITK_NOOP_STATEMENT
819 #ifdef ITK_FUTURE_LEGACY_REMOVE
820 # define itkStaticConstMacro(name, type, value) \
821 "Replace itkStaticConstMacro(name, type, value) with `static constexpr type name = value`"
822 # define itkGetStaticConstMacro(name) "Replace itkGetStaticConstMacro(name) with `Self::name`"
838 # define itkStaticConstMacro(name, type, value) static constexpr type name = value
840 # define itkGetStaticConstMacro(name) (Self::name)
844 #define itkSetInputMacro(name, type) \
845 virtual void Set##name(const type * _arg) \
847 itkDebugMacro("setting input " #name " to " << _arg); \
848 if (_arg != itkDynamicCastInDebugMode<type *>(this->ProcessObject::GetInput(#name))) \
850 this->ProcessObject::SetInput(#name, const_cast<type *>(_arg)); \
854 ITK_MACROEND_NOOP_STATEMENT
858 #define itkGetInputMacro(name, type) \
859 virtual const type * Get##name() const \
861 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
862 return itkDynamicCastInDebugMode<const type *>(this->ProcessObject::GetInput(#name)); \
864 ITK_MACROEND_NOOP_STATEMENT
869 #define itkSetDecoratedInputMacro(name, type) \
870 virtual void Set##name##Input(const SimpleDataObjectDecorator<type> * _arg) \
872 itkDebugMacro("setting input " #name " to " << _arg); \
873 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
875 this->ProcessObject::SetInput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
879 virtual void Set##name(const SimpleDataObjectDecorator<type> * _arg) { this->Set##name##Input(_arg); } \
880 virtual void Set##name(const type & _arg) \
882 using DecoratorType = SimpleDataObjectDecorator<type>; \
883 itkDebugMacro("setting input " #name " to " << _arg); \
884 const DecoratorType * oldInput = \
885 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
887 CLANG_SUPPRESS_Wfloat_equal \
888 if (oldInput && oldInput->Get() == _arg) \
893 auto newInput = DecoratorType::New(); \
894 newInput->Set(_arg); \
895 this->Set##name##Input(newInput); \
897 ITK_MACROEND_NOOP_STATEMENT
902 #define itkGetDecoratedInputMacro(name, type) \
903 virtual const SimpleDataObjectDecorator<type> * Get##name##Input() const \
905 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
906 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
908 virtual const type & Get##name() const \
910 itkDebugMacro("Getting input " #name); \
911 using DecoratorType = SimpleDataObjectDecorator<type>; \
912 const DecoratorType * input = \
913 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
914 if (input == nullptr) \
916 itkExceptionMacro(<< "input" #name " is not set"); \
918 return input->Get(); \
920 ITK_MACROEND_NOOP_STATEMENT
925 #define itkSetGetDecoratedInputMacro(name, type) \
926 itkSetDecoratedInputMacro(name, type); \
927 itkGetDecoratedInputMacro(name, type)
933 #define itkSetDecoratedObjectInputMacro(name, type) \
934 virtual void Set##name##Input(const DataObjectDecorator<type> * _arg) \
936 itkDebugMacro("setting input " #name " to " << _arg); \
937 if (_arg != itkDynamicCastInDebugMode<DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name))) \
939 this->ProcessObject::SetInput(#name, const_cast<DataObjectDecorator<type> *>(_arg)); \
943 virtual void Set##name(const type * _arg) \
945 using DecoratorType = DataObjectDecorator<type>; \
946 itkDebugMacro("setting input " #name " to " << _arg); \
947 const DecoratorType * oldInput = \
948 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
949 if (oldInput && oldInput->Get() == _arg) \
953 auto newInput = DecoratorType::New(); \
954 newInput->Set(_arg); \
955 this->Set##name##Input(newInput); \
957 ITK_MACROEND_NOOP_STATEMENT
964 #define itkGetDecoratedObjectInputMacro(name, type) \
965 virtual const DataObjectDecorator<type> * Get##name##Input() const \
967 itkDebugMacro("returning input " << #name " of " << this->ProcessObject::GetInput(#name)); \
968 return itkDynamicCastInDebugMode<const DataObjectDecorator<type> *>(this->ProcessObject::GetInput(#name)); \
970 virtual const type * Get##name() const \
972 itkDebugMacro("Getting input " #name); \
973 using DecoratorType = DataObjectDecorator<type>; \
974 const DecoratorType * input = \
975 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetInput(#name)); \
976 if (input == nullptr) \
980 return input->Get(); \
982 ITK_MACROEND_NOOP_STATEMENT
987 #define itkSetGetDecoratedObjectInputMacro(name, type) \
988 itkSetDecoratedObjectInputMacro(name, type); \
989 itkGetDecoratedObjectInputMacro(name, type)
993 #define itkSetMacro(name, type) \
994 virtual void Set##name(const type _arg) \
996 itkDebugMacro("setting " #name " to " << _arg); \
998 CLANG_SUPPRESS_Wfloat_equal \
999 if (this->m_##name != _arg) \
1001 this->m_##name = _arg; \
1006 ITK_MACROEND_NOOP_STATEMENT
1010 #define itkGetMacro(name, type) \
1011 virtual type Get##name() { return this->m_##name; } \
1012 ITK_MACROEND_NOOP_STATEMENT
1018 #define itkGetConstMacro(name, type) \
1019 virtual type Get##name() const { return this->m_##name; } \
1020 ITK_MACROEND_NOOP_STATEMENT
1027 #define itkGetConstReferenceMacro(name, type) \
1028 virtual const type & Get##name() const { return this->m_##name; } \
1029 ITK_MACROEND_NOOP_STATEMENT
1036 #define itkSetEnumMacro(name, type) \
1037 virtual void Set##name(const type _arg) \
1039 itkDebugMacro("setting " #name " to " << static_cast<long>(_arg)); \
1040 if (this->m_##name != _arg) \
1042 this->m_##name = _arg; \
1046 ITK_MACROEND_NOOP_STATEMENT
1053 #define itkGetEnumMacro(name, type) \
1054 virtual type Get##name() const { return this->m_##name; } \
1055 ITK_MACROEND_NOOP_STATEMENT
1061 #define itkSetStringMacro(name) \
1062 virtual void Set##name(const char * _arg) \
1064 if (_arg && (_arg == this->m_##name)) \
1070 this->m_##name = _arg; \
1074 this->m_##name = ""; \
1078 virtual void Set##name(const std::string & _arg) { this->Set##name(_arg.c_str()); } \
1079 ITK_MACROEND_NOOP_STATEMENT
1086 #define itkGetStringMacro(name) \
1087 virtual const char * Get##name() const { return this->m_##name.c_str(); } \
1088 ITK_MACROEND_NOOP_STATEMENT
1094 #define itkSetClampMacro(name, type, min, max) \
1095 virtual void Set##name(type _arg) \
1097 const type temp_extrema = (_arg <= min ? min : (_arg >= max ? max : _arg)); \
1098 itkDebugMacro("setting " << #name " to " << _arg); \
1100 CLANG_SUPPRESS_Wfloat_equal \
1101 if (this->m_##name != temp_extrema) \
1103 this->m_##name = temp_extrema; \
1108 ITK_MACROEND_NOOP_STATEMENT
1117 #define itkSetObjectMacro(name, type) \
1118 virtual void Set##name(type * _arg) \
1120 itkDebugMacro("setting " << #name " to " << _arg); \
1121 if (this->m_##name != _arg) \
1123 this->m_##name = _arg; \
1127 ITK_MACROEND_NOOP_STATEMENT
1156 #define itkGetConstObjectMacro(name, type) \
1157 virtual const type * Get##name() const { return this->m_##name.GetPointer(); } \
1158 ITK_MACROEND_NOOP_STATEMENT
1161 #if defined(ITK_FUTURE_LEGACY_REMOVE)
1167 # define itkGetObjectMacro(name, type) \
1168 virtual type * Get##name() \
1170 purposeful_error("itkGetObjectMacro should be replaced with itkGetModifiableObjectMacro."); \
1173 # define itkGetModifiableObjectMacro(name, type) \
1174 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1175 itkGetConstObjectMacro(name, type)
1177 #else // defined ( ITK_FUTURE_LEGACY_REMOVE )
1180 # define itkGetObjectMacro(name, type) \
1181 virtual type * Get##name() { return this->m_##name.GetPointer(); } \
1182 ITK_MACROEND_NOOP_STATEMENT
1183 # define itkGetModifiableObjectMacro(name, type) \
1184 virtual type * GetModifiable##name() { return this->m_##name.GetPointer(); } \
1185 itkGetConstObjectMacro(name, type); \
1186 itkGetObjectMacro(name, type)
1187 #endif // defined ( ITK_FUTURE_LEGACY_REMOVE )
1196 #define itkGetConstReferenceObjectMacro(name, type) \
1197 virtual const typename type::Pointer & Get##name() const { return this->m_##name; } \
1198 ITK_MACROEND_NOOP_STATEMENT
1204 #define itkSetConstObjectMacro(name, type) \
1205 virtual void Set##name(const type * _arg) \
1207 itkDebugMacro("setting " << #name " to " << _arg); \
1208 if (this->m_##name != _arg) \
1210 this->m_##name = _arg; \
1214 ITK_MACROEND_NOOP_STATEMENT
1219 #define itkBooleanMacro(name) \
1220 virtual void name##On() { this->Set##name(true); } \
1221 virtual void name##Off() { this->Set##name(false); }
1228 #define itkSetVectorMacro(name, type, count) \
1229 virtual void Set##name(type data[]) \
1232 for (i = 0; i < count; ++i) \
1235 CLANG_SUPPRESS_Wfloat_equal \
1236 if (data[i] != this->m_##name[i]) \
1245 for (i = 0; i < count; ++i) \
1247 this->m_##name[i] = data[i]; \
1251 ITK_MACROEND_NOOP_STATEMENT
1257 #define itkGetVectorMacro(name, type, count) \
1258 virtual type * Get##name() const { return this->m_##name; } \
1259 ITK_MACROEND_NOOP_STATEMENT
1265 #define itkGPUKernelClassMacro(kernel) class itkGPUKernelMacro(kernel)
1272 #define itkGPUKernelMacro(kernel) \
1276 ITK_DISALLOW_COPY_AND_MOVE(kernel); \
1277 kernel() = delete; \
1278 ~kernel() = delete; \
1279 static const char * GetOpenCLSource(); \
1283 #define itkGetOpenCLSourceFromKernelMacro(kernel) \
1284 static const char * GetOpenCLSource() { return kernel::GetOpenCLSource(); }
1288 #define itkPrintSelfObjectMacro(name) \
1289 if (static_cast<const LightObject *>(this->m_##name) == nullptr) \
1291 os << indent << #name << ": (null)" << std::endl; \
1295 os << indent << #name << ": " << std::endl; \
1296 this->m_##name->Print(os, indent.GetNextIndent()); \
1298 ITK_MACROEND_NOOP_STATEMENT
1302 #define itkSetDecoratedOutputMacro(name, type) \
1303 virtual void Set##name##Output(const SimpleDataObjectDecorator<type> * _arg) \
1305 itkDebugMacro("setting output " #name " to " << _arg); \
1306 if (_arg != itkDynamicCastInDebugMode<SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name))) \
1308 this->ProcessObject::SetOutput(#name, const_cast<SimpleDataObjectDecorator<type> *>(_arg)); \
1312 virtual void Set##name(const type & _arg) \
1314 using DecoratorType = SimpleDataObjectDecorator<type>; \
1315 itkDebugMacro("setting output " #name " to " << _arg); \
1316 DecoratorType * output = itkDynamicCastInDebugMode<DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1319 if (output->Get() == _arg) \
1325 output->Set(_arg); \
1330 auto newOutput = DecoratorType::New(); \
1331 newOutput->Set(_arg); \
1332 this->Set##name##Output(newOutput); \
1335 ITK_MACROEND_NOOP_STATEMENT
1339 #define itkGetDecoratedOutputMacro(name, type) \
1340 virtual const SimpleDataObjectDecorator<type> * Get##name##Output() const \
1342 itkDebugMacro("returning output " << #name " of " << this->ProcessObject::GetOutput(#name)); \
1343 return itkDynamicCastInDebugMode<const SimpleDataObjectDecorator<type> *>(this->ProcessObject::GetOutput(#name)); \
1345 virtual const type & Get##name() const \
1347 itkDebugMacro("Getting output " #name); \
1348 using DecoratorType = SimpleDataObjectDecorator<type>; \
1349 const DecoratorType * output = \
1350 itkDynamicCastInDebugMode<const DecoratorType *>(this->ProcessObject::GetOutput(#name)); \
1351 if (output == nullptr) \
1353 itkExceptionMacro(<< "output" #name " is not set"); \
1355 return output->Get(); \
1357 ITK_MACROEND_NOOP_STATEMENT
1370 #if defined(ITKV4_COMPATIBILITY)
1371 # define ITK_ITERATOR_VIRTUAL virtual
1372 # define ITK_ITERATOR_OVERRIDE override
1373 # define ITK_ITERATOR_FINAL
1374 #elif !defined(ITK_LEGACY_REMOVE)
1375 # define ITK_ITERATOR_VIRTUAL virtual
1376 # define ITK_ITERATOR_OVERRIDE override
1377 # define ITK_ITERATOR_FINAL final
1379 # define ITK_ITERATOR_VIRTUAL
1380 # define ITK_ITERATOR_OVERRIDE
1381 # define ITK_ITERATOR_FINAL
1384 #if defined(ITKV4_COMPATIBILITY)
1386 # define ITKv5_CONST
1389 # define ITKv5_CONST const
1392 #define itkExceptionObject_h
1394 #undef itkExceptionObject_h
1403 template <
typename TTarget,
typename TSource>
1405 itkDynamicCastInDebugMode(TSource x)
1412 TTarget rval = dynamic_cast<TTarget>(x);
1413 if (rval ==
nullptr)
1415 itkGenericExceptionMacro(<<
"Failed dynamic cast to " <<
typeid(TTarget).name()
1416 <<
" object type = " << x->GetNameOfClass());
1420 return static_cast<TTarget>(x);
1426 #define ITK_ALIGNAS(X) alignas(X)
1427 #define ITK_ALIGNOF(X) alignof(X)
1428 #define ITK_DEPRECATED [[deprecated]]
1429 #define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
1430 #define ITK_CONSTEXPR constexpr
1431 #define ITK_DELETED_FUNCTION = delete
1432 #define ITK_EXTERN_TEMPLATE extern
1433 #define ITK_FINAL final
1434 #define ITK_NOEXCEPT noexcept
1435 #define ITK_NOEXCEPT_EXPR(X) noexcept(X)
1436 #define ITK_NULLPTR nullptr
1437 #define ITK_OVERRIDE override
1438 #define ITK_STATIC_ASSERT(X) static_assert(X, #X)
1439 #define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
1440 #define ITK_THREAD_LOCAL thread_local
1442 #endif // end of itkMacro.h