TPCCLIB
Loading...
Searching...
No Matches
ird.c File Reference

Storing and processing of 4D image coordinate data. More...

#include "libtpcimgio.h"

Go to the source code of this file.

Functions

int string_to_xyzf (const char *str, IMG_PIXEL *v)
int irdReorder (IMG_RANGE *img_range)
int irdRead (char *irdfile, IMG_RANGE *img_range, char *status)
int irdCheck (IMG_RANGE *r, IMG *img)

Detailed Description

Storing and processing of 4D image coordinate data.

Author
Vesa Oikonen

Definition in file ird.c.

Function Documentation

◆ irdCheck()

int irdCheck ( IMG_RANGE * r,
IMG * img )

Check that image range definition is inside image data. If time frames are zero, then fix those to image frame range.

See also
irdReorder, irdRead
Returns
Returns 0 if successful.
Parameters
rPointer to image volume range data.
imgPointer to image data.

Definition at line 152 of file ird.c.

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}
unsigned short int dimx
unsigned short int dimt
unsigned short int dimz
unsigned short int dimy

◆ irdRead()

int irdRead ( char * irdfile,
IMG_RANGE * img_range,
char * status )

Read Image Range Definition File.

Returns
Returns 0 if successful.
See also
irdCheck, string_to_xyzf, irdReorder
Parameters
irdfileImage Range Definition File name, which contains 4D image volume corners (x y z f) in IFT format: corner1 = x y z f corner2 = x y z f; If time frames (f) are missing, then frame coordinate is set to 0.
img_rangeImage volume range
statusPointer to a string (allocated for at least 64 chars) where error message or other execution status will be written; enter NULL, if not needed

Definition at line 75 of file ird.c.

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}
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 irdReorder(IMG_RANGE *img_range)
Definition ird.c:44
int string_to_xyzf(const char *str, IMG_PIXEL *v)
Definition ird.c:14
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

◆ irdReorder()

int irdReorder ( IMG_RANGE * img_range)

Reorder Image Range Definition.

See also
vrdReorder

Function name was previously ifrReorder

Returns
Returns 0 if successful.
Parameters
img_rangeImage volume range; start and end range are set in correct order

Definition at line 44 of file ird.c.

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}

Referenced by irdRead().

◆ string_to_xyzf()

int string_to_xyzf ( const char * str,
IMG_PIXEL * v )

Read voxel coordinates including time frame from a string representation.

See also
string_to_xyz, irdRead
Returns
Returns 0 if successful, >0 if not.
Parameters
strString in format x,y,z,f or x y z f; frame (f) is optional; if f is not specified, then 0 is written in its place.
vPointer to image pixel struct; obligatory.

Definition at line 14 of file ird.c.

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}

Referenced by irdRead().