8 #include "iLinearSpectralModel.hh" 69 cout <<
"-- This class implements the Spectral Model : " << endl;
70 cout <<
"-- first introduced by J. Cunningham et al. then used in PET reconstruction for temporal regularisation by Andrew Reader et al " << endl;
71 cout <<
"-- It is used to model radiotracer dynamic behaviour with a set of decaying exponential functions ( exp(-β*t) ) " << endl;
72 cout <<
"-- The decaying exponential coefficients β are logarithmically equally spaced within the selected range of values " << endl;
73 cout <<
" All decaying exponentials are convolved with the interpolated Arterial Input Curve, before being discretised to the duration of the reconstruction frames " << endl;
75 cout <<
" The model must be initialized using a ASCII file with the following keywords and information :" << endl;
76 cout <<
" As this class inherits from the iLinearModel class, the following parameters must be declared inside the couple of the following specific tags: " << endl;
77 cout <<
" - DYNAMIC FRAMING/ENDDF " << endl;
78 cout <<
" - The ASCII file must contain the following keywords :" << endl;
79 cout <<
" 'AIC_input_file: path/to/file' (mandatory) The file containing the sampled Arterial Input Function " << endl;
80 cout <<
" The file must contain the following information in successive lines, separated by ',' " << endl;
81 cout <<
" -> AIC_number_of_points: " << endl;
82 cout <<
" -> AIC_time_points: " << endl;
83 cout <<
" -> AIC_data_points: " << endl;
84 cout <<
" -> AIC_units: 'seconds' or 'minutes' " << endl;
85 cout <<
" The following options are required for the specification of the spectral functions. "<< endl;
86 cout <<
" As in the spectral analysis method, the spectral functions are convolved with the interpolated Input Curve. "<< endl;
87 cout <<
" By default a function which is the interpolated Input Curve is added in the dataset (equivalent to convolution of the IC with a dirac function)" << endl;
88 cout <<
" The spectral functions created will be logarithmically spaced within the selected range " << endl;
89 cout <<
" Number_spectral_functions: x (mandatory) The number of spectral functions" << endl;
90 cout <<
" Fastest_rate: x (mandatory) The rate (1/min) for the fastest decaying exponential " << endl;
91 cout <<
" Slowest_rate: x (mandatory) The rate (1/min) for the slowest decaying exponential" << endl;
92 cout <<
" Full_trapping_basis_function: 1 or 0 (optional) Option to say whether we want to include a basis function to model full trapping of tracer (1) or not (0 by default) " << endl;
93 cout <<
" Blood_fraction_basis_function: 1 or 0 (optional) Option to say whether we want to include a basis function to model the blood fraction of the tracer (1) or not (0 by default) " << endl;
94 cout <<
" In this implementation and for the blood fraction it is assumed that the whole blood input curve and plasma input curve are the same (no change due to metabolism) " << endl;
96 cout <<
" 'Parametric_image_init: path ' (optional) path to an interfile image to be used as initialization for the parametric images." << endl;
98 cout <<
" -> Optimisation_method : x (mandatory) optimization method available options: " << endl;
99 cout <<
" x=0: Direct ( Implementation of basis functions side by system matrix in each tomographic iterative loop " << endl;
100 cout <<
" x=1: Nested EM " << endl;
101 cout <<
" x=2: Iterative non-negative Least-Square " << endl;
102 cout <<
" (C.L. Lawson and R.J. Hanson, Solving Least Squares Problems)" << endl;
122 if(
m_verbose >=3)
Cout(
"iLinearSpectralModel::ReadAndCheckConfigurationFileSpecific ..."<< endl);
134 Cerr(
"***** iLinearSpectralModel::ReadAndCheckConfigurationFileSpecific -> Error while trying to read and check generic configuration for linear models " <<
m_fileOptions << endl);
146 Cerr(
"***** iLinearModel::ReadAndCheckConfigurationFileSpecific -> Error while trying to read 'Number_spectral_functions' flag in " <<
m_fileOptions << endl);
152 int full_trapping_basis_input =-1 ;
155 Cerr(
"***** iLinearModel::ReadAndCheckConfigurationFileSpecific -> Error while trying to read 'Full_trapping_basis_function' flag in " <<
m_fileOptions << endl);
161 int blood_fraction_basis_input =-1 ;
164 Cerr(
"***** iLinearModel::ReadAndCheckConfigurationFileSpecific -> Error while trying to read 'Blood_fraction_basis_function' flag in " <<
m_fileOptions << endl);
181 Cerr(
"***** iLinearSpectralModel::ReadAndCheckConfigurationFileSpecific -> Error while trying to read 'Fastest_rate' flag in " <<
m_fileOptions << endl);
189 Cerr(
"***** iLinearSpectralModel::ReadAndCheckConfigurationFileSpecific -> Error while trying to read 'Slowest_rate' flag in " <<
m_fileOptions << endl);
197 Cerr(
"***** iLinearPatlakModel::ReadAndCheckConfigurationFileSpecific -> Error while trying to read configuration file at: " <<
m_fileOptions << endl);
217 if(
m_verbose >=3)
Cout(
"iLinearSpectralModel::ReadAndCheckConfigurationFileSpecific ..."<< endl);
220 Cerr(
"***** iLinearSpectralModel::ReadAndCheckOptionsList -> This model needs to use a file for its initialization. Use help for more info !" << endl);
257 Cerr(
"***** iLinearPatlakModel::CheckSpecificParameters -> A problem occurred while checking specific parameters ! " << endl);
279 Cerr(
"***** iLinearSpectralModel::InitializeSpecific() -> Must call CheckParameters functions before Initialize() !" << endl);
284 if(
m_verbose >=2)
Cout(
"iLinearSpectralModel::InitializeSpecific ..."<< endl);
288 Cerr(
"***** iLinearSpectralModel::InitializeSpecific() -> Error while performing generic initialisations for linear models !" << endl);
309 HPFLTNB halfDeltaT = (0.001 / 2);
311 a_IntegAICY[0] = a_AICIntrpY[0] * 0.001;
315 RunningSum += a_AICIntrpY[i - 1];
316 a_IntegAICY[i] = (a_AICIntrpY[0] + 2 * RunningSum + a_AICIntrpY[i]) * halfDeltaT;
326 RunningSum += a_IntegAICY[i];
336 if (a_IntegAICY)
delete [] (a_IntegAICY);
351 if(
m_verbose >=3)
Cout(
" iLinearSpectralModel::InitializeSpecific() -> Sampling exponential functions" << endl);
360 spectral_exp[ex] =
new HPFLTNB[total_samples];
366 for (
int i = 0; i < total_samples; i++)
368 spectral_exp[ex][i] = (
FLTNB) exp(-0.1 * mp_spectral_bank[ex] * i);
377 ConvSpectralFunctions[ex] =
new HPFLTNB[total_samples];
382 #pragma omp parallel for private(ex) schedule(static, 1) 386 for (
int i = 0; i < total_samples; i++)
388 for (
int j = i; j < total_samples; j++)
390 ConvSpectralFunctions[ex][j] += (a_AICIntrpYDown[i] * spectral_exp[ex][j - i]);
393 ConvSpectralFunctions[ex][i] *= 0.1;
395 if ( ConvSpectralFunctions[ex][i] <0 )
397 Cout(
" Negative spectral function value detected at " << i <<
", with value: "<< ConvSpectralFunctions[ex][i] <<
398 " -> Setting value to zero "<< endl);
399 ConvSpectralFunctions[ex][i] = 0 ;
401 if (std::isnan(ConvSpectralFunctions[ex][i]))
403 Cout(
" NaN spectral function value detected at " << i <<
"--> Setting value to zero "<< endl);
404 ConvSpectralFunctions[ex][i] = 0 ;
424 RunningSum+=ConvSpectralFunctions[ex][i];
437 if (spectral_exp[ex])
delete[] (spectral_exp[ex]);
438 if (spectral_exp)
delete[] (spectral_exp);
442 if (ConvSpectralFunctions[ex])
delete[] (ConvSpectralFunctions[ex]);
444 if (ConvSpectralFunctions)
delete[] (ConvSpectralFunctions);
450 halfDeltaT = (0.001 / 2);
457 RunningSum += a_AICIntrpY[i];
uint32_t GetFrameTimeStartInMs(int a_bed, int a_frame)
int ReadAndCheckOptionsList(string a_listOptions)
iLinearSpectralModel()
Constructor of iLinearSpectralModel. Simply set all data members to default values.
oImageDimensionsAndQuantification * mp_ID
void ShowHelp()
This function is used to print out general help about dynamic models.
int InitializeSpecific()
This function is used to initialize the model parametric images and basis functions.
int InitializeSpecificToAllLinearModels()
This function is used to initialize the parametric images and basis functions for all Linear Models...
bool m_full_trapping_basis_flag
This class implements a general linear dynamic model applied between the images of a dynamic acquisit...
void ShowBasisFunctions()
This function is used to print the basis functions.
FLTNB ** m2p_nestedModelTimeBasisFunctions
int CheckSpecificParametersForAllLinearModels()
This function is used to check parameters for all Linear Models. .
~iLinearSpectralModel()
Destructor of iLinearSpectralModel.
#define KEYWORD_MANDATORY
HPFLTNB * mp_spectral_bank
oArterialInputCurve * mp_ArterialInputCurve
int GetNbTimeFrames()
Get the number of time frames.
uint32_t GetFrameTimeStopInMs(int a_bed, int a_frame)
int CheckSpecificParameters()
This function is used to check whether all member variables have been correctly initialized or not...
bool m_blood_fraction_fasis_flag
int ReadAndCheckConfigurationFileSpecific()
This function is used to read options from a configuration file, specific to this model...
int ReadDataASCIIFile(const string &a_file, const string &a_keyword, T *ap_return, int a_nbElts, bool a_mandatoryFlag)
Look for "a_nbElts" elts in the "a_file" file matching the "a_keyword" string passed as parameter a...
int ReadAndCheckConfigurationFileSpecificToAllLinearModels()
This function is used to read parameters that are generic for all Linear Models. ...
void ShowHelpModelSpecific()
This function is used to print out specific help about the dynamic model and its options. It is pure virtual so must be implemented by children.