STIR  6.2.0
DynamicProjData.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2005 - 2011-01-04, Hammersmith Imanet Ltd
3  Copyright (C) 2013, Kris Thielemans
4  Copyright (C) 2013, 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__DynamicProjData__H__
12 #define __stir__DynamicProjData__H__
13 
19 #include "stir/MultipleProjData.h"
21 #include "stir/SegmentByView.h"
22 #include "stir/Succeeded.h"
23 #include "stir/error.h"
24 #include <string>
25 
26 START_NAMESPACE_STIR
27 
28 class Succeeded;
30 
36 class DynamicProjData : public MultipleProjData
37 {
38 public:
39  static unique_ptr<DynamicProjData> read_from_file(const std::string& filename);
40 
41  DynamicProjData() {}
42 
43  DynamicProjData(const MultipleProjData& m)
44  : MultipleProjData(m)
45  {}
46 
47  DynamicProjData(const shared_ptr<const ExamInfo>& exam_info_sptr)
48  : MultipleProjData(exam_info_sptr)
49  {}
50 
51  DynamicProjData(const shared_ptr<const ExamInfo>& exam_info_sptr, const int num_gates)
52  : MultipleProjData(exam_info_sptr, num_gates)
53  {}
54 
56 
65  const double get_start_time_in_secs_since_1970() const;
66 
68 
70  void set_start_time_in_secs_since_1970(const double start_time);
71  unsigned int get_num_frames() const { return this->get_num_proj_data(); }
72 
73  Succeeded write_to_ecat7(const std::string& filename) const;
74 
75  void set_time_frame_definitions(const TimeFrameDefinitions& time_frame_definitions);
76 
77  const TimeFrameDefinitions& get_time_frame_definitions() const;
78 
80 
81  void calibrate_frames(const float cal_factor)
82  {
83  for (unsigned int frame_num = 1; frame_num <= this->get_time_frame_definitions().get_num_frames(); ++frame_num)
84  for (int segment_num = (this->_proj_datas[frame_num - 1])->get_min_segment_num();
85  segment_num <= (this->_proj_datas[frame_num - 1])->get_max_segment_num();
86  ++segment_num)
87  {
88  for (int timing_pos_num = (this->_proj_datas[frame_num - 1])->get_min_tof_pos_num();
89  timing_pos_num <= (this->_proj_datas[frame_num - 1])->get_max_tof_pos_num();
90  ++timing_pos_num)
91  {
92  SegmentByView<float> segment_by_view(
93  (*(this->_proj_datas[frame_num - 1])).get_segment_by_view(segment_num, timing_pos_num));
94  segment_by_view *= cal_factor;
95  if ((*(this->_proj_datas[frame_num - 1])).set_segment(segment_by_view) == Succeeded::no)
96  {
97  error("DynamicProjData:calibrate_frames failed because set_segment_by_view failed");
98  }
99  }
100  }
101  }
102 
104 
106  {
107  // do reading/writing in a loop over segments
108  for (unsigned int frame_num = 1; frame_num <= this->get_time_frame_definitions().get_num_frames(); ++frame_num)
109  for (int segment_num = (this->_proj_datas[frame_num - 1])->get_min_segment_num();
110  segment_num <= (this->_proj_datas[frame_num - 1])->get_max_segment_num();
111  ++segment_num)
112  {
113  for (int timing_pos_num = (this->_proj_datas[frame_num - 1])->get_min_tof_pos_num();
114  timing_pos_num <= (this->_proj_datas[frame_num - 1])->get_max_tof_pos_num();
115  ++timing_pos_num)
116  {
117  SegmentByView<float> segment_by_view
118  = (*(this->_proj_datas[frame_num - 1])).get_segment_by_view(segment_num, timing_pos_num);
119  segment_by_view /= static_cast<float>(this->get_time_frame_definitions().get_duration(frame_num));
120  if ((*(this->_proj_datas[frame_num - 1])).set_segment(segment_by_view) == Succeeded::no)
121  {
122  error("DynamicProjData:calibrate_frames failed because set_segment_by_view failed");
123  }
124  }
125  }
126  }
127 };
128 
130 
137 template <>
139 {
140  template <typename iterT>
141  static iterT copy_to(const DynamicProjData& stir_object, iterT iter)
142  {
143  // std::cerr<<"Using DynamicProjData::copy_to\n";
144  return stir_object.copy_to(iter);
145  }
146 };
147 
149 
154 template <typename iterT>
155 void
156 fill_from(DynamicProjData& stir_object, iterT iter, iterT /*iter_end*/)
157 {
158  return stir_object.fill_from(iter);
159 }
160 
161 END_NAMESPACE_STIR
162 #endif
void calibrate_frames(const float cal_factor)
multiply data with a constant factor
Definition: DynamicProjData.h:81
Class used for storing time frame durations.
Definition: TimeFrameDefinitions.h:38
Declaration of class stir::Succeeded.
Declaration of class stir::TimeFrameDefinitions.
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::error()
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
void fill_from(DynamicProjData &stir_object, iterT iter, iterT)
set all elements of a MultipleProjData from an iterator
Definition: DynamicProjData.h:156
Declaration of class stir::MultipleProjData.
Dynamic projection data.
Definition: DynamicProjData.h:36
Declaration of class stir::SegmentByView.
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition: error.cxx:42
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
void divide_with_duration()
divide data with the corresponding frame duration
Definition: DynamicProjData.h:105