STIR  6.2.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 
26 #include "stir/ParsingObject.h"
27 #include "stir/RegisteredObject.h"
28 #include "stir/ProjData.h"
33 
34 START_NAMESPACE_STIR
35 
85 class ScatterSimulation : public RegisteredObject<ScatterSimulation>
86 {
87 public:
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&);
128 
129  void set_activity_image_sptr(const shared_ptr<const DiscretisedDensity<3, float>>);
130 
131  void set_activity_image(const std::string& filename);
134  void set_exam_info(const ExamInfo&);
135  void set_exam_info_sptr(const shared_ptr<const ExamInfo>);
136 
137  void set_output_proj_data_sptr(shared_ptr<ProjData>);
138 
139  void set_density_image_sptr(const shared_ptr<const DiscretisedDensity<3, float>>);
140 
141  void set_density_image(const std::string&);
144  void set_output_proj_data(const std::string&);
145 
146  void set_output_proj_data_sptr(const shared_ptr<const ExamInfo>, const shared_ptr<const ProjDataInfo>, const std::string&);
147 
148  void set_density_image_for_scatter_points_sptr(shared_ptr<const DiscretisedDensity<3, float>>);
149 
150  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);
152  void set_density_image_for_scatter_points(const std::string&);
154  void set_attenuation_threshold(const float);
156 
162  void set_randomly_place_scatter_points(const bool);
163 
164  void set_cache_enabled(const bool);
165 
167 
171  void downsample_density_image_for_scatter_points(float _zoom_xy, float _zoom_z, int _size_xy = -1, int _size_z = -1);
172 
174 
175  void set_downsample_scanner_bool(const bool arg);
176  bool get_downsample_scanner_bool() const;
178 
180 
181  int get_num_downsample_scanner_rings() const;
182  void set_num_downsample_scanner_rings(const int arg);
184 
186 
187  int get_num_downsample_scanner_dets() const;
188  void set_num_downsample_scanner_dets(const int arg);
190 
192 
195  Succeeded downsample_scanner(int new_num_rings = -1, int new_num_dets = -1);
197 
204  Succeeded downsample_images_to_scanner_size();
205 
207 
218  float detection_efficiency(const float energy) const;
219 
221 
222  static inline float dif_Compton_cross_section(const float cos_theta, float energy);
223 
224  static inline float total_Compton_cross_section(float energy);
225 
226  static inline float photon_energy_after_Compton_scatter(const float cos_theta, const float energy);
227 
228  static inline float photon_energy_after_Compton_scatter_511keV(const float cos_theta);
229 
230  static inline float total_Compton_cross_section_relative_to_511keV(const float energy);
232 
233  virtual Succeeded set_up();
234 
236  virtual void write_log(const double simulation_time, const float total_scatter);
237 
239  void set_use_cache(const bool);
241  bool get_use_cache() const;
242 
243 protected:
245 
246  virtual double process_data_for_view_segment_num(const ViewSegmentNumbers& vs_num);
247 
248  float compute_emis_to_det_points_solid_angle_factor(const CartesianCoordinate3D<float>& emis_point,
249  const CartesianCoordinate3D<float>& detector_coord);
250 
251  void set_defaults() override;
252  void initialise_keymap() override;
256  bool post_processing() override;
257 
258  enum image_type
259  {
260  act_image_type,
261  att_image_type
262  };
263  struct ScatterPoint
264  {
266  float mu_value;
267  };
268 
269  std::vector<ScatterPoint> scatt_points_vector;
270 
271  float scatter_volume;
272 
274 
277  void sample_scatter_points();
278 
280 
282  virtual void remove_cache_for_integrals_over_attenuation();
283 
285 
287  virtual void remove_cache_for_integrals_over_activity();
288 
294  static float max_cos_angle(const float low, const float approx, const float resolution_at_511keV);
296 
298  static float energy_lower_limit(const float low, const float approx, const float resolution_at_511keV);
299 
300  virtual void find_detectors(unsigned& det_num_A, unsigned& det_num_B, const Bin& bin) const;
301 
302  unsigned find_in_detection_points_vector(const CartesianCoordinate3D<float>& coord) const;
303 
304  CartesianCoordinate3D<float> shift_detector_coordinates_to_origin;
305 
307  double detection_efficiency_no_scatter(const unsigned det_num_A, const unsigned det_num_B) const;
308 
309  // next needs to be mutable because find_in_detection_points_vector is const
310  mutable std::vector<CartesianCoordinate3D<float>> detection_points_vector;
311 
313 
315  virtual double scatter_estimate(const Bin& bin) = 0;
316 
318 
319  static float integral_between_2_points(const DiscretisedDensity<3, float>& density,
320  const CartesianCoordinate3D<float>& point1,
321  const CartesianCoordinate3D<float>& point2);
322 
323  float exp_integral_over_attenuation_image_between_scattpoint_det(const CartesianCoordinate3D<float>& scatter_point,
324  const CartesianCoordinate3D<float>& detector_coord);
325 
326  float integral_over_activity_image_between_scattpoint_det(const CartesianCoordinate3D<float>& scatter_point,
327  const CartesianCoordinate3D<float>& detector_coord);
328 
329  float cached_integral_over_activity_image_between_scattpoint_det(const unsigned scatter_point_num, const unsigned det_num);
330 
331  float cached_exp_integral_over_attenuation_image_between_scattpoint_det(const unsigned scatter_point_num,
332  const unsigned det_num);
334 
335  std::string template_proj_data_filename;
336 
337  shared_ptr<ProjDataInfo> proj_data_info_sptr;
339  shared_ptr<ExamInfo> template_exam_info_sptr;
340 
341  std::string density_image_filename;
342 
343  std::string density_image_for_scatter_points_filename;
344 
345  std::string density_image_for_scatter_points_output_filename;
346 
347  shared_ptr<const DiscretisedDensity<3, float>> density_image_sptr;
348 
350  shared_ptr<const DiscretisedDensity<3, float>> activity_image_sptr;
351 
353 
356  void initialise_cache_for_scattpoint_det_integrals_over_attenuation();
358 
361  void initialise_cache_for_scattpoint_det_integrals_over_activity();
362 
366  shared_ptr<ProjData> output_proj_data_sptr;
367 
370 
374 
377  bool use_cache;
381  float zoom_xy;
383  float zoom_z;
392 
393  bool downsample_scanner_bool;
394  bool _already_set_up;
395 
396 private:
397  int total_detectors;
398 
399  Array<2, float> cached_activity_integral_scattpoint_det;
400  Array<2, float> cached_attenuation_integral_scattpoint_det;
401  shared_ptr<DiscretisedDensity<3, float>> density_image_for_scatter_points_sptr;
402 
403  // numbers that we don't want to recompute all the time
404  mutable float detector_efficiency_no_scatter;
405 
407 
415  void check_z_to_middle_consistent(const DiscretisedDensity<3, float>& _image, const std::string& name) const;
416 };
417 
418 END_NAMESPACE_STIR
419 
421 
422 #endif
int zoom_size_xy
Zoomed image size on plane XY. Defaults on -1.
Definition: ScatterSimulation.h:385
int downsample_scanner_dets
Number of detectors per ring of downsampled scanner.
Definition: ScatterSimulation.h:391
inline functions of stir::ScatterSimulation (cross sections)
shared_ptr< ExamInfo > template_exam_info_sptr
Definition: ScatterSimulation.h:339
Declaration of class stir::ProjDataInfoCylindricalNoArcCorr.
Declaration of class stir::ParsingObject.
float zoom_z
Zoom factor on Z axis. Defaults on 1.f.
Definition: ScatterSimulation.h:383
Declaration of class stir::ProjData.
bool randomly_place_scatter_points
boolean to see if we need to move the scatter point randomly within in its voxel
Definition: ScatterSimulation.h:372
int zoom_size_z
Zoomed image size on Z axis. Defaults on -1.
Definition: ScatterSimulation.h:387
bool has_exam_info() const
Returns true if template_exam_info_sptr has been set.
Definition: ScatterSimulation.h:102
std::string activity_image_filename
Filename for the initial activity estimate.
Definition: ScatterSimulation.h:379
int downsample_scanner_rings
Number of rings of downsampled scanner.
Definition: ScatterSimulation.h:389
alias for ViewgramIndices
Definition: ViewSegmentNumbers.h:33
Declaration of class stiir::RegisteredObject.
A class for storing coordinates and value of a single projection bin.
Definition: Bin.h:48
Helper class to provide registry mechanisms to a Base classSuppose you have a hierarchy of classes wi...
Definition: RegisteredObject.h:95
bool use_cache
boolean to see if we need to cache the integrals
Definition: ScatterSimulation.h:377
std::string output_proj_data_filename
Output proj_data fileanme prefix.
Definition: ScatterSimulation.h:364
float zoom_xy
Zoom factor on plane XY. Defaults on 1.f.
Definition: ScatterSimulation.h:381
Declaration of class stir::ProjDataInfoGenericNoArcCorr.
a class for storing information about 1 exam (or scan)
Definition: ExamInfo.h:41
Simulate the scatter probability using a model-based approach.
Definition: ScatterSimulation.h:85
Declaration of class stir::ProjDataInfoBlocksOnCylindricalNoArcCorr.
float attenuation_threshold
threshold below which a voxel in the attenuation image will not be considered as a candidate scatter ...
Definition: ScatterSimulation.h:369
defines the stir::VoxelsOnCartesianGrid class
An (abstract base) class that contains information on the projection data.
Definition: ProjDataInfo.h:69
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
shared_ptr< const DiscretisedDensity< 3, float > > activity_image_sptr
Pointer to hold the current activity estimation.
Definition: ScatterSimulation.h:350
shared_ptr< ProjData > output_proj_data_sptr
Shared ptr to hold the simulated data.
Definition: ScatterSimulation.h:366