TPCCLIB
Loading...
Searching...
No Matches
vol.c
Go to the documentation of this file.
1
5/*****************************************************************************/
7/*****************************************************************************/
8#include "libtpcimgio.h"
9/*****************************************************************************/
14 /* 0 */ "ok",
15 /* 1 */ "fault in calling routine",
16 /* 2 */ "out of memory"
17};
18/*****************************************************************************/
19
20/*****************************************************************************/
26void volInit(VOL *vol) {
27 if(VOL_TEST) printf("volInit()\n");
28 if(vol==NULL) return;
29 memset(vol, 0, sizeof(VOL));
32 vol->orientation=0;
33 vol->dimx=vol->dimy=vol->dimz=0;
34 vol->sizex=vol->sizey=vol->sizez=0;
35 vol->v=(float***)NULL;
36 vol->voxel=(float*)NULL;
37 vol->column=(float*)NULL;
38 vol->row=(float**)NULL;
39 vol->plane=(float***)NULL;
40}
41/*****************************************************************************/
42
43/*****************************************************************************/
50void svolInit(SVOL *svol) {
51 if(VOL_TEST) printf("svolInit()\n");
52 if(svol==NULL) return;
53 memset(svol, 0, sizeof(SVOL));
56 svol->orientation=0;
57 svol->dimx=svol->dimy=svol->dimz=0;
58 svol->sizex=svol->sizey=svol->sizez=0;
59 svol->scale_factor=1.0;
60 svol->v=(short int***)NULL;
61 svol->voxel=(short int*)NULL;
62 svol->column=(short int*)NULL;
63 svol->row=(short int**)NULL;
64 svol->plane=(short int***)NULL;
65}
66/*****************************************************************************/
67
68/*****************************************************************************/
74void volEmpty(VOL *vol) {
75 if(VOL_TEST) printf("volEmpty()\n");
76 if(vol==NULL || vol->status<IMG_STATUS_OCCUPIED) return;
77 /* Free up memory */
78 if(vol->_vxl!=NULL) free(vol->_vxl);
79 //if(vol->_col!=NULL) free(vol->_col); Same as _vxl
80 if(vol->_row!=NULL) free(vol->_row);
81 if(vol->_pln!=NULL) free(vol->_pln);
82 /* Set variables */
84 vol->orientation=0;
85 vol->dimx=vol->dimy=vol->dimz=0;
86 vol->sizex=vol->sizey=vol->sizez=0;
87 vol->v=(float***)NULL;
88 vol->voxel=(float*)NULL;
89 vol->column=(float*)NULL;
90 vol->row=(float**)NULL;
91 vol->plane=(float***)NULL;
92 /* Set status */
94}
95/*****************************************************************************/
96
97/*****************************************************************************/
103void svolEmpty(SVOL *svol) {
104 if(VOL_TEST) printf("svolEmpty()\n");
105 if(svol==NULL || svol->status<IMG_STATUS_OCCUPIED) return;
106 /* Free up memory */
107 if(svol->_vxl!=NULL) free(svol->_vxl);
108 //if(svol->_col!=NULL) free(svol->_col); Same as _vxl
109 if(svol->_row!=NULL) free(svol->_row);
110 if(svol->_pln!=NULL) free(svol->_pln);
111 /* Set variables */
112 svol->statmsg=_volStatusMessage[0];
113 svol->orientation=0;
114 svol->dimx=svol->dimy=svol->dimz=0;
115 svol->sizex=svol->sizey=svol->sizez=0;
116 svol->scale_factor=1.0;
117 svol->v=(short int***)NULL;
118 svol->voxel=(short int*)NULL;
119 svol->column=(short int*)NULL;
120 svol->row=(short int**)NULL;
121 svol->plane=(short int***)NULL;
122 /* Set status */
124}
125/*****************************************************************************/
126
127/*****************************************************************************/
139int volAllocate(VOL *vol, int planes, int rows, int columns) {
140 unsigned short int zi, ri;
141 int vxlNr, vi;
142 float **rptr, *cptr;
143
144 if(VOL_TEST) printf("voiAllocate(*vol, %d, %d, %d)\n", planes, rows, columns);
145 /* Check arguments */
146 if(vol==NULL) return(1); else vol->statmsg=_volStatusMessage[1];
147 if(vol->status==IMG_STATUS_UNINITIALIZED) return(1);
148 if(planes<1 || rows<1 || columns<1) return(2);
149 vxlNr=planes*rows*columns;
150
151 /* Check if correct volume size is already allocated */
152 if(vol->status>=IMG_STATUS_OCCUPIED) {
153 if(planes==vol->dimz && rows==vol->dimy && columns==vol->dimx) {
154 for(vi=0; vi<vxlNr; vi++) vol->_vxl[vi]=0;
155 return(0); /* that's it */
156 } else {
157 volEmpty(vol);
158 }
159 }
160 /* Allocate memory for volume data */
161 vol->_pln=(float***)malloc((size_t)planes*sizeof(float**));
162 if(vol->_pln==NULL) {
163 return(5);}
164 vol->_row=(float**)malloc((size_t)planes*rows*sizeof(float*));
165 if(vol->_row==NULL) {
166 free(vol->_pln); return(6);}
167 vol->_col=vol->_vxl=(float*)calloc((size_t)planes*rows*columns, sizeof(float));
168 if(vol->_vxl==NULL) {
169 free(vol->_pln); free(vol->_row); return(8);
170 }
171 /* Set data pointers */
172 rptr=vol->_row; cptr=vol->_col;
173 for(zi=0; zi<planes; zi++) {
174 vol->_pln[zi]=rptr;
175 for(ri=0; ri<rows; ri++) {
176 *rptr++=cptr; cptr+=columns;
177 }
178 }
179 vol->v=vol->_pln;
180 vol->plane=vol->_pln;
181 vol->column=vol->_col;
182 vol->row=vol->_row;
183 vol->voxel=vol->_vxl;
184 /* Ok */
185 vol->dimz=planes; vol->dimy=rows; vol->dimx=columns;
188 return(0);
189}
190/*****************************************************************************/
191
192/*****************************************************************************/
204int svolAllocate(SVOL *svol, int planes, int rows, int columns) {
205 unsigned short int zi, ri;
206 int vxlNr, vi;
207 short int **rptr, *cptr;
208
209 if(VOL_TEST) printf("svoiAllocate(*svol, %d, %d, %d)\n", planes, rows, columns);
210 /* Check arguments */
211 if(svol==NULL) return(1); else svol->statmsg=_volStatusMessage[1];
212 if(svol->status==IMG_STATUS_UNINITIALIZED) return(1);
213 if(planes<1 || rows<1 || columns<1) return(2);
214 vxlNr=planes*rows*columns;
215
216 /* Check if correct volume size is already allocated */
217 if(svol->status>=IMG_STATUS_OCCUPIED) {
218 if(planes==svol->dimz && rows==svol->dimy && columns==svol->dimx) {
219 for(vi=0; vi<vxlNr; vi++) svol->_vxl[vi]=0;
220 return(0); /* that's it */
221 } else {
222 svolEmpty(svol);
223 }
224 }
225 /* Allocate memory for volume data */
226 svol->_pln=(short int***)malloc((size_t)planes*sizeof(short int**));
227 if(svol->_pln==NULL) {
228 return(5);}
229 svol->_row=(short int**)malloc((size_t)planes*rows*sizeof(short int*));
230 if(svol->_row==NULL) {
231 free(svol->_pln); return(6);}
232 svol->_col=svol->_vxl=(short int*)calloc((size_t)planes*rows*columns, sizeof(short int));
233 if(svol->_vxl==NULL) {
234 free(svol->_pln); free(svol->_row); return(8);
235 }
236 /* Set data pointers */
237 rptr=svol->_row; cptr=svol->_col;
238 for(zi=0; zi<planes; zi++) {
239 svol->_pln[zi]=rptr;
240 for(ri=0; ri<rows; ri++) {
241 *rptr++=cptr; cptr+=columns;
242 }
243 }
244 svol->v=svol->_pln;
245 svol->plane=svol->_pln;
246 svol->column=svol->_col;
247 svol->row=svol->_row;
248 svol->voxel=svol->_vxl;
249 /* Ok */
250 svol->dimz=planes; svol->dimy=rows; svol->dimx=columns;
251 svol->statmsg=_volStatusMessage[0];
253 return(0);
254}
255/*****************************************************************************/
256
257/*****************************************************************************/
267int img2vol(IMG *img, VOL *vol, int frame) {
268 int ret;
269 unsigned short int zi, yi, xi, fi;
270
271 if(VOL_TEST) printf("img2vol(img, %d, vol)\n", frame);
272 /* Check input */
273 if(vol==NULL) return(1);
275 if(img->status!=IMG_STATUS_OCCUPIED) return(1);
276 if(frame<1 || img->dimt<frame) return(2);
277 if(vol->status==IMG_STATUS_UNINITIALIZED) return(1);
278
279 /* Allocate memory (if needed) for volume */
280 ret=volAllocate(vol, img->dimz, img->dimy, img->dimx);
281 if(ret) return(ret);
282
283 /* Copy data */
284 fi=frame-1;
285 vol->orientation=img->orientation;
286 vol->sizex=img->sizex; vol->sizey=img->sizey; vol->sizez=img->sizez;
287 for(zi=0; zi<vol->dimz; zi++)
288 for(yi=0; yi<vol->dimy; yi++)
289 for(xi=0; xi<vol->dimx; xi++)
290 vol->v[zi][yi][xi]=img->m[zi][yi][xi][fi];
291
292 return(0);
293}
294/*****************************************************************************/
295
296/*****************************************************************************/
305int img2svol(IMG *img, SVOL *svol, int frame) {
306 int ret;
307 unsigned short int zi, yi, xi, fi;
308 float fmin, fmax, g;
309
310 if(VOL_TEST) printf("img2svol(img, %d, svol)\n", frame);
311 /* Check input */
312 if(svol==NULL) return(1);
313 svol->statmsg=_volStatusMessage[1];
314 if(img->status!=IMG_STATUS_OCCUPIED) return(1);
315 if(frame<1 || img->dimt<frame) return(2);
316 if(svol->status==IMG_STATUS_UNINITIALIZED) return(1);
317
318 /* Allocate memory (if needed) for volume */
319 ret=svolAllocate(svol, img->dimz, img->dimy, img->dimx);
320 if(ret) return(ret);
321
322 /* Copy data */
323 fi=frame-1;
324 svol->orientation=img->orientation;
325 svol->sizex=img->sizex; svol->sizey=img->sizey; svol->sizez=img->sizez;
326 ret=imgFrameMinMax(img, frame, &fmin, &fmax); if(ret) return(10+ret);
327 if(fabs(fmin)>fabs(fmax)) g=fabs(fmin); else g=fabs(fmax);
328 if(g!=0) g=32766./g; else g=1.0;
329 for(zi=0; zi<svol->dimz; zi++)
330 for(yi=0; yi<svol->dimy; yi++)
331 for(xi=0; xi<svol->dimx; xi++)
332 svol->v[zi][yi][xi]=(short int)temp_roundf(g*img->m[zi][yi][xi][fi]);
333 svol->scale_factor=1.0/g;
334
335 return(0);
336}
337/*****************************************************************************/
338
339/*****************************************************************************/
351int vol2img(VOL *vol, IMG *img, int frame) {
352 unsigned short int zi, yi, xi, fi;
353
354 if(VOL_TEST) printf("vol2img(vol, img, %d)\n", frame);
355 /* Check input */
356 if(vol==NULL || vol->status!=IMG_STATUS_OCCUPIED) return(1);
358 if(img==NULL || img->status!=IMG_STATUS_OCCUPIED) return(1);
359 if(frame<1 || img->dimt<frame) return(2);
360 if(img->dimx!=vol->dimx || img->dimy!=vol->dimy) return(3);
361 if(img->dimz!=vol->dimz) return(4);
362
363 /* Copy data */
364 fi=frame-1;
365 for(zi=0; zi<vol->dimz; zi++)
366 for(yi=0; yi<vol->dimy; yi++)
367 for(xi=0; xi<vol->dimx; xi++)
368 img->m[zi][yi][xi][fi]=vol->v[zi][yi][xi];
369
370 return(0);
371}
372/*****************************************************************************/
373
374/*****************************************************************************/
385int svol2img(SVOL *svol, IMG *img, int frame) {
386 unsigned short int zi, yi, xi, fi;
387
388 if(VOL_TEST) printf("svol2img(svol, img, %d)\n", frame);
389 /* Check input */
390 if(svol==NULL || svol->status!=IMG_STATUS_OCCUPIED) return(1);
391 svol->statmsg=_volStatusMessage[1];
392 if(img==NULL || img->status!=IMG_STATUS_OCCUPIED) return(1);
393 if(frame<1 || img->dimt<frame) return(2);
394 if(img->dimx!=svol->dimx || img->dimy!=svol->dimy) return(3);
395 if(img->dimz!=svol->dimz) return(4);
396
397 /* Copy data */
398 fi=frame-1;
399 for(zi=0; zi<svol->dimz; zi++)
400 for(yi=0; yi<svol->dimy; yi++)
401 for(xi=0; xi<svol->dimx; xi++)
402 img->m[zi][yi][xi][fi]=(svol->scale_factor)*(float)svol->v[zi][yi][xi];
403
404 return(0);
405}
406/*****************************************************************************/
407
408/*****************************************************************************/
415void volInfo(VOL *vol, FILE *fp) {
416 if(VOL_TEST) printf("volInfo()\n");
417 if(vol==NULL || vol->status<=IMG_STATUS_UNINITIALIZED) {
418 fprintf(fp, "Volume data is not initialized.\n"); return;}
420 fprintf(fp, "Volume data is initialized but empty.\n"); return;}
421 if(vol->status==IMG_STATUS_ERROR) fprintf(stdout, "Volume data has errors.\n");
422 fprintf(fp, "Volume status: %s\n", vol->statmsg);
423 fprintf(fp, "Patient orientation: %d\n", vol->orientation);
424 fprintf(fp, "Voxel sizes (x, y, z): %g %g %g mm\n",
425 vol->sizex, vol->sizey, vol->sizez);
426 fprintf(fp, "Dimensions (x, y, z): %d %d %d\n",
427 vol->dimx, vol->dimy, vol->dimz);
428 return;
429}
430/*****************************************************************************/
431
432/*****************************************************************************/
439void svolInfo(SVOL *svol, FILE *fp) {
440 if(VOL_TEST) printf("svolInfo()\n");
441 if(svol==NULL || svol->status<=IMG_STATUS_UNINITIALIZED) {
442 fprintf(fp, "Volume data is not initialized.\n"); return;}
443 if(svol->status==IMG_STATUS_INITIALIZED) {
444 fprintf(fp, "Volume data is initialized but empty.\n"); return;}
445 if(svol->status==IMG_STATUS_ERROR) fprintf(stdout, "Volume data has errors.\n");
446 fprintf(fp, "Volume status: %s\n", svol->statmsg);
447 fprintf(fp, "Patient orientation: %d\n", svol->orientation);
448 fprintf(fp, "Voxel sizes (x, y, z): %g %g %g mm\n",
449 svol->sizex, svol->sizey, svol->sizez);
450 fprintf(fp, "Dimensions (x, y, z): %d %d %d\n",
451 svol->dimx, svol->dimy, svol->dimz);
452 fprintf(fp, "Scale factor: %g\n", svol->scale_factor);
453 return;
454}
455/*****************************************************************************/
456
457/*****************************************************************************/
464void volContents(VOL *vol, VOL_RANGE r, FILE *fp) {
465 int zi, yi, xi;
466
467 if(vol==NULL || vol->status!=IMG_STATUS_OCCUPIED) return;
468 if(r.z1<1 || r.y1<1 || r.x1<1) return;
469 if(r.z2<r.z1 || r.y2<r.y1 || r.x2<r.x1) return;
470 if(r.z2>vol->dimz || r.y2>vol->dimy || r.x2>vol->dimx) return;
471
472 for(zi=r.z1-1; zi<r.z2; zi++) {
473 fprintf(fp, "pl=%03d ", zi+1);
474 for(xi=r.x1-1; xi<r.x2; xi++) fprintf(fp, " x=%05d", xi+1);
475 fprintf(fp, "\n");
476 for(yi=r.y1-1; yi<r.y2; yi++) {
477 fprintf(fp, "y=%05d", yi+1);
478 for(xi=r.x1-1; xi<r.x2; xi++)
479 fprintf(fp, " %7.3f", vol->v[zi][yi][xi]);
480 fprintf(fp, "\n");
481 }
482 }
483}
484/*****************************************************************************/
485
486/*****************************************************************************/
494 VOL *vol,
496 VOL_RANGE *r,
498 VOL_PIXEL *maxp,
500 float *maxv,
502 VOL_PIXEL *minp,
504 float *minv
505) {
506 int zi, yi, xi;
507 float lmax, lmin;
508
509 if(vol==NULL || vol->status!=IMG_STATUS_OCCUPIED) return(1);
510
511 if(r!=NULL) {
512 if(r->z1<1 || r->y1<1 || r->x1<1) return(2);
513 if(r->z2<r->z1 || r->y2<r->y1 || r->x2<r->x1) return(3);
514 if(r->z2>vol->dimz || r->y2>vol->dimy || r->x2>vol->dimx) return(4);
515
516 zi=r->z1-1; yi=r->y1-1; xi=r->x1-1; lmax=lmin=vol->v[zi][yi][xi];
517 if(maxp!=NULL) {maxp->z=zi+1; maxp->y=yi+1; maxp->x=xi+1;}
518 if(minp!=NULL) {minp->z=zi+1; minp->y=yi+1; minp->x=xi+1;}
519 for(zi=r->z1-1; zi<r->z2; zi++) {
520 for(yi=r->y1-1; yi<r->y2; yi++) {
521 for(xi=r->x1-1; xi<r->x2; xi++) {
522 if(lmax<vol->v[zi][yi][xi]) {
523 lmax=vol->v[zi][yi][xi];
524 if(maxp!=NULL) {maxp->z=zi+1; maxp->y=yi+1; maxp->x=xi+1;}
525 } else if(lmin>vol->v[zi][yi][xi]) {
526 lmin=vol->v[zi][yi][xi];
527 if(minp!=NULL) {minp->z=zi+1; minp->y=yi+1; minp->x=xi+1;}
528 }
529 }
530 }
531 }
532 } else {
533 zi=yi=xi=0; lmax=lmin=vol->v[zi][yi][xi];
534 if(maxp!=NULL) {maxp->z=zi+1; maxp->y=yi+1; maxp->x=xi+1;}
535 if(minp!=NULL) {minp->z=zi+1; minp->y=yi+1; minp->x=xi+1;}
536 for(zi=0; zi<vol->dimz; zi++) {
537 for(yi=0; yi<vol->dimy; yi++) {
538 for(xi=0; xi<vol->dimx; xi++) {
539 if(lmax<vol->v[zi][yi][xi]) {
540 lmax=vol->v[zi][yi][xi];
541 if(maxp!=NULL) {maxp->z=zi+1; maxp->y=yi+1; maxp->x=xi+1;}
542 } else if(lmin>vol->v[zi][yi][xi]) {
543 lmin=vol->v[zi][yi][xi];
544 if(minp!=NULL) {minp->z=zi+1; minp->y=yi+1; minp->x=xi+1;}
545 }
546 }
547 }
548 }
549 }
550 if(maxv!=NULL) *maxv=lmax;
551 if(minv!=NULL) *minv=lmin;
552 return(0);
553}
554/*****************************************************************************/
555
556/*****************************************************************************/
564 VOL *vol,
566 VOL_RANGE *r,
568 float *avg
569) {
570 int zi, yi, xi, n=0;
571
572 if(vol==NULL || vol->status!=IMG_STATUS_OCCUPIED) return(1);
573 if(r!=NULL) {
574 if(r->z1<1 || r->y1<1 || r->x1<1) return(2);
575 if(r->z2<r->z1 || r->y2<r->y1 || r->x2<r->x1) return(3);
576 if(r->z2>vol->dimz || r->y2>vol->dimy || r->x2>vol->dimx) return(4);
577 }
578
579 *avg=0.0;
580 if(r!=NULL) {
581 for(zi=r->z1-1; zi<r->z2; zi++) {
582 for(yi=r->y1-1; yi<r->y2; yi++) {
583 for(xi=r->x1-1; xi<r->x2; xi++) {
584 *avg+=vol->v[zi][yi][xi]; n++;
585 }
586 }
587 }
588 } else {
589 for(zi=0; zi<vol->dimz; zi++) {
590 for(yi=0; yi<vol->dimy; yi++) {
591 for(xi=0; xi<vol->dimx; xi++) {
592 *avg+=vol->v[zi][yi][xi]; n++;
593 }
594 }
595 }
596 }
597 if(n>0) *avg/=(float)n;
598 return(0);
599}
600/*****************************************************************************/
601
602/*****************************************************************************/
609 VOL_RANGE *vol_range
610) {
611 int i;
612
613 /* Check that input is ok */
614 if(vol_range==NULL) return 1;
615 /* Change the order if necessary */
616 if(vol_range->x1<0 || vol_range->x2<0) return 2;
617 if(vol_range->x2<vol_range->x1) {
618 i=vol_range->x1; vol_range->x1=vol_range->x2; vol_range->x2=i;}
619 if(vol_range->y1<0 || vol_range->y2<0) return 3;
620 if(vol_range->y2<vol_range->y1) {
621 i=vol_range->y1; vol_range->y1=vol_range->y2; vol_range->y2=i;}
622 if(vol_range->z1<0 || vol_range->z2<0) return 4;
623 if(vol_range->z2<vol_range->z1) {
624 i=vol_range->z1; vol_range->z1=vol_range->z2; vol_range->z2=i;}
625 return 0;
626}
627/*****************************************************************************/
628
629/*****************************************************************************/
636 VOL_RANGE *vol_range
637) {
638 int x, y, z;
639
640 if(vol_range==NULL) return(0);
641 z=1+vol_range->z2-vol_range->z1;
642 x=1+vol_range->x2-vol_range->x1;
643 y=1+vol_range->y2-vol_range->y1;
644 return(z*x*y);
645}
646/*****************************************************************************/
647
648/*****************************************************************************/
655 char *str,
657 int *x,
659 int *y,
661 int *z
662) {
663 char *cptr, tmp[256];
664
665 strncpy(tmp, str, 255); tmp[255]=(char)0;
666 cptr=strtok(tmp, " ,;:()|-"); if(cptr==NULL) return 1;
667 *x=atoi(cptr); if(*x<1) return 1;
668 cptr=strtok(NULL, " ,;:()|-"); if(cptr==NULL) return 2;
669 *y=atoi(cptr); if(*y<1) return 1;
670 cptr=strtok(NULL, " ,;:()|-"); if(cptr==NULL) return 3;
671 *z=atoi(cptr); if(*z<1) return 1;
672 return 0;
673}
674/*****************************************************************************/
675
676/*****************************************************************************/
683 VOL_RANGE *r,
685 VOL *vol,
688 float in,
691 float out,
694 char *status
695) {
696 if(vol==NULL || vol->status!=IMG_STATUS_OCCUPIED) {
697 if(status!=NULL) strcpy(status, "invalid VOL struct");
698 return(1);
699 }
700 if(r->z2<r->z1 || r->y2<r->y1 || r->x2<r->x1) vrdReorder(r);
701 if(r->z1<1 || r->y1<1 || r->x1<1 ||
702 r->z2>vol->dimz || r->y2>vol->dimy || r->x2>vol->dimx)
703 {
704 if(status!=NULL) strcpy(status, "invalid volume range");
705 return(2);
706 }
707 if(isnan(in) && isnan(out)) {
708 if(status!=NULL) strcpy(status, "new values not given");
709 return(0);
710 }
711 int zi, yi, xi;
712
713 if(!isnan(in)) {
714 for(zi=r->z1-1; zi<r->z2; zi++)
715 for(yi=r->y1-1; yi<r->y2; yi++)
716 for(xi=r->x1-1; xi<r->x2; xi++)
717 vol->v[zi][yi][xi]=in;
718 }
719
720 if(!isnan(out)) {
721 for(zi=1; zi<=vol->dimz; zi++)
722 for(yi=1; yi<=vol->dimy; yi++)
723 for(xi=1; xi<=vol->dimx; xi++) {
724 if(zi>=r->z1 && zi<=r->z2 &&
725 yi>=r->y1 && yi<=r->y2 &&
726 xi>=r->x1 && xi<=r->x2)
727 continue;
728 vol->v[zi-1][yi-1][xi-1]=out;
729 }
730 }
731
732 if(status!=NULL) strcpy(status, "ok");
733 return(0);
734}
735/*****************************************************************************/
736
737/*****************************************************************************/
745 char *vrdfile,
747 VOL_RANGE *vol_range,
750 char *status
751) {
752 int ret, ii, x, y, z;
753 IFT ift;
754 char key[256];
755
756 /* Check that input is ok */
757 if(vrdfile==NULL || strlen(vrdfile)<1 || vol_range==NULL) {
758 if(status!=NULL) strcpy(status, "program error");
759 return 1;
760 }
761 /* Read VDF as IFT file */
762 iftInit(&ift); ret=iftRead(&ift, vrdfile, 1, 0); if(ret) {
763 if(status!=NULL) strcpy(status, ift.status);
764 iftEmpty(&ift); return 2;
765 }
766 /* Try to find keys 'corner1' and 'corner2' */
767 strcpy(key, "corner1"); ii=iftGet(&ift, key, 0);
768 if(ii>=0) {
769 ret=string_to_xyz(ift.item[ii].value, &x, &y, &z);
770 if(ret==0) {
771 vol_range->x1=x; vol_range->y1=y; vol_range->z1=z;
772 strcpy(key, "corner2"); ii=iftGet(&ift, key, 0);
773 if(ii>=0) {
774 ret=string_to_xyz(ift.item[ii].value, &x, &y, &z);
775 vol_range->x2=x; vol_range->y2=y; vol_range->z2=z;
776 if(ret==0) {
777 vrdReorder(vol_range);
778 if(status!=NULL) strcpy(status, "ok");
779 iftEmpty(&ift); return 0;
780 }
781 }
782 }
783 }
784 /* We are here only if keys were not found */
785 /* Lets not care about keys at all */
786 for(ii=0, ret=0; ii<ift.keyNr; ii++) {
787 if(ret==0 && string_to_xyz(ift.item[ii].value, &x, &y, &z)==0)
788 {
789 vol_range->x1=x; vol_range->y1=y; vol_range->z1=z;
790 ret++; continue;
791 }
792 if(ret==1 && string_to_xyz(ift.item[ii].value, &x, &y, &z)==0)
793 {
794 vol_range->x2=x; vol_range->y2=y; vol_range->z2=z;
795 ret++; break;
796 }
797 }
798 if(ret<2) {
799 if(status!=NULL) strcpy(status, "volume definitions not found");
800 iftEmpty(&ift); return 2;
801 }
802
803 vrdReorder(vol_range);
804 if(status!=NULL) strcpy(status, "ok");
805 iftEmpty(&ift);
806 return 0;
807}
808/*****************************************************************************/
809
810/*****************************************************************************/
void iftEmpty(IFT *ift)
Definition ift.c:60
void iftInit(IFT *ift)
Definition ift.c:45
int iftRead(IFT *ift, char *filename, int is_key_required, int verbose)
Definition iftfile.c:24
int iftGet(IFT *ift, char *key, int verbose)
Definition iftsrch.c:15
int imgFrameMinMax(IMG *img, int frame, float *minvalue, float *maxvalue)
Definition imgminmax.c:171
Header file for libtpcimgio.
#define IMG_STATUS_OCCUPIED
#define IMG_STATUS_INITIALIZED
#define IMG_STATUS_UNINITIALIZED
#define IMG_STATUS_ERROR
int temp_roundf(float e)
Definition petc99.c:20
int keyNr
Definition libtpcmisc.h:270
const char * status
Definition libtpcmisc.h:277
IFT_KEY_AND_VALUE * item
Definition libtpcmisc.h:279
float sizex
unsigned short int dimx
float **** m
char status
float sizey
unsigned short int dimz
unsigned short int dimy
int orientation
float sizez
float sizey
unsigned short int dimx
unsigned short int dimz
int orientation
short int ** row
float sizez
short int * voxel
unsigned short int dimy
short int *** plane
float scale_factor
char status
char * statmsg
short int *** v
float sizex
short int * column
char status
float * column
unsigned short int dimx
unsigned short int dimy
float ** row
int orientation
unsigned short int dimz
float sizex
char * statmsg
float *** plane
float * voxel
float *** v
float sizez
float sizey
char * _volStatusMessage[]
Definition vol.c:13
int string_to_xyz(char *str, int *x, int *y, int *z)
Definition vol.c:653
void svolInit(SVOL *svol)
Definition vol.c:50
void volContents(VOL *vol, VOL_RANGE r, FILE *fp)
Definition vol.c:464
int vrdReorder(VOL_RANGE *vol_range)
Definition vol.c:607
int VOL_TEST
Definition vol.c:6
int svolAllocate(SVOL *svol, int planes, int rows, int columns)
Definition vol.c:204
void volInit(VOL *vol)
Definition vol.c:26
void svolEmpty(SVOL *svol)
Definition vol.c:103
int volMax(VOL *vol, VOL_RANGE *r, VOL_PIXEL *maxp, float *maxv, VOL_PIXEL *minp, float *minv)
Definition vol.c:492
int svol2img(SVOL *svol, IMG *img, int frame)
Definition vol.c:385
int volAllocate(VOL *vol, int planes, int rows, int columns)
Definition vol.c:139
void volInfo(VOL *vol, FILE *fp)
Definition vol.c:415
int vrdVxlNr(VOL_RANGE *vol_range)
Definition vol.c:634
void volEmpty(VOL *vol)
Definition vol.c:74
void svolInfo(SVOL *svol, FILE *fp)
Definition vol.c:439
int img2vol(IMG *img, VOL *vol, int frame)
Definition vol.c:267
int img2svol(IMG *img, SVOL *svol, int frame)
Definition vol.c:305
int vrdRead(char *vrdfile, VOL_RANGE *vol_range, char *status)
Definition vol.c:742
int volAvg(VOL *vol, VOL_RANGE *r, float *avg)
Definition vol.c:562
int vrd2vol(VOL_RANGE *r, VOL *vol, float in, float out, char *status)
Definition vol.c:681
int vol2img(VOL *vol, IMG *img, int frame)
Definition vol.c:351