~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tools/sequence/seq_io.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2   seq_io.c
  3 
  4   NAT 7/4/97
  5 
  6   Modification: 4-Oct-99 by IH, DICOM functionality added
  7   
  8 */
  9 
 10 #include <stdio.h>
 11 #include <fcntl.h>
 12 #include <tina/sys.h>
 13 #include <tina/sysfuncs.h>
 14 #include <tina/math.h>
 15 #include <tina/mathfuncs.h>
 16 #include <tina/vision.h>
 17 #include <tina/visionfuncs.h>
 18 #include <tina/tv.h>
 19 #include <tina/file.h>
 20 #include <tina/filefuncs.h>
 21 #include <tina/image.h>
 22 #include <tina/seqdefs.h>
 23 #include <tina/seqoral.h>
 24 #include <tina/seqpro.h>
 25 
 26 
 27 static char     filename[512];
 28 static char     temp[512];
 29 #define AIFF_FILE       0
 30 #define ANLZ_FILE       1
 31 #define RAD_FILE        2
 32 #define NEMA_FILE       3
 33 #define MIPL_FILE       4
 34 #define AVS_FILE        5
 35 #define DICOM_FILE      6
 36 #define PGM_FILE        7
 37 
 38 #define VOXELS          450
 39 
 40 extern Imrect *mip_read_image(char *, int i);
 41  
 42 
 43 Vec3 *seq_input(Sequence *seq, int file_type)
 44 {
 45 
 46   Imrect  *im;
 47   int      i;
 48   char    *pfname[1];
 49   Vec3    *iscale=NULL;
 50 
 51   switch (file_type)
 52   {
 53      case AIFF_FILE:
 54         strcpy(filename, "");
 55         strcpy(temp,"");
 56 
 57         for(i = (seq->seq_end); i >= seq->seq_start; i--)
 58           {
 59             parse_fname(seq->filename,temp,i);
 60             sprintf(filename, "%s%s", temp, ".aiff");
 61             *pfname = filename;
 62             if (strchr(filename, '*') && !fname_resolve(NULL, filename, pfname))
 63             {
 64               error("seq_input: no such file or filename", warning);
 65               return(iscale);
 66             }
 67 
 68             if ((im = (Imrect *)aiff_read_image(*pfname)) != NULL)
 69             {
 70                set_frame_no(im, i);
 71                frame_insert(im, seq);
 72             }
 73            }
 74          break;
 75 
 76      case ANLZ_FILE:
 77         strcpy(filename, "");
 78         strcpy(temp,"");
 79  
 80         for(i = seq->seq_end ; i >= seq->seq_start ; i--)
 81           {
 82  
 83             if ((im = (Imrect *)ani_read_image(seq->filename,i)) != NULL)
 84             {
 85                set_frame_no(im, i);
 86                frame_insert(im, seq);
 87                if (prop_get(im->props,VOXELS)!=NULL)
 88                   iscale = (Vec3 *)prop_get(im->props,VOXELS);
 89             }
 90           }
 91          break;
 92 
 93      case RAD_FILE:
 94         strcpy(filename, "");
 95         strcpy(temp,"");
 96  
 97         for(i = seq->seq_end ; i >= seq->seq_start ; i--)
 98           {
 99             parse_fname(seq->filename,temp,i);
100             sprintf(filename, "%s%s", temp, ".rad");
101             *pfname = filename;
102             if (strchr(filename, '*') && !fname_resolve(NULL, filename, pfname))
103             {
104               error("seq_input: no such file or filename", warning);
105               return(iscale);
106             }
107  
108             if ((im = (Imrect *)rad_read_image(*pfname)) != NULL)
109             { 
110                 set_frame_no(im, i);
111                 frame_insert(im, seq);
112             }
113            }
114          break;
115 
116      case NEMA_FILE:
117         strcpy(filename, "");
118         strcpy(temp,"");
119  
120         for(i = (seq->seq_end); i >= seq->seq_start; i--)
121           {
122             parse_fname(seq->filename,temp,i);
123             sprintf(filename, "%s%s", temp, ".ani");
124             *pfname = filename;
125             if (strchr(filename, '*') && !fname_resolve(NULL, filename, pfname))
126             {
127               error("seq_input: no such file or filename", warning);
128               return(iscale);
129             }
130  
131             if ((im = (Imrect *)nema_read_image(*pfname)) != NULL)
132             {
133                set_frame_no(im, i);
134                frame_insert(im, seq);
135                if (prop_get(im->props,VOXELS)!=NULL)
136                   iscale = (Vec3 *)prop_get(im->props,VOXELS);
137             }
138            }
139          break;
140 
141      case MIPL_FILE:
142         strcpy(filename, "");
143         strcpy(temp,"");
144  
145         for(i = seq->seq_end ; i >= seq->seq_start ; i--)
146           {
147  
148             if ((im = (Imrect *)mip_read_image(seq->filename,i)) != NULL)
149             {
150                set_frame_no(im, i);
151                frame_insert(im, seq);
152                if (prop_get(im->props,VOXELS)!=NULL)
153                   iscale = (Vec3 *)prop_get(im->props,VOXELS);
154             }
155           }
156          break;
157 
158      case PGM_FILE:
159         strcpy(filename, "");
160         strcpy(temp,"");
161 
162         for(i = (seq->seq_end); i >= seq->seq_start; i--)
163           {
164             parse_fname(seq->filename,temp,i);
165             sprintf(filename, "%s%s", temp, ".pgm");
166             *pfname = filename;
167             if (strchr(filename, '*') && !fname_resolve(NULL, filename, pfname))
168             {
169               error("seq_input: no such file or filename", warning);
170               return(iscale);
171             }
172 
173             if ((im = (Imrect *)pgm_read_image(*pfname)) != NULL)
174             {
175                set_frame_no(im, i);
176                frame_insert(im, seq);
177             }
178            }
179          break;
180 
181      case DICOM_FILE:
182         strcpy(filename, "");
183         strcpy(temp,"");
184  
185         for(i = (seq->seq_end); i >= seq->seq_start; i--)
186           {
187             parse_fname(seq->filename,temp,i);
188             sprintf(filename, "%s%s", temp, "");  /* No df extension */
189             *pfname = filename;
190             if (strchr(filename, '*') && !fname_resolve(NULL, filename, pfname))
191             {
192               error("seq_input: no such file or filename", warning);
193               return(iscale);
194             }
195  
196             if ((im = (Imrect *)dicom_read_image(*pfname)) != NULL)
197             {
198                set_frame_no(im, i);
199                frame_insert(im, seq);
200                if (prop_get(im->props,VOXELS)!=NULL)
201                   iscale = (Vec3 *)prop_get(im->props,VOXELS);
202             }
203            }
204          break;
205 
206   }
207   return (iscale);
208 
209 }
210 
211 
212 void      seq_output(Sequence *params, int file_type)
213 {
214   List   *store = get_start_el();
215   int       i;
216 
217   switch (file_type)
218     {
219     case AIFF_FILE:
220       if (store == NULL)
221         {
222           sprintf(temp, " nothing to save in %s", params->filename);
223           error(temp, warning);
224           return;
225         }
226 
227       for(i = params->seq_start; i <= params->seq_end; i++)
228         {
229           parse_fname(params->filename,temp,i);
230           sprintf(filename, "%s%s", temp, ".aiff");
231 
232           if ((store == NULL) || (store->to == NULL))
233             {
234               sprintf(temp, " no data for %s, aborting", filename);
235               error(temp, warning);
236               return;
237             }
238                 
239           aiff_write_image(store->to, filename);
240           store = store->next;
241         }
242       break;
243     case RAD_FILE:
244       if (store == NULL)
245         {
246           sprintf(temp, " nothing to save in %s", params->filename);
247           error(temp, warning);
248           return;
249         }
250 
251 
252       for(i = params->seq_start; i <= params->seq_end; i++)
253         {
254           parse_fname(params->filename,temp,i);
255           sprintf(filename, "%s%s", temp, ".rad");
256 
257           if ((store == NULL) || (store->to == NULL))
258             {
259               sprintf(temp, " no data for %s, aborting", filename);
260               error(temp, warning);
261               return;
262             }
263 
264           rad_write_image(store->to, filename);
265           store = store->next;
266         }
267       break;
268     case ANLZ_FILE:
269       ani_write_image(params);
270       break;
271 
272     case PGM_FILE:
273       if (store == NULL)
274         {
275           sprintf(temp, " nothing to save in %s", params->filename);
276           error(temp, warning);
277           return;
278         }
279 
280       for(i = params->seq_start; i <= params->seq_end; i++)
281         {
282           parse_fname(params->filename,temp,i);
283           sprintf(filename, "%s%s", temp, ".pgm");
284 
285           if ((store == NULL) || (store->to == NULL))
286             {
287               sprintf(temp, " no data for %s, aborting", filename);
288               error(temp, warning);
289               return;
290             }
291           pgm_write_image(store->to, filename);
292           store = store->next;
293         }
294         break;
295     }
296   return;
297 }       
298 
299 Vec3 *read_image_seq(Sequence *data, int itype)
300 {
301 
302   List  *lptr = get_start_el();
303 
304   data->type = SEQ;
305 
306   if (lptr != NULL)
307     dd_list_rm(lptr, im_free);
308 
309   set_current_el(NULL);
310   set_start_el(NULL);
311   set_end_el(NULL);
312         
313   return(seq_input(data, itype)); 
314 }
315 
316 
317 
318 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.