STIR  6.2.0
MultipleProjData.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2005 - 2007-10-08, Hammersmith Imanet Ltd
3  Copyright (C) 2013, Kris Thielemans
4  Copyright (C) 2013, 2016-2020 University College London
5  This file is part of STIR.
6 
7  SPDX-License-Identifier: Apache-2.0
8 
9  See STIR/LICENSE.txt for details
10 */
11 #ifndef __stir_MultipleProjData__H__
12 #define __stir_MultipleProjData__H__
13 
20 #include "stir/ProjData.h"
21 #include "stir/ExamData.h"
22 #include "stir/shared_ptr.h"
23 #include "stir/Array.h"
24 #include "stir/is_null_ptr.h"
25 #include "stir/copy_fill.h"
26 #include "stir/error.h"
27 //#include "stir/Scanner.h"
28 #include <vector>
29 
30 START_NAMESPACE_STIR
31 
32 class MultipleProjData : public ExamData
33 {
34 public:
35  MultipleProjData()
36  : ExamData()
37  {}
38 
39  MultipleProjData(const shared_ptr<const ExamInfo>& exam_info_sptr)
40  : ExamData(exam_info_sptr)
41  {}
42 
50  MultipleProjData(const shared_ptr<const ExamInfo>& exam_info_sptr, const int num_gates);
51 
52  static unique_ptr<MultipleProjData> read_from_file(const std::string& parameter_file);
53 
54  // N.E.14/07/16 Inherited from ExamData
55  // //! Get a pointer to the exam information
56  // const ExamInfo*
57  // get_exam_info_ptr() const
58  // {
59  // return this->_exam_info_sptr.get();
60  // }
61 
62  // //! Get a shared pointer to the exam information
63  // shared_ptr<ExamInfo>
64  // get_exam_info_sptr() const
65  // {
66  // return this->_exam_info_sptr;
67  // }
68 
69  unsigned get_num_proj_data() const { return static_cast<unsigned>(this->_proj_datas.size()); }
70 
75  std::size_t get_proj_data_size() const { return _proj_datas.at(0)->size_all(); }
76 
78 
82  void resize(const unsigned new_size) { this->_proj_datas.resize(new_size); }
83 
85 
88  void set_proj_data_sptr(const shared_ptr<ProjData>& proj_data_sptr, const unsigned int index);
92  const ProjData& operator[](const unsigned int index) const
93  {
94  assert(index >= 1);
95  assert(index <= this->get_num_proj_data());
96  return *this->_proj_datas[index - 1];
97  }
101  const ProjData& get_proj_data(const unsigned int index) const { return (*this)[index]; }
102 
106  shared_ptr<ProjData> get_proj_data_sptr(const unsigned int index) const
107  {
108  assert(index >= 1);
109  assert(index <= this->get_num_proj_data());
110  return this->_proj_datas[index - 1];
111  }
112 
113  const shared_ptr<const ProjDataInfo> get_proj_data_info_sptr() const;
114  // return get_proj_data_sptr(1))->get_proj_data_info_sptr()
115 
117  unsigned int get_num_gates() const { return static_cast<unsigned int>(_proj_datas.size()); }
118 
124  template <typename iterT>
125  iterT copy_to(iterT array_iter) const
126  {
127  for (std::vector<shared_ptr<ProjData>>::const_iterator it = _proj_datas.begin(); it != _proj_datas.end(); ++it)
128  {
129  if (is_null_ptr(*(it)))
130  error("Dynamic/gated ProjData have not been properly allocated. Abort.");
131 
132  array_iter = stir::copy_to(*(*it), array_iter);
133  }
134  return array_iter;
135  }
136 
142  template <typename iterT>
143  void fill_from(iterT array_iter)
144  {
145  for (std::vector<shared_ptr<ProjData>>::iterator it = _proj_datas.begin(); it != _proj_datas.end(); ++it)
146  {
147  if (is_null_ptr(*(it)))
148  error("Dynamic ProjData have not been properly allocated.Abort.");
149 
150  array_iter = (*it)->fill_from(array_iter);
151  }
152  }
153 
157  std::size_t size_all() const
158  {
159  std::size_t size = 0;
160  for (std::size_t i_gate = 0; i_gate < this->get_num_gates(); i_gate++)
161  size += _proj_datas.at(i_gate)->size_all();
162 
163  return size;
164  }
165 
166 protected:
167  std::vector<shared_ptr<ProjData>> _proj_datas;
168  // shared_ptr<Scanner> _scanner_sptr;
169 protected:
170  // N.E:14/07/16 Inherited from ExamData.
171  // shared_ptr<ExamInfo> _exam_info_sptr;
172 };
173 
175 
181 template <>
182 struct CopyFill<MultipleProjData>
183 {
184  template <typename iterT>
185  static iterT copy_to(const MultipleProjData& stir_object, iterT iter)
186  {
187  // std::cerr<<"Using MultipleProjData::copy_to\n";
188  return stir_object.copy_to(iter);
189  }
190 };
191 
193 
197 template <typename iterT>
198 void
199 fill_from(MultipleProjData& stir_object, iterT iter, iterT /*iter_end*/)
200 {
201  return stir_object.fill_from(iter);
202 }
203 
204 END_NAMESPACE_STIR
205 #endif
iterT copy_to(const T &stir_object, iterT iter)
Copy all bins to a range specified by a iterator.
Definition: copy_fill.h:133
Helper class for stir::copy_to and stir::fill_from.
Definition: copy_fill.h:35
declaration of stir::ExamData
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
Declaration of class stir::ProjData.
defines the Array class for multi-dimensional (numeric) arrays
Declaration of stir::error()
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
Definition of stir::is_null_ptr functions.
Declaration of stir::copy_to and stir::fill_from templates.
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition: error.cxx:42
void fill_from(MultipleProjData &stir_object, iterT iter, iterT)
set all elements of a MultipleProjData from an iterator
Definition: MultipleProjData.h:199