libtpcmodext
 All Files Functions Variables Defines
Functions | Variables
include/libtpcmodext.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "curveio.h"
#include "imgio.h"
#include "imgproc.h"
#include "integr.h"
#include "nnls.h"
#include "llsqwt.h"
#include "pearson.h"
#include "median.h"
#include "mtga.h"
#include "libtpcsvg.h"
Include dependency graph for libtpcmodext.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void libtpcmodext_print_readme (FILE *fp)
void libtpcmodext_print_history (FILE *fp)
void libtpcmodext_print_dreadme (FILE *fp)
void libtpcmodext_print_dhistory (FILE *fp)
void libtpcmodext_print_build (FILE *fp)
int bf_srtm (double *t, double *cr, int n, int bfNr, double t3min, double t3max, DFT *bf)
int dftReadinput (DFT *input, DFT *tissue, char *filename, int *filetype, double *ti1, double *ti2, char *status)
int dftReadReference (DFT *tissue, char *filename, int *filetype, int *ref_index, char *status)
int dftReadModelingData (char *tissuefile, char *inputfile1, char *inputfile2, char *inputfile3, double *fitdur, int *fitframeNr, DFT *tis, DFT *inp, FILE *loginfo, int verbose, char *status)
int dftRobustMinMaxTAC (DFT *dft, int tacindex, double *minx, double *maxx, double *miny, double *maxy, int *mini, int *maxi)
int extrapolate_monoexp (DFT *dft, double *fittime, int *min_nr, int max_nr, double mintime, double extr_to, DFT *ext, FILE *loginfo, char *status)
int dftAutointerpolate (DFT *dft, DFT *dft2, double endtime)
int dftDoubleFrames (DFT *dft, DFT *dft2)
int dftDivideFrames (DFT *dft, int voi_index, int add_nr, DFT *dft2)
int dft_end_line (DFT *dft, double *fittime, int *min_nr, int max_nr, double mintime, int check_impr, FIT *fit, FILE *loginfo, char *status)
int dft_ln (DFT *dft1, DFT *dft2)
int fittime_from_dft (DFT *dft, double *startTime, double *endTime, int *first, int *last)
int fittime_from_img (IMG *img, double *fittime)
int check_times_dft_vs_img (IMG *img, DFT *dft)
int check_times_dft_vs_dft (DFT *dft1, DFT *dft2)
int copy_times_from_img_to_dft (IMG *img, DFT *dft)
int getActualSamplenr (DFT *dft, int ri)
int img_patlak (DFT *input, IMG *dyn_img, int start, int end, linefit_range fit_range, IMG *ki_img, IMG *ic_img, IMG *nr_img, char *status)
int img_k1_using_ki (DFT *input, IMG *dyn_img, int frame_nr, IMG *ki_img, IMG *k1_img, IMG *k2k3_img, char *status)
int dftInterpolateCheckStart (DFT *input, DFT *output, char *status)
int dftInterpolateCheckEnd (DFT *input, DFT *output, char *status)
int dftInterpolate (DFT *input, DFT *tissue, DFT *output, char *status)
int dftInterpolateInto (DFT *inp, DFT *tis, char *status)
int dftDerivative (DFT *dft, DFT *deriv, char *status)
int dftDerivative_old (DFT *dft, DFT *deriv, char *status)
int dftInterpolateForIMG (DFT *input, IMG *img, int frame_nr, DFT *output, double *ti1, double *ti2, int verbose, char *status)
int imgTimeIntegral (IMG *img, float t1, float t2, IMG *iimg, int calc_mode, char *status)
int dftTimeIntegral (DFT *dft, double t1, double t2, DFT *idft, int calc_mode, char *status)
int mrl_between_tacs (double *y1, double *y2, int n)
int plot_svg (DFT *dft, RES *res, int first, int last, char *main_title, char *x_title, char *y_title, char *fname)
int plotdata (DFT *dft, RES *res, int first, int last, char *mtitle, char *xtitle, char *ytitle, char *fname)
int plotdata_as_dft (DFT *dft, char *fname)
int plot_fit_svg (DFT *dft1, DFT *dft2, char *main_title, char *fname)
int plot_fitrange_svg (DFT *dft1, DFT *dft2, char *main_title, double x1, double x2, double y1, double y2, char *fname)
int cunit_check_dft_vs_img (DFT *dft, IMG *img, char *errmsg)
int dftWeightByFreq (DFT *dft)
int clusterTACs (IMG *dimg, IMG *cimg, int nr, DFT *tac, int verbose)

Variables

int MODEXT_TEST

Function Documentation

int bf_srtm ( double *  t,
double *  cr,
int  n,
int  bfNr,
double  t3min,
double  t3max,
DFT *  bf 
)

Calculates set of basis functions for SRTM

Returns:
Returns 0 if successful, otherwise nonzero.
Parameters:
tPET frame mid times
crNon-decay corrected Cr(t)
nNr of PET frames
bfNrNr of basis functions to calculate
t3mintheta3 min
t3maxtheta3 max
bfdata for basis functions is allocated and filled here

Definition at line 54 of file bf.c.

int check_times_dft_vs_dft ( DFT *  dft1,
DFT *  dft2 
)

Check whether sample times are the same (or very close to) in two DFT structs. Data sets are not edited. If DFT structs contain different sample number, then only common nr of samples are compared.

Returns:
Returns 0 in case of no match, 1 if times do match, and <1 in case of an error.
Parameters:
dft1Pointer to first DFT data; times can be both seconds or minutes, if unit is correctly set.
dft2Pointer to second DFT data; times can be both seconds or minutes, if unit is correctly set; sample nr may be different than in dft1.

Definition at line 209 of file fittime.c.

References MODEXT_TEST.

Referenced by dftInterpolate(), dftInterpolateForIMG(), and dftInterpolateInto().

int check_times_dft_vs_img ( IMG *  img,
DFT *  dft 
)

Check whether DFT sample times are the same (or very close to) as the frame times in IMG. This would suggest that DFT data originates from the same or similar PET scan. Specified data sets are not edited. If frame nr is different, then only the commong frames are compared.

Returns:
Returns 0 in case of no match, 1 if times do match, and <1 in case of an error.
Parameters:
imgPointer to IMG data; times must be in sec as usual
dftPointer to DFT data; times can be both seconds or minutes, if unit is correctly set; sample nr may be different than in IMG.

Definition at line 150 of file fittime.c.

References MODEXT_TEST.

Referenced by img_patlak().

int clusterTACs ( IMG *  dimg,
IMG *  cimg,
int  nr,
DFT *  tac,
int  verbose 
)

Allocates memory and calculates the values for average TACs for clusters.

Returns:
Returns 0 if ok, and >0 in case of an error.
Parameters:
dimgDynamic image
cimgCluster image
nrHighest cluster ID
tacPointer to initiated but empty DFT data
verboseVerbose level; if zero, then only warnings are printed into stderr

Definition at line 44 of file cluster.c.

int copy_times_from_img_to_dft ( IMG *  img,
DFT *  dft 
)

Copies frame times (especially start and end times, but also mid times) from an IMG data into DFT data, and sets DFT 'header' to indicate that frame start and end times are present.

Returns:
Returns 0 if successful and <>0 in case of an error.
Parameters:
imgPointer to IMG data; times must be in sec as usual
dftPointer to DFT data; times can be both seconds or minutes, if unit is correctly set; sample nr may be smaller than in IMG.

Definition at line 268 of file fittime.c.

References MODEXT_TEST.

Referenced by dftInterpolateForIMG(), and img_patlak().

int cunit_check_dft_vs_img ( DFT *  dft,
IMG *  img,
char *  errmsg 
)

Check that calibration units in IMG (PET image) and DFT (input TAC) are the same, and if not, then try to convert DFT calibration unit to IMG unit. If input unit is unknown, then assume it is the same as the PET unit.

Returns:
Returns 0 if successful, >0 in case of error, and <0 in case of a warning or error message to user is suggested.
Parameters:
dftPointer to DFT
imgPointer to IMG
errmsgChar pointer to string (at least of length 128) where possible error description or warning is copied; set to NULL if not necessary

Definition at line 53 of file units.c.

References MODEXT_TEST.

int dft_end_line ( DFT *  dft,
double *  fittime,
int *  min_nr,
int  max_nr,
double  mintime,
int  check_impr,
FIT *  fit,
FILE *  loginfo,
char *  status 
)

Fits line to the end-part of TACs. By default, the included data points are determined based on maximum adjusted R^2 from at least three points; regression to the larger number of points is used in case difference in adjusted R^2 values is not larger than 0.0001.

Returns:
Returns 0 when successful, otherwise <>0.
Parameters:
dftPointer to original TAC data
fittimeBy default, the search for the best line fit is started from the last sample towards the first sample; set fit time to -1 to use this default. However, if the end phase is unreliable or very noisy, you may want to set fittime to include only certain time range from the beginning. Function will write here the fittime that was actually used.
min_nrThe minimum number of samples used in searching the best fit; at least 2, but 3 is recommended. If data is very noisy, then this number may need to be increased. Function will write here the nr of samples that was actually used. This can be used as an alternative to mintime or in addition to it.
max_nrThe maximum number of samples used in searching the best fit; must be higher than min_nr, or set to -1 to not to limit the number.
mintimeMinimum time range used in searching the best fit. If data is very noisy, then this may need to be set, otherwise setting mintime to -1 will use the default. This can be used as an alternative to min_nr or in addition to it.
check_imprLinear fitting can be applied to all data subsets in the fit time range (check_impr=0), or fitting is stopped when increasing n does not improve the adjusted R^2 (check_impr=1); the latter mode is for compatibility with WinNonlin.
fitPointer to data for fitted parameters. Struct must be initiated. Any existing data is deleted. Additionally, adjusted R^2 is written as 3rd (non-documented) parameter.
loginfoGive file pointer (for example stdout) where log information is printed; NULL if not needed
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 540 of file extrapolate.c.

int dft_ln ( DFT *  dft1,
DFT *  dft2 
)

Natural logarithm (ln) transformation for TAC concentrations.

Returns:
Returns 0 when successful, otherwise <>0.
Parameters:
dft1Pointer to original TAC data
dft2Pointer to allocated memory for ln transformed TAC data; enter NULL, if original data is to be overwritten by ln transformed values.

Definition at line 703 of file extrapolate.c.

int dftAutointerpolate ( DFT *  dft,
DFT *  dft2,
double  endtime 
)

Interpolates TACs to automatically determined sample times with smaller intervals in the beginning. Only data in y arrays are interpolated; data in y2 and y3 are not used.

Returns:
Function returns 0 when succesful, else a value >= 1.
Parameters:
dftData to be interpolated is read from this struct
dft2Interpolated data is written in this struct; must be initiated; any previous content is deleted
endtimeThe length of interpolated/extrapolated data

Definition at line 306 of file extrapolate.c.

References MODEXT_TEST.

int dftDerivative ( DFT *  dft,
DFT *  deriv,
char *  status 
)

Calculate simple derivatives from regional PET TACs. This must not be used for any quantitative purpose.

Returns:
Returns 0 if successul.
Parameters:
dftDFT struct containing the regional tissue TACs
derivAllocated DFT struct for derivatives
statusPointer to allocated string where the status or error message is written; set to NULL if not needed

Definition at line 617 of file dftint.c.

int dftDerivative_old ( DFT *  dft,
DFT *  deriv,
char *  status 
)

Calculate simple derivatives from regional PET TACs. Old version. Requires that frame start and end times are known.

Returns:
Returns 0 if successul.
Parameters:
dftDFT struct containing the regional tissue TACs
derivAllocated DFT struct for derivatives
statusPointer to allocated string where the status or error message is written; set to NULL if not needed

Definition at line 573 of file dftint.c.

int dftDivideFrames ( DFT *  dft,
int  voi_index,
int  add_nr,
DFT *  dft2 
)

Interpolates TACs to automatically determined sample times with smaller intervals in the beginning. Only data in y arrays are interpolated; data in y2 and y3 are not used.

Returns:
Function returns 0 when succesful, else a value >= 1.
Parameters:
dftData to be interpolated into more time frames is read from this struct
voi_indexRegion index [0..voiNr-1] that is interpolated; <0 means all VOIs
add_nrNr of extra time frames that are created from each original frame; valid numers are 1-100; 1 doubles the frame number
dft2Interpolated data is written in this struct; must be initiated, may be allocated but do not need to be; any previous content is deleted

Definition at line 434 of file extrapolate.c.

References MODEXT_TEST.

int dftDoubleFrames ( DFT *  dft,
DFT *  dft2 
)

Doubles the TAC sample number by making each sample/frame into two by linear interpolation. Only data in y arrays are interpolated; data in y2 and y3 are not used.

Returns:
Function returns 0 when succesful, else a value >= 1.
Parameters:
dftData to be interpolated is read from this struct
dft2Interpolated data is written in this struct; must be initiated; any previous content is deleted

Definition at line 371 of file extrapolate.c.

int dftInterpolate ( DFT *  input,
DFT *  tissue,
DFT *  output,
char *  status 
)

Interpolate (and integrate) TAC data to sample times that are given with another TAC data. PET frame lengths are taken into account if available in tissue DFT struct. Input frame lengths are taken into account if the framing is same as with tissue data.

Returns:
Returns 0 if successful, and <>0 in case of an error.
Parameters:
inputData which is interpolated; make sure that time unit is the same as in tissue data; time range is checked to cover the tissue data
tissueData to which (sample times) the interpolation is done
outputPointer to initiated DFT into which interpolated values and integrals will be written
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 173 of file dftint.c.

References check_times_dft_vs_dft(), dftInterpolateCheckEnd(), and dftInterpolateCheckStart().

Referenced by dftReadinput().

Here is the call graph for this function:

int dftInterpolateCheckEnd ( DFT *  input,
DFT *  output,
char *  status 
)

Verify that data to-be-interpolated does not need too much extrapolation in the end, and that samples are not too sparse.

Returns:
Returns 0 if data is fine, 1 if extrapolation can be done, but there may be too few samples, and -1 if extrapolation in the end is impossible.
Parameters:
inputData that will be verified for reliable interpolation
outputData containing sample times for interpolated data
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 104 of file dftint.c.

References MODEXT_TEST.

Referenced by dftInterpolate(), and dftInterpolateInto().

int dftInterpolateCheckStart ( DFT *  input,
DFT *  output,
char *  status 
)

Verify that data to-be-interpolated does not need too much extrapolation in the beginning.

Returns:
Returns 0 if data is fine, 1 if it starts late but extrapolation can be done reliably, and -1 if extrapolation in the beginning would be too risky.
Parameters:
inputData that will be verified for reliable interpolation
outputData containing sample times for interpolated data
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 52 of file dftint.c.

References MODEXT_TEST.

Referenced by dftInterpolate(), dftInterpolateForIMG(), and dftInterpolateInto().

int dftInterpolateForIMG ( DFT *  input,
IMG *  img,
int  frame_nr,
DFT *  output,
double *  ti1,
double *  ti2,
int  verbose,
char *  status 
)

Interpolate (and integrate) TAC data to sample times that are given with IMG data. Input frame lengths are taken into account if they are available in DFT or if the framing is the same as in IMG data.

Returns:
Returns 0 if successful, and <>0 in case of an error.
Parameters:
inputData which is interpolated
imgData to which (sample times) the interpolation is done
frame_nrNumber of IMG frames that are needed; can be set to 0 if all frames can be included
outputPointer to initiated DFT into which interpolated values and integrals will be written at input sample times and units
ti1First time of input data before interpolation (in input time units); use this to check that required time range was measured; NULL if not needed
ti2Last time of input data before interpolation (in input time units); use this to check that required time range was measured; NULL if not needed
verboseVerbose level; set to zero to not to print any comments
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 110 of file misc.c.

References check_times_dft_vs_dft(), copy_times_from_img_to_dft(), and dftInterpolateCheckStart().

Here is the call graph for this function:

int dftInterpolateInto ( DFT *  inp,
DFT *  tis,
char *  status 
)

Interpolate (and integrate) TAC data to sample times that are given with another TAC data. New TAC is written into existing TAC data. PET frame lengths are taken into account if available in tissue DFT struct. Input frame lengths are taken into account if the framing is same as with tissue data.

Returns:
Returns 0 if successful, and <>0 in case of an error.
Parameters:
inpData which is interpolated; make sure that time unit is the same as in tissue data; time range is checked to cover the tissue data
tisData into which the interpolation is done
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 286 of file dftint.c.

References check_times_dft_vs_dft(), dftInterpolateCheckEnd(), and dftInterpolateCheckStart().

Referenced by dftReadModelingData(), and dftReadReference().

Here is the call graph for this function:

int dftReadinput ( DFT *  input,
DFT *  tissue,
char *  filename,
int *  filetype,
double *  ti1,
double *  ti2,
char *  status 
)

Read DFT format input TAC data to match the time frames in the specified tissue DFT file. Instead of input filename, a reference region name can be given: then all the matching tacs (based on roi names) are moved from the roi data to the input data, with the best match as first tac. Input data is interpolated (if necessary) and also integrated to y2[]. Input time and concentration units are tried to be converted to be the same as in tissue data.

Returns:
Returns 0 if succesful, and >0 in case of an error.
Parameters:
inputInput data, previous contents are cleared
tissuePET data containing frames and possible input regions
filenameInput data filename, or region name in PET data
filetypeType of input, as found out here; 1 and 2 =tac, 3=fit, 5=region name; enter NULL, if not needed
ti1First time of input data before interpolation (in tissue time units); use this to check that required time range was measured; NULL if not needed
ti2Last time of input data before interpolation (in tissue time units); use this to check that required time range was measured; NULL if not needed
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 70 of file dftinput.c.

References dftInterpolate(), and MODEXT_TEST.

Here is the call graph for this function:

int dftReadModelingData ( char *  tissuefile,
char *  inputfile1,
char *  inputfile2,
char *  inputfile3,
double *  fitdur,
int *  fitframeNr,
DFT *  tis,
DFT *  inp,
FILE *  loginfo,
int  verbose,
char *  status 
)

Read tissue and input data for modeling. Time units are converted to min and input calibration units to units of tissue data. Input data is NOT interpolated to tissue times. If input data extends much further than fit duration, the last part is removed to save computation time in simulations. Input data is verified not to end too early, and not to start too late.

Returns:
Returns 0 when successful, otherwise a non-zero value.
Parameters:
tissuefileTissue data filename; one time sample is sufficient here
inputfile11st input data filename
inputfile22nd input data filename (or NULL if only not needed)
inputfile33rd input data filename (or NULL if only not needed)
fitdurFit duration (in minutes); shortened if longer than tissue data
fitframeNrNr of time frames (samples) in tissue data that are inside fitdur will be written here
tisPointer to initiated DFT into which tissue data will be written
inpPointer to initiated DFT into which input data (plasma and/or blood) will be written
loginfoGive file pointer (for example stdout) where log information is printed; NULL if not needed; warnings will be printed in stderr anyway.
verboseVerbose level; if zero, then only warnings are printed into stderr
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 365 of file dftinput.c.

References dftInterpolateInto(), and fittime_from_dft().

Here is the call graph for this function:

int dftReadReference ( DFT *  tissue,
char *  filename,
int *  filetype,
int *  ref_index,
char *  status 
)

Read DFT format reference region TAC data and add it into DFT already containing other tissue TACs, if reference region TAC(s) are be given in a separate file. Alternative the reference region name can be given, which will then be selected from existing tissue TACs. Reference TACs are marked in DFT with sw=2 (best name 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 given value sw=2. When necessary, reference data is interpolated and units converted to match the existing tissue DFT. Reference TAC is also integrated into y2[].

Returns:
Returns the number of reference TACs, and <=0 in case of an error.
Parameters:
tissuePET data containing existing tissue TACs, possibly also reference regions
filenameReference TAC filename, or region name in previous data
filetypeType of input, as found out here; 1 and 2 =tac, 3=fit, 5=region name; enter NULL, if not needed
ref_indexIndex of the best reference region; enter NULL if not needed
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 228 of file dftinput.c.

References dftInterpolateInto(), and MODEXT_TEST.

Here is the call graph for this function:

int dftRobustMinMaxTAC ( DFT *  dft,
int  tacindex,
double *  minx,
double *  maxx,
double *  miny,
double *  maxy,
int *  mini,
int *  maxi 
)

Robust search of the min and max values of DFT TAC data. Data may contain NaN's, and indivial outliers are not taken as min or max.

Returns:
Returns 0 if successful.
Parameters:
dftPointer to the DFT TAC data to search
tacindexIndex of the only TAC which is searched for min and max; <0 if all
minxPointer to X at TAC min; set to NULL if not needed
maxxPointer to X at TAC max; set to NULL if not needed
minyPointer to min Y; set to NULL if not needed
maxyPointer to max Y; set to NULL if not needed
miniIndex of min TAC; set to NULL if not needed
maxiIndex of max TAC; set to NULL if not needed

Definition at line 631 of file dftinput.c.

int dftTimeIntegral ( DFT *  dft,
double  t1,
double  t2,
DFT *  idft,
int  calc_mode,
char *  status 
)

Integration of regional TAC data from time1 to time2, i.e. AUC(t1,t2). You may want to test the time range before applyin this routine, because this function accepts relatively large extrapolation large.

Returns:
Returns 0 when call was successful, and >0 in case of an error.
Parameters:
dftRegional TAC data in DFT struct. Number of samples must be at least one. If only one sample, then the integration time range must match with the possible frame start and times. Frames do not have to be continuous in time.
t1Time where to start integration (same unit as in TACs)
t2Time to stop integration (same unit as in TACs); must be higher than t1, except that t1=t2 is acceptable when calc_mode=average
idftPointer to initiated but empty AUC DFT data (output)
calc_modeCalculate integral or average: 0=integral, 1=average
statusPointer to a string (allocated for at least 128 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 379 of file dftint.c.

References MODEXT_TEST.

int dftWeightByFreq ( DFT *  dft)

Add weights based on sample frequency or frame length. Existing weights are overwritten.

Returns:
Returns 0 when successful, otherwise <>0.
Parameters:
dftSamples/frames must be sorted by sample time, but duplicate samples are allowed

Definition at line 48 of file weight.c.

int extrapolate_monoexp ( DFT *  dft,
double *  fittime,
int *  min_nr,
int  max_nr,
double  mintime,
double  extr_to,
DFT *  ext,
FILE *  loginfo,
char *  status 
)

Extrapolation of exponentially decreasing tail of PET radiotracer plasma curves. This is accomplished by fitting line to the end-part of the plot of the natural logarithm of tracer concentration against time. By default, the included data points are determined based on maximum adjusted R^2 from at least three points; fit to the larger number of points is used in case difference in adjusted R^2 values is not larger than 0.0001. This function is used and tested with program extrapol.

Returns:
Returns 0 when successful, otherwise <>0.
Parameters:
dftPointer to original TAC data
fittimeBy default, the search for the best line fit is started from the last sample towards the first sample; set fit time to -1 to use this default. However, if the end phase is unreliable or very noisy, you may want to set fittime to include only certain time range from the beginning. Function will write here the fittime that was actually used.
min_nrThe minimum number of samples used in searching the best fit; at least 2, but 3 is recommended. If data is very noisy, then this number may need to be increased. Function will write here the nr of samples that was actually used. This can be used as an alternative to mintime or in addition to it.
max_nrThe maximum number of samples used in searching the best fit; must be higher than min_nr, or set to -1 to not to limit the number.
mintimeMinimum time range used in searching the best fit. If data is very noisy, then this may need to be set, otherwise setting mintime to -1 will use the default. This can be used as an alternative to min_nr or in addition to it.
extr_toLast extrapolated sample time in same time units than in the data
extPointer to data for extrapolated TACs. Struct must be initiated. Any existing data is deleted.
loginfoGive file pointer (for example stdout) where log information is printed; NULL if not needed
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 87 of file extrapolate.c.

int fittime_from_dft ( DFT *  dft,
double *  startTime,
double *  endTime,
int *  first,
int *  last 
)

Reset user-defined fit time range to comply with DFT data.

Returns:
Returns the number of samples included in the fit range, or <0 in case of an error.
Parameters:
dftPointer to DFT containing (regional tissue) data; times can be in minutes or seconds, as long as units are defined.
startTimePointer 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.
endTimePointer 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.
firstFunction writes the index of the first included sample (frame) here
lastFunction writes the index of the last included sample (frame) here

Definition at line 65 of file fittime.c.

References MODEXT_TEST.

Referenced by dftReadModelingData().

int fittime_from_img ( IMG *  img,
double *  fittime 
)

Get the IMG frame end time of the last frame that is inside (mid time before) the specified maximum fittime.

Returns:
Returns the number of IMG frames included in the fittime, or <0 in case of an error.
Parameters:
imgPointer to IMG
fittimePointer containing originally the fit time maximum, after this the last included IMG frame end time. Unit must be seconds. Initially, set to <0 or to a very large value to include all frames.

Definition at line 120 of file fittime.c.

References MODEXT_TEST.

int getActualSamplenr ( DFT *  dft,
int  ri 
)

Returns the actual TAC sample number, not including NaNs, samples with negative x, duplicate samples, or samples with zero weights (if data is weighted).

Parameters:
dftPointer to TAC data in DFT struct; must be sorted by increasing x
riRegion index [0..voiNr-1]

Definition at line 307 of file fittime.c.

int img_k1_using_ki ( DFT *  input,
IMG *  dyn_img,
int  frame_nr,
IMG *  ki_img,
IMG *  k1_img,
IMG *  k2k3_img,
char *  status 
)

Computing pixel-by-pixel the K1 for irreversible PET tracers using previously determined Ki (K1*k3/(k2+k3) and bilinear regression.

Returns:
Returns 0 if succesful, and >1 in case of an error.
Parameters:
inputPointer to the TAC data to be used as model input. Sample times in minutes. Curve is interpolated to PET frame times, if necessary
dyn_imgPointer to dynamic PET image data. Image and input data must be in the same calibration units
frame_nrNr of frames that will be included in the fit [3-frame_nr]
ki_imgPointer to previously calculated Ki image
k1_imgPointer to initiated IMG structure where K1 values will be placed
k2k3_imgPointer to initiated IMG structure where (k2+k3) values will be placed; enter NULL, if not needed
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 52 of file img_k1.c.

References MODEXT_TEST.

int img_patlak ( DFT *  input,
IMG *  dyn_img,
int  start,
int  end,
linefit_range  fit_range,
IMG *  ki_img,
IMG *  ic_img,
IMG *  nr_img,
char *  status 
)

Computing pixel-by-pixel the graphical analysis for irreversible PET tracers (Gjedde-Patlak plot).

Returns:
Returns 0 if succesful, and >0 in case of an error.
Parameters:
inputPointer to the TAC data to be used as model input. Sample times in minutes. Curve is interpolated to PET frame times, if necessary
dyn_imgPointer to dynamic PET image data. Image and input data must be in the same calibration units
startThe range of frames where line is fitted, given as the frame start here and next the end index, i.e. [0..frame_nr-1]
endThe range of frames where line is fitted, given as the frame start above and here the end index, i.e. [0..frame_nr-1]
fit_rangeUse the whole range or based on data leave out points from the beginning; PRESET or EXCLUDE_BEGIN
ki_imgPointer to initiated IMG structure where Ki values will be placed
ic_imgPointer to initiated IMG structure where plot y axis intercept values will be placed; enter NULL, if not needed
nr_imgPointer to initiated IMG structure where the number of plot data points actually used in the fit is written; enter NULL, when not needed
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 61 of file img_patlak.c.

References check_times_dft_vs_img(), copy_times_from_img_to_dft(), and MODEXT_TEST.

Here is the call graph for this function:

int imgTimeIntegral ( IMG *  img,
float  t1,
float  t2,
IMG *  iimg,
int  calc_mode,
char *  status 
)

Integration of dynamic image from time1 to time2, storing integrals in iimg, which is allocated here. Frames do not have to be continuous in time. Time unit in integral is sec. Raw data (sinogram) must be divided by frame durations before calling this. You may want to test the time range before applyin this routine, because this function accepts relatively large extrapolation large.

Returns:
Returns errstatus, which is STATUS_OK (0) when call was successful, and >0 in case of an error.
Parameters:
imgIMG data; preferrably dynamic, if static, then the specified time range must match with the frame time
t1Time where to start integration (sec)
t2Time to stop integration (sec); must be higher than t1
iimgPointer to initiated but empty AUC IMG data
calc_modeCalculate integral or average: 0=integral, 1=average
statusPointer to a string (allocated for at least 128 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 236 of file misc.c.

void libtpcmodext_print_build ( FILE *  fp)

Print the build info to specified FILE pointer, use stdout for screen.

Definition at line 340 of file libtpcmodextv.c.

References COPYRIGHT, LIB_NAME, and LIB_VERSION.

Referenced by main(), and print_usage().

void libtpcmodext_print_dhistory ( FILE *  fp)

Print the library History to specified FILE pointer with Doxygen tags, use stdout for screen.

Definition at line 330 of file libtpcmodextv.c.

References libtpcmodext_print_history().

Referenced by main().

Here is the call graph for this function:

void libtpcmodext_print_dreadme ( FILE *  fp)

Print the library Readme to specified FILE pointer with Doxygen tags, use stdout for screen.

Definition at line 319 of file libtpcmodextv.c.

References COPYRIGHT, LIB_NAME, LIB_VERSION, and libtpcmodext_print_readme().

Referenced by main().

Here is the call graph for this function:

void libtpcmodext_print_history ( FILE *  fp)

Print the library History to specified FILE pointer, use stdout for screen.

Definition at line 142 of file libtpcmodextv.c.

Referenced by libtpcmodext_print_dhistory(), and main().

void libtpcmodext_print_readme ( FILE *  fp)

Print the library readme to specified FILE pointer, use stdout for screen.

Definition at line 54 of file libtpcmodextv.c.

References COPYRIGHT, LIB_NAME, and LIB_VERSION.

Referenced by libtpcmodext_print_dreadme(), and main().

int mrl_between_tacs ( double *  y1,
double *  y2,
int  n 
)

Return the maximum run length between given n length arrays of data

Parameters:
y1Array of data1; may contain NaNs
y2Array of data2; may contain NaNs
nNr of samples in array 1 and 2

Definition at line 45 of file mrl.c.

int plot_fit_svg ( DFT *  dft1,
DFT *  dft2,
char *  main_title,
char *  fname 
)

Writes plots of original and fitted TACs in SVG 1.1 format. Data must not contain NaNs.

Returns:
Returns 0 if successful, otherwise nonzero.
Parameters:
dft1Measured data points
dft2Fitted data points. Times can be different but unit must be the same.
main_titleString for plot main title, or NULL
fnameSVG filename; existing file is backed up

Definition at line 214 of file plotfit.c.

References MODEXT_TEST.

int plot_fitrange_svg ( DFT *  dft1,
DFT *  dft2,
char *  main_title,
double  x1,
double  x2,
double  y1,
double  y2,
char *  fname 
)

Writes specified range of plots of original and fitted TACs in SVG 1.1 format.

Returns:
Returns 0 if successful, otherwise nonzero.
Parameters:
dft1Measured data points
dft2Fitted data points. Times can be different but unit must be the same.
main_titleString for plot main title, or NULL
x1Start time; NaN if determined from data
x2End time; NaN if determined from data
y1Minimum y value; NaN if determined from data
y2Maximum y value; NaN if determined from data
fnameSVG filename; existing file is backed up

Definition at line 57 of file plotfit.c.

References MODEXT_TEST.

int plot_svg ( DFT *  dft,
RES *  res,
int  first,
int  last,
char *  main_title,
char *  x_title,
char *  y_title,
char *  fname 
)

Writes graphical analysis plots in SVG 1.1 format. Assumes that line slope and ic are in res->parameter[0] and [1].

Returns:
Returns 0 if successful, otherwise nonzero.
Parameters:
dftPlot points: X in y2, Y in y3
resResults containing parameters of line
firstFirst sample (starting from 0) used in linear fit
lastlast sample (starting from 0) used in linear fit
main_titleString for plot main title, or NULL
x_titleString for X axis title, or NULL
y_titleString for Y axis title, or NULL
fnameSVG filename; existing file is renamed as *.bak

Definition at line 70 of file plotdata.c.

int plotdata ( DFT *  dft,
RES *  res,
int  first,
int  last,
char *  mtitle,
char *  xtitle,
char *  ytitle,
char *  fname 
)

Write plot and line fit data in XHTML 1.1. Strict table format. Assumes that line slope and ic are in res->parameter[0] and [1].

Returns:
Returns 0 if successful, otherwise nonzero.
Parameters:
dftPlot points: X in y2, Y in y3
resResults containing parameters of line
firstFirst sample (starting from 0) used in linear fit
lastlast sample (starting from 0) used in linear fit
mtitleString for plot main title, or NULL
xtitleString for X axis title, or NULL
ytitleString for Y axis title, or NULL
fnameFilename for plot data; existing file is renamed as *%. If extension is .dft, plot data (excluding lines) is written in DFT format with x values as separate columns before corresponding y values.

Definition at line 207 of file plotdata.c.

References plotdata_as_dft().

Here is the call graph for this function:

int plotdata_as_dft ( DFT *  dft,
char *  fname 
)

Write plot data in DFT format with x values as separate columns before corresponding y values.

Returns:
Returns 0 if successful, otherwise nonzero.
Parameters:
dftPlot points: X in y2, Y in y3
fnameFilename for plot data

Definition at line 379 of file plotdata.c.

Referenced by plotdata().


Variable Documentation