5#include "tpcclibConfig.h"
37 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
38 if(verbose>0) printf(
"%s()\n", __func__);
39 if(inp==NULL || out==NULL) {
47 statusSet(status, __func__, __FILE__, __LINE__, ret);
51 for(
int i=0; i<inp->
tacNr; i++) {
56 for(
int i=0; i<inp->
tacNr; i++) {
62 statusSet(status, __func__, __FILE__, __LINE__, ret);
100 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
101 if(verbose>0) printf(
"%s()\n", __func__);
102 if(inp==NULL || xinp==NULL || xinp==tac || xinp==itac || xinp==iitac) {
106 if(tac==NULL && itac==NULL && iitac==NULL) {
126 for(
int i=0; i<inp->
sampleNr; i++) {
127 inp->
x[i]=xinp->
x[i]; inp->
x1[i]=xinp->
x1[i]; inp->
x2[i]=xinp->
x2[i];
135 double start1, end1, start2, end2, range2;
141 if(verbose>2) printf(
"time ranges: %g - %g vs %g - %g\n", start1, end1, start2, end2);
142 if(start1>start2+0.2*range2 || end1<end2-0.3*range2) {
151 if(iitac!=NULL)
tacFree(iitac);
195 if(verbose>2) printf(
" same frame times\n");
199 for(ri=0; ri<inp->
tacNr && ret==0; ri++) {
202 tac->
c[ri].
y[fi]=inp->
c[ri].
y[fi];
204 if(itac==NULL && iitac==NULL)
continue;
206 if(itac!=NULL) i1=itac->
c[ri].
y;
else i1=NULL;
207 if(iitac!=NULL) i2=iitac->
c[ri].
y;
else i2=NULL;
213 xinp->
x, NULL, i1, i2, xinp->
sampleNr, 4, 1, verbose-2);
218 if(iitac!=NULL)
tacFree(iitac);
228 if(verbose>2) printf(
" different frame times\n");
230 double *i0, *i1, *i2;
231 for(
int ri=0; ri<inp->
tacNr && ret==0; ri++) {
233 if(tac!=NULL) i0=tac->
c[ri].
y;
else i0=NULL;
234 if(itac!=NULL) i1=itac->
c[ri].
y;
else i1=NULL;
235 if(iitac!=NULL) i2=iitac->
c[ri].
y;
else i2=NULL;
238 xinp->
x1, xinp->
x2, i0, i1, i2, xinp->
sampleNr, 4, 1, verbose-2);
241 xinp->
x, i0, i1, i2, xinp->
sampleNr, 4, 1, verbose-2);
246 if(iitac!=NULL)
tacFree(iitac);
285 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
286 if(verbose>0) printf(
"%s()\n", __func__);
287 if(tac==NULL || inp==NULL) {
316 double start1, end1, start2, end2, range2;
323 printf(
"time ranges: %g - %g vs %g - %g\n", start1, end1, start2, end2);
324 if(start1>(start2+0.2*range2) || end1<(end2-0.3*range2)) {
343 for(
int i=0; i<inp->
tacNr; i++)
356 if(verbose>2) printf(
"same frame times\n");
360 for(ri=0; ri<inp->
tacNr && ret==0; ri++) {
362 tac->
c[tac->
tacNr+ri].
y[fi]=inp->
c[ri].
y[fi];
364 if(itac==NULL && iitac==NULL)
continue;
366 if(itac!=NULL) i1=itac->
c[itac->
tacNr+ri].
y;
else i1=NULL;
367 if(iitac!=NULL) i2=iitac->
c[iitac->
tacNr+ri].
y;
else i2=NULL;
373 tac->
x, NULL, i1, i2, tac->
sampleNr, 4, 1, verbose-2);
390 for(
int ri=0; ri<inp->
tacNr && ret==0; ri++) {
392 if(itac!=NULL) i1=itac->
c[itac->
tacNr+ri].
y;
else i1=NULL;
393 if(iitac!=NULL) i2=iitac->
c[iitac->
tacNr+ri].
y;
else i2=NULL;
397 i1, i2, tac->
sampleNr, 4, 1, verbose-2);
401 i1, i2, tac->
sampleNr, 4, 1, verbose-2);
439 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
440 if(verbose>0) {printf(
"%s(tac1, %g, %g, ...)\n", __func__, minfdur, maxfdur); fflush(stdout);}
441 if(tac==NULL || inp==NULL || inp->
sampleNr<1 || inp->
tacNr<1) {
445 if(minfdur>0.0 && maxfdur>0.0 && minfdur>maxfdur) {
459 if(minfdur>0.0 && freq<minfdur) freq=minfdur;
460 if(maxfdur>0.0 && freq>maxfdur) freq=maxfdur;
477 int nreq=ceil(xmax/freq);
479 if(nreq<1 || nreq>2E+06) {
496 for(
int i=0; i<nreq; i++) tac->
x1[i]=(
double)i*freq;
497 for(
int i=0; i<nreq; i++) tac->
x2[i]=(
double)(i+1)*freq;
498 for(
int i=0; i<nreq; i++) tac->
x[i]=0.5*(tac->
x1[i]+tac->
x2[i]);
501 if(verbose>2) {printf(
" interpolating...\n"); fflush(stdout);}
502 for(
int i=0; i<inp->
tacNr; i++) {
504 tac->
c[i].
y, NULL, NULL, tac->
sampleNr, 2, 1, 0)!=0) {
510 if(verbose>2) {printf(
" ... done.\n"); fflush(stdout);}
538 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
539 if(verbose>0) printf(
"%s(tac, %d, %g, %g)\n", __func__, ti, t1, t2);
545 if(ti<0 || ti>=tac->
tacNr) {
555 double xmin=nan(
""), xmax=nan(
"");
556 if(
tacXRange(tac, &xmin, &xmax)!=0 || t1>=xmax || t2<=xmin) {
562 double tx[2]; tx[0]=t1; tx[1]=t2;
567 if(
liInterpolate(tac->
x, tac->
c[ti].
y, tac->
sampleNr, tx, NULL, tyi, NULL, 2, 3, 1, verbose-10))
574 return(tyi[1]-tyi[0]);
584 statusSet(status, __func__, __FILE__, __LINE__, ret);
589 if(
liInterpolate(stac.
x, stac.
c[ti].
y, stac.
sampleNr, tx, NULL, tyi, NULL, 2, 3, 1, verbose-10))
598 return(tyi[1]-tyi[0]);
626 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
627 if(verbose>0) printf(
"%s(ttac, %d, btac, %g, %d, %d)\n", __func__, i, Vb, simVb, petVolume);
628 if(ttac==NULL || btac==NULL) {
640 if(!(Vb>=0.0) || !(Vb<=1.0)) {
644 if(Vb==1.0 && petVolume==0 && simVb==0) {
655 if(verbose>1) printf(
"subtracting blood\n");
656 for(
int ri=0; ri<ttac->
tacNr; ri++)
if(i<0 || i==ri) {
657 for(
int fi=0; fi<ttac->
sampleNr; fi++) {
658 ttac->
c[ri].
y[fi]-=Vb*btac->
c[0].
y[fi];
659 if(petVolume==0) ttac->
c[ri].
y[fi]/=(1.0-Vb);
663 if(verbose>1) printf(
"adding blood\n");
664 for(
int ri=0; ri<ttac->
tacNr; ri++)
if(i<0 || i==ri) {
665 for(
int fi=0; fi<ttac->
sampleNr; fi++) {
666 if(petVolume==0) ttac->
c[ri].
y[fi]*=(1.0-Vb);
667 ttac->
c[ri].
y[fi]+=Vb*btac->
c[0].
y[fi];
int liIntegrate(double *x, double *y, const int nr, double *yi, const int se, const int verbose)
Linear integration of TAC with trapezoidal method.
int liIntegratePET(double *x1, double *x2, double *y, int nr, double *ie, double *iie, const int verbose)
Calculate PET TAC AUC from start to each time frame, as averages during each frame.
int liInterpolate(double *x, double *y, const int nr, double *newx, double *newy, double *newyi, double *newyii, const int newnr, const int se, const int ee, const int verbose)
Linear interpolation and/or integration with trapezoidal method.
int liInterpolateForPET(double *x, double *y, const int nr, double *newx1, double *newx2, double *newy, double *newyi, double *newyii, const int newnr, const int se, const int ee, const int verbose)
Linear TAC interpolation and/or integration to PET frames.
int tacInterpolateToEqualLengthFrames(TAC *inp, double minfdur, double maxfdur, TAC *tac, TPCSTATUS *status)
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 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 allocati...
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,...
int tacIntegrate(TAC *inp, TAC *out, TPCSTATUS *status)
Integrate TACs from one TAC structure into a new TAC structure.
double tacAUC(TAC *tac, int ti, double t1, double t2, TPCSTATUS *status)
Calculates TAC AUC from t1 to t2.
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
int verbose
Verbose level, used by statusPrint() etc.
int tacDuplicate(TAC *tac1, TAC *tac2)
Make a duplicate of TAC structure.
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
int tacAllocateMore(TAC *tac, int tacNr)
int tacCopyTacchdr(TACC *d1, TACC *d2)
int tacCopyHdr(TAC *tac1, TAC *tac2)
Copy TAC header data from tac1 to tac2.
int tacXMatch(TAC *d1, TAC *d2, const int verbose)
Check whether sample (frame) times are the same (or very close to) in two TAC structures.
int tacFramesToSteps(TAC *inp, TAC *out, TPCSTATUS *status)
Transform TAC with frames into TAC with frames represented with stepwise changing dot-to-dot data.
int tacGetSampleInterval(TAC *d, double ilimit, double *minfdur, double *maxfdur)
Get the shortest and longest sampling intervals or frame lengths in TAC structure.
int tacXCopy(TAC *tac1, TAC *tac2, int i1, int i2)
int tacIsX(TAC *d)
Verify if TAC structure contains reasonable x values (times).
int tacXRange(TAC *d, double *xmin, double *xmax)
Get the range of x values (times) in TAC structure.
Header file for library libtpcextensions.
@ TPCERROR_INVALID_XRANGE
Invalid sample time range.
@ TPCERROR_INVALID_VALUE
Invalid value.
@ TPCERROR_FAIL
General error.
@ TPCERROR_TOO_BIG
File is too big.
@ TPCERROR_OUT_OF_MEMORY
Cannot allocate memory.
@ TPCERROR_INVALID_X
Invalid sample time.
@ TPCERROR_NO_DATA
File contains no data.
@ TPCERROR_MISSING_DATA
File contains missing values.
@ TPCERROR_INCOMPATIBLE_DATA
Incompatible data.
Header file for libtpcli.
Header file for library libtpctac.
Header file for libtpctacmod.