|
TPCCLIB
|
Header file for libtpctacmod. More...
#include "tpcclibConfig.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include "tpcextensions.h"#include "tpcli.h"#include "tpctac.h"#include "tpcmodels.h"#include "tpcpar.h"#include "tpcfunc.h"Go to the source code of this file.
Data Structures | |
| struct | DELAYCMFITDATA |
Functions | |
| int | tacIntegrate (TAC *inp, TAC *out, TPCSTATUS *status) |
| Integrate TACs from one TAC structure into a new TAC structure. | |
| int | tacIntegrateFE (TAC *inp, TAC *out, TAC *out2, TPCSTATUS *status) |
| Integrate TACs from one TAC structure into a new TAC structure. Integrals are calculated at frame end times. | |
| int | tacInterpolate (TAC *inp, TAC *xinp, TAC *tac, TAC *itac, TAC *iitac, TPCSTATUS *status) |
| Interpolate and/or integrate TACs from one TAC structure into a new TAC structure, using sample times from another TAC structure which is not changed. | |
| int | tacInterpolateInto (TAC *inp, TAC *tac, TAC *itac, TAC *iitac, TPCSTATUS *status) |
| Add TACs from one TAC structure into another TAC structure, interpolating the input TACs and allocating space if necessary. | |
| double | tacAUC (TAC *tac, int ti, double t1, double t2, TPCSTATUS *status) |
| Calculates TAC AUC from t1 to t2. | |
| int | tacInput2sim (TAC *itac, TAC *ttac, TAC *stac, TPCSTATUS *status) |
| Modify input TAC based on tissue TAC, for use in simulations. | |
| int | tacVb (TAC *ttac, const int i, TAC *btac, double Vb, const int simVb, const int petVolume, TPCSTATUS *status) |
| Correct TTACs for vascular blood, or simulate its effect. | |
| int | tacInterpolateToEqualLengthFrames (TAC *inp, double minfdur, double maxfdur, TAC *tac, TPCSTATUS *status) |
| int | tacFittime (TAC *d, double *startTime, double *endTime, int *first, int *last, TPCSTATUS *status) |
| int | tacReadModelingData (const char *tissuefile, const char *inputfile1, const char *inputfile2, const char *inputfile3, double *fitdur, int cutInput, int *fitSampleNr, TAC *tis, TAC *inp, TPCSTATUS *status) |
| Read tissue and input data for modelling. | |
| int | tacReadReference (TAC *tis, const char *reference, TAC *ref, int *refIndex, TPCSTATUS *status) |
| Read reference tissue TAC. | |
| int | tacReadModelingInput (const char *inputfile1, const char *inputfile2, const char *inputfile3, TAC *inp, TPCSTATUS *status) |
| Read arterial input data for modelling. | |
| int | tacPlotFitSVG (TAC *tac1, TAC *tac2, const char *main_title, const double x1, const double x2, const double y1, const double y2, const char *fname, TPCSTATUS *status) |
| int | tacPlotLineSVG (TAC *tac, const char *main_title, const double x1, const double x2, const double y1, const double y2, const char *fname, TPCSTATUS *status) |
| int | mtgaPlotSVG (MTAC *mtac, const char *main_title, const char *fname, TPCSTATUS *status) |
| int | tacPlotHistogramSVG (TAC *d, const char *main_title, const double x1, const double x2, const double y1, const double y2, const char *fname, TPCSTATUS *status) |
| int | tacAllocateWithPAR (TAC *tac, PAR *par, int sampleNr, TPCSTATUS *status) |
| Allocate TAC based on data in PAR. | |
| int | parAllocateWithTAC (PAR *par, TAC *tac, int parNr, TPCSTATUS *status) |
| Allocate PAR based on data in TAC. | |
| int | tacToPAR (TAC *tac, PAR *par, TPCSTATUS *status) |
| Copy the contents of TAC struct into PAR struct. | |
| int | tacDelay (TAC *tac, double dt, int ti, TPCSTATUS *status) |
| Move TAC y values (concentrations) in time, keeping sample times (x values) intact. | |
| void | initDelayCMFitData (DELAYCMFITDATA *d) |
| Before first use, initiate the data structure for delay time estimation. | |
| void | freeDelayCMFitData (DELAYCMFITDATA *d) |
| After last use, free memory in the data structure for delay time estimation. | |
| int | tacDelayCMFit (TAC *btac, TAC *ttac, int ci, double dtmin, double dtmax, double fitend, double dtstep, double *dt, int mode, int model, DELAYCMFITDATA *tdata, TPCSTATUS *status) |
| Fit time delay between PET tissue and plasma or blood curve. | |
| int | mfCreateTAC (PAR *par, double endx, double dx, TAC *tac, TPCSTATUS *status) |
| Make TAC(s) based on mathematical functions in PAR format. | |
Header file for libtpctacmod.
libtpctacmod contains functions needed in reading and processing PET TAC data for modelling and fitting.
Definition in file tpctacmod.h.
|
extern |
After last use, free memory in the data structure for delay time estimation.
| d | Pointer to the data structure to be initialized. |
Definition at line 150 of file delay.c.
Referenced by tacDelayCMFit().
|
extern |
Before first use, initiate the data structure for delay time estimation.
| d | Pointer to the data structure to be initialized. |
Definition at line 131 of file delay.c.
Referenced by tacDelayCMFit().
Make TAC(s) based on mathematical functions in PAR format.
| par | Pointer to PAR structure containing functions for TACs. |
| endx | End time (x) of created TAC data. TAC will always start at zero. |
| dx | Step size (delta x). |
| tac | Pointer to initiated TAC structure. Any previous contents are deleted. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 26 of file mftac.c.
|
extern |
MTGA plots in SVG format.
| mtac | Pointer to MTAC structure, which contains plot data of tissue regions, each in its own TAC structure. TAC must contain the plot x axis values, and three y columns: points included in regression, points not included, and points representing the fitted line. |
| main_title | String for plot main title, or "". |
| fname | SVG file name. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 489 of file tacfitplot.c.
Allocate PAR based on data in TAC.
Region number, names, etc are copied from given TAC.
| par | Pointer to initiated PAR struct; any old contents are deleted. PAR tacNr and parNr will be set, although contents will be empty. |
| tac | Pointer to TAC struct which contains at least the TAC number and names. |
| parNr | Nr of parameters to allocate. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 90 of file partac.c.
Referenced by tacToPAR().
Allocate TAC based on data in PAR.
TAC region number, names, and units are copied from given PAR.
| tac | Pointer to initiated TAC structure; any old contents are deleted. TAC sampleNr and tacNr will be set, although contents will be empty. |
| par | Pointer to PAR structure which contains at least the TAC number and names. |
| sampleNr | Nr of samples (time frames) to allocate. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 28 of file partac.c.
Calculates TAC AUC from t1 to t2.
| tac | Pointer to TAC structure. |
| ti | Index [0..tacNr-1] of the TAC to calculate AUC from. |
| t1 | AUC start time. |
| t2 | AUC end time. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 486 of file litac.c.
Move TAC y values (concentrations) in time, keeping sample times (x values) intact.
If TAC has frame start and end times, this function tries to retain the AUC with stepwise frame interpretation. If you wish to prevent this, then set tac->isframe=0 before calling this function and after it set back tac->isframe=1.
| tac | Pointer to TAC structure. |
| dt | Time (in TAC tunit's) to move the TAC forward (negative time moves TAC backward). |
| ti | Index [0..tacNr-1] of the TAC to move, or <0 to move all TACs. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 29 of file delay.c.
|
extern |
Fit time delay between PET tissue and plasma or blood curve.
Initial part of tissue curve is fitted with a range of input curves moved in time, using linearised one or two-tissue compartment model with blood volume term. The time that provides the best fit is selected. It is assumed that tissue heterogeneity, dispersion of the blood curve, metabolites, and variable plasma-to-blood ratio will only minimally impact the time delay estimate, since only the initial part of the data is fitted, especially if reversible two-tissue model (R2tCM) is used.
| btac | Pointer to input data (blood or plasma curve). Units of input and tissue TAC must match. All but first curve in TAC are ignored. Enter NULL in subsequent runs |
| ttac | Pointer to tissue data. Units of input and tissue TAC must match. All but first curve in TAC are ignored. |
| ci | Index [0..ttac->tacNr-1] of tissue tac to use. |
| dtmin | Minimum delay to be tested, for example -10 s, in the same units as in TACs. Not used in subsequent runs with tdata. |
| dtmax | Maximum delay to be tested, for example +50 s, in the same units as in TACs. Not used in subsequent runs with tdata. |
| fitend | Fitting uses data from 0 to end time, for example 120 s, in the same units as in TACs. In case of short PET scan, end time may need to be reduced so that input TAC with negative delay extends to the fit end. Not used in subsequent runs with tdata. |
| dtstep | The step length for moving the input curve, for example 1 s, in the same units as in TACs. Not used in subsequent runs with tdata. |
| dt | Pointer for the time delay estimate. Positive delay time means that tissue curve is delayed as compared to the input curve, and vice versa. Thus, input curve needs to be moved by the delay time to match the tissue curve. |
| mode | Mode for multilinear equations: 0=integrals and 2nd integrals, 1=derivates and 2nd derivates (experimental), 2=integrals and derivates (experimental). |
| model | Model: 0=R1TCM, 1=I2TCM, 2=R2TCM. |
| tdata | Pointer to temporary data structure, which quickens subsequent runs with other tissue TACs; enter NULL if not needed. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 179 of file delay.c.
|
extern |
Reset user-defined fit time range to comply with TAC data.
| d | Pointer to TAC containing (regional tissue) data; times can be in minutes or seconds, as long as units are defined. TAC sampleNr is not changed in this function. |
| startTime | Pointer containing originally the requested fit start time (min). This is changed to contain the time of the first included frame. Unit must be minutes. Initially, set to <0 to start from the beginning of the data. |
| endTime | Pointer containing originally the requested fit end time (min). This is changed to contain the time of the last included frame. Unit must be minutes. Initially, set to <0 or to a very large value to reach to the end of data. |
| first | Function writes the index of the first included sample (frame) here; enter NULL if not needed. |
| last | Function writes the index of the last included sample (frame) here; enter NULL if not needed. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 25 of file tacmodelinput.c.
Referenced by tacReadModelingData().
Modify input TAC based on tissue TAC, for use in simulations.
| itac | Pointer to original input TAC structure. Not modified. Data must not have missing values. |
| ttac | Pointer to tissue TAC structure. Not modified. Data must not have missing values. |
| stac | Pointer to the new input data, containing input data with new sample times. |
| status | Pointer to status data; obligatory. |
Definition at line 29 of file lisim.c.
Referenced by bfm1TCM().
Integrate TACs from one TAC structure into a new TAC structure.
PET frame lengths are taken into account, if available.
| inp | Pointer to source TAC structure. |
| out | Pointer to target TAC structure into which the integrated TAC(s) are written. Structure must be initiated; any previous contents are deleted. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 27 of file litac.c.
Integrate TACs from one TAC structure into a new TAC structure. Integrals are calculated at frame end times.
TAC must contain frame start and end times.
| inp | Pointer to source TAC structure. |
| out | Pointer to target TAC structure into which the integrated TAC(s) are written. Structure must be initiated; any previous contents are deleted. |
| out2 | Pointer to target TAC structure into which the 2nd integrals are written. Structure must be initiated; any previous contents are deleted. Enter NULL if not needed. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 75 of file litac.c.
|
extern |
Interpolate and/or integrate TACs from one TAC structure into a new TAC structure, using sample times from another TAC structure which is not changed.
PET frame lengths of output TACs are taken into account in interpolation, if available. Input frame lengths are taken into account if the framing is same as with output TACs, otherwise frame middle times are used.
| inp | Pointer to source TAC structure; make sure that x (time) and y (concentration) units are the same as in output TAC structure, because input time range is verified to cover the output data range. Detailed verification of suitability of TAC for interpolation must be done elsewhere. |
| xinp | Pointer to TAC structure which contains the x values (sample times) for the interpolation and integration. Data in this TAC structure is not modified. |
| tac | Pointer to target TAC structure into which the interpolated input TAC(s) are added. Structure must be initiated; any previous contents are deleted. Enter NULL if not needed. |
| itac | Pointer to target TAC structure into which the integrated input TAC(s) are added. Structure must be initiated; any previous contents are deleted. Enter NULL if not needed. |
| iitac | Pointer to target TAC structure into which 2nd integrals of input TAC(s) are added. Structure must be initiated; any previous contents are deleted. Enter NULL if not needed. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 141 of file litac.c.
Add TACs from one TAC structure into another TAC structure, interpolating the input TACs and allocating space if necessary.
PET frame lengths of output TACs are taken into account in interpolation, if available. Input frame lengths are taken into account if the framing is same as with output TACs, otherwise frame middle times are used.
| inp | Pointer to source TAC struct; make sure that x (time) and y (concentration) units are the same as in output TAC struct, because input time range is verified to cover the output data range. Detailed verification of suitability of TAC for interpolation must be done elsewhere. |
| tac | Pointer to target TAC struct into which the input TAC(s) are added. Struct must contain at least one TAC, and the x or x1 and x2 values. |
| itac | Pointer to target TAC struct into which integrated input TAC(s) are added; enter NULL if not needed. |
| iitac | Pointer to target TAC struct into which 2nd integrals of input TAC(s) are added; enter NULL if not needed. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 330 of file litac.c.
Referenced by tacReadModelingData(), and tacReadModelingInput().
|
extern |
Interpolate TAC data into data with equal frame lengths, starting from zero.
By default, the shortest frame length or sampling interval in the input data is used.
| inp | Pointer to source TAC struct. Missing values are not allowed. |
| minfdur | Minimum frame length; if NaN or <=0 then not applied, otherwise frame lengths are not allowed to be lower. |
| maxfdur | Maximum frame length; if NaN or <=0 then not applied, otherwise frame lengths are not allowed to be higher. |
| tac | Pointer to target TAC struct into which the interpolated TACs are written. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 214 of file lisim.c.
|
extern |
Writes specified range of plots of original and fitted TACs in SVG format.
| tac1 | Measured data points. Frame mid times must be set. |
| tac2 | Fitted data points. Times can be different but unit must be the same as in tac1. |
| main_title | String for plot main title, or "". |
| x1 | Start time; NaN if determined from data. |
| x2 | End time; NaN if determined from data. |
| y1 | Minimum y value; NaN if determined from data. |
| y2 | Maximum y value; NaN if determined from data. |
| fname | SVG file name. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 27 of file tacfitplot.c.
|
extern |
SVG plot of histogram from data given in TAC data structure.
| d | Pointer to TAC structure. Only the first dataset is used. |
| main_title | String for plot main title, or "". |
| x1 | Start x value; NaN if determined from data. |
| x2 | End x value; NaN if determined from data. |
| y1 | Minimum y value; NaN if determined from data. |
| y2 | Maximum y value; NaN if determined from data. |
| fname | SVG file name. |
| status | Pointer to status data; obligatory. |
Definition at line 30 of file histplot.c.
|
extern |
Writes specified range of line plots of TACs in SVG format.
| tac | TAC data points. |
| main_title | String for plot main title, or "". |
| x1 | Start time; NaN if determined from data. |
| x2 | End time; NaN if determined from data. |
| y1 | Minimum y value; NaN if determined from data. |
| y2 | Maximum y value; NaN if determined from data. |
| fname | SVG file name. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 273 of file tacfitplot.c.
|
extern |
Read tissue and input data for modelling.
Time units are converted to min and input calibration units to the units of tissue data. Input data is NOT interpolated to tissue times, but original sample times are kept. If input data extends much further than fit duration, the last part is removed to save computation time in simulations. Input data ranges or TAC shapes are NOT verified.
| tissuefile | Tissue data file name; one time sample is sufficient here; required. |
| inputfile1 | 1st input data file name; required. |
| inputfile2 | 2nd input data file name (or NULL or empty string if not needed); required, if inputfile3 is given. |
| inputfile3 | 3rd input data file name (or NULL or empty string if not needed). |
| fitdur | Fit duration (in minutes); shortened if longer than tissue data; input data is cut (if requested) so that it will not be much longer. Tissue TACs are NOT cut to this time. |
| cutInput | Cut off too many input samples to make calculation faster by entering <>0 here, or 0 to keep all input samples (which may be needed for delay correction). |
| fitSampleNr | Nr of time frames (samples) in tissue data that are inside fitdur will be written here; enter NULL if not needed. |
| tis | Pointer to initiated TAC struct into which tissue data will be written; required. |
| inp | Pointer to initiated TAC struct into which input data (plasma and/or blood) TACs will be written; required. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 130 of file tacmodelinput.c.
|
extern |
Read arterial input data for modelling.
Time and calibration units to the units of the first data. Input data ranges or TAC shapes are NOT verified.
| inputfile1 | 1st input data file name; required. |
| inputfile2 | 2nd input data file name (or NULL or empty string if not needed); required, if inputfile3 is given. |
| inputfile3 | 3rd input data file name (or NULL or empty string if not needed). |
| inp | Pointer to initiated TAC data structure into which input data (plasma and/or blood) TACs will be written; required. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 560 of file tacmodelinput.c.
|
extern |
Read reference tissue TAC.
Reference tissue TAC is read either from a TAC file or from TAC structure containing all regional TACs based on its name. Reference tissue TACs are then either placed in a separate TAC structure, if provided by the user, or added/marked inside the existing TAC structure. Reference TAC(s) are marked with sw=2 (best or only match) or sw=1; if reference region file contains several TACs then the one which contains name 'mean' or 'avg' or has shortest total name length is assumed to be the best guess of true reference region and marked with value sw=2. When necessary, reference data units are converted to match the existing tissue TAC. If reference TAC(s) are read from a file, then this function verifies that the sample times do match the existing TACs. Reference TAC shapes are NOT verified.
| tis | Pointer to TAC structure containing the regional tissue TACs, possibly also the reference TAC(s). If pointer to reference TAC structure is not given (below), then the reference TAC(s) are marked/added in this TAC structure; otherwise reference TAC(s) may be moved from this structure into the reference TAC structure. |
| reference | String containing either the name of reference TAC file, or reference region name or number in the TAC structure (above). |
| ref | Pointer to output TAC structure into which the reference tissue TACs are placed. Enter NULL, if reference TACs are to be placed/kept in the TAC structure with all tissue TACs. TACs in this structure will be marked with either sw=2 (best guess of true reference region) or sw=1 (less probable reference TACs). Any previous contents are deleted. |
| refIndex | Index of the best reference region; enter NULL if not needed. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 390 of file tacmodelinput.c.
Copy the contents of TAC struct into PAR struct.
In addition to data, the header contents such as region names and units are copied if possible.
| tac | Pointer to the TAC struct to be copied. |
| par | Pointer to PAR struct; any old contents are deleted. |
| status | Pointer to status data; enter NULL if not needed |
Definition at line 169 of file partac.c.
|
extern |
Correct TTACs for vascular blood, or simulate its effect.
| ttac | Pointer to TAC data to process. |
| i | Index of TAC to be processed; enter <0 to process all. |
| btac | Pointer to BTAC data to subtract or add; must contain exactly same sample times as TTAC and y values must be in the same units. |
| Vb | Vb fraction [0,1]. |
| simVb | Switch to either subtract vascular volume (0) or to simulate it (1). |
| petVolume | Switch to model vascular volume as either 0 : Cpet = (1-Vb)*Ct + Vb*Cb, or 1 : Cpet = Ct + Vb*Cb |
| status | Pointer to status data; obligatory. |
Definition at line 138 of file lisim.c.