Skip to content

Commit

Permalink
Merge pull request #1120 from SyneRBI/set_modality
Browse files Browse the repository at this point in the history
Implement set/get modality methods for SIRF STIR.ImageData
  • Loading branch information
KrisThielemans authored Jul 6, 2022
2 parents 2e4af20 + 759b2f3 commit 825edde
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 65 deletions.
9 changes: 4 additions & 5 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

## v3.3.0

* SPECTUBMatrix for (simple) usage in SPECT added.
* Added a new acquisition model `SPECTUBMatrix` for (simple) usage in SPECT.
`sirf.STIR.ImageData` has now a way to set/get the modality.

* interactive Python demos superseded by SIRF-Exercises notebooks removed.

* arguments setting number of CG iterations and verbosity of output
of acquisition models method norm() added.
of acquisition models method `norm()` added.

* path for ISMRMRD shared library when generating MR data fixed.

* extension processing in ISMRMRDImageData::write fixed.
* extension processing in `ISMRMRDImageData::write` fixed.

* Python int array check/conversion ensuring C++ compatibility added.

* C/Python interfaces for computing prior value added.

* STIR spect matrix added.

* Zenodo citation file added.


Expand Down
24 changes: 0 additions & 24 deletions src/common/include/sirf/common/MRImageData.h

This file was deleted.

22 changes: 0 additions & 22 deletions src/common/include/sirf/common/PETImageData.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ limitations under the License.
#include <ismrmrd/dataset.h>

#include "sirf/common/DataContainer.h"
#include "sirf/common/MRImageData.h"
#include "sirf/common/ImageData.h"
#include "sirf/common/multisort.h"
#include "sirf/Gadgetron/cgadgetron_shared_ptr.h"
#include "sirf/Gadgetron/gadgetron_image_wrap.h"
Expand Down Expand Up @@ -612,7 +612,7 @@ namespace sirf {
*/

class ISMRMRDImageData : public MRImageData {
class ISMRMRDImageData : public ImageData {
public:
//ISMRMRDImageData(ISMRMRDImageData& id, const char* attr,
//const char* target); //does not build, have to be in the derived class
Expand Down Expand Up @@ -894,7 +894,7 @@ namespace sirf {
ImageWrapIter;
typedef std::vector<gadgetron::shared_ptr<ImageWrap> >::const_iterator
ImageWrapIter_const;
class Iterator : public MRImageData::Iterator {
class Iterator : public ImageData::Iterator {
public:
Iterator(ImageWrapIter iw, int n, int i, const ImageWrap::Iterator& it) :
iw_(iw), n_(n), i_(i), iter_(it), end_((**iw).end())
Expand Down Expand Up @@ -966,7 +966,7 @@ namespace sirf {
gadgetron::shared_ptr<Iterator> sptr_iter_;
};

class Iterator_const : public MRImageData::Iterator_const {
class Iterator_const : public ImageData::Iterator_const {
public:
Iterator_const(ImageWrapIter_const iw, int n, int i,
const ImageWrap::Iterator_const& it) :
Expand Down
6 changes: 5 additions & 1 deletion src/xSTIR/cSTIR/cstir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ void* cSTIR_setParameter
try {
CAST_PTR(DataHandle, hs, ptr_s);
CAST_PTR(DataHandle, hv, ptr_v);
if (sirf::iequals(obj, "ListmodeToSinograms"))
if (sirf::iequals(obj, "ImageData"))
return cSTIR_setImageDataParameter(ptr_s, name, ptr_v);
else if (sirf::iequals(obj, "ListmodeToSinograms"))
return cSTIR_setListmodeToSinogramsParameter(ptr_s, name, ptr_v);
else if (sirf::iequals(obj, "SeparableGaussianImageFilter"))
return cSTIR_setSeparableGaussianImageFilterParameter(ptr_s, name, ptr_v);
Expand Down Expand Up @@ -242,6 +244,8 @@ void* cSTIR_parameter(const void* ptr, const char* obj, const char* name)
else if (sirf::iequals(obj, "TruncateToCylindricalFOVImageProcessor"))
return cSTIR_truncateToCylindricalFOVImageProcessorParameter
(handle, name);
else if (sirf::iequals(obj, "ImageData"))
return cSTIR_ImageDataParameter(handle, name);
else if (sirf::iequals(obj, "RayTracingMatrix"))
return cSTIR_rayTracingMatrixParameter(handle, name);
else if (sirf::iequals(obj, "SPECTUBMatrix"))
Expand Down
21 changes: 21 additions & 0 deletions src/xSTIR/cSTIR/cstir_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ wrongFloatParameterValue
return wrongParameterValue(name, buff, file, line);
}

void*
sirf::cSTIR_setImageDataParameter(void* hp, const char* name, const void* hv)
{
STIRImageData& id = objectFromHandle<STIRImageData>(hp);
if (sirf::iequals(name, "modality"))
id.set_modality(charDataFromHandle(hv));
else
return parameterNotFound(name, __FILE__, __LINE__);
return new DataHandle;
}

void*
sirf::cSTIR_ImageDataParameter(void* hp, const char* name)
{
STIRImageData& id = objectFromHandle<STIRImageData>(hp);
if (sirf::iequals(name, "modality"))
return charDataHandleFromCharData(id.modality().c_str());
else
return parameterNotFound(name, __FILE__, __LINE__);
}

void*
sirf::cSTIR_setListmodeToSinogramsParameter(void* hp, const char* name, const void* hv)
{
Expand Down
6 changes: 6 additions & 0 deletions src/xSTIR/cSTIR/include/sirf/STIR/cstir_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ limitations under the License.

namespace sirf {

void*
cSTIR_setImageDataParameter(void* hp, const char* name, const void* hv);

void*
cSTIR_ImageDataParameter(void* hp, const char* name);

void*
cSTIR_setListmodeToSinogramsParameter(void* hp, const char* name, const void* hv);

Expand Down
23 changes: 16 additions & 7 deletions src/xSTIR/cSTIR/include/sirf/STIR/stir_data_containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ limitations under the License.
#include "sirf/common/JacobiCG.h"
#include "sirf/common/DataContainer.h"
#include "sirf/common/ANumRef.h"
#include "sirf/common/PETImageData.h"
#include "sirf/common/ImageData.h"
#include "sirf/common/GeometricalInfo.h"
#include "stir/ZoomOptions.h"

Expand Down Expand Up @@ -735,11 +735,8 @@ namespace sirf {
additioanally, implements the linear algebra functionality specified by the
abstract base class aDatacontainer.
*/
//class STIRImageData : public aDataContainer < float > {
class STIRImageData : public PETImageData { //<Iterator, Iterator_const> {
class STIRImageData : public ImageData {
public:
//typedef PETImageData<Iterator, Iterator_const>::Iter BaseIter;
//typedef PETImageData<Iterator, Iterator_const>::Iter_const BaseIter_const;
typedef ImageData::Iterator BaseIter;
typedef ImageData::Iterator_const BaseIter_const;
class Iterator : public BaseIter {
Expand Down Expand Up @@ -893,12 +890,24 @@ namespace sirf {
{
return false;
}

unsigned int items() const
{
return 1;
}
/// Write to file

std::string modality() const
{
ExamInfo ex_info = data().get_exam_info();
return ex_info.imaging_modality.get_name();
}
void set_modality(const std::string& mod)
{
ExamInfo ex_info = data().get_exam_info();
ex_info.imaging_modality = ImagingModality(mod);
data().set_exam_info(ex_info);
}

/// Write to file
virtual void write(const std::string &filename) const;
/// Write to file using format file.
/*! This allows speciyfing the output file format used by STIR using a text file.
Expand Down
19 changes: 17 additions & 2 deletions src/xSTIR/cSTIR/tests/test1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ limitations under the License.

#include "stir/common.h"
#include "stir/IO/stir_ecat_common.h"
#include "stir/ExamData.h"

#include "sirf/common/iequals.h"
#include "sirf/STIR/stir_x.h"
Expand Down Expand Up @@ -113,11 +114,25 @@ int test1()
std::cout << geom_info.get_info().c_str();
ok = (geom_info == geom_info_copy);
if (ok)
std::cout << "== ok\n";
std::cout << "geom_info == ok\n";
else
std::cout << "== failed \n";
std::cout << "geom_info == failed \n";
fail = fail || !ok;

// show and change modality demo
std::string mod = image_data.modality();
std::cout << '\n' << "modality: " << mod << '\n';
image_data.set_modality("NM");
std::cout << "new modality set: " << image_data.modality() << '\n';
ok = sirf::iequals(image_data.modality(), "NM");
if (ok)
std::cout << "set_modality ok\n";
else
std::cout << "set_modality failed \n";
fail = fail || !ok;
// restore
image_data.set_modality(mod);

// create additive term
shared_ptr<PETAcquisitionData> sptr_a = acq_data.new_acquisition_data();
PETAcquisitionData& at = *sptr_a;
Expand Down
11 changes: 11 additions & 0 deletions src/xSTIR/pSTIR/STIR.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@ def same_object(self):
"""See DataContainer method."""
return ImageData()

def modality(self):
"""Returns imaging modality as Python string."""
return parms.char_par(self.handle, 'ImageData', 'modality')

def set_modality(self, mod):
"""Sets imaging modality.
mod: "PT" or "NM" or "MR" or "CT" or "US" or "Optical"
"""
return parms.set_char_par(self.handle, 'ImageData', 'modality', mod)

def initialise(self, dim, vsize=(1., 1., 1.), origin=(0., 0., 0.)):
"""
Sets image size and geometric information.
Expand Down

0 comments on commit 825edde

Please sign in to comment.