Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/vis12/src/lib/common/image.c
ViewVC logotype

Diff of /branches/vis12/src/lib/common/image.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1806, Sat Apr 7 00:02:25 2012 UTC revision 1807, Sat Apr 7 12:00:48 2012 UTC
# Line 287  Line 287 
287  #undef I  #undef I
288  }  }
289    
290  static Nrrd *LoadNrrdFile (const char *filename)  static void Error (WorldPrefix_t *wrld, const char *fmt, ...)
291    {
292        char buf[1024];
293        va_list ap;
294    
295        va_start (ap, fmt);
296        vsnprintf (buf, sizeof(buf), fmt, ap);
297        va_end (ap);
298    
299        wrld->err = NEWSTR(buf);
300    }
301    
302    static Nrrd *LoadNrrdFile (WorldPrefix_t *wrld, const char *filename)
303  {  {
304    /* create a nrrd; at this point this is just an empty container */    /* create a nrrd; at this point this is just an empty container */
305      Nrrd *nin = nrrdNew();      Nrrd *nin = nrrdNew();
306    
307    /* read in the nrrd from file */    /* read in the nrrd from file */
308      if (nrrdLoad(nin, filename, NULL)) {      if (nrrdLoad(nin, filename, NULL) != 0) {
309          char *err = biffGetDone(NRRD);          wrld->err = biffGetDone(NRRD);
310          fprintf (stderr, "Diderot: trouble reading \"%s\":\n%s", filename, err);          return 0;
         free (err);  
         return NULL;  
311      }      }
312    
313      return nin;      return nin;
# Line 309  Line 319 
319      return (nin->axis[i].kind != nrrdKindSpace);      return (nin->axis[i].kind != nrrdKindSpace);
320  }  }
321    
322  /* load image data from Nrrd files */  Status_t Diderot_SetImage1D (WorldPrefix_t *wrld, Nrrd *nin, Diderot_image1D_t **imgOut)
 Status_t Diderot_LoadImage1D (Diderot_string_t name, Diderot_image1D_t **imgOut)  
323  {  {
     Nrrd *nin = LoadNrrdFile (name);  
324      Diderot_image1D_t *img = (Diderot_image1D_t *)malloc(sizeof(Diderot_image1D_t));      Diderot_image1D_t *img = (Diderot_image1D_t *)malloc(sizeof(Diderot_image1D_t));
325    
326    // compute the offset to the first space axis    // compute the offset to the first space axis
# Line 321  Line 329 
329  // FIXME: we should also be checking the shape of the voxels and the type of the samples.  // FIXME: we should also be checking the shape of the voxels and the type of the samples.
330    // check that the image format is what we expect    // check that the image format is what we expect
331      if (nin->spaceDim != 1) {      if (nin->spaceDim != 1) {
332          fprintf(stderr, "nrrd file \"%s\" has unexpected dimension %d, expected 1\n",          Error (wrld, "nrrd has unexpected dimension %d, expected 1\n", nin->spaceDim);
             name, nin->spaceDim);  
333          return DIDEROT_FAIL;          return DIDEROT_FAIL;
334      }      }
335      else if (CheckAxis(nin, base)) {      else if (CheckAxis(nin, base)) {
336          fprintf(stderr,          Error (wrld, "nrrd has unexpected axis structure: %s\n",
             "nrrd file \"%s\" has unexpected axis structure: %s\n",  
             name,  
337              airEnumStr(nrrdKind, nin->axis[base].kind));              airEnumStr(nrrdKind, nin->axis[base].kind));
338          return DIDEROT_FAIL;          return DIDEROT_FAIL;
339      }      }
# Line 338  Line 343 
343      img->data = nin->data;      img->data = nin->data;
344      img->dataSzb =  nrrdElementSize(nin) * nrrdElementNumber(nin);      img->dataSzb =  nrrdElementSize(nin) * nrrdElementNumber(nin);
345    
346  //printf("LoadImage \"%s\": space dim = 1, axes = <%d>\n",  //printf("SetImage \"%s\": space dim = 1, axes = <%d>\n",
347  //name, img->size[base+0]);  //name, img->size[base+0]);
348    
349    // from the Nrrd file, we load the scaling and translation    // from the Nrrd file, we load the scaling and translation
# Line 352  Line 357 
357      return DIDEROT_OK;      return DIDEROT_OK;
358  }  }
359    
360  Status_t Diderot_LoadImage2D (Diderot_string_t name, Diderot_image2D_t **imgOut)  /* load image data from Nrrd files */
361    Status_t Diderot_LoadImage1D (WorldPrefix_t *wrld, Diderot_string_t name, Diderot_image1D_t **imgOut)
362    {
363        Nrrd *nin = LoadNrrdFile (wrld, name);
364        if (nin == 0)
365            return DIDEROT_FAIL;
366        else
367            return Diderot_SetImage1D (wrld, nin, imgOut);
368    }
369    
370    Status_t Diderot_SetImage2D (WorldPrefix_t *wrld, Nrrd *nin, Diderot_image2D_t **imgOut)
371  {  {
     Nrrd *nin = LoadNrrdFile (name);  
372      Diderot_image2D_t *img = (Diderot_image2D_t *)malloc(sizeof(Diderot_image2D_t));      Diderot_image2D_t *img = (Diderot_image2D_t *)malloc(sizeof(Diderot_image2D_t));
373    
374    // compute the offset to the first space axis    // compute the offset to the first space axis
# Line 362  Line 376 
376    
377    // check that the image format is what we expect    // check that the image format is what we expect
378      if (nin->spaceDim != 2) {      if (nin->spaceDim != 2) {
379          fprintf(stderr, "nrrd file \"%s\" has unexpected dimension %d, expected 2\n",          Error (wrld, "nrrd has unexpected dimension %d, expected 2\n", nin->spaceDim);
             name, nin->spaceDim);  
380          return DIDEROT_FAIL;          return DIDEROT_FAIL;
381      }      }
382      else if (CheckAxis(nin, base) || CheckAxis(nin, base+1)) {      else if (CheckAxis(nin, base) || CheckAxis(nin, base+1)) {
383          fprintf(stderr,          Error (wrld, "nrrd has unexpected axis structure: %s %s\n",
             "nrrd file \"%s\" has unexpected axis structure: %s %s\n",  
             name,  
384              airEnumStr(nrrdKind, nin->axis[base].kind),              airEnumStr(nrrdKind, nin->axis[base].kind),
385              airEnumStr(nrrdKind, nin->axis[base+1].kind));              airEnumStr(nrrdKind, nin->axis[base+1].kind));
386          return DIDEROT_FAIL;          return DIDEROT_FAIL;
# Line 412  Line 423 
423      return DIDEROT_OK;      return DIDEROT_OK;
424  }  }
425    
426  Status_t Diderot_LoadImage3D (Diderot_string_t name, Diderot_image3D_t **imgOut)  /* load image data from Nrrd files */
427    Status_t Diderot_LoadImage2D (WorldPrefix_t *wrld, Diderot_string_t name, Diderot_image2D_t **imgOut)
428  {  {
429      Nrrd *nin = LoadNrrdFile (name);      Nrrd *nin = LoadNrrdFile (wrld, name);
430        if (nin == 0)
431            return DIDEROT_FAIL;
432        else
433            return Diderot_SetImage2D (wrld, nin, imgOut);
434    }
435    
436    Status_t Diderot_SetImage3D (WorldPrefix_t *wrld, Nrrd *nin, Diderot_image3D_t **imgOut)
437    {
438    // compute the offset to the first space axis    // compute the offset to the first space axis
439      int base = nin->dim - nin->spaceDim;      int base = nin->dim - nin->spaceDim;
440    
441    // check that the image format is what we expect    // check that the image format is what we expect
442      if (nin->spaceDim != 3) {      if (nin->spaceDim != 3) {
443          fprintf(stderr, "nrrd file \"%s\" has unexpected dimension %d, expected 3\n",          Error (wrld, "nrrd has unexpected dimension %d, expected 3\n", nin->spaceDim);
             name, nin->spaceDim);  
444          return DIDEROT_FAIL;          return DIDEROT_FAIL;
445      }      }
446      else if (CheckAxis(nin, base) || CheckAxis(nin, base+1) || CheckAxis(nin, base+2)) {      else if (CheckAxis(nin, base) || CheckAxis(nin, base+1) || CheckAxis(nin, base+2)) {
447          fprintf(stderr,          Error (wrld, "nrrd has unexpected axis structure: %s %s %s\n",
             "nrrd file \"%s\" has unexpected axis structure: %s %s %s\n",  
             name,  
448              airEnumStr(nrrdKind, nin->axis[base].kind),              airEnumStr(nrrdKind, nin->axis[base].kind),
449              airEnumStr(nrrdKind, nin->axis[base+1].kind),              airEnumStr(nrrdKind, nin->axis[base+1].kind),
450              airEnumStr(nrrdKind, nin->axis[base+2].kind));              airEnumStr(nrrdKind, nin->axis[base+2].kind));
# Line 474  Line 490 
490      *imgOut = img;      *imgOut = img;
491      return DIDEROT_OK;      return DIDEROT_OK;
492  }  }
493    
494    /* load image data from Nrrd files */
495    Status_t Diderot_LoadImage3D (WorldPrefix_t *wrld, Diderot_string_t name, Diderot_image3D_t **imgOut)
496    {
497        Nrrd *nin = LoadNrrdFile (wrld, name);
498        if (nin == 0)
499            return DIDEROT_FAIL;
500        else
501            return Diderot_SetImage3D (wrld, nin, imgOut);
502    }

Legend:
Removed from v.1806  
changed lines
  Added in v.1807

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0