From dfb675a9f8b9f89dedf85c321c0e1545d803e690 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Fri, 7 Jun 2024 05:15:01 +0100 Subject: [PATCH 1/5] add fall-through for Array::is_contiguous() (#1446) Make sure it always returns `true` when getting out of the loop. Fixing my suggestion to @markus-jehl (sorry!) --- src/include/stir/Array.inl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/include/stir/Array.inl b/src/include/stir/Array.inl index b7591166c..ee778dbd1 100644 --- a/src/include/stir/Array.inl +++ b/src/include/stir/Array.inl @@ -49,6 +49,7 @@ Array::is_contiguous() const if (mem != &(*(*this)[i + 1].begin_all())) return false; } + return true; } template From 93615c83f54d40f43cb7b0a7e082c62272c7e7fb Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Fri, 7 Jun 2024 05:19:09 +0100 Subject: [PATCH 2/5] add all apply/undo from BinNormalisation Most derived classes did not have `apply(ProjData&)` etc. Fixes #1175 --- .../recon_buildblock/BinNormalisationFromAttenuationImage.h | 3 +++ .../stir/recon_buildblock/BinNormalisationFromProjData.h | 5 ++++- .../recon_buildblock/BinNormalisationPETFromComponents.h | 5 ++++- src/include/stir/recon_buildblock/BinNormalisationSPECT.h | 4 ++++ src/include/stir/recon_buildblock/ChainedBinNormalisation.h | 5 ++++- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/include/stir/recon_buildblock/BinNormalisationFromAttenuationImage.h b/src/include/stir/recon_buildblock/BinNormalisationFromAttenuationImage.h index 22ea0ac35..54ec70f4e 100644 --- a/src/include/stir/recon_buildblock/BinNormalisationFromAttenuationImage.h +++ b/src/include/stir/recon_buildblock/BinNormalisationFromAttenuationImage.h @@ -89,7 +89,10 @@ class BinNormalisationFromAttenuationImage */ Succeeded set_up(const shared_ptr& exam_info_sptr, const shared_ptr&) override; + // import all apply/undo methods from base-class (we'll override some below) using base_type::apply; + using base_type::undo; + //! Normalise some data /*! This means \c multiply with the data in the projdata object diff --git a/src/include/stir/recon_buildblock/BinNormalisationFromProjData.h b/src/include/stir/recon_buildblock/BinNormalisationFromProjData.h index f8844258f..3e3edecd7 100644 --- a/src/include/stir/recon_buildblock/BinNormalisationFromProjData.h +++ b/src/include/stir/recon_buildblock/BinNormalisationFromProjData.h @@ -81,12 +81,15 @@ class BinNormalisationFromProjData : public RegisteredParsingObject& exam_info_sptr, const shared_ptr&) override; + // import all apply/undo methods from base-class (we'll override some below) + using base_type::apply; + using base_type::undo; + //! Normalise some data /*! This means \c multiply with the data in the projdata object passed in the constructor. */ - void apply(RelatedViewgrams& viewgrams) const override; //! Undo the normalisation of some data diff --git a/src/include/stir/recon_buildblock/BinNormalisationPETFromComponents.h b/src/include/stir/recon_buildblock/BinNormalisationPETFromComponents.h index 329a1ef05..c77bf4f95 100644 --- a/src/include/stir/recon_buildblock/BinNormalisationPETFromComponents.h +++ b/src/include/stir/recon_buildblock/BinNormalisationPETFromComponents.h @@ -98,11 +98,14 @@ class BinNormalisationPETFromComponents : public BinNormalisation /*! Compares the stored ProjDataInfo with the ProjDataInfo supplied. */ Succeeded set_up(const shared_ptr& exam_info_sptr, const shared_ptr&) override; + // import all apply/undo methods from base-class (we'll override some below) + using base_type::apply; + using base_type::undo; + //! Normalise some data /*! This means \c divide with the efficiency model. 0/0 is set to 0. */ - void apply(RelatedViewgrams& viewgrams) const override; using base_type::apply; diff --git a/src/include/stir/recon_buildblock/BinNormalisationSPECT.h b/src/include/stir/recon_buildblock/BinNormalisationSPECT.h index 8c89af475..dbe94a7c5 100644 --- a/src/include/stir/recon_buildblock/BinNormalisationSPECT.h +++ b/src/include/stir/recon_buildblock/BinNormalisationSPECT.h @@ -58,6 +58,10 @@ class BinNormalisationSPECT float get_dead_time_efficiency(const DetectionPosition<>& det_pos, const double start_time, const double end_time) const; + // import all apply/undo methods from base-class (we'll override some below) + using base_type::apply; + using base_type::undo; + void apply(RelatedViewgrams& viewgrams) const override; void undo(RelatedViewgrams& viewgrams) const override; diff --git a/src/include/stir/recon_buildblock/ChainedBinNormalisation.h b/src/include/stir/recon_buildblock/ChainedBinNormalisation.h index 0ecf59cce..64d62ea2a 100644 --- a/src/include/stir/recon_buildblock/ChainedBinNormalisation.h +++ b/src/include/stir/recon_buildblock/ChainedBinNormalisation.h @@ -90,11 +90,14 @@ class ChainedBinNormalisation : public RegisteredParsingObject& exam_info_sptr, const shared_ptr&) override; + // import all apply/undo methods from base-class (we'll override some below) + using base_type::apply; + using base_type::undo; + //! Normalise some data /*! This calls apply() of the 2 BinNormalisation members */ - void apply(RelatedViewgrams& viewgrams) const override; #if 0 virtual void apply(ProjData&) const override; From 332a274cfd532082fcff123843890cd3c7e65fc6 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Fri, 7 Jun 2024 05:23:48 +0100 Subject: [PATCH 3/5] small correction to doxygen --- src/include/stir/Array.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/stir/Array.h b/src/include/stir/Array.h index 1fbe148a8..f0c904438 100644 --- a/src/include/stir/Array.h +++ b/src/include/stir/Array.h @@ -143,7 +143,7 @@ class Array : public NumericVectorWithOffset, e \c data_sptr.get() block. Therefore, any modifications to the array will modify the data at \c data_sptr.get(). This will be true until the Array is resized. - The C-array \data_ptr will be accessed with the last dimension running fastest + The C-array \a data_ptr will be accessed with the last dimension running fastest ("row-major" order). */ inline Array(const IndexRange& range, shared_ptr data_sptr); From 93738ccd80a5b0227ec61ff7eac89cd8e82cfd79 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Fri, 7 Jun 2024 05:27:29 +0100 Subject: [PATCH 4/5] [SWIG] re-ordering of includes to fix doc DataSymmetriesForViewSegmentNumbers.h was included after stir_projdata.i, meaning that `get_related_viewgrams` had documentation problems. --- src/swig/CMakeLists.txt | 2 ++ src/swig/stir.i | 3 ++- src/swig/stir_projdata.i | 34 +----------------------- src/swig/stir_projdata_coords.i | 46 +++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 src/swig/stir_projdata_coords.i diff --git a/src/swig/CMakeLists.txt b/src/swig/CMakeLists.txt index 4110241d6..396dd0c2b 100644 --- a/src/swig/CMakeLists.txt +++ b/src/swig/CMakeLists.txt @@ -92,9 +92,11 @@ set(swig_stir_dependencies stir_coordinates.i stir_dataprocessors.i stir_exam.i + stir_LOR.i stir_normalisation.i stir_objectivefunctions.i stir_priors.i + stir_projdata_coords.i stir_projdata.i stir_listmode.i stir_projectors.i diff --git a/src/swig/stir.i b/src/swig/stir.i index a90824e9b..3047e4e1c 100644 --- a/src/swig/stir.i +++ b/src/swig/stir.i @@ -1036,9 +1036,10 @@ ADD_REPR(stir::Succeeded, %arg($self->succeeded() ? "yes" : "no")); %include "stir_exam.i" %shared_ptr(stir::DataSymmetriesForViewSegmentNumbers); +%include "stir_projdata_coords.i" +%include "stir/DataSymmetriesForViewSegmentNumbers.h" %include "stir_projdata.i" %include "stir_listmode.i" -%include "stir/DataSymmetriesForViewSegmentNumbers.h" %include "stir_voxels.i" %include "stir_voxels_IO.i" diff --git a/src/swig/stir_projdata.i b/src/swig/stir_projdata.i index 6a1e0eb43..2166c03f5 100644 --- a/src/swig/stir_projdata.i +++ b/src/swig/stir_projdata.i @@ -34,39 +34,6 @@ %shared_ptr(stir::Sinogram); %shared_ptr(stir::Viewgram); -%shared_ptr(stir::DetectionPosition); -%shared_ptr(stir::DetectionPositionPair); - -%attributeref(stir::DetectionPosition, unsigned int, tangential_coord); -%attributeref(stir::DetectionPosition, unsigned int, axial_coord); -%attributeref(stir::DetectionPosition, unsigned int, radial_coord); -%include "stir/DetectionPosition.h" -ADD_REPR(stir::DetectionPosition, %arg(*$self)) -%template(DetectionPosition) stir::DetectionPosition; - -%attributeref(stir::DetectionPositionPair, int, timing_pos); -%attributeref(stir::DetectionPositionPair, stir::DetectionPosition, pos1); -%attributeref(stir::DetectionPositionPair, stir::DetectionPosition, pos2); -%include "stir/DetectionPositionPair.h" -ADD_REPR(stir::DetectionPositionPair, %arg(*$self)) -%template(DetectionPositionPair) stir::DetectionPositionPair; - -%attributeref(stir::SegmentIndices, int, segment_num); -%attributeref(stir::SegmentIndices, int, timing_pos_num); -%attributeref(stir::ViewgramIndices, int, view_num); -%attributeref(stir::SinogramIndices, int, axial_pos_num); -%attributeref(stir::Bin, int, axial_pos_num); -%attributeref(stir::Bin, int, tangential_pos_num); -%attributeref(stir::Bin, int, timing_pos_num); -%attributeref(stir::Bin, int, time_frame_num); -%attribute(stir::Bin, float, bin_value, get_bin_value, set_bin_value); -%include "stir/SegmentIndices.h" -%include "stir/ViewgramIndices.h" -%include "stir/SinogramIndices.h" -%include "stir/Bin.h" -ADD_REPR(stir::Bin, %arg(*$self)) - - %newobject stir::Scanner::get_scanner_from_name; %include "stir/Scanner.h" @@ -264,6 +231,7 @@ namespace stir { namespace stir { %template(FloatViewgram) Viewgram; + %template(FloatRelatedViewgrams) RelatedViewgrams; %template(FloatSinogram) Sinogram; // TODO don't want to give a name %template(FloatSegment) Segment; diff --git a/src/swig/stir_projdata_coords.i b/src/swig/stir_projdata_coords.i new file mode 100644 index 000000000..4bb25c04e --- /dev/null +++ b/src/swig/stir_projdata_coords.i @@ -0,0 +1,46 @@ +/* + Copyright (C) 2023, 2024 University College London + This file is part of STIR. + + SPDX-License-Identifier: Apache-2.0 + + See STIR/LICENSE.txt for details +*/ +/*! + \file + \brief Interface file for SWIG: stir::Bin, stir:DetectionPosition etc + + \author Kris Thielemans +*/ + +%shared_ptr(stir::DetectionPosition); +%shared_ptr(stir::DetectionPositionPair); + +%attributeref(stir::DetectionPosition, unsigned int, tangential_coord); +%attributeref(stir::DetectionPosition, unsigned int, axial_coord); +%attributeref(stir::DetectionPosition, unsigned int, radial_coord); +%include "stir/DetectionPosition.h" +ADD_REPR(stir::DetectionPosition, %arg(*$self)) +%template(DetectionPosition) stir::DetectionPosition; + +%attributeref(stir::DetectionPositionPair, int, timing_pos); +%attributeref(stir::DetectionPositionPair, stir::DetectionPosition, pos1); +%attributeref(stir::DetectionPositionPair, stir::DetectionPosition, pos2); +%include "stir/DetectionPositionPair.h" +ADD_REPR(stir::DetectionPositionPair, %arg(*$self)) +%template(DetectionPositionPair) stir::DetectionPositionPair; + +%attributeref(stir::SegmentIndices, int, segment_num); +%attributeref(stir::SegmentIndices, int, timing_pos_num); +%attributeref(stir::ViewgramIndices, int, view_num); +%attributeref(stir::SinogramIndices, int, axial_pos_num); +%attributeref(stir::Bin, int, axial_pos_num); +%attributeref(stir::Bin, int, tangential_pos_num); +%attributeref(stir::Bin, int, timing_pos_num); +%attributeref(stir::Bin, int, time_frame_num); +%attribute(stir::Bin, float, bin_value, get_bin_value, set_bin_value); +%include "stir/SegmentIndices.h" +%include "stir/ViewgramIndices.h" +%include "stir/SinogramIndices.h" +%include "stir/Bin.h" +ADD_REPR(stir::Bin, %arg(*$self)) From d43b2efb0c40ddda3f3965c9981ab2b07ec2ce17 Mon Sep 17 00:00:00 2001 From: Kris Thielemans Date: Fri, 7 Jun 2024 06:00:42 +0100 Subject: [PATCH 5/5] remove duplication of using statements --- .../stir/recon_buildblock/BinNormalisationPETFromComponents.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/include/stir/recon_buildblock/BinNormalisationPETFromComponents.h b/src/include/stir/recon_buildblock/BinNormalisationPETFromComponents.h index c77bf4f95..714ffca9b 100644 --- a/src/include/stir/recon_buildblock/BinNormalisationPETFromComponents.h +++ b/src/include/stir/recon_buildblock/BinNormalisationPETFromComponents.h @@ -108,13 +108,12 @@ class BinNormalisationPETFromComponents : public BinNormalisation */ void apply(RelatedViewgrams& viewgrams) const override; - using base_type::apply; //! Undo the normalisation of some data /*! This means \c multiply with the efficiency model. */ void undo(RelatedViewgrams& viewgrams) const override; - using base_type::undo; + float get_bin_efficiency(const Bin& bin) const override; #if 0