STIR  6.2.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"
31 #include "stir/SegmentBySinogram.h"
32 #include "stir/SegmentByView.h"
33 #include "stir/SegmentIndices.h"
34 #include "stir/ViewgramIndices.h"
35 #include "stir/SinogramIndices.h"
36 
37 //#include <ios>
38 
39 #include "stir/ExamData.h"
40 
41 START_NAMESPACE_STIR
42 
43 template <typename elemT>
44 class RelatedViewgrams;
45 class DataSymmetriesForViewSegmentNumbers;
46 template <typename elemT>
47 class SegmentBySinogram;
48 template <typename elemT>
49 class SegmentByView;
50 template <typename elemT>
51 class Viewgram;
52 template <typename elemT>
53 class Sinogram;
54 class Succeeded;
55 class ProjDataInMemory;
56 // class ExamInfo;
57 
103 class ProjData : public ExamData
104 {
105 #ifdef SWIG
106  public: // SWIG needs self_type exposed
107 #endif
108  typedef ProjData self_type;
109 
110 public:
112  static shared_ptr<ProjData> read_from_file(const std::string& filename, const std::ios::openmode open_mode = std::ios::in);
113 
115  ProjData();
117  ProjData(const shared_ptr<const ExamInfo>& exam_info_sptr, const shared_ptr<const ProjDataInfo>& proj_data_info_ptr);
118 #if 0
119  // it would be nice to have something like this. However, it's implementation
120  // normally fails as we'd need to use set_viewgram or so, which is virtual, but
121  // this doesn't work inside a constructor
122  ProjData(const ProjData&);
123 #endif
124 
126  ~ProjData() override
127  {}
129  inline shared_ptr<const ProjDataInfo> get_proj_data_info_sptr() const;
131 
134  virtual Viewgram<float> get_viewgram(const int view,
135  const int segment_num,
136  const bool make_num_tangential_poss_odd = false,
137  const int timing_pos = 0) const = 0;
139  inline Viewgram<float> get_viewgram(const ViewgramIndices&) const;
140 
142  virtual Succeeded set_viewgram(const Viewgram<float>&) = 0;
144 
147  virtual Sinogram<float> get_sinogram(const int ax_pos_num,
148  const int segment_num,
149  const bool make_num_tangential_poss_odd = false,
150  const int timing_pos = 0) const = 0;
152  inline Sinogram<float> get_sinogram(const SinogramIndices&) const;
153 
155  virtual Succeeded set_sinogram(const Sinogram<float>&) = 0;
156  // //! Get Bin value
157  // virtual float get_bin_value(const Bin& this_bin) const = 0;
158 
160  unique_ptr<ProjDataInMemory> get_subset(const std::vector<int>& views) const;
161 
163  Viewgram<float> get_empty_viewgram(const ViewgramIndices&) const;
164 
166 
169  Viewgram<float> get_empty_viewgram(const int view,
170  const int segment_num,
171  const bool make_num_tangential_poss_odd = false,
172  const int timing_pos = 0) const;
173 
175  Sinogram<float> get_empty_sinogram(const SinogramIndices&) const;
176 
178 
181  Sinogram<float> get_empty_sinogram(const int ax_pos_num,
182  const int segment_num,
183  const bool make_num_tangential_poss_odd = false,
184  const int timing_pos = 0) const;
185 
187  SegmentByView<float> get_empty_segment_by_view(const SegmentIndices&) const;
189  SegmentBySinogram<float> get_empty_segment_by_sinogram(const SegmentIndices&) const;
191 
194  SegmentByView<float> get_empty_segment_by_view(const int segment_num,
195  const bool make_num_tangential_poss_odd = false,
196  const int timing_pos = 0) const;
198 
201  SegmentBySinogram<float> get_empty_segment_by_sinogram(const int segment_num,
202  const bool make_num_tangential_poss_odd = false,
203  const int timing_pos = 0) const;
204 
206 
209  virtual SegmentBySinogram<float> get_segment_by_sinogram(const int segment_num, const int timing_pos = 0) const;
210 
212  inline SegmentBySinogram<float> get_segment_by_sinogram(const SegmentIndices&) const;
213 
215 
218  virtual SegmentByView<float> get_segment_by_view(const int segment_num, const int timing_pos = 0) const;
219 
221  inline SegmentByView<float> get_segment_by_view(const SegmentIndices&) const;
222 
224  virtual Succeeded set_segment(const SegmentBySinogram<float>&);
226  virtual Succeeded set_segment(const SegmentByView<float>&);
227 
229  // TODOTOF remove timing_pos arg
230  virtual RelatedViewgrams<float> get_related_viewgrams(const ViewgramIndices&,
231  const shared_ptr<DataSymmetriesForViewSegmentNumbers>&,
232  const bool make_num_tangential_poss_odd = false,
233  const int timing_pos = 0) const;
235  virtual Succeeded set_related_viewgrams(const RelatedViewgrams<float>& viewgrams);
236  // //! Get related bin values
237  // //! \todo This function temporaliry has as input a vector<Bin> instead this should be replaced by RelatedBins.
238  // std::vector<float> get_related_bin_values(const std::vector<Bin>&) const;
239 
241  RelatedViewgrams<float> get_empty_related_viewgrams(const ViewgramIndices& viewgram_indices,
242  const shared_ptr<DataSymmetriesForViewSegmentNumbers>& symmetries_ptr,
243  const bool make_num_tangential_poss_odd = false,
244  const int timing_pos = 0) const;
245 
247 
248  virtual void fill(const float value);
249 
251 
255  virtual void fill(const ProjData&);
256 
258 
263  static std::vector<int> standard_segment_sequence(const ProjDataInfo& pdi);
264 
266 
280  template <typename iterT>
281  iterT fill_from(iterT array_iter)
282  {
283  // A type check would be useful.
284  // BOOST_STATIC_ASSERT((boost::is_same<typename std::iterator_traits<iterT>::value_type, Type>::value));
285 
286  for (int k = this->get_proj_data_info_sptr()->get_min_tof_pos_num();
287  k <= this->get_proj_data_info_sptr()->get_max_tof_pos_num();
288  ++k)
289  {
290  for (int s : standard_segment_sequence(*this->get_proj_data_info_sptr()))
291  {
292  auto segment = this->get_empty_segment_by_sinogram(s, false, k);
293  // cannot use std::copy sadly as needs end-iterator for range
294  for (auto seg_iter = segment.begin_all(); seg_iter != segment.end_all();
295  /*empty*/)
296  *seg_iter++ = *array_iter++;
297  this->set_segment(segment);
298  }
299  }
300  return array_iter;
301  }
302 
304 
313  template <typename iterT>
314  iterT copy_to(iterT array_iter) const
315  {
316  for (int k = this->get_proj_data_info_sptr()->get_min_tof_pos_num();
317  k <= this->get_proj_data_info_sptr()->get_max_tof_pos_num();
318  ++k)
319  {
320  for (int s : standard_segment_sequence(*this->get_proj_data_info_sptr()))
321  {
322  const auto segment = this->get_segment_by_sinogram(s, k);
323  array_iter = std::copy(segment.begin_all_const(), segment.end_all_const(), array_iter);
324  }
325  }
326  return array_iter;
327  }
328 
330  inline int get_num_segments() const;
332  inline int get_num_axial_poss(const int segment_num) const;
334  inline int get_num_views() const;
336  inline int get_num_tangential_poss() const;
338  inline int get_num_tof_poss() const;
340  inline int get_min_tof_pos_num() const;
342  inline int get_max_tof_pos_num() const;
344  inline int get_tof_mash_factor() const;
346  inline int get_min_segment_num() const;
348  inline int get_max_segment_num() const;
350  inline int get_min_axial_pos_num(const int segment_num) const;
352  inline int get_max_axial_pos_num(const int segment_num) const;
354  inline int get_min_view_num() const;
356  inline int get_max_view_num() const;
358  inline int get_min_tangential_pos_num() const;
360  inline int get_max_tangential_pos_num() const;
362 
365  inline int get_num_sinograms() const;
367 
370  inline int get_num_non_tof_sinograms() const;
372  inline std::size_t size_all() const;
374  inline std::vector<int> get_original_view_nums() const;
375 
377  Succeeded write_to_file(const std::string& filename) const;
378 
382  virtual float sum() const;
383 
385  virtual float find_max() const;
386 
388  virtual float find_min() const;
389 
391  virtual double norm() const;
392 
394  virtual double norm_squared() const;
395 
397  virtual self_type& operator+=(const self_type& v);
398 
400  virtual self_type& operator-=(const self_type& v);
401 
403  virtual self_type& operator*=(const self_type& v);
404 
406  virtual self_type& operator/=(const self_type& v);
407 
409  virtual self_type& operator+=(const float v);
410 
412  virtual self_type& operator-=(const float v);
413 
415  virtual self_type& operator*=(const float v);
416 
418  virtual self_type& operator/=(const float v);
419 
421  STIR_DEPRECATED virtual void axpby(const float a, const ProjData& x, const float b, const ProjData& y);
422 
424  virtual void xapyb(const ProjData& x, const float a, const ProjData& y, const float b);
425 
427  virtual void xapyb(const ProjData& x, const ProjData& a, const ProjData& y, const ProjData& b);
428 
430  virtual void sapyb(const float a, const ProjData& y, const float b);
431 
433  virtual void sapyb(const ProjData& a, const ProjData& y, const ProjData& b);
435 
436 protected:
437  shared_ptr<const ProjDataInfo> proj_data_info_sptr;
438 };
439 
440 END_NAMESPACE_STIR
441 
442 #include "stir/ProjData.inl"
443 #endif
#define STIR_DEPRECATED
Deprecation macro.
Definition: deprecated.h:19
iterT fill_from(iterT array_iter)
set all bins from an array iterator
Definition: ProjData.h:281
A class for 2d projection data.
Definition: FBP3DRPReconstruction.h:39
Declaration of class stir::Succeeded.
~ProjData() override
Destructor.
Definition: ProjData.h:126
A very simple class to store segment numbers and any other indices that define a segment.
Definition: SegmentIndices.h:33
Declaration of class stir::ProjDataInfo.
Definition of class stir::SegmentIndices.
A class for storing (3d) projection data with fixed SegmentIndices.
Definition: FBP3DRPReconstruction.h:41
declaration of stir::ExamData
Definition of class stir::SinogramIndices.
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
Implementations for inline functions of class stir::ProjData.
iterT copy_to(iterT array_iter) const
Copy all bins to a range specified by a (forward) iterator.
Definition: ProjData.h:314
defines the 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
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:47
Definition of class stir::ViewgramIndices.
double norm_squared(const BasicCoordinate< num_dimensions, coordT > &p1)
compute (inner_product(p1,p1))
Definition: BasicCoordinate.inl:415
Declaration of class stir::SegmentByView.
double norm(const BasicCoordinate< num_dimensions, coordT > &p1)
compute sqrt(inner_product(p1,p1))
Definition: BasicCoordinate.inl:426
A very simple class to store all dincies to get a (2D) Sinogram.
Definition: SinogramIndices.h:33
An (abstract base) class that contains information on the projection data.
Definition: ProjDataInfo.h:69
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
A very simple class to store all dincies to get a (2D) Viewgram.
Definition: ViewgramIndices.h:32
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
Declaration of class stir::SegmentBySinogram.
base class for data objects such as ProjData etcProvides an ExamInfo member.
Definition: ExamData.h:33