STIR 6.4.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*/
19
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
27START_NAMESPACE_STIR
28
29class Succeeded;
30
39{
40#ifdef STIR_COMPILING_SWIG_WRAPPER
41 // SWIG needs this typedef to be public
42public:
43#endif
44 typedef ProjDataInMemory self_type;
45 typedef ProjData base_type;
46
47public:
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
64 ProjDataInMemory(shared_ptr<const ExamInfo> const& exam_info_sptr,
65 shared_ptr<const ProjDataInfo> const& proj_data_info_ptr,
66 Array<1, float>&& buffer);
67
69 ProjDataInMemory(const ProjData& proj_data);
70
72 ProjDataInMemory(const ProjDataInMemory& proj_data);
73
75 static shared_ptr<ProjDataInMemory> read_from_file(const std::string& filename);
76
77 Viewgram<float> get_viewgram(const int view_num,
78 const int segment_num,
79 const bool make_num_tangential_poss_odd = false,
80 const int timing_pos = 0) const override;
81 Succeeded set_viewgram(const Viewgram<float>& v) override;
82
83 Sinogram<float> get_sinogram(const int ax_pos_num,
84 const int segment_num,
85 const bool make_num_tangential_poss_odd = false,
86 const int timing_pos = 0) const override;
87
88 Succeeded set_sinogram(const Sinogram<float>& s) override;
89
91 SegmentBySinogram<float> get_segment_by_sinogram(const int segment_num, const int timing_pos = 0) const override;
93 SegmentByView<float> get_segment_by_view(const int segment_num, const int timing_pos = 0) const override;
94
99
101
102 void fill(const float value) override;
103
105
109 void fill(const ProjData&) override;
110
112 ~ProjDataInMemory() override;
113
115 float get_bin_value(const Bin& bin) const;
116
117 void set_bin_value(const Bin& bin);
118
122 float sum() const override;
123
125 float find_max() const override;
126
128 float find_min() const override;
129
131 double norm() const override;
132
134 double norm_squared() const override;
135
137 self_type operator+(const self_type& iv) const;
138
140 self_type operator-(const self_type& iv) const;
141
143 self_type operator*(const self_type& iv) const;
144
146 self_type operator/(const self_type& iv) const;
147
149 self_type operator+(const float a) const;
150
152 self_type operator-(const float a) const;
153
155 self_type operator*(const float a) const;
156
158 self_type operator/(const float a) const;
159
160 // corresponding assignment operators
161
163 self_type& operator+=(const base_type& v) override;
164
166 self_type& operator-=(const base_type& v) override;
167
169 self_type& operator*=(const base_type& v) override;
170
172 self_type& operator/=(const base_type& v) override;
173
175 self_type& operator+=(const float v) override;
176
178 self_type& operator-=(const float v) override;
179
181 self_type& operator*=(const float v) override;
182
184 self_type& operator/=(const float v) override;
185
187 STIR_DEPRECATED void axpby(const float a, const ProjData& x, const float b, const ProjData& y) override;
188
192 void xapyb(const ProjData& x, const float a, const ProjData& y, const float b) override;
193
197 void xapyb(const ProjData& x, const ProjData& a, const ProjData& y, const ProjData& b) override;
198
202 void sapyb(const float a, const ProjData& y, const float b) override;
203
207 void sapyb(const ProjData& a, const ProjData& y, const ProjData& b) override;
209
214 typedef Array<1, float>::iterator iterator;
215 typedef Array<1, float>::const_iterator const_iterator;
216 typedef Array<1, float>::full_iterator full_iterator;
217 typedef Array<1, float>::const_full_iterator const_full_iterator;
219
221 iterator begin()
222 {
223 return buffer.begin();
224 }
225
226 const_iterator begin() const
227 {
228 return buffer.begin();
229 }
230
231 iterator end()
232 {
233 return buffer.end();
234 }
235
236 const_iterator end() const
237 {
238 return buffer.end();
239 }
240
241 iterator begin_all()
242 {
243 return buffer.begin_all();
244 }
245
246 const_iterator begin_all() const
247 {
248 return buffer.begin_all();
249 }
250
251 iterator end_all()
252 {
253 return buffer.end_all();
254 }
255
256 const_iterator end_all() const
257 {
258 return buffer.end_all();
259 }
260
262
263
265 {
266 return buffer.get_data_ptr();
267 }
268
270 const float* get_const_data_ptr() const
271 {
272 return buffer.get_const_data_ptr();
273 }
274
277 {
278 buffer.release_data_ptr();
279 }
280
283 {
284 buffer.release_const_data_ptr();
285 }
286
287
288private:
289 Array<1, float> buffer;
290
292 void create_buffer(const bool initialise_with_0 = false);
294 void initialise_layout_metadata();
296 std::streamoff offset;
298 std::streamoff offset_3d_data;
299
301 std::vector<int> segment_sequence;
303 std::vector<int> timing_poss_sequence;
304
306
307 std::streamoff get_index(const Bin&) const;
308};
309
310inline double
311norm(const ProjDataInMemory& p)
312{
313 return p.norm();
314}
315
316inline double
317norm_squared(const ProjDataInMemory& p)
318{
319 return p.norm_squared();
320}
321
322END_NAMESPACE_STIR
323
324#endif
defines the stir::Array class for multi-dimensional (numeric) arrays
Declaration of class stir::ProjData.
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
FullArrayIterator< typename base_type::iterator, typename Array< num_dimensions - 1, elemT >::full_iterator, elemT, full_reference, full_pointer > full_iterator
This defines an iterator type that iterates through all elements.
Definition Array.h:117
FullArrayIterator< typename base_type::const_iterator, typename Array< num_dimensions - 1, elemT >::const_full_iterator, elemT, const_full_reference, const_full_pointer > const_full_iterator
As full_iterator, but for const objects.
Definition Array.h:125
A class for storing coordinates and value of a single projection bin.
Definition Bin.h:49
void release_const_data_ptr() const
signal end of access to const float*
Definition ProjDataInMemory.h:282
self_type operator-(const self_type &iv) const
elem by elem subtraction
Definition ProjDataInMemory.cxx:493
const_iterator end_all() const
end value for iterating through all elements in the (const) array, see iterator
Definition ProjDataInMemory.h:256
const_iterator begin() const
start value for iterating through all elements in the (const) array, see iterator
Definition ProjDataInMemory.h:226
double norm_squared() const override
return L2-norm squared (sum of squares)
Definition ProjDataInMemory.cxx:410
iterator end()
end value for iterating through all elements in the array, see iterator
Definition ProjDataInMemory.h:231
SegmentBySinogram< float > get_segment_by_sinogram(const int segment_num, const int timing_pos=0) const override
Get all sinograms for the given segment.
Definition ProjDataInMemory.cxx:282
Succeeded set_viewgram(const Viewgram< float > &v) override
Set viewgram.
Definition ProjDataInMemory.cxx:162
void xapyb(const ProjData &x, const float a, const ProjData &y, const float b) override
set values of the array to x*a+y*b, where a and b are scalar, and x and y are ProjData....
Definition ProjDataInMemory.cxx:548
float get_bin_value(const Bin &bin) const
Returns a value of a bin.
Definition ProjDataInMemory.cxx:374
void release_data_ptr()
signal end of access to float*
Definition ProjDataInMemory.h:276
self_type & operator*=(const base_type &v) override
multiplying elements of the current data with elements of v
Definition ProjDataInMemory.cxx:437
self_type & operator-=(const base_type &v) override
subtracting elements of v from the current data
Definition ProjDataInMemory.cxx:427
Viewgram< float > get_viewgram(const int view_num, const int segment_num, const bool make_num_tangential_poss_odd=false, const int timing_pos=0) const override
Get viewgram.
Definition ProjDataInMemory.cxx:134
self_type operator*(const self_type &iv) const
elem by elem multiplication
Definition ProjDataInMemory.cxx:500
iterator begin_all()
start value for iterating through all elements in the array, see iterator
Definition ProjDataInMemory.h:241
void sapyb(const float a, const ProjData &y, const float b) override
set values of the array to self*a+y*b where a and b are scalar, y is ProjData This implementation req...
Definition ProjDataInMemory.cxx:624
Succeeded set_sinogram(const Sinogram< float > &s) override
Set sinogram.
Definition ProjDataInMemory.cxx:260
self_type operator/(const self_type &iv) const
elem by elem division
Definition ProjDataInMemory.cxx:507
self_type operator+(const self_type &iv) const
elem by elem addition
Definition ProjDataInMemory.cxx:486
ProjDataInMemory(shared_ptr< const ExamInfo > const &exam_info_sptr, shared_ptr< const ProjDataInfo > const &proj_data_info_ptr, const bool initialise_with_0=true)
constructor with only info, but no data
Definition ProjDataInMemory.cxx:49
SegmentByView< float > get_segment_by_view(const int segment_num, const int timing_pos=0) const override
Get all viewgrams for the given segment.
Definition ProjDataInMemory.cxx:295
Succeeded set_segment(const SegmentBySinogram< float > &) override
Set all sinograms for the given segment.
Definition ProjDataInMemory.cxx:302
float * get_data_ptr()
member function for access to the data via a float*
Definition ProjDataInMemory.h:264
iterator end_all()
end value for iterating through all elements in the array, see iterator
Definition ProjDataInMemory.h:251
STIR_DEPRECATED void axpby(const float a, const ProjData &x, const float b, const ProjData &y) override
Definition ProjDataInMemory.cxx:542
self_type & operator+=(const base_type &v) override
adding elements of v to the current data
Definition ProjDataInMemory.cxx:416
const float * get_const_data_ptr() const
member function for access to the data via a const float*
Definition ProjDataInMemory.h:270
void fill(const float value) override
set all bins to the same value
Definition ProjDataInMemory.cxx:336
static shared_ptr< ProjDataInMemory > read_from_file(const std::string &filename)
A static member to get the projection data in memory from a file.
Definition ProjDataInMemory.cxx:368
float find_min() const override
return minimum value of all elements
Definition ProjDataInMemory.cxx:398
const_iterator end() const
end value for iterating through all elements in the (const) array, see iterator
Definition ProjDataInMemory.h:236
iterator begin()
start value for iterating through all elements in the array, see iterator
Definition ProjDataInMemory.h:221
Sinogram< float > get_sinogram(const int ax_pos_num, const int segment_num, const bool make_num_tangential_poss_odd=false, const int timing_pos=0) const override
Get sinogram.
Definition ProjDataInMemory.cxx:239
const_iterator begin_all() const
start value for iterating through all elements in the (const) array, see iterator
Definition ProjDataInMemory.h:246
float find_max() const override
return maximum value of all elements
Definition ProjDataInMemory.cxx:392
self_type & operator/=(const base_type &v) override
dividing all elements of the current data by elements of v
Definition ProjDataInMemory.cxx:447
double norm() const override
return L2-norm (sqrt of sum of squares)
Definition ProjDataInMemory.cxx:404
ProjData()
Empty constructor.
Definition ProjData.cxx:394
A class for storing (3d) projection data with fixed SegmentIndices.
Definition SegmentBySinogram.h:51
A class for storing (3d) projection data with fixed SegmentIndices.
Definition SegmentByView.h:52
A class for 2d projection data.
Definition Sinogram.h:47
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition Succeeded.h:44
A class for 2d projection data.
Definition Viewgram.h:49
#define STIR_DEPRECATED
Deprecation macro.
Definition deprecated.h:21
double norm_squared(const BasicCoordinate< num_dimensions, coordT > &p1)
compute (inner_product(p1,p1))
Definition BasicCoordinate.inl:415