38 if(t==NULL || cr==NULL || n<2 || bfNr<1 || t3min<1.0E-10 || t3min>=t3max)
return(1);
39 if(bf==NULL || bf->
voiNr>0)
return(1);
42 ret=
dftSetmem(bf, n, bfNr);
if(ret)
return(2);
47 for(bi=0; bi<bf->
voiNr; bi++) {
48 snprintf(bf->
voi[bi].
voiname, 6,
"B%5.5d", bi+1);
53 for(fi=0; fi<bf->
frameNr; fi++) bf->
x[fi]=t[fi];
56 a=log10(t3min); b=log10(t3max); c=(b-a)/(
double)(bfNr-1);
57 for(bi=0; bi<bf->
voiNr; bi++) {
58 bf->
voi[bi].
size=pow(10.0, (
double)bi*c+a);
62 for(bi=0; bi<bf->
voiNr; bi++) {
64 ret=
simC1(t, cr, n, 1.0, a, bf->
voi[bi].
y);
97 printf(
"\n%s(*inp, *tis, *bf, %d, %g, %g, status, %d)\n", __func__,
98 bfNr, k2min, k2max, verbose);
101 if(input==NULL || tissue==NULL || bf==NULL) {
102 if(status!=NULL) strcpy(status,
"program error");
106 if(status!=NULL) strcpy(status,
"no input data");
110 if(status!=NULL) strcpy(status,
"no pet data");
114 if(status!=NULL) strcpy(status,
"invalid time units");
118 if(status!=NULL) strcpy(status,
"invalid nr of basis functions");
121 if(k2min<1.0E-10) k2min=1.0E-10;
122 if(k2min>=k2max || k2min<0.0) {
123 if(status!=NULL) strcpy(status,
"invalid k2 range");
127 printf(
"input timerange: %g - %g\n", input->
x[0], input->
x[input->
frameNr-1]);
128 printf(
"tissue timerange: %g - %g\n", tissue->
x[0], tissue->
x[tissue->
frameNr-1]);
132 if(verbose>1) printf(
"allocating memory for basis functions\n");
134 if(status!=NULL) strcpy(status,
"out of memory");
142 for(
int bi=0; bi<bf->
voiNr; bi++) {
143 snprintf(bf->
voi[bi].
voiname, 6,
"B%5.5d", bi+1);
148 for(
int fi=0; fi<bf->
frameNr; fi++) {
149 bf->
x[fi]=tissue->
x[fi];
150 bf->
x1[fi]=tissue->
x1[fi];
151 bf->
x2[fi]=tissue->
x2[fi];
155 if(verbose>1) printf(
"computing k2 values\n");
157 a=log10(k2min); b=log10(k2max); c=(b-a)/(
double)(bfNr-1);
158 if(verbose>20) printf(
"a=%g b=%g, c=%g\n", a, b, c);
159 for(
int bi=0; bi<bf->
voiNr; bi++) {
160 bf->
voi[bi].
size=pow(10.0, (
double)bi*c+a);
168 sim=(
double*)malloc(input->
frameNr*
sizeof(
double));
170 if(status!=NULL) strcpy(status,
"out of memory");
175 if(verbose>1) printf(
"computing basis functions at input sample times\n");
176 for(
int bi=0; bi<bf->
voiNr; bi++) {
179 if(status!=NULL) strcpy(status,
"simulation problem");
184 printf(
"\nk2 := %g\n", a);
185 printf(
"simulated TAC:\n");
186 for(
int fi=0; fi<input->
frameNr; fi++)
187 printf(
" %12.6f %12.3f\n", input->
x[fi], sim[fi]);
198 if(status!=NULL) strcpy(status,
"simulation problem");
206 if(verbose>1) printf(
"%s() done.\n\n", __func__);
207 if(status!=NULL) strcpy(status,
"ok");
240 printf(
"\n%s(*inp, *tis, *bf, %d, %g, %g, status, %d)\n", __func__,
241 bfNr, thetamin, thetamax, verbose);
244 if(input==NULL || tissue==NULL || bf==NULL) {
245 if(status!=NULL) strcpy(status,
"program error");
246 else if(verbose>0) fprintf(stderr,
"invalid function parameters\n");
250 if(status!=NULL) strcpy(status,
"no input data");
251 else if(verbose>0) fprintf(stderr,
"invalid input data\n");
255 if(status!=NULL) strcpy(status,
"no pet data");
256 else if(verbose>0) fprintf(stderr,
"invalid PET data\n");
260 if(status!=NULL) strcpy(status,
"invalid time units");
261 else if(verbose>0) fprintf(stderr,
"invalid time units\n");
265 if(status!=NULL) strcpy(status,
"invalid nr of basis functions");
266 else if(verbose>0) fprintf(stderr,
"invalid number of basis functions\n");
269 if(thetamin<0.0) thetamin=0.0;
270 if(thetamin>=thetamax) {
271 if(status!=NULL) strcpy(status,
"invalid theta range");
272 else if(verbose>0) fprintf(stderr,
"invalid theta range\n");
276 printf(
"input timerange: %g - %g\n", input->
x[0], input->
x[input->
frameNr-1]);
277 printf(
"tissue timerange: %g - %g\n", tissue->
x[0], tissue->
x[tissue->
frameNr-1]);
281 if(verbose>1) printf(
"allocating memory for basis functions\n");
284 if(status!=NULL) strcpy(status,
"out of memory");
285 else if(verbose>0) fprintf(stderr,
"out of memory\n");
293 for(bi=0; bi<bf->
voiNr; bi++) {
294 snprintf(bf->
voi[bi].
voiname, 6,
"B%5.5d", bi+1);
299 for(fi=0; fi<bf->
frameNr; fi++) {
300 bf->
x[fi]=tissue->
x[fi];
301 bf->
x1[fi]=tissue->
x1[fi];
302 bf->
x2[fi]=tissue->
x2[fi];
306 if(verbose>1) printf(
"computing theta values\n");
307 a=thetamin; b=thetamax; c=(b-a)/(
double)(bfNr-1);
308 if(verbose>20) printf(
"a=%g b=%g, c=%g\n", a, b, c);
309 for(bi=0; bi<bf->
voiNr; bi++) bf->
voi[bi].
size=(
double)bi*c+a;
312 printf(
"theta step size: %g\n", c);
317 sim=(
double*)malloc(input->
frameNr*
sizeof(
double));
319 if(status!=NULL) strcpy(status,
"out of memory");
320 else if(verbose>0) fprintf(stderr,
"out of memory\n");
325 if(verbose>1) printf(
"computing basis functions at input sample times\n");
326 for(bi=0; bi<bf->
voiNr; bi++) {
330 if(status!=NULL) strcpy(status,
"simulation problem");
331 else if(verbose>0) fprintf(stderr,
"simulation problem\n");
332 free(sim);
dftEmpty(bf);
return(20);
335 printf(
"\ntheta := %g\n", a);
336 printf(
"simulated TAC:\n");
337 for(fi=0; fi<input->
frameNr; fi++)
338 printf(
" %12.6f %12.3f\n", input->
x[fi], sim[fi]);
348 if(status!=NULL) strcpy(status,
"simulation problem");
349 else if(verbose>0) fprintf(stderr,
"simulation problem\n");
350 free(sim);
dftEmpty(bf);
return(20);
356 if(verbose>1) printf(
"%s() done.\n\n", __func__);
357 if(status!=NULL) strcpy(status,
"ok");
int bfRadiowater(DFT *input, DFT *tissue, DFT *bf, int bfNr, double k2min, double k2max, char *status, int verbose)
int bf_srtm(double *t, double *cr, int n, int bfNr, double t3min, double t3max, DFT *bf)
int bfIrr2TCM(DFT *input, DFT *tissue, DFT *bf, int bfNr, double thetamin, double thetamax, char *status, int verbose)
int dftCopymainhdr2(DFT *dft1, DFT *dft2, int ow)
int dftSetmem(DFT *data, int frameNr, int voiNr)
int interpolate(double *x, double *y, int nr, double *newx, double *newy, double *newyi, double *newyii, int newnr)
Linear interpolation and integration.
int interpolate4pet(double *x, double *y, int nr, double *newx1, double *newx2, double *newy, double *newyi, double *newyii, int newnr)
Interpolate and integrate TAC to PET frames.
#define DFT_FORMAT_STANDARD
#define DFT_TIME_STARTEND
int simC1(double *t, double *ca, int nr, double k1, double k2, double *ct)
Header file for libtpcmodext.
char voiname[MAX_REGIONSUBNAME_LEN+1]
char name[MAX_REGIONNAME_LEN+1]
char hemisphere[MAX_REGIONSUBNAME_LEN+1]
char place[MAX_REGIONSUBNAME_LEN+1]