STIR  6.3.0
ProjDataInMemory.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016, UCL
3  Copyright (C) 2002 - 2011-02-23, Hammersmith Imanet Ltd
4  Copyright (C) 2019-2020, 2023, UCL
5  This file is part of STIR.
6 
7  SPDX-License-Identifier: Apache-2.0
8 
9  See STIR/LICENSE.txt for details
10 */
20 #ifndef __stir_ProjDataInMemory_H__
21 #define __stir_ProjDataInMemory_H__
22 
23 #include "stir/ProjData.h"
24 #include "stir/Array.h"
25 #include <string>
26 
27 START_NAMESPACE_STIR
28 
29 class Succeeded;
30 
38 class ProjDataInMemory : public ProjData
39 {
40 #ifdef STIR_COMPILING_SWIG_WRAPPER
41  // SWIG needs this typedef to be public
42 public:
43 #endif
45  typedef ProjData base_type;
46 
47 public:
49 
55  ProjDataInMemory(shared_ptr<const ExamInfo> const& exam_info_sptr,
56  shared_ptr<const ProjDataInfo> const& proj_data_info_ptr,
57  const bool initialise_with_0 = true);
58 
60  ProjDataInMemory(const ProjData& proj_data);
61 
63  ProjDataInMemory(const ProjDataInMemory& proj_data);
64 
66  static shared_ptr<ProjDataInMemory> read_from_file(const std::string& filename);
67 
68  Viewgram<float> get_viewgram(const int view_num,
69  const int segment_num,
70  const bool make_num_tangential_poss_odd = false,
71  const int timing_pos = 0) const override;
72  Succeeded set_viewgram(const Viewgram<float>& v) override;
73 
74  Sinogram<float> get_sinogram(const int ax_pos_num,
75  const int segment_num,
76  const bool make_num_tangential_poss_odd = false,
77  const int timing_pos = 0) const override;
78 
79  Succeeded set_sinogram(const Sinogram<float>& s) override;
80 
82  SegmentBySinogram<float> get_segment_by_sinogram(const int segment_num, const int timing_pos = 0) const override;
84  SegmentByView<float> get_segment_by_view(const int segment_num, const int timing_pos = 0) const override;
85 
87  Succeeded set_segment(const SegmentBySinogram<float>&) override;
89  Succeeded set_segment(const SegmentByView<float>&) override;
90 
92 
93  void fill(const float value) override;
94 
96 
100  void fill(const ProjData&) override;
101 
103  ~ProjDataInMemory() override;
104 
106  float get_bin_value(Bin& bin);
107 
108  void set_bin_value(const Bin& bin);
109 
113  float sum() const override;
114 
116  float find_max() const override;
117 
119  float find_min() const override;
120 
122  double norm() const override;
123 
125  double norm_squared() const override;
126 
128  self_type operator+(const self_type& iv) const;
129 
131  self_type operator-(const self_type& iv) const;
132 
134  self_type operator*(const self_type& iv) const;
135 
137  self_type operator/(const self_type& iv) const;
138 
140  self_type operator+(const float a) const;
141 
143  self_type operator-(const float a) const;
144 
146  self_type operator*(const float a) const;
147 
149  self_type operator/(const float a) const;
150 
151  // corresponding assignment operators
152 
154  self_type& operator+=(const base_type& v) override;
155 
157  self_type& operator-=(const base_type& v) override;
158 
160  self_type& operator*=(const base_type& v) override;
161 
163  self_type& operator/=(const base_type& v) override;
164 
166  self_type& operator+=(const float v) override;
167 
169  self_type& operator-=(const float v) override;
170 
172  self_type& operator*=(const float v) override;
173 
175  self_type& operator/=(const float v) override;
176 
178  STIR_DEPRECATED void axpby(const float a, const ProjData& x, const float b, const ProjData& y) override;
179 
183  void xapyb(const ProjData& x, const float a, const ProjData& y, const float b) override;
184 
188  void xapyb(const ProjData& x, const ProjData& a, const ProjData& y, const ProjData& b) override;
189 
193  void sapyb(const float a, const ProjData& y, const float b) override;
194 
198  void sapyb(const ProjData& a, const ProjData& y, const ProjData& b) override;
200 
204  typedef Array<1, float>::iterator iterator;
206  typedef Array<1, float>::const_iterator const_iterator;
207  typedef Array<1, float>::full_iterator full_iterator;
208  typedef Array<1, float>::const_full_iterator const_full_iterator;
210 
212  iterator begin()
213  {
214  return buffer.begin();
215  }
217  const_iterator begin() const
218  {
219  return buffer.begin();
220  }
222  iterator end()
223  {
224  return buffer.end();
225  }
227  const_iterator end() const
228  {
229  return buffer.end();
230  }
232  iterator begin_all()
233  {
234  return buffer.begin_all();
235  }
237  const_iterator begin_all() const
238  {
239  return buffer.begin_all();
240  }
242  iterator end_all()
243  {
244  return buffer.end_all();
245  }
247  const_iterator end_all() const
248  {
249  return buffer.end_all();
250  }
251 
253 
254  float* get_data_ptr()
256  {
257  return buffer.get_data_ptr();
258  }
259 
261  const float* get_const_data_ptr() const
262  {
263  return buffer.get_const_data_ptr();
264  }
265 
268  {
269  buffer.release_data_ptr();
270  }
271 
274  {
275  buffer.release_const_data_ptr();
276  }
278 
279 private:
280  Array<1, float> buffer;
281 
283  void create_buffer(const bool initialise_with_0 = false);
285  std::streamoff offset;
287  std::streamoff offset_3d_data;
288 
290  std::vector<int> segment_sequence;
292  std::vector<int> timing_poss_sequence;
293 
295 
296  std::streamoff get_index(const Bin&) const;
297 };
298 
299 inline double
300 norm(const ProjDataInMemory& p)
301 {
302  return p.norm();
303 }
304 
305 inline double
307 {
308  return p.norm_squared();
309 }
310 
311 END_NAMESPACE_STIR
312 
313 #endif
A class which reads/writes projection data from/to memory.
Definition: ProjDataInMemory.h:38
#define STIR_DEPRECATED
Deprecation macro.
Definition: deprecated.h:21
A class for 2d projection data.
Definition: FBP3DRPReconstruction.h:39
iterator begin_all()
start value for iterating through all elements in the array, see iterator
Definition: ProjDataInMemory.h:232
iterator begin()
start value for iterating through all elements in the array, see iterator
Definition: ProjDataInMemory.h:212
const float * get_const_data_ptr() const
member function for access to the data via a const float*
Definition: ProjDataInMemory.h:261
A class for storing (3d) projection data with fixed SegmentIndices.
Definition: FBP3DRPReconstruction.h:41
double norm_squared() const override
return L2-norm squared (sum of squares)
Definition: ProjDataInMemory.cxx:389
const_iterator begin() const
start value for iterating through all elements in the (const) array, see iterator ...
Definition: ProjDataInMemory.h:217
Declaration of class stir::ProjData.
double norm() const override
return L2-norm (sqrt of sum of squares)
Definition: ProjDataInMemory.cxx:383
defines the stir::Array class for multi-dimensional (numeric) arrays
A class for storing (3d) projection data with fixed SegmentIndices.
Definition: ArcCorrection.h:40
unique_ptr< DataT > read_from_file(const FileSignature &signature, FileT file)
Function that reads data from file using the default InputFileFormatRegistry, using the provided File...
Definition: read_from_file.h:46
const_iterator begin_all() const
start value for iterating through all elements in the (const) array, see iterator ...
Definition: ProjDataInMemory.h:237
double norm_squared(const BasicCoordinate< num_dimensions, coordT > &p1)
compute (inner_product(p1,p1))
Definition: BasicCoordinate.inl:415
void release_data_ptr()
signal end of access to float*
Definition: ProjDataInMemory.h:267
A class for storing coordinates and value of a single projection bin.
Definition: Bin.h:48
const_iterator end_all() const
end value for iterating through all elements in the (const) array, see iterator
Definition: ProjDataInMemory.h:247
void release_const_data_ptr() const
signal end of access to const float*
Definition: ProjDataInMemory.h:273
iterator end()
end value for iterating through all elements in the array, see iterator
Definition: ProjDataInMemory.h:222
double norm(const BasicCoordinate< num_dimensions, coordT > &p1)
compute sqrt(inner_product(p1,p1))
Definition: BasicCoordinate.inl:426
This class defines multi-dimensional (numeric) arrays.
Definition: Array.h:77
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
const_iterator end() const
end value for iterating through all elements in the (const) array, see iterator
Definition: ProjDataInMemory.h:227
elemT sum(IterT start, IterT end, elemT init)
Compute the sum of a sequence using operator+=(), using an initial value.
Definition: more_algorithms.inl:52
The (abstract) base class for the projection data.
Definition: ProjData.h:103
iterator end_all()
end value for iterating through all elements in the array, see iterator
Definition: ProjDataInMemory.h:242