31 this->set_is_decay_corrected(
false);
38 this->_plasma_blood_plot = plasma_blood_plot;
39 this->set_is_decay_corrected(
false);
40 this->_isotope_halflife = -1.;
52 std::ifstream data_stream(input_string.c_str());
54 error(
"cannot read plasma data from file.\n");
58 std::string first_line;
59 if (std::getline(data_stream, first_line))
62 first_line.erase(std::find_if(first_line.rbegin(),
64 std::bind(std::not_equal_to<char>(),
' ', std::placeholders::_1))
67 first_line.erase(first_line.begin(),
68 std::find_if(first_line.begin(),
70 std::bind(std::not_equal_to<char>(),
' ', std::placeholders::_1)));
74 long converted = strtol(first_line.c_str(), &p, 10);
76 error(
"First line of input function file (" + input_string +
") is not number of samples");
78 _sample_size = converted;
82 error(
"Input function file (" + input_string +
") is empty");
87 float sample_time = 0, blood_sample_radioactivity = 0, plasma_sample_radioactivity = 0;
88 data_stream >> sample_time;
89 data_stream >> plasma_sample_radioactivity;
90 data_stream >> blood_sample_radioactivity;
93 const PlasmaSample current_sample(sample_time, plasma_sample_radioactivity, blood_sample_radioactivity);
94 (this->_plasma_blood_plot).push_back(current_sample);
96 this->set_is_decay_corrected(
false);
117 this->_plasma_blood_plot = plasma_blood_plot;
124 _time_shift = time_shift;
125 for (std::vector<PlasmaSample>::iterator cur_iter = this->_plasma_blood_plot.begin();
126 cur_iter != this->_plasma_blood_plot.end();
128 cur_iter->set_time_in_s(cur_iter->get_time_in_s() + time_shift);
135 return PlasmaData::_time_shift;
142 return this->_isotope_halflife;
149 this->_isotope_halflife = isotope_halflife;
155 this->_plasma_fdef = plasma_fdef;
159PlasmaData::get_time_frame_definitions()
const
161 return this->_plasma_fdef;
165PlasmaData::set_is_decay_corrected(
const bool is_decay_corrected)
167 this->_is_decay_corrected = is_decay_corrected;
171PlasmaData::get_is_decay_corrected()
const
173 return this->_is_decay_corrected;
180 if (this->_is_decay_corrected ==
true)
181 warning(
"PlasmaData are already decay corrected");
184 assert(this->_isotope_halflife > 0);
185 for (std::vector<PlasmaSample>::iterator cur_iter = this->_plasma_blood_plot.begin();
186 cur_iter != this->_plasma_blood_plot.end();
189 cur_iter->set_plasma_counts_in_kBq(
static_cast<float>(
190 cur_iter->get_plasma_counts_in_kBq() *
decay_correction_factor(_isotope_halflife, cur_iter->get_time_in_s())));
191 cur_iter->set_blood_counts_in_kBq(
static_cast<float>(
194 PlasmaData::set_is_decay_corrected(
true);
202 if (this->_is_decay_corrected ==
false)
205 warning(
"Correcting for decay while sampling into frames.");
206 this->set_is_decay_corrected(
true);
208 std::vector<double> start_times_vector;
209 std::vector<double> durations_vector;
211 std::vector<PlasmaSample> samples_in_frames_vector(num_frames);
212 PlasmaData::const_iterator cur_iter;
213 std::vector<PlasmaSample>::iterator frame_iter = samples_in_frames_vector.begin();
216 for (
unsigned int frame_num = 1; frame_num <= num_frames && frame_iter != samples_in_frames_vector.end();
217 ++frame_num, ++frame_iter)
219 std::vector<double> time_frame_vector;
220 std::vector<double> plasma_frame_vector;
221 std::vector<double> blood_frame_vector;
222 const double frame_start_time = time_frame_def.get_start_time(frame_num);
223 const double frame_end_time = time_frame_def.get_end_time(frame_num);
225 for (cur_iter = (this->_plasma_blood_plot).
begin(); cur_iter != (this->_plasma_blood_plot).end(); ++cur_iter)
227 const double cur_time = (*cur_iter).get_time_in_s();
228 if (cur_time < frame_start_time)
230 const double cur_plasma_cnt = (*cur_iter).get_plasma_counts_in_kBq();
231 const double cur_blood_cnt = (*cur_iter).get_blood_counts_in_kBq();
232 if (cur_time < frame_end_time)
234 plasma_frame_vector.push_back(cur_plasma_cnt);
235 blood_frame_vector.push_back(cur_blood_cnt);
236 time_frame_vector.push_back(cur_time);
240 if (plasma_frame_vector.size()
243 plasma_frame_vector.push_back(0.);
244 blood_frame_vector.push_back(0.);
245 time_frame_vector.push_back((frame_start_time + frame_end_time) * .5);
249 plasma_frame_vector.push_back(cur_plasma_cnt);
250 blood_frame_vector.push_back(cur_blood_cnt);
251 time_frame_vector.push_back(cur_time);
256 if (time_frame_vector.size() != 1)
258 frame_iter->set_blood_counts_in_kBq(
260 / (time_frame_vector[time_frame_vector.size() - 1] - time_frame_vector[0])));
261 frame_iter->set_plasma_counts_in_kBq(
263 / (time_frame_vector[time_frame_vector.size() - 1] - time_frame_vector[0])));
264 frame_iter->set_time_in_s(0.5 * (time_frame_vector[time_frame_vector.size() - 1] + time_frame_vector[0]));
265 start_times_vector.push_back(time_frame_vector[0]);
266 durations_vector.push_back(time_frame_vector[time_frame_vector.size() - 1] - time_frame_vector[0]);
268 else if (time_frame_vector.size() == 1)
270 frame_iter->set_plasma_counts_in_kBq(
static_cast<float>(plasma_frame_vector[0]));
271 frame_iter->set_blood_counts_in_kBq(
static_cast<float>(blood_frame_vector[0]));
272 frame_iter->set_time_in_s(time_frame_vector[0]);
273 start_times_vector.push_back(frame_start_time);
274 durations_vector.push_back(frame_end_time - frame_start_time);
277 PlasmaData plasma_data_in_frames(samples_in_frames_vector);
279 plasma_data_in_frames.set_is_decay_corrected(this->_is_decay_corrected);
282 return plasma_data_in_frames;
286PlasmaData::const_iterator
289 return this->_plasma_blood_plot.begin();
292PlasmaData::const_iterator
293PlasmaData::end()
const
295 return this->_plasma_blood_plot.end();
299PlasmaData::size()
const
301 return static_cast<unsigned>(this->_plasma_blood_plot.size());
A class for storing plasma and blood samples of a single study.
Definition PlasmaData.h:34
double get_isotope_halflife() const
Function to get the isotope halflife.
Definition PlasmaData.inl:140
void set_time_frame_definitions(const TimeFrameDefinitions &plasma_fdef)
Definition PlasmaData.inl:153
double get_time_shift()
Function to get the time shift.
Definition PlasmaData.inl:133
void shift_time(const double time_shift)
Function to shift the time data.
Definition PlasmaData.inl:122
PlasmaData get_sample_data_in_frames(TimeFrameDefinitions time_frame_def)
Sorts the plasma_data into frames.
Definition PlasmaData.inl:200
~PlasmaData()
default constructor
Definition PlasmaData.inl:44
void set_plot(const std::vector< PlasmaSample > &plasma_blood_plot)
Function to set the plasma_blood_plot.
Definition PlasmaData.inl:115
void read_plasma_data(const std::string input_string)
Implementation to read the input function from ONLY a 3-columns data file (Time-InputFunctionRadioact...
Definition PlasmaData.inl:50
void set_isotope_halflife(const double isotope_halflife)
Function to set the isotope halflife.
Definition PlasmaData.inl:147
PlasmaData(const std::vector< PlasmaSample > &plasma_blood_plot)
constructor giving a vector
Definition PlasmaData.inl:36
const_iterator begin() const
begin() and end() iterators for the plasma curve and the size() function
Definition PlasmaData.inl:287
void decay_correct_PlasmaData()
Function to decay correct the data.
Definition PlasmaData.inl:177
Definition PlasmaSample.h:38
Class used for storing time frame durations.
Definition TimeFrameDefinitions.h:39
unsigned int get_num_frames() const
Get number of frames.
Definition TimeFrameDefinitions.cxx:92
Simple functions to compute the decay correction factor.
Declaration of stir::error()
void error(const char *const s,...)
Print error with format string a la printf and throw exception.
Definition error.cxx:42
void warning(const char *const s,...)
Print warning with format string a la printf.
Definition warning.cxx:41
double decay_correction_factor(const double isotope_halflife, const double start_time, const double end_time)
Compute decay-correction factor for a time frame.
Definition decay_correction_factor.h:36
elemT integrate_discrete_function(const std::vector< elemT > &coordinates, const std::vector< elemT > &values, const int interpolation_order=1)
numerical integration of a 1D function
Definition integrate_discrete_function.inl:26
Declaration of stir::integrate_discrete_function function.
Declaration of stir::warning()