STIR 6.4.0
ProjData.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2000 PARAPET partners
3 Copyright (C) 2000- 2012, Hammersmith Imanet Ltd
4 Copyright (C) 2016, 2017, University of Hull
5 Copyright (C) 2013, 2015-2017, 2020, 2023 University College London
6 This file is part of STIR.
7
8 SPDX-License-Identifier: Apache-2.0 AND License-ref-PARAPET-license
9
10 See STIR/LICENSE.txt for details
11*/
22#ifndef __stir_ProjData_H__
23#define __stir_ProjData_H__
24
25#include "stir/Array.h"
26#include "stir/shared_ptr.h"
27#include "stir/ProjDataInfo.h"
28#include <string>
29#include <iostream>
30#include "stir/Succeeded.h"
32#include "stir/SegmentByView.h"
33#include "stir/SegmentIndices.h"
36
37//#include <ios>
38
39#include "stir/ExamData.h"
41
42START_NAMESPACE_STIR
43
44template <typename elemT>
45class RelatedViewgrams;
46class DataSymmetriesForViewSegmentNumbers;
47template <typename elemT>
48class SegmentBySinogram;
49template <typename elemT>
50class SegmentByView;
51template <typename elemT>
52class Viewgram;
53template <typename elemT>
54class Sinogram;
55class Succeeded;
56class ProjDataInMemory;
57// class ExamInfo;
58
105{
106#ifdef STIR_COMPILING_SWIG_WRAPPER
107public: // SWIG needs self_type exposed
108#endif
109 typedef ProjData self_type;
110
111public:
113 static shared_ptr<ProjData> read_from_file(const std::string& filename, const std::ios::openmode open_mode = std::ios::in);
114
116 ProjData();
118 ProjData(const shared_ptr<const ExamInfo>& exam_info_sptr, const shared_ptr<const ProjDataInfo>& proj_data_info_ptr);
119#if 0
120 // it would be nice to have something like this. However, it's implementation
121 // normally fails as we'd need to use set_viewgram or so, which is virtual, but
122 // this doesn't work inside a constructor
123 ProjData(const ProjData&);
124#endif
125
127
130 virtual Viewgram<float> get_viewgram(const int view,
131 const int segment_num,
132 const bool make_num_tangential_poss_odd = false,
133 const int timing_pos = 0) const = 0;
135 inline Viewgram<float> get_viewgram(const ViewgramIndices&) const;
136
140
143 virtual Sinogram<float> get_sinogram(const int ax_pos_num,
144 const int segment_num,
145 const bool make_num_tangential_poss_odd = false,
146 const int timing_pos = 0) const = 0;
148 inline Sinogram<float> get_sinogram(const SinogramIndices&) const;
149
152 // //! Get Bin value
153 // virtual float get_bin_value(const Bin& this_bin) const = 0;
154
156 unique_ptr<ProjDataInMemory> get_subset(const std::vector<int>& views) const;
157
160
162
165 Viewgram<float> get_empty_viewgram(const int view,
166 const int segment_num,
167 const bool make_num_tangential_poss_odd = false,
168 const int timing_pos = 0) const;
169
172
174
177 Sinogram<float> get_empty_sinogram(const int ax_pos_num,
178 const int segment_num,
179 const bool make_num_tangential_poss_odd = false,
180 const int timing_pos = 0) const;
181
187
191 const bool make_num_tangential_poss_odd = false,
192 const int timing_pos = 0) const;
194
198 const bool make_num_tangential_poss_odd = false,
199 const int timing_pos = 0) const;
200
202
205 virtual SegmentBySinogram<float> get_segment_by_sinogram(const int segment_num, const int timing_pos = 0) const;
206
209
211
214 virtual SegmentByView<float> get_segment_by_view(const int segment_num, const int timing_pos = 0) const;
215
218
223
225 // TODOTOF remove timing_pos arg
227 const shared_ptr<DataSymmetriesForViewSegmentNumbers>&,
228 const bool make_num_tangential_poss_odd = false,
229 const int timing_pos = 0) const;
232 // //! Get related bin values
233 // //! \todo This function temporaliry has as input a vector<Bin> instead this should be replaced by RelatedBins.
234 // std::vector<float> get_related_bin_values(const std::vector<Bin>&) const;
235
238 const shared_ptr<DataSymmetriesForViewSegmentNumbers>& symmetries_ptr,
239 const bool make_num_tangential_poss_odd = false,
240 const int timing_pos = 0) const;
241
243
244 virtual void fill(const float value);
245
247
251 virtual void fill(const ProjData&);
252
254
259 static std::vector<int> standard_segment_sequence(const ProjDataInfo& pdi);
260
262
276 template <typename iterT>
277 iterT fill_from(iterT array_iter)
278 {
279 // A type check would be useful.
280 // BOOST_STATIC_ASSERT((boost::is_same<typename std::iterator_traits<iterT>::value_type, Type>::value));
281
282 for (int k = this->get_proj_data_info_sptr()->get_min_tof_pos_num();
283 k <= this->get_proj_data_info_sptr()->get_max_tof_pos_num();
284 ++k)
285 {
287 {
288 auto segment = this->get_empty_segment_by_sinogram(s, false, k);
289 // cannot use std::copy sadly as needs end-iterator for range
290 for (auto seg_iter = segment.begin_all(); seg_iter != segment.end_all();
291 /*empty*/)
292 *seg_iter++ = *array_iter++;
293 this->set_segment(segment);
294 }
295 }
296 return array_iter;
297 }
298
300
309 template <typename iterT>
310 iterT copy_to(iterT array_iter) const
311 {
312 for (int k = this->get_proj_data_info_sptr()->get_min_tof_pos_num();
313 k <= this->get_proj_data_info_sptr()->get_max_tof_pos_num();
314 ++k)
315 {
317 {
318 const auto segment = this->get_segment_by_sinogram(s, k);
319 array_iter = std::copy(segment.begin_all_const(), segment.end_all_const(), array_iter);
320 }
321 }
322 return array_iter;
323 }
324
326
329 inline int get_num_sinograms() const;
331
334 inline int get_num_non_tof_sinograms() const;
336 inline std::size_t size_all() const;
338 inline std::vector<int> get_original_view_nums() const;
339
341 Succeeded write_to_file(const std::string& filename) const;
342
346 virtual float sum() const;
347
349 virtual float find_max() const;
350
352 virtual float find_min() const;
353
355 virtual double norm() const;
356
358 virtual double norm_squared() const;
359
361 virtual self_type& operator+=(const self_type& v);
362
364 virtual self_type& operator-=(const self_type& v);
365
367 virtual self_type& operator*=(const self_type& v);
368
370 virtual self_type& operator/=(const self_type& v);
371
373 virtual self_type& operator+=(const float v);
374
376 virtual self_type& operator-=(const float v);
377
379 virtual self_type& operator*=(const float v);
380
382 virtual self_type& operator/=(const float v);
383
385 STIR_DEPRECATED virtual void axpby(const float a, const ProjData& x, const float b, const ProjData& y);
386
388 virtual void xapyb(const ProjData& x, const float a, const ProjData& y, const float b);
389
391 virtual void xapyb(const ProjData& x, const ProjData& a, const ProjData& y, const ProjData& b);
392
394 virtual void sapyb(const float a, const ProjData& y, const float b);
395
397 virtual void sapyb(const ProjData& a, const ProjData& y, const ProjData& b);
399};
400
401END_NAMESPACE_STIR
402
403#include "stir/ProjData.inl"
404#endif
defines the stir::Array class for multi-dimensional (numeric) arrays
declaration of stir::DataWithProjDataInfo
declaration of stir::ExamData
Declaration of class stir::ProjDataInfo.
Implementations for inline functions of class stir::ProjData.
Declaration of class stir::SegmentBySinogram.
Declaration of class stir::SegmentByView.
Definition of class stir::SegmentIndices.
Definition of class stir::SinogramIndices.
Declaration of class stir::Succeeded.
Definition of class stir::ViewgramIndices.
virtual shared_ptr< const ProjDataInfo > get_proj_data_info_sptr() const
Get shared pointer to ProjData info.
Definition DataWithProjDataInfo.cxx:37
int get_min_tof_pos_num() const
Get the index of the first timing position.
Definition DataWithProjDataInfo.inl:105
DataWithProjDataInfo()
Default constructor sets internal member to 0.
Definition DataWithProjDataInfo.cxx:20
ExamData()
ExamData.
Definition ExamData.cxx:21
An (abstract base) class that contains information on the projection data.
Definition ProjDataInfo.h:70
The (abstract) base class for the projection data.
Definition ProjData.h:105
Viewgram< float > get_empty_viewgram(const ViewgramIndices &) const
Get empty viewgram.
Definition ProjData.cxx:189
virtual SegmentByView< float > get_segment_by_view(const int segment_num, const int timing_pos=0) const
Get segment by view.
Definition ProjData.cxx:329
SegmentBySinogram< float > get_empty_segment_by_sinogram(const SegmentIndices &) const
Get empty segment by sino.
Definition ProjData.cxx:233
virtual SegmentBySinogram< float > get_segment_by_sinogram(const int segment_num, const int timing_pos=0) const
Get segment by sinogram.
Definition ProjData.cxx:319
Sinogram< float > get_empty_sinogram(const SinogramIndices &) const
Get empty_sinogram.
Definition ProjData.cxx:195
SegmentByView< float > get_empty_segment_by_view(const SegmentIndices &) const
Get empty segment by view.
Definition ProjData.cxx:239
virtual Succeeded set_sinogram(const Sinogram< float > &)=0
Set sinogram.
virtual Succeeded set_related_viewgrams(const RelatedViewgrams< float > &viewgrams)
Set related viewgrams.
Definition ProjData.cxx:295
virtual RelatedViewgrams< float > get_related_viewgrams(const ViewgramIndices &, const shared_ptr< DataSymmetriesForViewSegmentNumbers > &, const bool make_num_tangential_poss_odd=false, const int timing_pos=0) const
Get related viewgrams.
Definition ProjData.cxx:256
iterT copy_to(iterT array_iter) const
Copy all bins to a range specified by a (forward) iterator.
Definition ProjData.h:310
unique_ptr< ProjDataInMemory > get_subset(const std::vector< int > &views) const
construct projection data that stores a subset of the views
Definition ProjData.cxx:166
iterT fill_from(iterT array_iter)
set all bins from an array iterator
Definition ProjData.h:277
virtual Succeeded set_segment(const SegmentBySinogram< float > &)
Set segment by sinogram.
Definition ProjData.cxx:339
virtual Succeeded set_viewgram(const Viewgram< float > &)=0
Set viewgram.
RelatedViewgrams< float > get_empty_related_viewgrams(const ViewgramIndices &viewgram_indices, const shared_ptr< DataSymmetriesForViewSegmentNumbers > &symmetries_ptr, const bool make_num_tangential_poss_odd=false, const int timing_pos=0) const
Get empty related viewgrams, where the symmetries_ptr specifies the symmetries to use.
Definition ProjData.cxx:245
virtual void fill(const float value)
set all bins to the same value
Definition ProjData.cxx:361
virtual Viewgram< float > get_viewgram(const int view, const int segment_num, const bool make_num_tangential_poss_odd=false, const int timing_pos=0) const =0
Get viewgram.
static shared_ptr< ProjData > read_from_file(const std::string &filename, const std::ios::openmode open_mode=std::ios::in)
A static member to get the projection data from a file.
Definition ProjData.cxx:89
virtual 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 =0
Get sinogram.
ProjData()
Empty constructor.
Definition ProjData.cxx:394
static std::vector< int > standard_segment_sequence(const ProjDataInfo &pdi)
Return a vector with segment numbers in a standard order.
Definition ProjData.cxx:641
A class for storing viewgrams which are related by symmetry.
Definition RelatedViewgrams.h:41
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 very simple class to store segment numbers and any other indices that define a segment.
Definition SegmentIndices.h:34
A very simple class to store all dincies to get a (2D) Sinogram.
Definition SinogramIndices.h:34
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 very simple class to store all dincies to get a (2D) Viewgram.
Definition ViewgramIndices.h:33
A class for 2d projection data.
Definition Viewgram.h:49
#define STIR_DEPRECATED
Deprecation macro.
Definition deprecated.h:21
double norm(const BasicCoordinate< num_dimensions, coordT > &p1)
compute sqrt(inner_product(p1,p1))
Definition BasicCoordinate.inl:426
double norm_squared(const BasicCoordinate< num_dimensions, coordT > &p1)
compute (inner_product(p1,p1))
Definition BasicCoordinate.inl:415
std::string write_to_file(const std::string &filename, const DataT &data)
Function that writes data to file using the default OutputFileFormat.
Definition write_to_file.h:46
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
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast into the stir names...