From bf143870abc31e6f7d5872aa8f0c34831c5c41f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C5=BEenan=20Zuki=C4=87?= Date: Tue, 19 Sep 2023 16:01:10 -0400 Subject: [PATCH] ENH: Wrap LabelSetMeasures in LabelOverlapMeasuresImageFilter This exposes the return value from itk::LabelOverlapMeasuresImageFilter::GetLabelSetMeasures() as a Python dictionary instead of *'> This is needed for convenient use of the class from Python. The class has been un-nested to make wrapping easier/possible. --- .../itkLabelOverlapMeasuresImageFilter.h | 37 +++++++++++-------- .../ImageStatistics/wrapping/CMakeLists.txt | 4 ++ .../itkLabelOverlapMeasuresImageFilter.i | 10 +++++ ...pMeasuresImageFilter_LabelSetMeasures.wrap | 4 ++ Wrapping/Generators/Python/PyBase/pyBase.i | 1 + 5 files changed, 40 insertions(+), 16 deletions(-) create mode 100644 Modules/Filtering/ImageStatistics/wrapping/itkLabelOverlapMeasuresImageFilter.i create mode 100644 Modules/Filtering/ImageStatistics/wrapping/itkLabelOverlapMeasuresImageFilter_LabelSetMeasures.wrap diff --git a/Modules/Filtering/ImageStatistics/include/itkLabelOverlapMeasuresImageFilter.h b/Modules/Filtering/ImageStatistics/include/itkLabelOverlapMeasuresImageFilter.h index 5a7ea64dcead..5277cfcae04d 100644 --- a/Modules/Filtering/ImageStatistics/include/itkLabelOverlapMeasuresImageFilter.h +++ b/Modules/Filtering/ImageStatistics/include/itkLabelOverlapMeasuresImageFilter.h @@ -25,6 +25,22 @@ namespace itk { +/** \class LabelOverlapLabelSetMeasures + * \brief Metrics stored per label + * \ingroup ITKImageStatistics + */ +class LabelOverlapLabelSetMeasures +{ +public: + // default constructor/copy/move etc... + + SizeValueType m_Source{ 0 }; + SizeValueType m_Target{ 0 }; + SizeValueType m_Union{ 0 }; + SizeValueType m_Intersection{ 0 }; + SizeValueType m_SourceComplement{ 0 }; + SizeValueType m_TargetComplement{ 0 }; +}; /** \class LabelOverlapMeasuresImageFilter * \brief Computes overlap measures between the set same set of labels of @@ -73,25 +89,14 @@ class ITK_TEMPLATE_EXPORT LabelOverlapMeasuresImageFilter : public ImageSink::RealType; - /** \class LabelSetMeasures - * \brief Metrics stored per label - * \ingroup ITKImageStatistics - */ - class LabelSetMeasures - { - public: - // default constructor/copy/move etc... +#ifndef ITK_FUTURE_LEGACY_REMOVE + /** Type to use for computations. */ + using LabelSetMeasures = LabelOverlapLabelSetMeasures; +#endif // !ITK_FUTURE_LEGACY_REMOVE - SizeValueType m_Source{ 0 }; - SizeValueType m_Target{ 0 }; - SizeValueType m_Union{ 0 }; - SizeValueType m_Intersection{ 0 }; - SizeValueType m_SourceComplement{ 0 }; - SizeValueType m_TargetComplement{ 0 }; - }; /** Type of the map used to store data per label */ - using MapType = std::unordered_map; + using MapType = std::unordered_map; using MapIterator = typename MapType::iterator; using MapConstIterator = typename MapType::const_iterator; diff --git a/Modules/Filtering/ImageStatistics/wrapping/CMakeLists.txt b/Modules/Filtering/ImageStatistics/wrapping/CMakeLists.txt index 61d2168cffbd..52986d8dd3ed 100644 --- a/Modules/Filtering/ImageStatistics/wrapping/CMakeLists.txt +++ b/Modules/Filtering/ImageStatistics/wrapping/CMakeLists.txt @@ -1,2 +1,6 @@ itk_wrap_module(ITKImageStatistics) +if(ITK_WRAP_PYTHON) + set(WRAPPER_SUBMODULE_ORDER itkLabelOverlapMeasuresImageFilter_LabelSetMeasures) + list(APPEND WRAPPER_SWIG_LIBRARY_FILES "${CMAKE_CURRENT_LIST_DIR}/itkLabelOverlapMeasuresImageFilter.i") +endif() itk_auto_load_and_end_wrap_submodules() diff --git a/Modules/Filtering/ImageStatistics/wrapping/itkLabelOverlapMeasuresImageFilter.i b/Modules/Filtering/ImageStatistics/wrapping/itkLabelOverlapMeasuresImageFilter.i new file mode 100644 index 000000000000..bbd3312e8b32 --- /dev/null +++ b/Modules/Filtering/ImageStatistics/wrapping/itkLabelOverlapMeasuresImageFilter.i @@ -0,0 +1,10 @@ +%include + +%template(hashmapUCLOLSM) std::unordered_map< unsigned char, itk::LabelOverlapLabelSetMeasures >; +%template(hashmapSCLOLSM) std::unordered_map< signed char, itk::LabelOverlapLabelSetMeasures >; +%template(hashmapUSLOLSM) std::unordered_map< unsigned short, itk::LabelOverlapLabelSetMeasures >; +%template(hashmapSSLOLSM) std::unordered_map< signed short, itk::LabelOverlapLabelSetMeasures >; +%template(hashmapULLOLSM) std::unordered_map< unsigned long, itk::LabelOverlapLabelSetMeasures >; +%template(hashmapSLLOLSM) std::unordered_map< signed long, itk::LabelOverlapLabelSetMeasures >; +%template(hashmapULLLOLSM) std::unordered_map< unsigned long long, itk::LabelOverlapLabelSetMeasures >; +%template(hashmapSLLLOLSM) std::unordered_map< signed long long, itk::LabelOverlapLabelSetMeasures >; diff --git a/Modules/Filtering/ImageStatistics/wrapping/itkLabelOverlapMeasuresImageFilter_LabelSetMeasures.wrap b/Modules/Filtering/ImageStatistics/wrapping/itkLabelOverlapMeasuresImageFilter_LabelSetMeasures.wrap new file mode 100644 index 000000000000..4613e0f31583 --- /dev/null +++ b/Modules/Filtering/ImageStatistics/wrapping/itkLabelOverlapMeasuresImageFilter_LabelSetMeasures.wrap @@ -0,0 +1,4 @@ +set(WRAPPER_AUTO_INCLUDE_HEADERS OFF) +itk_wrap_include("itkLabelOverlapMeasuresImageFilter.h") +itk_wrap_simple_class("itk::LabelOverlapLabelSetMeasures") +set(WRAPPER_AUTO_INCLUDE_HEADERS ON) diff --git a/Wrapping/Generators/Python/PyBase/pyBase.i b/Wrapping/Generators/Python/PyBase/pyBase.i index 431f4632d43a..b69b0fbf0e61 100644 --- a/Wrapping/Generators/Python/PyBase/pyBase.i +++ b/Wrapping/Generators/Python/PyBase/pyBase.i @@ -23,6 +23,7 @@ from . import _ITKCommonPython %include %include %include +%include %include %include