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);
89 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
90 if(verbose>0) printf(
"%s()\n", __func__);
91 if(inp==NULL || out==NULL) {
105 statusSet(status, __func__, __FILE__, __LINE__, ret);
112 statusSet(status, __func__, __FILE__, __LINE__, ret);
117 for(
int i=0; i<inp->
tacNr; i++) {
126 statusSet(status, __func__, __FILE__, __LINE__, ret);
164 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
165 if(verbose>0) printf(
"%s()\n", __func__);
166 if(inp==NULL || xinp==NULL || xinp==tac || xinp==itac || xinp==iitac) {
170 if(tac==NULL && itac==NULL && iitac==NULL) {
190 for(
int i=0; i<inp->
sampleNr; i++) {
191 inp->
x[i]=xinp->
x[i]; inp->
x1[i]=xinp->
x1[i]; inp->
x2[i]=xinp->
x2[i];
199 double start1, end1, start2, end2, range2;
205 if(verbose>2) printf(
"time ranges: %g - %g vs %g - %g\n", start1, end1, start2, end2);
206 if(start1>start2+0.2*range2 || end1<end2-0.3*range2) {
215 if(iitac!=NULL)
tacFree(iitac);
259 if(verbose>2) printf(
" same frame times\n");
263 for(ri=0; ri<inp->
tacNr && ret==0; ri++) {
266 tac->
c[ri].
y[fi]=inp->
c[ri].
y[fi];
268 if(itac==NULL && iitac==NULL)
continue;
270 if(itac!=NULL) i1=itac->
c[ri].
y;
else i1=NULL;
271 if(iitac!=NULL) i2=iitac->
c[ri].
y;
else i2=NULL;
277 xinp->
x, NULL, i1, i2, xinp->
sampleNr, 4, 1, verbose-2);
282 if(iitac!=NULL)
tacFree(iitac);
292 if(verbose>2) printf(
" different frame times\n");
294 double *i0, *i1, *i2;
295 for(
int ri=0; ri<inp->
tacNr && ret==0; ri++) {
297 if(tac!=NULL) i0=tac->
c[ri].
y;
else i0=NULL;
298 if(itac!=NULL) i1=itac->
c[ri].
y;
else i1=NULL;
299 if(iitac!=NULL) i2=iitac->
c[ri].
y;
else i2=NULL;
302 xinp->
x1, xinp->
x2, i0, i1, i2, xinp->
sampleNr, 4, 1, verbose-2);
305 xinp->
x, i0, i1, i2, xinp->
sampleNr, 4, 1, verbose-2);
310 if(iitac!=NULL)
tacFree(iitac);
349 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
350 if(verbose>0) printf(
"%s()\n", __func__);
351 if(tac==NULL || inp==NULL) {
380 double start1, end1, start2, end2, range2;
387 printf(
"time ranges: %g - %g vs %g - %g\n", start1, end1, start2, end2);
388 if(start1>(start2+0.2*range2) || end1<(end2-0.3*range2)) {
407 for(
int i=0; i<inp->
tacNr; i++)
420 if(verbose>2) printf(
"same frame times\n");
424 for(ri=0; ri<inp->
tacNr && ret==0; ri++) {
426 tac->
c[tac->
tacNr+ri].
y[fi]=inp->
c[ri].
y[fi];
428 if(itac==NULL && iitac==NULL)
continue;
430 if(itac!=NULL) i1=itac->
c[itac->
tacNr+ri].
y;
else i1=NULL;
431 if(iitac!=NULL) i2=iitac->
c[iitac->
tacNr+ri].
y;
else i2=NULL;
437 tac->
x, NULL, i1, i2, tac->
sampleNr, 4, 1, verbose-2);
454 for(
int ri=0; ri<inp->
tacNr && ret==0; ri++) {
456 if(itac!=NULL) i1=itac->
c[itac->
tacNr+ri].
y;
else i1=NULL;
457 if(iitac!=NULL) i2=iitac->
c[iitac->
tacNr+ri].
y;
else i2=NULL;
461 i1, i2, tac->
sampleNr, 4, 1, verbose-2);
465 i1, i2, tac->
sampleNr, 4, 1, verbose-2);
501 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
502 if(verbose>0) printf(
"%s(tac, %d, %g, %g)\n", __func__, ti, t1, t2);
508 if(ti<0 || ti>=tac->
tacNr) {
518 double xmin=nan(
""), xmax=nan(
"");
519 if(
tacXRange(tac, &xmin, &xmax)!=0 || t1>=xmax || t2<=xmin) {
525 double tx[2]; tx[0]=t1; tx[1]=t2;
530 if(
liInterpolate(tac->
x, tac->
c[ti].
y, tac->
sampleNr, tx, NULL, tyi, NULL, 2, 3, 1, verbose-10))
537 return(tyi[1]-tyi[0]);
547 statusSet(status, __func__, __FILE__, __LINE__, ret);
552 if(
liInterpolate(stac.
x, stac.
c[ti].
y, stac.
sampleNr, tx, NULL, tyi, NULL, 2, 3, 1, verbose-10))
561 return(tyi[1]-tyi[0]);
int liIntegrateFE(double *x1, double *x2, double *y, int nr, double *ie, double *iie, const int verbose)
Linear integration of PET TAC to frame end times.
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 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 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...
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 tacXCopy(TAC *tac1, TAC *tac2, int i1, int i2)
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_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.
Header file for libtpcli.
Header file for library libtpctac.
Header file for libtpctacmod.