TPCCLIB
Toggle main menu visibility
Loading...
Searching...
No Matches
libtpcroi
ecat_roi_old.c
Go to the documentation of this file.
1
5
/*****************************************************************************/
6
#include "
libtpcroi.h
"
7
/*****************************************************************************/
8
9
/*****************************************************************************/
13
void
roiDel
(
15
ROI_list
*rl,
17
int
ind
18
) {
19
if
(ind==0){
20
for
(
int
r=0; r<rl->
nr
; r++) {
21
if
(rl->
roi
[r].
point_nr
>0) {
22
free(rl->
roi
[r].
x
);
23
free(rl->
roi
[r].
y
);
24
rl->
roi
[r].
point_nr
=0;
25
}
26
}
27
rl->
nr
=0;
28
}
else
{
29
if
(ind>rl->
nr
)
return
;
30
/* free x and y for given ROI */
31
if
(rl->
roi
[ind-1].
point_nr
>0) {
32
free(rl->
roi
[ind-1].
x
);
33
free(rl->
roi
[ind-1].
y
);
34
rl->
roi
[ind-1].
point_nr
=0;
35
}
36
/* copy memory */
37
for
(
int
j=ind; j<rl->
nr
; j++)
38
memcpy(&rl->
roi
[j-1], &rl->
roi
[j],
sizeof
(
ROI
));
39
rl->
nr
--;
40
}
41
}
42
/*****************************************************************************/
43
44
/*****************************************************************************/
48
int
roiRead
(
50
const
char
*fname,
52
ROI_list
*rl
53
) {
54
int
i, j, n, ch;
55
FILE *fp;
56
char
imgfile[FILENAME_MAX], roiname[FILENAME_MAX];
57
float
zoom, recon_zoom;
58
int
matrix, type, status, pos_x, pos_y, w, h, t, roi, npts, x, y;
59
60
/* Open ROI file */
61
if
((fp=fopen(fname,
"r"
)) == NULL) {
62
strcpy(
roierrmsg
,
"cannot open file"
);
63
return
(1);
64
}
65
66
n=0;
67
while
(1) {
68
/* Read first '*' */
69
ch=fgetc(fp);
if
(ch==EOF || ch!=
'*'
)
break
;
70
71
/* Read image file name */
72
if
(fscanf(fp,
"%s "
, imgfile)==EOF) {
73
strcpy(
roierrmsg
,
"cannot read image filename"
);
74
fclose(fp);
return
(3);
75
}
76
77
/* Read zooms */
78
if
(fscanf(fp,
"%f %f "
, &zoom, &recon_zoom)==EOF) {
79
strcpy(
roierrmsg
,
"cannot read zoom values"
);
80
fclose(fp);
return
(4);}
81
if
(recon_zoom==0.0) recon_zoom=1.0;
82
83
/* Read matrix -> t */
84
if
(fscanf(fp,
"%d %d %d %d %d %d %d %d "
, &matrix, &type, &status,
85
&pos_x, &pos_y, &w, &h, &t)==EOF) {
86
strcpy(
roierrmsg
,
"cannot read ROI definitions"
);
87
fclose(fp);
return
(5);
88
}
89
90
/* Read ROI nr and name */
91
if
(fscanf(fp,
"%d "
, &roi)==EOF) {
92
strcpy(
roierrmsg
,
"cannot read ROI number"
);
93
fclose(fp);
return
(6);
94
}
95
for
(i=j=0; j<3 && i<FILENAME_MAX-1; i++) {
96
roiname[i]=(char)getc(fp);
97
if
(roiname[i]==
'/'
) j++;
else
j=0;
98
}
99
j=i-3; roiname[j]=(char)0;
100
{
101
char
buf[FILENAME_MAX]; strcpy(buf, roiname);
102
int
c=
strncpyCleanSpaces
(roiname, buf, 128);
103
if
(c==0) sprintf(roiname,
"ROI%d"
, roi);
104
else
strReplaceChar
(roiname,
' '
,
'_'
);
105
}
106
107
/* Read the number of points */
108
(void)getc(fp); (void)getc(fp);
/* skip 0 and space */
109
if
(fscanf(fp,
"%d "
, &npts)==EOF) {
110
strcpy(
roierrmsg
,
"cannot read nr of ROI border points"
);
111
fclose(fp);
return
(8);
112
}
113
114
/* Allocate memory for ROI */
115
if
(rl->_allocNr==0){ rl->
roi
=malloc(
sizeof
(
ROI
)); rl->_allocNr++;}
116
else
if
(rl->_allocNr<=rl->
nr
){
117
rl->
roi
=(
ROI
*)realloc((
char
*)rl->
roi
, (rl->
nr
+1)*
sizeof
(
ROI
));
118
rl->_allocNr++;
119
}
120
if
(rl->
roi
==NULL) {
121
strcpy(
roierrmsg
,
"out of memory"
);
122
fclose(fp); rl->
nr
=0;
return
(11);
123
}
124
125
126
/* Copy data */
127
strcpy(rl->
roi
[rl->
nr
].
imgfile
, imgfile);
128
rl->
roi
[rl->
nr
].
zoom
= zoom;
129
rl->
roi
[rl->
nr
].
recon_zoom
= recon_zoom;
130
rl->
roi
[rl->
nr
].
matnum
= matrix;
131
rl->
roi
[rl->
nr
].
type
= type;
132
rl->
roi
[rl->
nr
].
status
= status;
133
rl->
roi
[rl->
nr
].
pos_x
= pos_x;
134
rl->
roi
[rl->
nr
].
pos_y
= pos_y;
135
rl->
roi
[rl->
nr
].
w
= w;
136
rl->
roi
[rl->
nr
].
h
= h;
137
rl->
roi
[rl->
nr
].
t
= t;
138
rl->
roi
[rl->
nr
].
roi
= roi;
139
strcpy(rl->
roi
[rl->
nr
].
roiname
, roiname);
140
rl->
roi
[rl->
nr
].
point_nr
= npts;
141
rl->
roi
[rl->
nr
].
userdata
=NULL;
142
rl->
nr
++;
143
n++;
144
145
/* If TRACE ROI, read points */
146
if
(type==
ROI_TRACE
) {
147
if
((rl->
roi
[rl->
nr
-1].
x
=malloc((npts+1)*
sizeof
(
int
)))==NULL) {
148
strcpy(
roierrmsg
,
"cannot read ROI border definition"
);
149
fclose(fp); rl->
nr
--;
return
(12);
150
}
151
if
((rl->
roi
[rl->
nr
-1].
y
=malloc((npts+1)*
sizeof
(
int
)))==NULL) {
152
strcpy(
roierrmsg
,
"cannot read ROI border definition"
);
153
fclose(fp); rl->
nr
--; free((
char
*)rl->
roi
[rl->
nr
-1].
x
);
return
(13);
154
}
155
for
(i=0; i<npts; i++)
156
if
(fscanf(fp,
"%d %d"
, &x, &y) == EOF) {
157
strcpy(
roierrmsg
,
"cannot read ROI border definition"
);
158
free((
char
*)rl->
roi
[rl->
nr
-1].
x
); free((
char
*)rl->
roi
[rl->
nr
-1].
y
);
159
fclose(fp); rl->
nr
--;
return
(9);
160
}
else
{
161
rl->
roi
[rl->
nr
-1].
x
[i]=x; rl->
roi
[rl->
nr
-1].
y
[i]=y;
162
}
163
do
{ch=getc(fp);}
while
(ch!=EOF && ch!=
'\n'
);
164
/* make sure that ROI start and end are connected (extra memory was allocated previously) */
165
if
(rl->
roi
[rl->
nr
-1].
x
[npts-1]!=0 || rl->
roi
[rl->
nr
-1].
y
[npts-1]!=0) {
166
rl->
roi
[rl->
nr
-1].
x
[npts]=0;
167
rl->
roi
[rl->
nr
-1].
y
[npts]=0;
168
npts++; rl->
roi
[rl->
nr
-1].
point_nr
++;
169
}
170
}
171
}
172
fclose(fp);
173
if
(n==0) {
174
strcpy(
roierrmsg
,
"error in ROI file"
);
175
return
(2);
176
}
177
/* Make points for others than trace ROIs */
178
for
(i=rl->
nr
-n; i<rl->nr; i++) {
179
switch
(rl->
roi
[i].
type
) {
180
case
ROI_RECTANGULAR
: j=
roiComputeRect
(&rl->
roi
[i]);
break
;
181
case
ROI_CIRCULAR
: j=
roiComputeCirc
(&rl->
roi
[i]);
break
;
182
case
ROI_ELLIPSE
: j=
roiComputeElli
(&rl->
roi
[i]);
break
;
183
case
ROI_TRACE
: j=0;
break
;
184
default
: j=-1;
185
}
186
if
(j) {
187
strcpy(
roierrmsg
,
"cannot read ROI border definition"
);
188
rl->
nr
-=n;
return
(21);
189
}
190
}
191
return
(0);
192
}
193
/*****************************************************************************/
194
195
/*****************************************************************************/
199
int
roiComputeCirc
(
201
ROI
*roi
202
) {
203
int
i, d, x, y, n, r, s;
204
205
r=roi->
w
;
206
if
((roi->
x
=malloc(
sizeof
(
int
)))==NULL)
return
(-1);
207
if
((roi->
y
=malloc(
sizeof
(
int
)))==NULL) {free((
char
*)roi->
x
);
return
(-1);}
208
roi->
x
[0]=0; roi->
y
[0]=r;
209
if
(r==0) n=1;
else
{
210
for
(x=1, y=r, d=3-2*r, n=1; x<=y; x++) {
211
if
(d<0) d=d+4*x+6;
else
{d=d+4*(x-y)+10; y-=1;}
212
if
((roi->
x
=(
int
*)realloc((
char
*)roi->
x
, (n+1)*
sizeof
(
int
)))==NULL)
213
return
(-1);
214
if
((roi->
y
=(
int
*)realloc((
char
*)roi->
y
, (n+1)*
sizeof
(
int
)))==NULL) {
215
free((
char
*)roi->
x
); free((
char
*)roi->
y
);
return
(-1);}
216
roi->
x
[n]=x; roi->
y
[n]=y;
217
n++;
218
}
219
}
220
for
(i=n-1, s=i; i>0; i--) {
221
if
((roi->
x
=(
int
*)realloc((
char
*)roi->
x
, (n+1)*
sizeof
(
int
)))==NULL)
222
return
(-1);
223
if
((roi->
y
=(
int
*)realloc((
char
*)roi->
y
, (n+1)*
sizeof
(
int
)))==NULL) {
224
free((
char
*)roi->
x
); free((
char
*)roi->
y
);
return
(-1);}
225
roi->
x
[n]=roi->
y
[--s]; roi->
y
[n++]=roi->
x
[s];
226
}
227
for
(i=n-1, s=i; i>0; i--) {
228
if
((roi->
x
=(
int
*)realloc((
char
*)roi->
x
, (n+1)*
sizeof
(
int
)))==NULL)
229
return
(-1);
230
if
((roi->
y
=(
int
*)realloc((
char
*)roi->
y
, (n+1)*
sizeof
(
int
)))==NULL) {
231
free((
char
*)roi->
x
); free((
char
*)roi->
y
);
return
(-1);}
232
roi->
x
[n]=roi->
x
[--s]; roi->
y
[n++]=-roi->
y
[s];
233
}
234
for
(i=n-1, s=i; i>0; i--) {
235
if
((roi->
x
=(
int
*)realloc((
char
*)roi->
x
, (n+1)*
sizeof
(
int
)))==NULL)
236
return
(-1);
237
if
((roi->
y
=(
int
*)realloc((
char
*)roi->
y
, (n+1)*
sizeof
(
int
)))==NULL) {
238
free((
char
*)roi->
x
); free((
char
*)roi->
y
);
return
(-1);}
239
roi->
x
[n]=-roi->
x
[--s]; roi->
y
[n++]=roi->
y
[s];
240
}
241
roi->
point_nr
=n;
242
243
return
(0);
244
}
245
/*****************************************************************************/
246
247
/*****************************************************************************/
251
int
roiComputeElli
(
253
ROI
*roi
254
) {
255
int
i, ix, iy,
/*ox,*/
oy, n, s, w, h;
256
257
w=roi->
w
; h=roi->
h
;
258
if
((roi->
x
=malloc(
sizeof
(
int
)))==NULL)
return
(-1);
259
if
((roi->
y
=malloc(
sizeof
(
int
)))==NULL) {free((
char
*)roi->
x
);
return
(-1);}
260
roi->
x
[0]=0; roi->
y
[0]=h;
261
n=1; oy=h;
262
for
(ix=1; ix<w; ix++) {
263
iy=(
jsqrt
(h+h*h*(w-ix)*(w+ix)))/w;
if
(oy-iy>1)
break
;
264
if
((roi->
x
=(
int
*)realloc((
char
*)roi->
x
, (n+1)*
sizeof
(
int
)))==NULL)
265
return
-1;
266
if
((roi->
y
=(
int
*)realloc((
char
*)roi->
y
, (n+1)*
sizeof
(
int
)))==NULL) {
267
free((
char
*)roi->
x
); free((
char
*)roi->
y
);
return
-1;}
268
roi->
x
[n]=ix; roi->
y
[n++]=iy;
269
oy=iy;
270
}
271
/*ox=ix;*/
272
for
(iy=oy-1; iy>=0; iy--) {
273
ix=(
jsqrt
(w+w*w*(h-iy)*(h+iy)))/h;
274
if
((roi->
x
=(
int
*)realloc((
char
*)roi->
x
, (n+1)*
sizeof
(
int
)))==NULL)
275
return
-1;
276
if
((roi->
y
=(
int
*)realloc((
char
*)roi->
y
, (n+1)*
sizeof
(
int
)))==NULL) {
277
free((
char
*)roi->
x
); free((
char
*)roi->
y
);
return
-1;}
278
roi->
x
[n]=ix; roi->
y
[n++]=iy;
279
/*ox=ix;*/
280
}
281
for
(i=n-1, s=i; i>0; i--) {
282
if
((roi->
x
=(
int
*)realloc((
char
*)roi->
x
, (n+1)*
sizeof
(
int
)))==NULL)
283
return
-1;
284
if
((roi->
y
=(
int
*)realloc((
char
*)roi->
y
, (n+1)*
sizeof
(
int
)))==NULL) {
285
free((
char
*)roi->
x
); free((
char
*)roi->
y
);
return
-1;}
286
roi->
x
[n]=roi->
x
[--s]; roi->
y
[n++]=-roi->
y
[s];
287
}
288
for
(i=n-1, s=i; i>0; i--) {
289
if
((roi->
x
=(
int
*)realloc((
char
*)roi->
x
, (n+1)*
sizeof
(
int
)))==NULL)
290
return
-1;
291
if
((roi->
y
=(
int
*)realloc((
char
*)roi->
y
, (n+1)*
sizeof
(
int
)))==NULL) {
292
free((
char
*)roi->
x
); free((
char
*)roi->
y
);
return
-1;}
293
roi->
x
[n]=-roi->
x
[--s]; roi->
y
[n++]=roi->
y
[s];
294
}
295
roi->
point_nr
=n;
296
297
return
(0);
298
}
299
/*****************************************************************************/
300
301
/*****************************************************************************/
307
int
roiFillGaps
(
309
int
*x,
311
int
*y,
313
int
nr,
315
int
**ffx,
317
int
**ffy
318
) {
319
int
verbose=0;
320
321
if
(verbose>0) {printf(
"roiFillGaps(.., %d, ..)\n"
, nr); fflush(stdout);}
322
323
/* Check data */
324
if
(nr<1 || x==NULL || y==NULL || ffx==NULL || ffy==NULL)
return
(0);
325
326
/* Allocate memory for new data */
327
if
(verbose>1) {printf(
" allocate memory\n"
); fflush(stdout);}
328
int
*fx, *fy;
329
if
((fx=malloc(nr*
sizeof
(
int
)))==NULL)
return
-1;
330
if
((fy=malloc(nr*
sizeof
(
int
)))==NULL) {free((
char
*)fx);
return
-1;}
331
332
/* Process from first to last (last->first is done already) */
333
if
(verbose>1) {printf(
" process\n"
); fflush(stdout);}
334
int
nx, ny, x2=0, y2=0;
335
int
n=0, j=0;
336
float
k;
337
for
(
int
i=1, n=j=0; i<nr; i++) {
338
if
(verbose>2) {printf(
" i=%d j=%d nr+n=%d \n"
, i, j, nr+n); fflush(stdout);}
339
int
x1=x[i-1];
340
int
y1=y[i-1];
341
x2=x[i];
342
y2=y[i];
343
int
dx=x2-x1;
344
int
dy=y2-y1;
345
fx[j]=x1; fy[j++]=y1;
346
if
(abs(dx)<2 && abs(dy)<2)
continue
;
347
if
(abs(dx)>=abs(dy)) {
348
k=(float)dy/(
float
)dx;
349
if
(x2>x1)
350
for
(nx=x1+1; nx<x2; nx++) {
351
ny=y1+(int)
temp_roundf
(k*(nx-x1));
352
fx[j]=nx; fy[j++]=ny; n++;
353
if
((fx=(
int
*)realloc((
char
*)fx, (nr+n)*
sizeof
(
int
)))==NULL) {
354
free((
char
*)fy);
return
-1;}
355
if
((fy=(
int
*)realloc((
char
*)fy, (nr+n)*
sizeof
(
int
)))==NULL) {
356
free((
char
*)fx);
return
-1;}
357
}
358
else
359
for
(nx=x1-1; nx>x2; nx--) {
360
ny=y1+(int)
temp_roundf
(k*(nx-x1));
361
fx[j]=nx; fy[j++]=ny; n++;
362
if
((fx=(
int
*)realloc((
char
*)fx, (nr+n)*
sizeof
(
int
)))==NULL) {
363
free((
char
*)fy);
return
-1;}
364
if
((fy=(
int
*)realloc((
char
*)fy, (nr+n)*
sizeof
(
int
)))==NULL) {
365
free((
char
*)fx);
return
-1;}
366
}
367
}
else
{
368
k=(float)dx/(
float
)dy;
369
if
(y2>y1)
370
for
(ny=y1+1; ny<y2; ny++) {
371
nx=x1+(int)
temp_roundf
(k*(ny-y1));
372
fx[j]=nx; fy[j++]=ny; n++;
373
if
((fx=(
int
*)realloc((
char
*)fx, (nr+n)*
sizeof
(
int
)))==NULL) {
374
free((
char
*)fy);
return
-1;}
375
if
((fy=(
int
*)realloc((
char
*)fy, (nr+n)*
sizeof
(
int
)))==NULL) {
376
free((
char
*)fx);
return
-1;}
377
}
378
else
379
for
(ny=y1-1; ny>y2; ny--) {
380
nx=x1+(int)
temp_roundf
(k*(ny-y1));
381
fx[j]=nx; fy[j++]=ny; n++;
382
if
((fx=(
int
*)realloc((
char
*)fx, (nr+n)*
sizeof
(
int
)))==NULL) {
383
free((
char
*)fy);
return
-1;}
384
if
((fy=(
int
*)realloc((
char
*)fy, (nr+n)*
sizeof
(
int
)))==NULL) {
385
free((
char
*)fx);
return
-1;}
386
}
387
}
388
}
389
fx[j]=x2; fy[j++]=y2; n=j;
390
*ffx=fx; *ffy=fy;
391
return
(n);
392
}
393
/*****************************************************************************/
394
395
/*****************************************************************************/
404
int
roiOnOff
(
406
ROI
*roi,
408
int
dimx,
410
int
dimy,
412
char
**m
413
) {
414
int
i, j, n, *x, *y, pos_x, pos_y, *fx, *fy;
415
int
verbose=0;
416
417
if
(verbose>0) {printf(
"roiOnOff()\n"
); fflush(stdout);}
418
419
/* Check the parameters */
420
if
(roi==NULL || dimx<2 || dimy<2 || m==NULL) {
421
strcpy(
roierrmsg
,
"invalid arguments for roiOnOff()"
);
422
return
(1);
423
}
424
425
/* Copy ROI points */
426
strcpy(
roierrmsg
,
"out of memory"
);
427
if
((x=malloc((roi->
point_nr
)*
sizeof
(
int
)))==NULL)
return
(2);
428
if
((y=malloc((roi->
point_nr
)*
sizeof
(
int
)))==NULL) {free((
char
*)x);
return
(2);}
429
pos_x=roi->
pos_x
;
430
pos_y=roi->
pos_y
;
431
for
(i=0; i<roi->
point_nr
; i++) {
// list starts, and usually ends, with 0,0
432
x[i]=pos_x+roi->
x
[i];
433
y[i]=pos_y+roi->
y
[i];
434
}
435
436
/* Fill the gaps between points */
437
if
(verbose>1) {printf(
"fill gaps\n"
); fflush(stdout);}
438
n=
roiFillGaps
(x, y, roi->
point_nr
, &fx, &fy);
439
if
(n<1) {
440
strcpy(
roierrmsg
,
"cannot fill the gaps in ROI border"
);
441
free((
char
*)x); free((
char
*)y);
return
(3);
442
}
443
444
/* Set matrix */
445
if
(verbose>1) {printf(
"prepare matrix\n"
); fflush(stdout);}
446
for
(i=0; i<dimy; i++)
for
(j=0; j<dimx; j++) m[j][i]=(
char
)0;
447
for
(i=0; i<n; i++)
if
(fx[i]>=0 && fx[i]<dimx && fy[i]>=0 && fy[i]<dimy)
448
m[fx[i]][fy[i]]=(char)1;
449
450
/* Fill the inside of ROI */
451
if
(verbose>1) {printf(
"fill matrix\n"
); fflush(stdout);}
452
for
(i=0; i<dimy; i++)
if
(m[0][i]==0) m[0][i]=2;
else
break
;
453
for
(i=dimy-1; i>=0; i--)
if
(m[0][i]==0) m[0][i]=2;
else
break
;
454
for
(i=0; i<dimy; i++)
if
(m[dimx-1][i]==0) m[dimx-1][i]=2;
else
break
;
455
for
(i=dimy-1; i>=0; i--)
if
(m[dimx-1][i]==0) m[dimx-1][i]=2;
else
break
;
456
for
(i=0; i<dimx; i++)
if
(m[i][0]==0) m[i][0]=2;
else
break
;
457
for
(i=dimx-1; i>=0; i--)
if
(m[i][0]==0) m[i][0]=2;
else
break
;
458
for
(i=0; i<dimx; i++)
if
(m[i][dimy-1]==0) m[i][dimy-1]=2;
else
break
;
459
for
(i=dimx-1; i>=0; i--)
if
(m[i][dimy-1]==0) m[i][dimy-1]=2;
else
break
;
460
for
(i=0; i<dimy; i++)
for
(j=0; j<dimx; j++) {
461
if
(m[j][i]!=2)
continue
;
462
if
(i>0 && m[j][i-1]==0) {m[j][i-1]=2; j=-1; i-=2;
continue
;}
463
if
(j>0 && m[j-1][i]==0) {m[j-1][i]=2; j-=2;
continue
;}
464
if
(j+1<dimx) {
if
(m[j+1][i]!=1) m[j+1][i]=2;}
465
if
(i+1<dimy) {
if
(m[j][i+1]!=1) m[j][i+1]=2;}
466
m[j][i]=3;
467
}
468
for
(i=0; i<dimy; i++)
for
(j=0; j<dimx; j++)
469
if
(m[j][i]==0) m[j][i]=2;
else
if
(m[j][i]>1) m[j][i]=0;
470
//if(m[j][i]<2) m[j][i]=1; else m[j][i]=0;
471
472
/* Free memory */
473
if
(verbose>1) {printf(
"clean-up\n"
); fflush(stdout);}
474
free((
char
*)x); free((
char
*)y);
475
free((
char
*)fx); free((
char
*)fy);
476
477
return
(0);
478
}
479
/*****************************************************************************/
480
481
/*****************************************************************************/
483
void
roiOnOffPrint
(
485
int
dimx,
487
int
dimy,
489
char
**m
490
) {
491
printf(
"\non-off matrix:\n"
); fflush(stdout);
492
if
(m==NULL || dimx<1 || dimy<1) {printf(
"empty\n"
);
return
;}
493
for
(
int
yi=0; yi<dimy; yi++) {
494
for
(
int
xi=0; xi<dimx; xi++) printf(
"%d"
, m[xi][yi]);
495
printf(
"\n"
);
496
}
497
}
498
/*****************************************************************************/
499
500
/*****************************************************************************/
504
int
roiSave
(
506
const
char
*fname,
508
ROI_list
*rl
509
) {
510
int
i, j;
511
FILE *fp;
512
513
/* Check arguments */
514
if
(!fname[0] || rl==NULL || rl->
nr
<1) {
515
strcpy(
roierrmsg
,
"invalid arguments for roiSave()"
);
516
return
(1);
517
}
518
519
/* Create file */
520
if
((fp=fopen(fname,
"w"
))==NULL) {
521
strcpy(
roierrmsg
,
"cannot open file"
);
522
return
(2);
523
}
524
525
for
(i=0; i<rl->
nr
; i++) {
526
/* Write first line */
527
if
(fprintf(fp,
"*%s %f %f %d %d %d %d %d %d %d %d %d %s///%d %d\n"
,
528
rl->
roi
[i].
imgfile
, rl->
roi
[i].
zoom
, rl->
roi
[i].
recon_zoom
,
529
rl->
roi
[i].
matnum
, rl->
roi
[i].
type
, rl->
roi
[i].
status
,
530
rl->
roi
[i].
pos_x
, rl->
roi
[i].
pos_y
, rl->
roi
[i].
w
, rl->
roi
[i].
h
,
531
rl->
roi
[i].
t
, rl->
roi
[i].
roi
, rl->
roi
[i].
roiname
,
532
0, rl->
roi
[i].
point_nr
) < 10 ) {
533
strcpy(
roierrmsg
,
"cannot write data"
);
534
fclose(fp);
return
(3);
535
}
536
/* Write second line, if trace ROI */
537
if
(rl->
roi
[i].
type
!=
ROI_TRACE
)
continue
;
538
for
(j=0; j<rl->
roi
[i].
point_nr
; j++)
539
fprintf(fp,
"%d %d "
, rl->
roi
[i].
x
[j], rl->
roi
[i].
y
[j]);
540
fprintf(fp,
"\n"
);
541
}
542
543
/* Close file */
544
fclose(fp);
545
546
return
(0);
547
}
548
/*****************************************************************************/
549
550
/*****************************************************************************/
554
int
roiAppend
(
556
char
*fname,
558
ROI_list
*rl,
560
int
ind
561
) {
562
int
i, j;
563
FILE *fp;
564
565
/* Check arguments */
566
if
(!fname[0] || rl==NULL || rl->
nr
<1) {
567
strcpy(
roierrmsg
,
"invalid arguments for roiAppend()"
);
568
return
(1);
569
}
570
571
/* Create file */
572
if
((fp=fopen(fname,
"a"
))==NULL) {
573
strcpy(
roierrmsg
,
"cannot open file"
);
574
return
(2);
575
}
576
577
/* Check ind, which roi to append to file */
578
if
(ind==0) {
579
for
(i=0; i<rl->
nr
; i++) {
580
/* Write first line */
581
if
(fprintf(fp,
"*%s %f %f %d %d %d %d %d %d %d %d %d %s///%d %d\n"
,
582
rl->
roi
[i].
imgfile
, rl->
roi
[i].
zoom
, rl->
roi
[i].
recon_zoom
,
583
rl->
roi
[i].
matnum
, rl->
roi
[i].
type
, rl->
roi
[i].
status
,
584
rl->
roi
[i].
pos_x
, rl->
roi
[i].
pos_y
, rl->
roi
[i].
w
, rl->
roi
[i].
h
,
585
rl->
roi
[i].
t
, rl->
roi
[i].
roi
, rl->
roi
[i].
roiname
,
586
0, rl->
roi
[i].
point_nr
) < 10 ) {
587
strcpy(
roierrmsg
,
"cannot write data"
);
588
fclose(fp);
return
(3);
589
}
590
/* Write second line, if trace ROI */
591
if
(rl->
roi
[i].
type
!=
ROI_TRACE
)
continue
;
592
for
(j=0; j<rl->
roi
[i].
point_nr
; j++)
593
fprintf(fp,
"%d %d "
, rl->
roi
[i].
x
[j], rl->
roi
[i].
y
[j]);
594
fprintf(fp,
"\n"
);
595
}
596
}
else
if
(ind>0) {
597
i=ind-1;
598
/* Write first line */
599
if
(fprintf(fp,
"*%s %f %f %d %d %d %d %d %d %d %d %d %s///%d %d\n"
,
600
rl->
roi
[i].
imgfile
, rl->
roi
[i].
zoom
, rl->
roi
[i].
recon_zoom
,
601
rl->
roi
[i].
matnum
, rl->
roi
[i].
type
, rl->
roi
[i].
status
,
602
rl->
roi
[i].
pos_x
, rl->
roi
[i].
pos_y
, rl->
roi
[i].
w
, rl->
roi
[i].
h
,
603
rl->
roi
[i].
t
, rl->
roi
[i].
roi
, rl->
roi
[i].
roiname
,
604
0, rl->
roi
[i].
point_nr
) < 10 ) {
605
strcpy(
roierrmsg
,
"cannot write data"
);
606
fclose(fp);
return
(3);
607
}
608
/* Write second line, if trace ROI */
609
//if(rl->roi[i].type!=ROI_TRACE) continue;
610
for
(j=0; j<rl->
roi
[i].
point_nr
; j++)
611
fprintf(fp,
"%d %d "
, rl->
roi
[i].
x
[j], rl->
roi
[i].
y
[j]);
612
fprintf(fp,
"\n"
);
613
}
614
615
/* Close file */
616
fclose(fp);
617
return
(0);
618
}
619
/*****************************************************************************/
620
621
/*****************************************************************************/
roierrmsg
char roierrmsg[128]
Definition
ecat_roi.c:11
roiComputeRect
int roiComputeRect(ROI *roi)
Definition
ecat_roi.c:264
jsqrt
int jsqrt(int n)
Definition
ecat_roi.c:617
roiOnOffPrint
void roiOnOffPrint(int dimx, int dimy, char **m)
Definition
ecat_roi_old.c:483
roiComputeElli
int roiComputeElli(ROI *roi)
Definition
ecat_roi_old.c:251
roiRead
int roiRead(const char *fname, ROI_list *rl)
Definition
ecat_roi_old.c:48
roiDel
void roiDel(ROI_list *rl, int ind)
Definition
ecat_roi_old.c:13
roiComputeCirc
int roiComputeCirc(ROI *roi)
Definition
ecat_roi_old.c:199
roiAppend
int roiAppend(char *fname, ROI_list *rl, int ind)
Definition
ecat_roi_old.c:554
roiSave
int roiSave(const char *fname, ROI_list *rl)
Definition
ecat_roi_old.c:504
roiFillGaps
int roiFillGaps(int *x, int *y, int nr, int **ffx, int **ffy)
Definition
ecat_roi_old.c:307
roiOnOff
int roiOnOff(ROI *roi, int dimx, int dimy, char **m)
Definition
ecat_roi_old.c:404
strReplaceChar
void strReplaceChar(char *str, char c1, char c2)
Definition
strext.c:159
strncpyCleanSpaces
int strncpyCleanSpaces(char *s1, const char *s2, int maxlen)
Definition
strext.c:308
temp_roundf
int temp_roundf(float e)
Definition
petc99.c:20
libtpcroi.h
Header file for libtpcroi.
ROI_CIRCULAR
#define ROI_CIRCULAR
Definition
libtpcroi.h:36
ROI_ELLIPSE
#define ROI_ELLIPSE
Definition
libtpcroi.h:38
ROI_TRACE
#define ROI_TRACE
Definition
libtpcroi.h:40
ROI_RECTANGULAR
#define ROI_RECTANGULAR
Definition
libtpcroi.h:34
ROI_list
Definition
libtpcroi.h:94
ROI_list::roi
ROI * roi
Definition
libtpcroi.h:104
ROI_list::nr
int nr
Definition
libtpcroi.h:98
ROI
Definition
libtpcroi.h:43
ROI::zoom
float zoom
Definition
libtpcroi.h:47
ROI::pos_x
int pos_x
Definition
libtpcroi.h:57
ROI::t
int t
Definition
libtpcroi.h:65
ROI::x
int * x
Definition
libtpcroi.h:72
ROI::pos_y
int pos_y
Definition
libtpcroi.h:59
ROI::type
int type
Definition
libtpcroi.h:53
ROI::roiname
char roiname[256]
Definition
libtpcroi.h:69
ROI::matnum
int matnum
Definition
libtpcroi.h:51
ROI::point_nr
int point_nr
Definition
libtpcroi.h:78
ROI::roi
int roi
Definition
libtpcroi.h:67
ROI::status
int status
Definition
libtpcroi.h:55
ROI::h
int h
Definition
libtpcroi.h:63
ROI::userdata
void * userdata
Definition
libtpcroi.h:80
ROI::recon_zoom
float recon_zoom
Definition
libtpcroi.h:49
ROI::y
int * y
Definition
libtpcroi.h:75
ROI::imgfile
char imgfile[FILENAME_MAX]
Definition
libtpcroi.h:45
ROI::w
int w
Definition
libtpcroi.h:61
Generated on
for TPCCLIB by
1.17.0