STIR  6.2.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 SWIG
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 
65  Viewgram<float> get_viewgram(const int view_num,
66  const int segment_num,
67  const bool make_num_tangential_poss_odd = false,
68  const int timing_pos = 0) const override;
69  Succeeded set_viewgram(const Viewgram<float>& v) override;
70 
71  Sinogram<float> get_sinogram(const int ax_pos_num,
72  const int segment_num,
73  const bool make_num_tangential_poss_odd = false,
74  const int timing_pos = 0) const override;
75 
76  Succeeded set_sinogram(const Sinogram<float>& s) override;
77 
79  SegmentBySinogram<float> get_segment_by_sinogram(const int segment_num, const int timing_pos = 0) const override;
81  SegmentByView<float> get_segment_by_view(const int segment_num, const int timing_pos = 0) const override;
82 
84  Succeeded set_segment(const SegmentBySinogram<float>&) override;
86  Succeeded set_segment(const SegmentByView<float>&) override;
87 
89 
90  void fill(const float value) override;
91 
93 
97  void fill(const ProjData&) override;
98 
100  ~ProjDataInMemory() override;
101 
103  float get_bin_value(Bin& bin);
104 
105  void set_bin_value(const Bin& bin);
106 
110  float sum() const override;
111 
113  float find_max() const override;
114 
116  float find_min() const override;
117 
119  double norm() const override;
120 
122  double norm_squared() const override;
123 
125  self_type operator+(const self_type& iv) const;
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 float a) 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 
148  // corresponding assignment operators
149 
151  self_type& operator+=(const base_type& v) override;
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 float 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  STIR_DEPRECATED void axpby(const float a, const ProjData& x, const float b, const ProjData& y) override;
176 
180  void xapyb(const ProjData& x, const float a, const ProjData& y, const float b) override;
181 
185  void xapyb(const ProjData& x, const ProjData& a, const ProjData& y, const ProjData& b) override;
186 
190  void sapyb(const float a, const ProjData& y, const float b) override;
191 
195  void sapyb(const ProjData& a, const ProjData& y, const ProjData& b) override;
197 
201  typedef Array<1, float>::iterator iterator;
203  typedef Array<1, float>::const_iterator const_iterator;
204  typedef Array<1, float>::full_iterator full_iterator;
205  typedef Array<1, float>::const_full_iterator const_full_iterator;
207 
209  iterator begin()
210  {
211  return buffer.begin();
212  }
214  const_iterator begin() const
215  {
216  return buffer.begin();
217  }
219  iterator end()
220  {
221  return buffer.end();
222  }
224  const_iterator end() const
225  {
226  return buffer.end();
227  }
229  iterator begin_all()
230  {
231  return buffer.begin_all();
232  }
234  const_iterator begin_all() const
235  {
236  return buffer.begin_all();
237  }
239  iterator end_all()
240  {
241  return buffer.end_all();
242  }
244  const_iterator end_all() const
245  {
246  return buffer.end_all();
247  }
248 
250 
251  float* get_data_ptr()
253  {
254  return buffer.get_data_ptr();
255  }
256 
258  const float* get_const_data_ptr() const
259  {
260  return buffer.get_const_data_ptr();
261  }
262 
265  {
266  buffer.release_data_ptr();
267  }
268 
271  {
272  buffer.release_const_data_ptr();
273  }
275 
276 private:
277  Array<1, float> buffer;
278 
280  void create_buffer(const bool initialise_with_0 = false);
282  std::streamoff offset;
284  std::streamoff offset_3d_data;
285 
287  std::vector<int> segment_sequence;
289  std::vector<int> timing_poss_sequence;
290 
292 
293  std::streamoff get_index(const Bin&) const;
294 };
295 
296 inline double
297 norm(const ProjDataInMemory& p)
298 {
299  return p.norm();
300 }
301 
302 inline double
304 {
305  return p.norm_squared();
306 }
307 
308 END_NAMESPACE_STIR
309 
310 #endif
A class which reads/writes projection data from/to memory.
Definition: ProjDataInMemory.h:38
#define STIR_DEPRECATED
Deprecation macro.
Definition: deprecated.h:19
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:229
iterator begin()
start value for iterating through all elements in the array, see iterator
Definition: ProjDataInMemory.h:209
const float * get_const_data_ptr() const
member function for access to the data via a const float*
Definition: ProjDataInMemory.h:258
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:390
const_iterator begin() const
start value for iterating through all elements in the (const) array, see iterator ...
Definition: ProjDataInMemory.h:214
Declaration of class stir::ProjData.
double norm() const override
return L2-norm (sqrt of sum of squares)
Definition: ProjDataInMemory.cxx:384
defines the Array class for multi-dimensional (numeric) arrays
A class for storing (3d) projection data with fixed SegmentIndices.
Definition: ArcCorrection.h:40
const_iterator begin_all() const
start value for iterating through all elements in the (const) array, see iterator ...
Definition: ProjDataInMemory.h:234
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:264
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:244
void release_const_data_ptr() const
signal end of access to const float*
Definition: ProjDataInMemory.h:270
iterator end()
end value for iterating through all elements in the array, see iterator
Definition: ProjDataInMemory.h:219
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:73
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:224
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:239