STIR  6.2.0
NiftyPETHelper.h
Go to the documentation of this file.
1 //
2 //
3 
4 #ifndef __stir_gpu_NiftyPETHelper_h__
5 #define __stir_gpu_NiftyPETHelper_h__
6 
29 /*
30  Copyright (C) 2019-2020, University College London
31  This file is part of STIR.
32 
33  SPDX-License-Identifier: Apache-2.0
34 
35  See STIR/LICENSE.txt for details
36 */
37 
38 #include "stir/shared_ptr.h"
39 #include "stir/Scanner.h"
40 
41 // Forward declarations
42 struct Cnst;
43 struct txLUTs;
44 struct axialLUT;
45 
46 START_NAMESPACE_STIR
47 
48 template <int num_dimensions, typename elemT>
49 class DiscretisedDensity;
50 class ProjData;
51 template <typename elemT>
52 class Viewgram;
53 template <typename elemT>
54 class VoxelsOnCartesianGrid;
55 
61 {
62 public:
65  : _already_set_up(false),
66  _span(-1),
67  _devid(0),
68  _att(-1),
69  _scanner_type(Scanner::Unknown_scanner)
70  {}
71 
73  virtual ~NiftyPETHelper();
74 
76  void set_cuda_device_id(const int devid) { _devid = char(devid); }
77 
79  void set_span(const char span) { _span = span; }
80 
82  void set_att(const char att) { _att = att; }
83 
85  void set_verbose(const bool verbose) { _verbose = verbose; }
86 
88  void set_scanner_type(const Scanner::Type scanner_type) { _scanner_type = scanner_type; }
89 
91  void set_up();
92 
94  static std::vector<float> create_niftyPET_image();
95 
97  static shared_ptr<VoxelsOnCartesianGrid<float>> create_stir_im();
98 
100  std::vector<float> create_niftyPET_sinogram_no_gaps() const;
101 
103  std::vector<float> create_niftyPET_sinogram_with_gaps() const;
104 
106  static void convert_image_stir_to_niftyPET(std::vector<float>& np, const DiscretisedDensity<3, float>& stir);
107 
109  static void convert_image_niftyPET_to_stir(DiscretisedDensity<3, float>& stir, const std::vector<float>& np_vec);
110 
112  void convert_proj_data_stir_to_niftyPET(std::vector<float>& np_vec, const ProjData& stir) const;
113 
115  void convert_viewgram_stir_to_niftyPET(std::vector<float>& np_vec, const Viewgram<float>& viewgram) const;
116 
118  void convert_proj_data_niftyPET_to_stir(ProjData& stir_sptr, const std::vector<float>& np_vec) const;
119 
121  void remove_gaps(std::vector<float>& sino_no_gaps, const std::vector<float>& sino_w_gaps) const;
122 
124  void put_gaps(std::vector<float>& sino_w_gaps, const std::vector<float>& sino_no_gaps) const;
125 
127  void back_project(std::vector<float>& image, const std::vector<float>& sino_no_gaps) const;
128 
130  void forward_project(std::vector<float>& sino_no_gaps, const std::vector<float>& image) const;
131 
133  static shared_ptr<ProjData> create_stir_sino();
134 
136  void lm_to_proj_data(shared_ptr<ProjData>& prompts_sptr,
137  shared_ptr<ProjData>& delayeds_sptr,
138  shared_ptr<ProjData>& randoms_sptr,
139  shared_ptr<ProjData>& norm_sptr,
140  const int tstart,
141  const int tstop,
142  const std::string& lm_binary_file,
143  const std::string& norm_binary_file = "") const;
144 
145 private:
147  void check_set_up() const;
148 
150  void permute(std::vector<float>& output_array,
151  const std::vector<float>& orig_array,
152  const unsigned output_dims[3],
153  const unsigned* permute_order) const;
154 
156  unsigned convert_NiftyPET_proj_3d_to_1d_idx(const unsigned ang, const unsigned bins, const unsigned sino) const;
157 
159  void convert_NiftyPET_proj_1d_to_3d_idx(unsigned& ang, unsigned& bins, unsigned& sino, const unsigned idx) const;
160 
161  bool _already_set_up;
162  char _span;
163  char _devid;
164  shared_ptr<Cnst> _cnt_sptr;
165  int _nsinos;
166  char _att;
167  std::vector<int> _isub;
168  bool _verbose;
169  Scanner::Type _scanner_type;
170  shared_ptr<txLUTs> _txlut_sptr;
171  shared_ptr<axialLUT> _axlut_sptr;
172 
173  std::vector<float> _crs;
174  std::vector<short> _s2c;
175 
176  // Get axLUT
177  std::vector<float> _li2rng;
178  std::vector<short> _li2sn;
179  std::vector<char> _li2nos;
180 };
181 
182 END_NAMESPACE_STIR
183 
184 #endif // __stir_gpu_NiftyPETHelper_h__
Namespace for the STIR library (and some/most of its applications)
Definition: General_Reconstruction.cxx:6
NiftyPETHelper()
Default constructor.
Definition: NiftyPETHelper.h:64
Type
enum for all predefined scanners
Definition: Scanner.h:140
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
A class for storing some info on the scanner.
Definition: Scanner.h:107
Declaration of class stir::Scanner.
Helper class for the wrapped NiftyPET projectors.
Definition: NiftyPETHelper.h:60
void set_span(const char span)
Set span.
Definition: NiftyPETHelper.h:79
void set_scanner_type(const Scanner::Type scanner_type)
Set scanner type.
Definition: NiftyPETHelper.h:88
void set_cuda_device_id(const int devid)
Set CUDA device ID.
Definition: NiftyPETHelper.h:76
void set_verbose(const bool verbose)
Set verbosity level for CUDA output.
Definition: NiftyPETHelper.h:85
The (abstract) base class for the projection data.
Definition: ProjData.h:103
void set_att(const char att)
Set emission (0) or transmission (1) - whether to exp{-result} for attenuation maps.
Definition: NiftyPETHelper.h:82