Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing SPECTUB global variables to class members #1169

Merged
merged 5 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions documentation/release_5.2.htm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ <h3>Bug fixes</h3>

<h3>New functionality</h3>
<ul>
<li>Global variables in SPECTUB have been substituted by class members, such that multiple SPECTUB projectors can be used.
<br /><a href="https://github.com/UCL/STIR/pull/1169/">PR #1169</a>.
</li>
<li>Scatter estimation is now smoothed in axial direction for BlocksOnCylindrical scanners.
<br /><a href="https://github.com/UCL/STIR/pull/1172/">PR #1172</a>.
</li>
Expand Down
14 changes: 10 additions & 4 deletions src/include/stir/recon_buildblock/ProjMatrixByBinSPECTUB.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Bin;
End Projection Matrix By Bin SPECT UB Parameters:=
\endverbatim
*/

//using namespace SPECTUB;
class ProjMatrixByBinSPECTUB :
public RegisteredParsingObject<
ProjMatrixByBinSPECTUB,
Expand All @@ -90,14 +90,17 @@ class ProjMatrixByBinSPECTUB :
//! Default constructor (calls set_defaults())
ProjMatrixByBinSPECTUB();

// disable copy-constructor as currently unsafe to copy due to bare pointers
ProjMatrixByBinSPECTUB(const ProjMatrixByBinSPECTUB&) = delete;

//! Destructor (deallocates UB SPECT memory)
~ProjMatrixByBinSPECTUB();

//! Checks all necessary geometric info
virtual void set_up(
const shared_ptr<const ProjDataInfo>& proj_data_info_ptr,
const shared_ptr<const DiscretisedDensity<3,float> >& density_info_ptr // TODO should be Info only
);
);

bool get_keep_all_views_in_cache() const;
//! Enable keeping the matrix in memory
Expand Down Expand Up @@ -146,7 +149,6 @@ class ProjMatrixByBinSPECTUB :

void
set_resolution_model(const float collimator_sigma_0_in_mm, const float collimator_slope_in_mm, const bool full_3D = true);

private:

// parameters that will be parsed
Expand All @@ -172,6 +174,9 @@ class ProjMatrixByBinSPECTUB :

bool already_setup;

mutable SPECTUB::wm_da_type wm;
mutable SPECTUB::wmh_type wmh; // this could be an arry of wmh_type for each index
float * Rrad;

virtual void
calculate_proj_matrix_elems_for_one_bin(
Expand Down Expand Up @@ -206,7 +211,8 @@ class ProjMatrixByBinSPECTUB :
int maxszb;


void compute_one_subset(const int kOS) const;
void compute_one_subset(const int kOS,
const float *Rrad) const;
void delete_UB_SPECT_arrays();
mutable std::vector<bool> subset_already_processed;
};
Expand Down
22 changes: 11 additions & 11 deletions src/include/stir/recon_buildblock/SPECTUB_Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,38 +319,38 @@ typedef struct
//... functions from wmtools_SPECT.cpp .........................................


void write_wm_FC (); // to write double array weight matrix
void write_wm_FC (wm_da_type &wm); // to write double array weight matrix

void write_wm_hdr (); // to write header of a matrix
void write_wm_hdr (wm_da_type &wm, wmh_type &wmh); // to write header of a matrix

void write_wm_STIR (); // to write matrix in STIR format
void write_wm_STIR (SPECTUB::wm_da_type& wm); // to write matrix in STIR format


void index_calc ( int *indexs ); // to calculate projection index order in subsets
void index_calc (int *indexs , wmh_type &wmh); // to calculate projection index order in subsets

void read_Rrad (); // to read variable rotation radius from a text file (1 radius per line)
void read_Rrad (float *Rrad, wmh_type &wmh); // to read variable rotation radius from a text file (1 radius per line)

//
//void col_params ( collim_type *COL ); // to fill collimator structure
//
//void read_col_params ( collim_type *COL); // to read collimator parameters from a file


void fill_ang ( angle_type *ang ); // to fill angle structure
void fill_ang (angle_type *ang , wmh_type &wmh, const float *Rrad); // to fill angle structure

void generate_msk ( bool *msk_3d, bool *msk_2d, float *att, volume_type *vol); // to create a boolean mask for wm (no weights outside the msk)
void generate_msk (bool *msk_3d, bool *msk_2d, float *att, volume_type *vol, wmh_type &wmh); // to create a boolean mask for wm (no weights outside the msk)

void read_msk_file ( bool * msk ); // to read mask from a file
void read_msk_file (bool * msk , wmh_type &wmh); // to read mask from a file


void read_att_map ( float *attmap ); // to read attenuation map from a file
void read_att_map (float *attmap , wmh_type &wmh); // to read attenuation map from a file


int max_psf_szb ( angle_type *ang );
int max_psf_szb (angle_type *ang , wmh_type &wmh);

float calc_sigma_h ( voxel_type vox, collim_type COL);

float calc_sigma_v ( voxel_type vox, collim_type COL);
float calc_sigma_v (voxel_type vox, collim_type COL, wmh_type &wmh);


char *itoa ( int n, char *s); // to conver integer to ascii
Expand Down
90 changes: 42 additions & 48 deletions src/include/stir/recon_buildblock/SPECTUB_Weight3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,68 +23,62 @@
Berta Marti Fuster, Carles Falcon, Charalampos Tsoumpas, Lefteris Livieratos, Pablo Aguiar, Albert Cot, Domenec Ros and Kris Thielemans,
<i>Integration of advanced 3D SPECT modeling into the open-source STIR framework</i>,
Med. Phys. 40, 092502 (2013); http://dx.doi.org/10.1118/1.4816676

\todo Variables wm, wmh and Rrad are currently global variables. This means that this code would be very dangerous
in a parallel setting.
*/

namespace SPECTUB {

/* Global variables: the matrix etc TODO
Need to be defined elsewhere

A lot of the functions below modify these variables.
*/
extern wm_da_type wm; //! weight (or probability) matrix
extern wmh_type wmh; //! information to construct wm
extern float * Rrad; //! radii per view


void wm_calculation( const int kOS,
const angle_type *const ang,
voxel_type vox,
bin_type bin,
const volume_type& vol,
const proj_type& prj,
const float *attmap,
const bool *msk_3d,
const bool *msk_2d,
const int maxszb,
const discrf_type *const gaussdens,
const int *const NITEMS
);
void wm_calculation(const int kOS,
const SPECTUB::angle_type *const ang,
SPECTUB::voxel_type vox,
bin_type bin,
const SPECTUB::volume_type& vol,
const proj_type& prj,
const float *attmap,
const bool *msk_3d,
const bool *msk_2d,
const int maxszb,
const SPECTUB::discrf_type *const gaussdens,
const int *const NITEMS,
SPECTUB::wm_da_type& wm,
SPECTUB::wmh_type& wmh,
const float *Rrad
);

void wm_size_estimation (int kOS,
const angle_type * const ang,
voxel_type vox,
bin_type bin,
const volume_type& vol,
const proj_type& prj,
const bool * const msk_3d,
const bool *const msk_2d,
const int maxszb,
const discrf_type * const gaussdens,
int *NITEMS);
const SPECTUB::angle_type * const ang,
SPECTUB::voxel_type vox,
bin_type bin,
const SPECTUB::volume_type& vol,
const SPECTUB::proj_type& prj,
const bool * const msk_3d,
const bool *const msk_2d,
const int maxszb,
const SPECTUB::discrf_type * const gaussdens,
int *NITEMS,
SPECTUB::wmh_type &wmh,
const float *Rrad);


//... geometric component ............................................

void calc_gauss ( discrf_type *gaussdens );
void calc_gauss ( SPECTUB::discrf_type *gaussdens );

void calc_vxprj ( angle_type *ang );
void calc_vxprj ( SPECTUB::angle_type *ang );

void voxel_projection ( voxel_type *vox, float * eff, float lngcmd2 );
void voxel_projection (SPECTUB::voxel_type *vox, float * eff, float lngcmd2 , SPECTUB::wmh_type &wmh);

void fill_psf_no( psf2da_type *psf, psf1d_type *psf1d_h, const voxel_type& vox, const angle_type * const ang, float szdx );
void fill_psf_no(SPECTUB::psf2da_type *psf, SPECTUB::psf1d_type *psf1d_h, const SPECTUB::voxel_type& vox, const angle_type * const ang, float szdx , SPECTUB::wmh_type &wmh);

void fill_psf_2d( psf2da_type *psf, psf1d_type *psf1d_h, const voxel_type& vox, discrf_type const*const gaussdens, float szdx );
void fill_psf_2d( SPECTUB::psf2da_type *psf, SPECTUB::psf1d_type *psf1d_h, const SPECTUB::voxel_type& vox, SPECTUB::discrf_type const*const gaussdens, float szdx, SPECTUB::wmh_type &wmh);

void fill_psf_3d(psf2da_type *psf,
psf1d_type *psf1d_h,
psf1d_type *psf1d_v,
const voxel_type& vox, discrf_type const * const gaussdens, float szdx, float thdx, float thcmd2 );
void fill_psf_3d(SPECTUB::psf2da_type *psf,
SPECTUB::psf1d_type *psf1d_h,
SPECTUB::psf1d_type *psf1d_v,
const SPECTUB::voxel_type& vox, SPECTUB::discrf_type const * const gaussdens,
float szdx, float thdx, float thcmd2,
wmh_type &wmh);

void calc_psf_bin ( float center_psf, float binszcm, discrf_type const * const vxprj, psf1d_type *psf );
void calc_psf_bin (float center_psf, float binszcm, SPECTUB::discrf_type const * const vxprj, SPECTUB::psf1d_type *psf , SPECTUB::wmh_type &wmh);


//... attenuation...................................................
Expand All @@ -94,9 +88,9 @@ void calc_psf_bin ( float center_psf, float binszcm, discrf_type const * const v

//void size_attpth_full( psf2da_type *psf, voxel_type vox, volume_type vol, float *att, angle_type *ang );

void calc_att_path ( const bin_type& bin, const voxel_type& vox, const volume_type& vol, attpth_type *attpth );
void calc_att_path ( const bin_type& bin, const SPECTUB::voxel_type& vox, const SPECTUB::volume_type& vol, SPECTUB::attpth_type *attpth );

float calc_att ( const attpth_type *const attpth, const float *const attmap, int islc );
float calc_att (const SPECTUB::attpth_type *const attpth, const float *const attmap, int islc , SPECTUB::wmh_type &wmh);

int comp_dist ( float dx, float dy, float dz, float dlast );

Expand Down
Loading