STIR  6.2.0
ProjMatrixByBin.h
Go to the documentation of this file.
1 #ifndef __stir_recon_buildblock_ProjMatrixByBin_H__
2 #define __stir_recon_buildblock_ProjMatrixByBin_H__
3 
16 /*
17  Copyright (C) 2000 PARAPET partners
18  Copyright (C) 2000-2009, Hammersmith Imanet Ltd
19  Copyright (C) 2013, 2015, 2022 University College London
20  Copyright (C) 2016, University of Hull
21 
22  This file is part of STIR.
23 
24  SPDX-License-Identifier: Apache-2.0 AND License-ref-PARAPET-license
25 
26  See STIR/LICENSE.txt for details
27 */
28 
29 #include "stir/RegisteredObject.h"
30 #include "stir/ParsingObject.h"
33 #include "stir/shared_ptr.h"
34 #include "stir/VectorWithOffset.h"
35 #include "stir/TimedObject.h"
37 #include "stir/numerics/FastErf.h"
38 #include <cstdint>
39 //#include <map>
40 #include <unordered_map>
41 #ifdef STIR_OPENMP
42 # include <omp.h>
43 #endif
44 
45 START_NAMESPACE_STIR
46 
47 /* TODO
48 class ProjMatrixElemsForOneViewgram;
49 class SubsetInfo;
50 */
51 
52 class Bin;
53 
78 class ProjMatrixByBin : public RegisteredObject<ProjMatrixByBin>, public TimedObject
79 {
80 public:
81  ~ProjMatrixByBin() override {}
82 
84 
90  virtual void set_up(const shared_ptr<const ProjDataInfo>& proj_data_info_ptr,
91  const shared_ptr<const DiscretisedDensity<3, float>>& density_info_ptr // TODO should be Info only
92  )
93  = 0;
94 
95  virtual ProjMatrixByBin* clone() const = 0;
96 
98  inline const DataSymmetriesForBins* get_symmetries_ptr() const;
100  inline const shared_ptr<DataSymmetriesForBins> get_symmetries_sptr() const;
101 
103 
110  inline void get_proj_matrix_elems_for_one_bin(ProjMatrixElemsForOneBin&, const Bin&) const;
111 
112 #if 0
113  // TODO
119  virtual void write_to_file_by_bin(
120  const char * const file_name_without_extension) const;
121 #endif
122  // TODO implement this one at some point ?
123  /*
124  virtual void write_to_file_by_voxel(
125  const char * const file_name_without_extension);
126  */
127 
128  // void set_maximum_cache_size(const unsigned long size){;}
129  /* TODO
130  void set_subset_usage(const SubsetInfo&, const int num_access_times);
131  */
132  void enable_cache(const bool v = true);
133  void store_only_basic_bins_in_cache(const bool v = true);
134 
135  bool is_cache_enabled() const;
136  bool does_cache_store_only_basic_bins() const;
137 
138  // void reserve_num_elements_in_cache(const std::size_t);
140  void clear_cache() const;
141 
142 protected:
143  shared_ptr<DataSymmetriesForBins> symmetries_sptr;
144 
146 
150  ProjMatrixByBin();
151 
158  virtual void calculate_proj_matrix_elems_for_one_bin(ProjMatrixElemsForOneBin&) const = 0;
159 
161 
163 
164  void set_defaults() override;
166 
167  void initialise_keymap() override;
169 
170  bool post_processing() override;
171 
173 
174  bool cache_disabled;
175  bool cache_stores_only_basic_bins;
178 
185  Succeeded get_cached_proj_matrix_elems_for_one_bin(ProjMatrixElemsForOneBin&) const;
186 
189  shared_ptr<const VoxelsOnCartesianGrid<float>> image_info_sptr;
190 
192  shared_ptr<const ProjDataInfo> proj_data_info_sptr;
193 
195  void cache_proj_matrix_elems_for_one_bin(const ProjMatrixElemsForOneBin&) const;
196 
197 private:
198  typedef std::uint64_t CacheKey;
200  // note: sum needs to be less than 64 - 3 (for the 3 sign bits)
202  const CacheKey tang_pos_bits = 12;
203  const CacheKey axial_pos_bits = 28;
204  const CacheKey timing_pos_bits = 20;
206  // typedef std::map<CacheKey, ProjMatrixElemsForOneBin> MapProjMatrixElemsForOneBin;
207  typedef std::unordered_map<CacheKey, ProjMatrixElemsForOneBin> MapProjMatrixElemsForOneBin;
208  typedef MapProjMatrixElemsForOneBin::iterator MapProjMatrixElemsForOneBinIterator;
209  typedef MapProjMatrixElemsForOneBin::const_iterator const_MapProjMatrixElemsForOneBinIterator;
210 
213 #ifdef STIR_OPENMP
215 #endif
216 
218  // KT 15/05/2002 not static anymore as it uses cache_stores_only_basic_bins
219  CacheKey cache_key(const Bin& bin) const;
220 
224  void enable_tof(const shared_ptr<const ProjDataInfo>& proj_data_info_sptr, const bool v = true);
225 
227  float gauss_sigma_in_mm;
229  float r_sqrt2_gauss_sigma;
230 
232  inline void apply_tof_kernel(ProjMatrixElemsForOneBin& probabilities) const;
233 
235  inline float get_tof_value(const float d1, const float d2) const;
236 
238  FastErf erf_interpolation;
239 };
240 
241 END_NAMESPACE_STIR
242 
244 
245 #endif // __ProjMatrixByBin_H__
Declaration of class stir::DataSymmetriesForBins.
A class for encoding/finding symmetries common to the geometry of the projection data and the discret...
Definition: DataSymmetriesForBins.h:67
A templated class for vectors, but with indices starting not from 0.
Definition: ArrayFilter1DUsingConvolution.h:31
Implementation of an erf interpolation.
Declaration of class stir::ParsingObject.
bool tof_enabled
If activated TOF reconstruction will be performed.
Definition: ProjMatrixByBin.h:177
This is the (abstract) base class for all projection matrices which are organised by &#39;bin&#39;...
Definition: ProjMatrixByBin.h:78
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
Implementations of inline functions for class stir::ProjMatrixByBin.
base class for all objects which need timers. At the moment, there&#39;s only a CPU timer.
Definition: TimedObject.h:35
shared_ptr< const ProjDataInfo > proj_data_info_sptr
We need a local copy of the proj_data_info to get the integration boundaries and RayTracing.
Definition: ProjMatrixByBin.h:192
Declaration of class stiir::RegisteredObject.
A class for storing coordinates and value of a single projection bin.
Definition: Bin.h:48
declares the stir::TimedObject class
Helper class to provide registry mechanisms to a Base classSuppose you have a hierarchy of classes wi...
Definition: RegisteredObject.h:95
defines the stir::VectorWithOffset class
Declaration of class stir::ProjMatrixElemsForOneBin.
This stores the non-zero projection matrix elements for every &#39;densel&#39; that contributes to a given bi...
Definition: ProjMatrixElemsForOneBin.h:68
defines the stir::VoxelsOnCartesianGrid class
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
shared_ptr< const VoxelsOnCartesianGrid< float > > image_info_sptr
We need a local copy of the discretised density in order to find the cartesian coordinates of each vo...
Definition: ProjMatrixByBin.h:189