Skip to content

Commit

Permalink
Merge pull request #1316 from KrisThielemans/DetectionPositionFixes
Browse files Browse the repository at this point in the history
DetectionPosition fixes
  • Loading branch information
KrisThielemans authored Jan 6, 2024
2 parents 21eb434 + 1d26b90 commit 75a9342
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
7 changes: 7 additions & 0 deletions documentation/release_6.0.htm
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ <h4>Python (and MATLAB)</h4>
derived classes.
</li>
</ul>
</li>
<li>
add <code>DetectionPositionPair.__repr__</code> for printing and
change order of text in <code>DetectionPosition.__repr__</code> to
fit with constructor to avoid confusion.<br>
<a href="https://github.com/UCL/STIR/pull/1316">PR #1316</a>
</li>
</ul>


Expand Down
27 changes: 23 additions & 4 deletions src/include/stir/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Copyright (C) 2000 PARAPET partners
Copyright (C) 2000-2009 Hammersmith Imanet Ltd
Copyright (C) 2013 Kris Thielemans
Copyright (C) 2023 University College London
Copyright (C) 2023, 2024 University College London
This file is part of STIR.
Expand All @@ -29,6 +29,7 @@
#include "stir/BasicCoordinate.h"
#include "stir/Bin.h"
#include "stir/DetectionPosition.h"
#include "stir/DetectionPositionPair.h"
#include <iostream>
#include <vector>

Expand Down Expand Up @@ -86,6 +87,7 @@ operator<<(std::ostream& str, const std::vector<elemT>& v);

/*!
\brief Outputs a Bin to a stream.
\ingroup projdata
Output is of the form
\verbatim
Expand All @@ -103,17 +105,34 @@ inline std::ostream& operator<<(std::ostream& out, const Bin& bin)

/*!
\brief Outputs a DetectionPosition to a stream.
\ingroup projdata
Output is of the form
\verbatim
[radial=.., axial=..., tangential=...]
[tangential=..., axial=..., radial=...]
\endverbatim
*/
template <class T>
inline std::ostream& operator<<(std::ostream& out, const DetectionPosition<T>& det_pos)
{
return out << "[radial=" << det_pos.radial_coord() << ", axial=" << det_pos.axial_coord()
<< ", tangential=" << det_pos.tangential_coord() << "]";
return out << "[tangential=" << det_pos.tangential_coord() << ", axial=" << det_pos.axial_coord()
<< ", radial=" << det_pos.radial_coord() << "]";
}

/*!
\brief Outputs a DetectionPosition to a stream.
\ingroup projdata
Output is of the form
\verbatim
[pos1=..., pos2=..., timing_pos=...]
\endverbatim
*/
template <class T>
inline std::ostream& operator<<(std::ostream& out, const DetectionPositionPair<T>& det_pos)
{
return out << "[pos1=" << det_pos.pos1() << ", pos2=" << det_pos.pos2()
<< ", timing_pos=" << det_pos.timing_pos() << "]";
}

/*!
Expand Down
4 changes: 2 additions & 2 deletions src/recon_buildblock/BinNormalisationFromECAT8.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,8 @@ get_uncalibrated_bin_efficiency(const Bin& bin) const {
uncompressed_bin, detection_position_pair);


const DetectionPosition<>& pos1 = detection_position_pair.pos1();
const DetectionPosition<>& pos2 = detection_position_pair.pos2();
//const DetectionPosition<>& pos1 = detection_position_pair.pos1();
//const DetectionPosition<>& pos2 = detection_position_pair.pos2();
float lor_efficiency= 0.;

/*
Expand Down
12 changes: 3 additions & 9 deletions src/swig/stir_projdata.i
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,18 @@
%attributeref(stir::DetectionPosition<unsigned int>, unsigned int, axial_coord);
%attributeref(stir::DetectionPosition<unsigned int>, unsigned int, radial_coord);
%include "stir/DetectionPosition.h"
#ifdef STIR_TOF
ADD_REPR(stir::DetectionPosition, %arg(*$self))
#endif
%template(DetectionPosition) stir::DetectionPosition<unsigned int>;

%attributeref(stir::DetectionPositionPair<unsigned int>, int, timing_pos);
%attributeref(stir::DetectionPositionPair<unsigned int>, stir::DetectionPosition<unsigned int>, pos1);
%attributeref(stir::DetectionPositionPair<unsigned int>, stir::DetectionPosition<unsigned int>, pos2);
%include "stir/DetectionPositionPair.h"
#ifdef STIR_TOF
//ADD_REPR(stir::DetectionPositionPair, %arg(*$self))
#endif
ADD_REPR(stir::DetectionPositionPair, %arg(*$self))
%template(DetectionPositionPair) stir::DetectionPositionPair<unsigned int>;

%attributeref(stir::SegmentIndices, int, segment_num);
#ifdef STIR_TOF
%attributeref(stir::SegmentIndices, int, timing_pos_num);
#endif
%attributeref(stir::ViewgramIndices, int, view_num);
%attributeref(stir::SinogramIndices, int, axial_pos_num);
%attributeref(stir::Bin, int, axial_pos_num);
Expand All @@ -69,9 +64,8 @@ ADD_REPR(stir::DetectionPosition, %arg(*$self))
%include "stir/ViewgramIndices.h"
%include "stir/SinogramIndices.h"
%include "stir/Bin.h"
#ifdef STIR_TOF
ADD_REPR(stir::Bin, %arg(*$self))
#endif


%newobject stir::Scanner::get_scanner_from_name;
%include "stir/Scanner.h"
Expand Down
13 changes: 12 additions & 1 deletion src/swig/test/python/test_buildblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,18 @@ def test_zoom_image():
assert abs(zoomed_image[ind]-1)<.001
zoomed_image=zoom_image(image, zoom, offset, offset, new_size, ZoomOptions(ZoomOptions.preserve_projections))
assert abs(zoomed_image[ind]-1./(zoom))<.001


def test_DetectionPositionPair():
d1=DetectionPosition(1,2,0)
d2=DetectionPosition(4,5,6)
dp=DetectionPositionPair(d1,d2,3)
assert d1==dp.pos1
assert d2==dp.pos2
assert dp.timing_pos == 3
dp.pos1.tangential_coord = 7
assert dp.pos1.tangential_coord == 7
assert d1.tangential_coord == 1

def test_Scanner():
scanner=Scanner.get_scanner_from_name("ECAT 962")
assert scanner.get_num_rings()==32
Expand Down

0 comments on commit 75a9342

Please sign in to comment.