Calculate set of basis functions for generic radiowater model.
46 {
47 int verbose=0;
if(status!=NULL) verbose=status->
verbose;
48 if(verbose>0) printf("%s(itac, ttac, %d, %g, %g, %d, bf)\n", __func__, bfNr, k2min, k2max, distr);
49 if(input==NULL || tissue==NULL || bf==NULL) {
52 }
56 }
58 if(verbose>1) printf("invalid sample or BF number\n");
61 }
62 if(fabs(k2min)<1.0E-10 || fabs(k2min)>=k2max) {
63 if(verbose>1) printf("invalid k2 range\n");
66 }
67
68 int ret;
69
70
75 }
76 }
77
78
79 if(verbose>1) printf("allocating memory for basis functions\n");
83 statusSet(status, __func__, __FILE__, __LINE__, ret);
84 return ret;
85 }
86
91 for(
int bi=0; bi<bf->
tacNr; bi++) sprintf(bf->
c[bi].
name,
"B%5.5d", bi+1);
92
93 if(verbose>1) printf("computing k2 values\n");
94 int zero=0;
if(k2min<0.0) {zero=1; bf->
c[0].
size=0.0;}
95 if(distr==0) {
96 double a, b, c;
97 a=log10(fabs(k2min)); b=log10(k2max); c=(b-a)/(double)(bfNr-1-zero);
98 for(
int bi=zero; bi<bf->
tacNr; bi++) {
99 bf->
c[bi].
size=pow(10.0, (
double)(bi-zero)*c+a);
100 }
101 } else {
102 double c=(k2max-fabs(k2min))/(double)(bfNr-1-zero);
103 for(
int bi=zero; bi<bf->
tacNr; bi++) {
104 bf->
c[bi].
size=fabs(k2min)+(double)(bi-zero)*c;
105 }
106 }
107
108
109#if(0)
110
111
112 double *sim;
113 sim=(
double*)malloc(input->
sampleNr*
sizeof(
double));
114 if(sim==NULL) {
117 }
118
119
120 double *cbi=NULL;
122
123
124 if(verbose>1) printf("using BTAC integral as simulation input\n");
125 cbi=(
double*)malloc(input->
sampleNr*
sizeof(
double));
126 if(cbi==NULL) {
129 }
131 if(ret) {
132 if(verbose>1) printf("liIntegratePET() = %d\n", ret);
135 }
136 }
137 if(verbose>1) printf("computing basis functions\n");
138 ret=0;
139 for(
int bi=0; bi<bf->
tacNr && !ret; bi++) {
142 } else {
144 }
145 if(ret) break;
146 if(verbose>100) {
147 printf(
"\nk2 := %g\n", bf->
c[bi].
size);
148 printf("simulated TAC:\n");
149 for(
int i=0; i<input->
sampleNr; i++) printf(
" %12.6f %12.3f\n", input->
x[i], sim[i]);
150 }
151
154 tissue->
x1, tissue->
x2, bf->
c[bi].
y, NULL, NULL, bf->
sampleNr, 4, 1, verbose-8);
155 else
157 bf->
c[bi].
y, NULL, NULL, bf->
sampleNr, 4, 1, verbose-8);
158 if(ret) break;
159 }
160 free(sim); free(cbi);
161 if(ret) {
164 }
165
166#else
167
168
169
173
174
175 double *sim;
176 sim=(
double*)malloc(inp.
sampleNr*
sizeof(
double));
177 if(sim==NULL) {
180 }
181
182 if(verbose>1) printf("computing basis functions\n");
183 ret=0;
184 for(
int bi=0; bi<bf->
tacNr && !ret; bi++) {
186 if(ret) break;
187 if(verbose>100) {
188 printf(
"\nk2 := %g\n", bf->
c[bi].
size);
189 printf("simulated TAC:\n");
190 for(
int i=0; i<inp.
sampleNr; i++) printf(
" %12.6f %12.3f\n", inp.
x[i], sim[i]);
191 }
192
195 tissue->
x1, tissue->
x2, bf->
c[bi].
y, NULL, NULL, bf->
sampleNr, 4, 1, verbose-8);
196 else
198 bf->
c[bi].
y, NULL, NULL, bf->
sampleNr, 4, 1, verbose-8);
199 if(ret) break;
200 }
201 free(sim);
202 if(ret) {
205 }
206
208#endif
209
210
213}
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 tacInput2sim(TAC *itac, TAC *ttac, TAC *stac, TPCSTATUS *status)
Modify input TAC based on tissue TAC, for use in simulations.
int simC1(double *t, double *ca, const int nr, const double k1, const double k2, double *ct)
int simC1_i(double *t, double *cai, const int nr, const double k1, const double k2, double *ct)
void statusInit(TPCSTATUS *s)
void statusSet(TPCSTATUS *s, const char *func, const char *srcfile, int srcline, tpcerror error)
void statusFree(TPCSTATUS *s)
char name[MAX_TACNAME_LEN+1]
int verbose
Verbose level, used by statusPrint() etc.
int forgiving
Force level, 0 for strict tests for data units etc.
int tacAllocate(TAC *tac, int sampleNr, int tacNr)
int tacXCopy(TAC *tac1, TAC *tac2, int i1, int i2)
@ TPCERROR_INVALID_VALUE
Invalid value.
@ TPCERROR_UNKNOWN_UNIT
Unknown data unit.
@ TPCERROR_FAIL
General error.
@ TPCERROR_OUT_OF_MEMORY
Cannot allocate memory.
@ TPCERROR_NO_DATA
File contains no data.
@ TPCERROR_TOO_FEW
File contains too few samples.
@ TAC_FORMAT_TSV_UK
UK TSV (point as decimal separator).