STIR  6.2.0
DynamicDiscretisedDensity.h
Go to the documentation of this file.
1 //
2 //
12 /*
13  Copyright (C) 2005 - 2011-01-12, Hammersmith Imanet Ltd
14  Copyright (C) 2011-07-01 - 2011, Kris Thielemans
15  Copyright (C) 2018-2020 University College London
16  This file is part of STIR.
17 
18  SPDX-License-Identifier: Apache-2.0
19 
20  See STIR/LICENSE.txt for details
21 */
22 
23 #ifndef __stir_DynamicDiscretisedDensity_H__
24 #define __stir_DynamicDiscretisedDensity_H__
25 
27 #include "stir/shared_ptr.h"
29 #include "stir/Scanner.h"
30 #include "stir/NestedIterator.h"
31 #include "stir/is_null_ptr.h"
32 #include <vector>
33 #include <string>
34 
35 START_NAMESPACE_STIR
36 
37 class Succeeded;
38 
46 {
47 public:
49 
52 
54 
55 private:
57  typedef std::vector<shared_ptr<singleDiscDensT>> DensitiesT;
58 
59 public:
64 
65  static DynamicDiscretisedDensity* read_from_file(const std::string& filename);
66 
68 
70 
71  DynamicDiscretisedDensity(const TimeFrameDefinitions& time_frame_definitions,
72  const double scan_start_time_in_secs_since_1970,
73  const shared_ptr<Scanner>& scanner_sptr)
74  {
75  _densities.resize(time_frame_definitions.get_num_frames());
76  shared_ptr<ExamInfo> _exam_info_sptr(new ExamInfo);
77  _exam_info_sptr->set_time_frame_definitions(time_frame_definitions);
78  _exam_info_sptr->start_time_in_secs_since_1970 = scan_start_time_in_secs_since_1970;
79  this->exam_info_sptr = _exam_info_sptr;
80  _scanner_sptr = scanner_sptr;
81  }
83  DynamicDiscretisedDensity(const TimeFrameDefinitions& time_frame_definitions,
84  const double scan_start_time_in_secs_since_1970,
85  const shared_ptr<Scanner>& scanner_sptr,
86  const shared_ptr<singleDiscDensT>& density_sptr)
87  {
88  _densities.resize(time_frame_definitions.get_num_frames());
89  shared_ptr<ExamInfo> _exam_info_sptr;
90  if (is_null_ptr(density_sptr->get_exam_info_sptr()))
91  _exam_info_sptr.reset(new ExamInfo);
92  else
93  _exam_info_sptr = density_sptr->get_exam_info_sptr()->create_shared_clone();
94  _exam_info_sptr->set_time_frame_definitions(time_frame_definitions);
95  _exam_info_sptr->start_time_in_secs_since_1970 = scan_start_time_in_secs_since_1970;
96  this->exam_info_sptr = _exam_info_sptr;
97 
98  _scanner_sptr = scanner_sptr;
99 
100  for (unsigned int frame_num = 1; frame_num <= time_frame_definitions.get_num_frames(); ++frame_num)
101  {
102  shared_ptr<singleDiscDensT> density_frame_sptr(density_sptr->get_empty_copy());
103  ExamInfo this_exam_info(*exam_info_sptr);
104  this_exam_info.set_time_frame_definitions(TimeFrameDefinitions(time_frame_definitions, frame_num));
105  density_frame_sptr->set_exam_info(this_exam_info);
106  this->_densities[frame_num - 1] = density_frame_sptr;
107  }
108  }
109 
110  DynamicDiscretisedDensity& operator=(const DynamicDiscretisedDensity& argument);
111 
116  inline full_iterator begin_all();
117  inline const_full_iterator begin_all() const;
118  inline const_full_iterator begin_all_const() const;
119  inline full_iterator end_all();
120  inline const_full_iterator end_all() const;
121  inline const_full_iterator end_all_const() const;
123 
131  void set_density(const singleDiscDensT& density, const unsigned int frame_num);
132  /*
133  DynamicDiscretisedDensity( TimeFrameDefinitions time_frame_defintions,shared_ptr<Scanner>,
134  std::vector<shared_ptr<DiscretiseDensity<3,float> > _densities);
135  */
136 
137  const std::vector<shared_ptr<singleDiscDensT>>& get_densities() const;
138 
139  const singleDiscDensT& get_density(const unsigned int frame_num) const;
140 
141  const singleDiscDensT& operator[](const unsigned int frame_num) const { return this->get_density(frame_num); }
142 
144  singleDiscDensT& get_density(const unsigned int frame_num);
145 
146  singleDiscDensT& operator[](const unsigned int frame_num) { return this->get_density(frame_num); }
148 
149  const float get_isotope_halflife() const;
150 
151  float get_calibration_factor() const;
152 
154  const singleDiscDensT& at(const unsigned int frame_num) const { return this->get_density(frame_num); }
155 
157  singleDiscDensT& at(const unsigned int frame_num) { return this->get_density(frame_num); }
158 
160 
169  const double get_start_time_in_secs_since_1970() const;
170 
171  const float get_scanner_default_bin_size() const;
172 
173  void set_time_frame_definitions(const TimeFrameDefinitions& time_frame_definitions)
174  {
175  shared_ptr<ExamInfo> sptr = this->exam_info_sptr->create_shared_clone();
176  sptr->set_time_frame_definitions(time_frame_definitions);
177  this->exam_info_sptr = sptr;
178  }
179 
180  void set_scanner(const Scanner& scanner) { this->_scanner_sptr.reset(new Scanner(scanner)); }
181 
182  const TimeFrameDefinitions& get_time_frame_definitions() const;
183 
184  unsigned get_num_time_frames() const { return this->get_time_frame_definitions().get_num_time_frames(); }
185 
190  Succeeded write_to_ecat7(const std::string& filename) const;
191 
192  void calibrate_frames() const;
197  void decay_correct_frames();
198  void set_if_decay_corrected(const bool is_decay_corrected);
199  void set_calibration_factor(const float calibration_factor);
200  void set_num_densities(const int num_densities) { _densities.resize(num_densities); }
201 
202 private:
203  // warning: if adding any new members, you have to change the copy constructor as well.
204  // TimeFrameDefinitions _time_frame_definitions;
205  DensitiesT _densities;
206  shared_ptr<Scanner> _scanner_sptr;
207  bool _is_decay_corrected;
208  // double _start_time_in_secs_since_1970;
209 };
210 
211 END_NAMESPACE_STIR
212 
214 
215 #endif //__stir_DynamicDiscretisedDensity_H__
NestedIterator< DensitiesT::const_iterator, ConstPtrBeginEndAllFunction< DensitiesT::const_iterator > > const_full_iterator
typedef for const iterator that runs over all densels in all frames
Definition: DynamicDiscretisedDensity.h:63
Class used for storing time frame durations.
Definition: TimeFrameDefinitions.h:38
singleDiscDensT & at(const unsigned int frame_num)
at method
Definition: DynamicDiscretisedDensity.h:157
unsigned int get_num_time_frames() const
Get number of frames.
Definition: TimeFrameDefinitions.cxx:92
Declaration of class stir::TimeFrameDefinitions.
Import of std::shared_ptr, std::dynamic_pointer_cast and std::static_pointer_cast (or corresponding b...
defines the stir::DiscretisedDensity class
Class NestedIterator implements a (forward) iterator using a pair of &#39;nested&#39; iterators.
Definition: NestedIterator.h:93
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
A class for storing some info on the scanner.
Definition: Scanner.h:107
Class of multiple image frames, one for each time frame Each time frame is a DiscretisedDensity<3,float>
Definition: DynamicDiscretisedDensity.h:45
DynamicDiscretisedDensity(const TimeFrameDefinitions &time_frame_definitions, const double scan_start_time_in_secs_since_1970, const shared_ptr< Scanner > &scanner_sptr, const shared_ptr< singleDiscDensT > &density_sptr)
Construct an empty DynamicDiscretisedDensity based on a shared_ptr<DiscretisedDensity<3,float> >
Definition: DynamicDiscretisedDensity.h:83
Definition of stir::is_null_ptr functions.
Declaration of class stir::Scanner.
NestedIterator< DensitiesT::iterator, PtrBeginEndAllFunction< DensitiesT::iterator > > full_iterator
typedef for iterator that runs over all densels in all frames
Definition: DynamicDiscretisedDensity.h:61
a class for storing information about 1 exam (or scan)
Definition: ExamInfo.h:41
unsigned int get_num_frames() const
Get number of frames.
Definition: TimeFrameDefinitions.cxx:86
a class containing an enumeration type that can be used by functions to signal successful operation o...
Definition: Succeeded.h:43
This file declares the stir::NestedIterator class and supporting function objects.
const singleDiscDensT & at(const unsigned int frame_num) const
at method
Definition: DynamicDiscretisedDensity.h:154
DynamicDiscretisedDensity hierarchy_base_type
A typedef that can be used what the base of the hierarchy is.
Definition: DynamicDiscretisedDensity.h:51
base class for data objects such as ProjData etcProvides an ExamInfo member.
Definition: ExamData.h:33
Inline implementations of class stir::DynamicDiscretisedDensity.