TPCCLIB
Loading...
Searching...
No Matches
ird.c
Go to the documentation of this file.
1
5/*****************************************************************************/
6#include "libtpcimgio.h"
7/*****************************************************************************/
8
9/*****************************************************************************/
17 const char *str,
19 IMG_PIXEL *v
20) {
21 if(v==NULL) return 1;
22 v->x=v->y=v->z=v->f=0;
23
24 char *cptr, tmp[256];
25 strncpy(tmp, str, 255); tmp[255]=(char)0;
26 cptr=strtok(tmp, " ,;:()|-"); if(cptr==NULL) return 1;
27 v->x=atoi(cptr); if(v->x<1) return 1;
28 cptr=strtok(NULL, " ,;:()|-"); if(cptr==NULL) return 2;
29 v->y=atoi(cptr); if(v->y<1) return 1;
30 cptr=strtok(NULL, " ,;:()|-"); if(cptr==NULL) return 3;
31 v->z=atoi(cptr); if(v->z<1) return 1;
32 cptr=strtok(NULL, " ,;:()|-"); if(cptr==NULL) return 0;
33 v->f=atoi(cptr);
34 return 0;
35}
36/*****************************************************************************/
37
38/*****************************************************************************/
46 IMG_RANGE *img_range
47) {
48 int i;
49
50 /* Check that input is ok */
51 if(img_range==NULL) return 1;
52 /* Change the order if necessary */
53 if(img_range->x1<0 || img_range->x2<0) return 2;
54 if(img_range->x2<img_range->x1) {
55 i=img_range->x1; img_range->x1=img_range->x2; img_range->x2=i;}
56 if(img_range->y1<0 || img_range->y2<0) return 3;
57 if(img_range->y2<img_range->y1) {
58 i=img_range->y1; img_range->y1=img_range->y2; img_range->y2=i;}
59 if(img_range->z1<0 || img_range->z2<0) return 4;
60 if(img_range->z2<img_range->z1) {
61 i=img_range->z1; img_range->z1=img_range->z2; img_range->z2=i;}
62 if(img_range->f1<0 || img_range->f2<0) return 5;
63 if(img_range->f2<img_range->f1) {
64 i=img_range->f1; img_range->f1=img_range->f2; img_range->f2=i;}
65
66 return 0;
67}
68/*****************************************************************************/
69
70/*****************************************************************************/
80 char *irdfile,
82 IMG_RANGE *img_range,
85 char *status
86) {
87 int ret, ii;
88 IFT ift;
89 char key[256];
90 IMG_PIXEL v;
91
92 /* Check that input is ok */
93 if(irdfile==NULL || strnlen(irdfile, 2)<1 || img_range==NULL) {
94 if(status!=NULL) strcpy(status, "program error");
95 return 1;
96 }
97 /* Read IDF as IFT file */
98 iftInit(&ift); ret=iftRead(&ift, irdfile, 1, 0); if(ret) {
99 if(status!=NULL) strcpy(status, ift.status);
100 iftEmpty(&ift); return 2;
101 }
102 /* Try to find keys 'corner1' and 'corner2' */
103 strcpy(key, "corner1"); ii=iftGet(&ift, key, 0);
104 if(ii>=0) {
105 ret=string_to_xyzf(ift.item[ii].value, &v);
106 if(ret==0) {
107 img_range->x1=v.x; img_range->y1=v.y; img_range->z1=v.z; img_range->f1=v.f;
108 strcpy(key, "corner2"); ii=iftGet(&ift, key, 0);
109 if(ii>=0) {
110 ret=string_to_xyzf(ift.item[ii].value, &v);
111 img_range->x2=v.x; img_range->y2=v.y; img_range->z2=v.z; img_range->f2=v.f;
112 if(ret==0) {
113 irdReorder(img_range);
114 if(status!=NULL) strcpy(status, "ok");
115 iftEmpty(&ift); return 0;
116 }
117 }
118 }
119 }
120 /* We are here only if keys were not found */
121 /* Lets not care about keys at all */
122 for(ii=0, ret=0; ii<ift.keyNr; ii++) {
123 if(ret==0 && string_to_xyzf(ift.item[ii].value, &v)==0)
124 {
125 img_range->x1=v.x; img_range->y1=v.y; img_range->z1=v.z; img_range->f1=v.f;
126 ret++; continue;
127 }
128 if(ret==1 && string_to_xyzf(ift.item[ii].value, &v)==0)
129 {
130 img_range->x2=v.x; img_range->y2=v.y; img_range->z2=v.z; img_range->f2=v.f;
131 ret++; break;
132 }
133 }
134 if(ret<2) {
135 if(status!=NULL) strcpy(status, "volume definitions not found");
136 iftEmpty(&ift); return 2;
137 }
138
139 irdReorder(img_range);
140 if(status!=NULL) strcpy(status, "ok");
141 iftEmpty(&ift);
142 return 0;
143}
144/*****************************************************************************/
145
146/*****************************************************************************/
154 IMG_RANGE *r,
156 IMG *img
157) {
158 if(r==NULL || img==NULL) return(1);
159 if(img->dimx<1 || img->dimy<1 || img->dimz<1 || img->dimt<1) return(2);
160
161 if(r->x1<1 || r->x1>img->dimx) return(11);
162 if(r->x2<1 || r->x2>img->dimx) return(12);
163
164 if(r->y1<1 || r->y1>img->dimy) return(21);
165 if(r->y2<1 || r->y2>img->dimy) return(22);
166
167 if(r->z1<1 || r->z1>img->dimz) return(31);
168 if(r->z2<1 || r->z2>img->dimz) return(32);
169
170 /* If time frame range is not set, then set it now */
171 if(r->f1<1 && r->f2<1) {
172 r->f1=1; r->f2=img->dimt;
173 return(0);
174 }
175 /* else check as usual */
176 if(r->f1<1 || r->f1>img->dimt) return(41);
177 if(r->f2<1 || r->f2>img->dimt) return(42);
178 return(0);
179}
180/*****************************************************************************/
181
182/*****************************************************************************/
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 irdRead(char *irdfile, IMG_RANGE *img_range, char *status)
Definition ird.c:75
int irdReorder(IMG_RANGE *img_range)
Definition ird.c:44
int irdCheck(IMG_RANGE *r, IMG *img)
Definition ird.c:152
int string_to_xyzf(const char *str, IMG_PIXEL *v)
Definition ird.c:14
Header file for libtpcimgio.
size_t strnlen(const char *s, size_t n)
Definition strext.c:181
int keyNr
Definition libtpcmisc.h:270
const char * status
Definition libtpcmisc.h:277
IFT_KEY_AND_VALUE * item
Definition libtpcmisc.h:279
unsigned short int dimx
unsigned short int dimt
unsigned short int dimz
unsigned short int dimy