STIR 6.4.0
ScatterSimulation.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2018 - 2019 University of Hull
3 Copyright (C) 2004 - 2009 Hammersmith Imanet Ltd
4 Copyright (C) 2013 - 2016, 2019, 2020, 2022 University College London
5 Copyright (C) 2022, National Physical Laboratory
6 This file is part of STIR.
7
8 SPDX-License-Identifier: Apache-2.0
9
10 See STIR/LICENSE.txt for details
11*/
12#ifndef __stir_scatter_ScatterSimulation_H__
13#define __stir_scatter_ScatterSimulation_H__
14
25
26#include "stir/ParsingObject.h"
28#include "stir/ProjData.h"
33
34START_NAMESPACE_STIR
35
84
85class ScatterSimulation : public RegisteredObject<ScatterSimulation>
86{
87public:
90
91 ~ScatterSimulation() override;
92
93 virtual Succeeded process_data();
95 virtual std::string method_info() const = 0;
97 virtual void ask_parameters();
99
100 inline bool has_template_proj_data_info() const { return !stir::is_null_ptr(proj_data_info_sptr); }
102 inline bool has_exam_info() const { return !stir::is_null_ptr(template_exam_info_sptr); }
104
106
107 shared_ptr<ProjData> get_output_proj_data_sptr() const;
108
109 inline int get_num_scatter_points() const { return static_cast<int>(this->scatt_points_vector.size()); }
111 shared_ptr<const ProjDataInfo> get_template_proj_data_info_sptr() const;
113 shared_ptr<const ExamInfo> get_exam_info_sptr() const;
114
115 const DiscretisedDensity<3, float>& get_activity_image() const;
116 const DiscretisedDensity<3, float>& get_attenuation_image() const;
117 const DiscretisedDensity<3, float>& get_attenuation_image_for_scatter_points() const;
119 shared_ptr<const DiscretisedDensity<3, float>> get_density_image_for_scatter_points_sptr() const;
121
123
124
125 void set_template_proj_data_info(const std::string&);
126
127 void set_template_proj_data_info(const ProjDataInfo& arg);
128
129 void set_template_proj_data_info(shared_ptr<const ProjDataInfo> arg);
130
131 void set_activity_image_sptr(const shared_ptr<const DiscretisedDensity<3, float>>);
132
133 void set_activity_image(const std::string& filename);
136 void set_exam_info(const ExamInfo&);
137 void set_exam_info_sptr(const shared_ptr<const ExamInfo>);
138
139 void set_output_proj_data_sptr(shared_ptr<ProjData>);
140
141 void set_density_image_sptr(const shared_ptr<const DiscretisedDensity<3, float>>);
142
143 void set_density_image(const std::string&);
146 void set_output_proj_data(const std::string&);
147
148 void set_output_proj_data_sptr(const shared_ptr<const ExamInfo>, const shared_ptr<const ProjDataInfo>, const std::string&);
149
150 void set_density_image_for_scatter_points_sptr(shared_ptr<const DiscretisedDensity<3, float>>);
151
152 void set_image_downsample_factors(float factor_xy = 1.f, float factor_z = 1.f, int _size_zoom_xy = -1, int _size_zoom_z = -1);
154 void set_density_image_for_scatter_points(const std::string&);
156 void set_attenuation_threshold(const float);
158
164 void set_randomly_place_scatter_points(const bool);
165
166 void set_cache_enabled(const bool);
167
169
173 void downsample_density_image_for_scatter_points(float _zoom_xy, float _zoom_z, int _size_xy = -1, int _size_z = -1);
174
176
177 void set_downsample_scanner_bool(const bool arg);
178 bool get_downsample_scanner_bool() const;
180
182
183 int get_num_downsample_scanner_rings() const;
184 void set_num_downsample_scanner_rings(const int arg);
186
188
189 int get_num_downsample_scanner_dets() const;
190 void set_num_downsample_scanner_dets(const int arg);
192
194
197 Succeeded downsample_scanner(int new_num_rings = -1, int new_num_dets = -1);
199
206 Succeeded downsample_images_to_scanner_size();
207
209
220 float detection_efficiency(const float energy) const;
221
223
224 static inline float dif_Compton_cross_section(const float cos_theta, float energy);
225
226 static inline float total_Compton_cross_section(float energy);
227
228 static inline float photon_energy_after_Compton_scatter(const float cos_theta, const float energy);
229
230 static inline float photon_energy_after_Compton_scatter_511keV(const float cos_theta);
231
232 static inline float total_Compton_cross_section_relative_to_511keV(const float energy);
234
235 virtual Succeeded set_up();
236
238 virtual void write_log(const double simulation_time, const float total_scatter);
239
241 void set_use_cache(const bool);
243 bool get_use_cache() const;
244
245protected:
247
248 virtual double process_data_for_view_segment_num(const ViewSegmentNumbers& vs_num);
249
250 float compute_emis_to_det_points_solid_angle_factor(const CartesianCoordinate3D<float>& emis_point,
251 const CartesianCoordinate3D<float>& detector_coord);
252
253 void set_defaults() override;
254 void initialise_keymap() override;
258 bool post_processing() override;
259
260 enum image_type
261 {
262 act_image_type,
263 att_image_type
264 };
265 struct ScatterPoint
266 {
267 CartesianCoordinate3D<float> coord;
268 float mu_value;
269 };
270
271 std::vector<ScatterPoint> scatt_points_vector;
272
273 float scatter_volume;
274
276
279 void sample_scatter_points();
280
282
284 virtual void remove_cache_for_integrals_over_attenuation();
285
287
289 virtual void remove_cache_for_integrals_over_activity();
290
295
297 static float max_cos_angle(const float low, const float approx, const float resolution_at_511keV);
298
300 static float energy_lower_limit(const float low, const float approx, const float resolution_at_511keV);
301
302 virtual void find_detectors(unsigned& det_num_A, unsigned& det_num_B, const Bin& bin) const;
303
304 unsigned find_in_detection_points_vector(const CartesianCoordinate3D<float>& coord) const;
305
306 CartesianCoordinate3D<float> shift_detector_coordinates_to_origin;
307
309 double detection_efficiency_no_scatter(const unsigned det_num_A, const unsigned det_num_B) const;
310
311 // next needs to be mutable because find_in_detection_points_vector is const
312 mutable std::vector<CartesianCoordinate3D<float>> detection_points_vector;
313
315
317 virtual double scatter_estimate(const Bin& bin) = 0;
318
320
321 static float integral_between_2_points(const DiscretisedDensity<3, float>& density,
322 const CartesianCoordinate3D<float>& point1,
323 const CartesianCoordinate3D<float>& point2);
324
325 float exp_integral_over_attenuation_image_between_scattpoint_det(const CartesianCoordinate3D<float>& scatter_point,
326 const CartesianCoordinate3D<float>& detector_coord);
327
328 float integral_over_activity_image_between_scattpoint_det(const CartesianCoordinate3D<float>& scatter_point,
329 const CartesianCoordinate3D<float>& detector_coord);
330
331 float cached_integral_over_activity_image_between_scattpoint_det(const unsigned scatter_point_num, const unsigned det_num);
332
333 float cached_exp_integral_over_attenuation_image_between_scattpoint_det(const unsigned scatter_point_num,
334 const unsigned det_num);
336
337 std::string template_proj_data_filename;
338
339 shared_ptr<const ProjDataInfo> proj_data_info_sptr;
341 shared_ptr<ExamInfo> template_exam_info_sptr;
342
343 std::string density_image_filename;
344
345 std::string density_image_for_scatter_points_filename;
346
347 std::string density_image_for_scatter_points_output_filename;
348
349 shared_ptr<const DiscretisedDensity<3, float>> density_image_sptr;
350
352 shared_ptr<const DiscretisedDensity<3, float>> activity_image_sptr;
353
355
360
364
368 shared_ptr<ProjData> output_proj_data_sptr;
369
372
376
383 float zoom_xy;
385 float zoom_z;
394
395 bool downsample_scanner_bool;
396 bool _already_set_up;
397
398private:
399 int total_detectors;
400
401 Array<2, float> cached_activity_integral_scattpoint_det;
402 Array<2, float> cached_attenuation_integral_scattpoint_det;
403 shared_ptr<DiscretisedDensity<3, float>> density_image_for_scatter_points_sptr;
404
405 // numbers that we don't want to recompute all the time
406 mutable float detector_efficiency_no_scatter;
407
409
417 void check_z_to_middle_consistent(const DiscretisedDensity<3, float>& _image, const std::string& name) const;
418};
419
420END_NAMESPACE_STIR
421
423
424#endif
Declaration of class stir::ParsingObject.
Declaration of class stir::ProjDataInfoBlocksOnCylindricalNoArcCorr.
Declaration of class stir::ProjDataInfoCylindricalNoArcCorr.
Declaration of class stir::ProjDataInfoGenericNoArcCorr.
Declaration of class stir::ProjData.
Declaration of class stiir::RegisteredObject.
inline functions of stir::ScatterSimulation (cross sections)
defines the stir::VoxelsOnCartesianGrid class
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
A class for storing coordinates and value of a single projection bin.
Definition Bin.h:49
a templated class for 3-dimensional coordinates.
Definition CartesianCoordinate3D.h:53
This abstract class is the basis for all image representations.
Definition DiscretisedDensity.h:99
bool has_exam_info() const
Returns true if template_exam_info_sptr has been set.
Definition ScatterSimulation.h:102
virtual std::string method_info() const =0
gives method information
float zoom_xy
Zoom factor on plane XY. Defaults on 1.f.
Definition ScatterSimulation.h:383
int downsample_scanner_dets
Number of detectors per ring of downsampled scanner.
Definition ScatterSimulation.h:393
int downsample_scanner_rings
Number of rings of downsampled scanner.
Definition ScatterSimulation.h:391
virtual double scatter_estimate(const Bin &bin)=0
virtual function that computes the scatter for one (downsampled) bin
ScatterSimulation()
Default constructor.
Definition ScatterSimulation.cxx:53
int zoom_size_z
Zoomed image size on Z axis. Defaults on -1.
Definition ScatterSimulation.h:389
int zoom_size_xy
Zoomed image size on plane XY. Defaults on -1.
Definition ScatterSimulation.h:387
std::string activity_image_filename
Filename for the initial activity estimate.
Definition ScatterSimulation.h:381
shared_ptr< ExamInfo > template_exam_info_sptr
Definition ScatterSimulation.h:341
bool randomly_place_scatter_points
boolean to see if we need to move the scatter point randomly within in its voxel
Definition ScatterSimulation.h:374
void initialise_cache_for_scattpoint_det_integrals_over_activity()
set-up cache for activity integrals
Definition cached_single_scatter_integrals.cxx:57
float attenuation_threshold
threshold below which a voxel in the attenuation image will not be considered as a candidate scatter ...
Definition ScatterSimulation.h:371
shared_ptr< ProjData > output_proj_data_sptr
Shared ptr to hold the simulated data.
Definition ScatterSimulation.h:368
bool use_cache
boolean to see if we need to cache the integrals
Definition ScatterSimulation.h:379
shared_ptr< const DiscretisedDensity< 3, float > > activity_image_sptr
Pointer to hold the current activity estimation.
Definition ScatterSimulation.h:352
void initialise_cache_for_scattpoint_det_integrals_over_attenuation()
set-up cache for attenuation integrals
Definition cached_single_scatter_integrals.cxx:42
std::string output_proj_data_filename
Output proj_data fileanme prefix.
Definition ScatterSimulation.h:366
float zoom_z
Zoom factor on Z axis. Defaults on 1.f.
Definition ScatterSimulation.h:385
virtual void ask_parameters()
prompts the user to enter parameter values manually
Definition ScatterSimulation.cxx:242
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition Succeeded.h:44