changeset 2409:6b594f624680

* added a bunch of bug fixes from Claude.
author rotor <rotor>
date Wed, 12 Dec 2007 20:55:26 +0000
parents 4ae5977fbfd8
children e647ccf58b71
files ChangeLog libsrc/image_conversion.c libsrc2/dimension.c libsrc2/volume.c progs/mincresample/resample_volumes.c
diffstat 5 files changed, 87 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,16 @@
 MINC 2:
+2007-12-06 Claude Lepage <claude@bic.mni.mcgill.ca>
+	* Freed more memory in miicv_free (libsrc/image_conversion.c)
+	* Added cubic interpolation in mincresample for x-y slices
+	* Fixed seg fault bug with null history string (libsrc/minc_convenience.c)
+	* Changed hard-coded strings for MIxspace (y,z) (libsrc2/volume.c and
+          libsrc2/dimension.c)
+	* Made global variables static in minccompress to avoid conflict with libz
+
+2007-12-03 Andrew L Janke <a.janke@gmail.com>
+	* changed all global variables to static in progs directory to 
+	   avoid possible linker errors in the future. 
+
 2007-10-23  Andrew L Janke <a.janke@gmail.com>
 	* Added most things needed for a CMake build
 	* Fixed a linking bug with nii2mnc and mnc2nii
--- a/libsrc/image_conversion.c
+++ b/libsrc/image_conversion.c
@@ -34,7 +34,10 @@
 @CREATED    : July 27, 1992. (Peter Neelin, Montreal Neurological Institute)
 @MODIFIED   : 
  * $Log: image_conversion.c,v $
- * Revision 6.13  2004-12-14 23:53:46  bert
+ * Revision 6.14  2007-12-12 20:55:26  rotor
+ *  * added a bunch of bug fixes from Claude.
+ *
+ * Revision 6.13  2004/12/14 23:53:46  bert
  * Get rid of compilation warnings
  *
  * Revision 6.12  2004/10/15 13:45:28  bert
@@ -156,7 +159,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[] = "$Header: /private-cvsroot/minc/libsrc/image_conversion.c,v 6.13 2004-12-14 23:53:46 bert Exp $ MINC (MNI)";
+static char rcsid[] = "$Header: /private-cvsroot/minc/libsrc/image_conversion.c,v 6.14 2007-12-12 20:55:26 rotor Exp $ MINC (MNI)";
 #endif
 
 #include "minc_private.h"
@@ -329,6 +332,16 @@
    FREE(icvp);
    minc_icv_list[icvid]=NULL;
 
+   /* Delete entire structure if no longer in use. */
+   int new_icv;
+   for (new_icv=0; new_icv<minc_icv_list_nalloc; new_icv++)
+      if (minc_icv_list[new_icv]!=NULL) break;
+
+   if (new_icv>=minc_icv_list_nalloc) {
+      FREE(minc_icv_list);
+      minc_icv_list_nalloc=0;
+   }
+
    MI_RETURN(MI_NOERROR);
 }
 
--- a/libsrc2/dimension.c
+++ b/libsrc2/dimension.c
@@ -193,19 +193,19 @@
   switch (class) {
   case MI_DIMCLASS_SPATIAL:
     handle->class  = MI_DIMCLASS_SPATIAL;
-    if (strcmp(name, "xspace") == 0) {
+    if (strcmp(name, MIxspace) == 0) {
       handle->direction_cosines[MI2_X] = 1.0;
       handle->direction_cosines[MI2_Y] = 0.0;
       handle->direction_cosines[MI2_Z] = 0.0;
       handle->comments = strdup("X increases from patient left to right");
     }
-    else if (strcmp(name, "yspace") == 0) {
+    else if (strcmp(name, MIyspace) == 0) {
       handle->direction_cosines[MI2_X] = 0.0;
       handle->direction_cosines[MI2_Y] = 1.0;
       handle->direction_cosines[MI2_Z] = 0.0;
       handle->comments = strdup("Y increases from patient posterior to anterior");
     }
-    else if (strcmp(name, "zspace") == 0) {
+    else if (strcmp(name, MIzspace) == 0) {
       handle->direction_cosines[MI2_X] = 0.0;
       handle->direction_cosines[MI2_Y] = 0.0;
       handle->direction_cosines[MI2_Z] = 1.0;
--- a/libsrc2/volume.c
+++ b/libsrc2/volume.c
@@ -992,13 +992,13 @@
             hdim->direction_cosines[MI2_X] = 0.0;
             hdim->direction_cosines[MI2_Y] = 0.0;
             hdim->direction_cosines[MI2_Z] = 0.0;
-            if (!strcmp(dimname, "xspace")) {
+            if (!strcmp(dimname, MIxspace)) {
                 hdim->direction_cosines[MI2_X] = 1.0;
             }
-            else if (!strcmp(dimname, "yspace")) {
+            else if (!strcmp(dimname, MIyspace)) {
                 hdim->direction_cosines[MI2_Y] = 1.0;
             }
-            else if (!strcmp(dimname, "zspace")) {
+            else if (!strcmp(dimname, MIzspace)) {
                 hdim->direction_cosines[MI2_Z] = 1.0;
             }
         }
--- a/progs/mincresample/resample_volumes.c
+++ b/progs/mincresample/resample_volumes.c
@@ -6,7 +6,10 @@
 @CREATED    : February 8, 1993 (Peter Neelin)
 @MODIFIED   : 
  * $Log: resample_volumes.c,v $
- * Revision 6.6  2006-05-19 00:13:39  bert
+ * Revision 6.7  2007-12-12 20:55:26  rotor
+ *  * added a bunch of bug fixes from Claude.
+ *
+ * Revision 6.6  2006/05/19 00:13:39  bert
  * Add config.h
  *
  * Revision 6.5  2005/07/13 21:34:25  bert
@@ -93,7 +96,7 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincresample/resample_volumes.c,v 6.6 2006-05-19 00:13:39 bert Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/progs/mincresample/resample_volumes.c,v 6.7 2007-12-12 20:55:26 rotor Exp $";
 #endif
 
 #if HAVE_CONFIG_H
@@ -680,17 +683,29 @@
    slcmax = volume->size[SLC_AXIS] - 1;
    rowmax = volume->size[ROW_AXIS] - 1;
    colmax = volume->size[COL_AXIS] - 1;
-   if ((coord[SLICE]  < 0) || (coord[SLICE]  > slcmax) ||
-       (coord[ROW]    < 0) || (coord[ROW]    > rowmax) ||
-       (coord[COLUMN] < 0) || (coord[COLUMN] > colmax)) {
-      *result = volume->fillvalue;
-      return FALSE;
+
+   /* Identify a slice or a volume. Slice must be in x-y. */
+   if( slcmax == 0 ) {
+     /* 2-d slice */
+     if( (coord[ROW] < 0) || (coord[ROW] > rowmax) ||
+         (coord[COLUMN] < 0) || (coord[COLUMN] > colmax) ) {
+       *result = volume->fillvalue;
+       return FALSE;
+     }
+   } else {
+     /* 3-d volume */
+     if( (coord[SLICE]  < 0) || (coord[SLICE]  > slcmax) ||
+         (coord[ROW]    < 0) || (coord[ROW]    > rowmax) ||
+         (coord[COLUMN] < 0) || (coord[COLUMN] > colmax) ) {
+       *result = volume->fillvalue;
+       return FALSE;
+     }
    }
 
    /* Get the whole and fractional part of the coordinate */
-   slcind = (long) coord[SLICE];
-   rowind = (long) coord[ROW];
-   colind = (long) coord[COLUMN];
+   slcind = (long)coord[SLICE];
+   rowind = (long)coord[ROW];
+   colind = (long)coord[COLUMN];
    frac[0] = coord[SLICE]  - slcind;
    frac[1] = coord[ROW]    - rowind;
    frac[2] = coord[COLUMN] - colind;
@@ -698,16 +713,39 @@
    rowind--;
    colind--;
 
-   /* Check for edges - do linear interpolation at edges */
+   /* Check for dimension of image. */
+
+   /* Check for edges in the 2-d plane - do linear interpolation at edges */
+   /* Note: Spline stencil is right-sided, so ok to start at 0. */
+   if( slcmax == 0 && rowmax > 0 && colmax > 0 ) {
+     if( (rowind > rowmax-3) || (rowind < 0) ||
+         (colind > colmax-3) || (colind < 0)) {
+       return trilinear_interpolant(volume, coord, result);
+     } else {
+       slcind = 0;  /* there is only slice 0 */
+       index[0]=slcind; index[1]=rowind; index[2]=colind;
+       if( do_Ncubic_interpolation(volume, index, 1, frac, result) ) {
+         /* scaling not done for a slice in do_Ncubic_interpolation, */
+         /* only done for a volume */
+         *result = (*result) * volume->scale[slcind] + volume->offset[slcind];
+         return TRUE;
+       } else {
+         return FALSE;
+       }
+     }
+   }
+
+   /* Check for edges in the 3-d volume - do linear interpolation at edges */
+   /* Note: Spline stencil is right-sided, so ok to start at 0. */
    if ((slcind > slcmax-3) || (slcind < 0) ||
        (rowind > rowmax-3) || (rowind < 0) ||
        (colind > colmax-3) || (colind < 0)) {
       return trilinear_interpolant(volume, coord, result);
+   } else {
+     index[0]=slcind; index[1]=rowind; index[2]=colind;
+     /* Do the interpolation and return its value */
+     return do_Ncubic_interpolation(volume, index, 0, frac, result);
    }
-   index[0]=slcind; index[1]=rowind; index[2]=colind;
-
-   /* Do the interpolation and return its value */
-   return do_Ncubic_interpolation(volume, index, 0, frac, result);
 
 }
 
@@ -757,6 +795,7 @@
           (v3 < volume->vrange[0]) || (v3 > volume->vrange[1])) {
          found_fillvalue = TRUE;
       }
+
    }
 
    /* Otherwise, recurse */