changeset 1674:a5477d6cbd6e

*** empty log message ***
author baghdadi <baghdadi>
date Tue, 10 Feb 2004 20:26:59 +0000
parents fb755638b4fe
children 154cf586c8ad
files libsrc2/dimension.c libsrc2/m2util.c libsrc2/volprops.c libsrc2/volume.c
diffstat 4 files changed, 119 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/libsrc2/dimension.c
+++ b/libsrc2/dimension.c
@@ -1204,59 +1204,64 @@
 
 static int error_cnt = 0;
 
+#define CX 10
+#define CY 10
+#define CZ 6
+#define NDIMS 3
 
 int main(int argc, char **argv)
 {
-  mihandle_t vol, vol1;
+  mihandle_t vol;
   int r;
-  midimhandle_t dimh, dimh1,dimh2, dimh3; 
-  midimhandle_t dim[4];
+  midimhandle_t dimh, dimh1,dimh2; 
+  midimhandle_t dim[3];
   mivolumeprops_t props;
   double cosines[3];
   double offsets[3];
   double widths[3];
   int n;
   midimhandle_t dimens[3];
+  unsigned long coords[NDIMS];
+    unsigned long count[NDIMS];
+    int i,j,k;
+    struct test {
+        int r;
+        int g;
+        int b;
+    } voxel;
+    int result = 1;
+  /* Write data one voxel at a time. */
+    for (i = 0; i < NDIMS; i++) {
+        count[i] = 1;
+    }
+
+    r = minew_volume_props(&props);
+    r = miset_props_compression_type(props, MI_COMPRESS_ZLIB);
+    r = miset_props_zlib_compression(props, 3);
+     r = miset_props_multi_resolution(props, 1, 3);
+  if (r < 0) {
+    TESTRPT("failed", r);
+  }
   
-  r = minew_volume_props(&props);
-  r = miset_props_compression_type(props, MI_COMPRESS_ZLIB);
-  r = miset_props_zlib_compression(props, 3);
-  r = micreate_dimension("xspace",MI_DIMCLASS_SPATIAL,MI_DIMATTR_REGULARLY_SAMPLED, 100,&dimh);
+  r = micreate_dimension("xspace",MI_DIMCLASS_SPATIAL,MI_DIMATTR_REGULARLY_SAMPLED, 10,&dimh);
   if (r < 0) {
     TESTRPT("failed", r);
   }
   dim[0]=dimh;
   
-  r = micreate_dimension("yspace",MI_DIMCLASS_SPATIAL,MI_DIMATTR_REGULARLY_SAMPLED, 12,&dimh1);
+  r = micreate_dimension("yspace",MI_DIMCLASS_SPATIAL,MI_DIMATTR_REGULARLY_SAMPLED, 10,&dimh1);
   if (r < 0) {
     TESTRPT("failed", r);
   }
   dim[1]=dimh1;
-  r = micreate_dimension("z",MI_DIMCLASS_SPATIAL,MI_DIMATTR_NOT_REGULARLY_SAMPLED, 3,&dimh2);
-  if (r < 0) {
-    TESTRPT("failed", r);
-  }
-  
-  offsets[0]=1.5;
-  offsets[1]=2.5;
-  offsets[2]=3.5;
-  r = miset_dimension_offsets(dimh2, 3, 0, offsets);
-  r = miget_dimension_cosines(dimh1, cosines);
+  r = micreate_dimension("zspace",MI_DIMCLASS_SPATIAL,MI_DIMATTR_REGULARLY_SAMPLED, 6,&dimh2);
   if (r < 0) {
     TESTRPT("failed", r);
   }
   
   dim[2]=dimh2;
-   r = micreate_dimension("zfrequency",MI_DIMCLASS_SFREQUENCY,MI_DIMATTR_REGULARLY_SAMPLED,3,&dimh3);
-  if (r < 0) {
-    TESTRPT("failed", r);
-  }
-  r = miget_dimension_cosines(dimh3, cosines);
-  if (r < 0) {
-    TESTRPT("failed", r);
-  } 
-  dim[3]=dimh3;
-  r = micreate_volume("test.h5", 4, dim, MI_TYPE_UINT, MI_CLASS_INT,props,&vol);
+ 
+  r = micreate_volume("test_multi_h5.mnc", 3, dim, MI_TYPE_UINT, MI_CLASS_REAL,props,&vol);
   if (r < 0) {
     TESTRPT("failed", r);
   }
@@ -1266,37 +1271,44 @@
     TESTRPT("failed", r);
   }
   
-  r =miset_dimension_description(dimh3, "this is funny");
-  if ( r < 0) {
-    TESTRPT("failed", r);
-  }
-  widths[0]=2;
-  widths[1]=3.5;
-  widths[2]=4.5;
-  r = miset_dimension_widths(dimh2, 3, 0, widths);
-  r = miget_volume_dimensions(vol, MI_DIMCLASS_ANY, 0, 0, 4, dimens);
-  if (r < 0) {
-    TESTRPT("failed", r);
-  }
-  //printf(" %s %s %s \n", dimens[0]->name, dimens[1]->name, dimens[2]->name);
-  //printf(" %s \n", dimens[3]->comments);
-  //printf(" %s \n", dimens[0]->comments);
-  //printf( " %f %f %f \n", dimens[2]->offsets[0], dimens[2]->offsets[1], dimens[2]->offsets[2] );
-  //printf( " %f %f %f \n", dimens[2]->widths[0], dimens[2]->widths[1], dimens[2]->widths[2] );
   r = miget_volume_dimension_count(vol, MI_DIMCLASS_SPATIAL, MI_DIMATTR_ALL, &n);
   if (r < 0) {
     TESTRPT("failed", r);
   }
   printf( " N is %d \n", n);
+
+  for (i = 0; i < CX; i++) {
+        for (j = 0; j < CY; j++) {
+            for (k = 0; k < CZ; k++) {
+                coords[0] = i;
+                coords[1] = j;
+                coords[2] = k;
+
+                voxel.r = i;
+                voxel.g = j;
+                voxel.b = k;
+                
+                result = miset_voxel_value_hyperslab(vol, MI_TYPE_UINT,
+						     coords, count, &voxel);
+                if (result < 0) {
+                    TESTRPT("Error writing voxel", result);
+                }
+            }
+        }
+    }
+
+  /* call miselect_resolution() 
+   */
  
+  r = miflush_from_resolution(vol, 3);
+  if (r < 0) {
+    TESTRPT("failed", r);
+  }
   r = miclose_volume(vol);
   if (r < 0) {
     TESTRPT("failed", r);
   }
-  r= miopen_volume("test.h5",MI2_OPEN_READ ,&vol);
-  if (r < 0) {
-    TESTRPT("failed", r);
-  }
+  
   if (error_cnt != 0) {
     fprintf(stderr, "%d error%s reported\n", 
 	    error_cnt, (error_cnt == 1) ? "" : "s");
--- a/libsrc2/m2util.c
+++ b/libsrc2/m2util.c
@@ -908,17 +908,14 @@
                     for (z = 0; z < scale; z++) {
                         int x1,y1,z1;
                         double t;
-
                         x1 = x;
                         y1 = y + (j * scale);
                         z1 = z + (k * scale);
-
                         t = in_ptr[((x1 * isize[1]) + y1) * isize[2] + z1];
                         d += t;
                     }
                 }
             }
-
             d /= total;
             out_ptr[(j * osize[1]) + k] = d;
         }
@@ -961,6 +958,7 @@
      */
     sprintf(path, "%d/image", igrp);
     idst_id = H5Dopen(loc_id, path);
+    
     if (idst_id < 0) {
         return (MI_ERROR);
     }
@@ -979,21 +977,23 @@
     /* Calculate the size of the new thumbnail.
      */
     for (i = 0; i < ndims; i++) {
-	osize[i] = isize[i] / scale; 
+	osize[i] = isize[i] / scale;
 	if (osize[i] == 0) {	/* Too small? */
 	    return (MI_ERROR);
 	}
     }
-
+    /* Create dataspace for new resolution
+     */
     ofspc_id = H5Screate_simple(ndims, osize, NULL);
-
+    
     sprintf(path, "%d/image", ogrp);
+    
     /* TODO: Non-default properties */
     odst_id = H5Dcreate(loc_id, path, typ_id, ofspc_id, H5P_DEFAULT);
     if (odst_id < 0) {
         odst_id = H5Dopen(loc_id, path);
     }
-
+    
     /* Calculate the input buffer size - scale slices.
      */
     in_bytes = scale * isize[1] * isize[2] * sizeof(double);
@@ -1029,7 +1029,7 @@
 	H5Dread(idst_id, H5T_NATIVE_DOUBLE, imspc_id, ifspc_id, H5P_DEFAULT, in_ptr);
 
         midownsample_slice(in_ptr, out_ptr, isize, osize, scale);
-
+	
 	start[0] = slice;
 	start[1] = 0;
 	start[2] = 0;
@@ -1037,18 +1037,22 @@
 	count[1] = osize[1];
 	count[2] = osize[2];
 	H5Sselect_hyperslab(ofspc_id, H5S_SELECT_SET, start, NULL, count, NULL);
+	
 	H5Dwrite(odst_id, H5T_NATIVE_DOUBLE, omspc_id, ofspc_id, H5P_DEFAULT, 
                  out_ptr);
     }
-
+    
     free(in_ptr);
-    free(out_ptr);
+    // THIS CALL RESULTS IN segfault, NOT SURE WHY!
+    //free(out_ptr);
+    
     H5Sclose(omspc_id);
     H5Sclose(imspc_id);
     H5Dclose(odst_id);
     H5Tclose(typ_id);
     H5Sclose(ofspc_id);
     H5Sclose(ifspc_id);
+    
     return (MI_NOERROR);
 }
 
@@ -1063,29 +1067,33 @@
     hsize_t i;
     char name[128];
     size_t length;
-
+  
     grp_id = H5Gopen(file_id, "/minc-2.0/image");
+    
     if (grp_id >= 0) {
-        if (H5Gget_num_objs(grp_id, &n) != 0) {
+        if (H5Gget_num_objs(grp_id, &n) >= 0) {
             for (i = 0; i < n; i++) {
-                length = sizeof(name);
-                H5Gget_objname_by_idx(grp_id, i, name, length);
+	        length = sizeof(name);
+                if (H5Gget_objname_by_idx(grp_id, i, name, 128) < 0) {
+		  return (MI_ERROR);
+		}
                 fprintf(stderr, "Found group %s\n", name);
                 prv_grp_no = grp_no;
                 grp_no = atoi(name);
                 if (grp_no != 0) {
                     fprintf(stderr, "Updating group #%d from #%d\n", 
                             grp_no, prv_grp_no);
-                    minc_update_thumbnail(grp_id, prv_grp_no, grp_no);
+		    minc_update_thumbnail(grp_id, prv_grp_no, grp_no);
                 }
             }
         }
         else {
             fprintf(stderr, "error getting object count?\n");
         }
-
+	
         H5Gclose(grp_id);
-    }
+	
+    } 
     else {
         fprintf(stderr, "error opening group?\n");
 	
--- a/libsrc2/volprops.c
+++ b/libsrc2/volprops.c
@@ -170,14 +170,14 @@
 miset_props_multi_resolution(mivolumeprops_t props, BOOLEAN enable_flag,
 			    int depth)
 {
-  if (props == NULL || depth > MAX_RESOLUTION_GROUP || depth < 0) {
+  int i;
+  if (props == NULL || depth > MAX_RESOLUTION_GROUP || depth <= 0) {
     return (MI_ERROR);
   }
   
   if (enable_flag){
     props->enable_flag = enable_flag;
     props->depth = depth;
-   
   }
   else {
     return (MI_ERROR);
@@ -216,13 +216,16 @@
     return (MI_ERROR);
   }
   /* Check given depth with the available depth in file.
+     Make sure the selected resolution does exist.
    */
-  if (depth <= volume->create_props->depth) {
-    printf(" THIS RESOLUTION IS ALREADY COMPUTED!!! \n");
+  if (depth > volume->create_props->depth) {
+    printf(" THIS RESOLUTION DOES NOT EXIST!!! \n");
     return (0);
   }
   else {
-    minc_update_thumbnail(grp_id,0 ,depth);
+    if (minc_update_thumbnail(grp_id,0 ,depth) < 0) {
+      return (MI_ERROR);
+    }
   }
 
  return (MI_NOERROR);
@@ -234,13 +237,20 @@
 miflush_from_resolution(mihandle_t volume, int depth)
 {
   int i;
-  if ( volume->hdf_id < 0 || depth > MAX_RESOLUTION_GROUP || depth < 0) {
+  
+  if ( volume->hdf_id < 0 || depth > MAX_RESOLUTION_GROUP || depth <= 0) {
     return (MI_ERROR);
   }
-  for(i=0; i<depth; i++) {
-    miselect_resolution(volume, i+1);
+  
+  if (depth > volume->create_props->depth) {
+    printf(" THIS RESOLUTION DOES NOT EXIST!!! \n");
+    return (0);
   }
-  
+  else {
+    if (minc_update_thumbnails(volume->hdf_id) < 0) {
+      return (MI_ERROR);
+    }
+  }
   
  return (MI_NOERROR);
 }
--- a/libsrc2/volume.c
+++ b/libsrc2/volume.c
@@ -30,7 +30,8 @@
     hid_t dataspace_id;
     hid_t dset_id;
     hsize_t hdf_size[MI2_MAX_VAR_DIMS];
-
+    hid_t grp_id;
+    hsize_t n;
     /* Try creating IMAGE dataset i.e. /minc-2.0/image/0/image
      */
 
@@ -120,7 +121,9 @@
         volume->imax_id = dset_id;
         hdf_var_declare(volume->hdf_id, "image-max", "/minc-2.0/image/0/image-max", ndims, hdf_size);
         H5Sclose(dataspace_id);
+	
     }
+
     return (MI_NOERROR);
 }
 
@@ -225,7 +228,7 @@
   if (file_id < 0) {
     return (MI_ERROR);
   }
-  
+
   hdf_plist = H5Pcreate(H5P_DATASET_CREATE);
   if (hdf_plist < 0) {
     return (MI_ERROR);
@@ -276,6 +279,15 @@
     }
   }
   
+  /* See if Multi-res is set to a level above 0 and if yes create subgroups*/
+  if (create_props != NULL && create_props->depth > 0) {
+    for (i=0; i < create_props->depth ; i++) {
+      if (minc_create_thumbnail(file_id, i+1) < 0) {
+	return (MI_ERROR);
+      }
+    }
+  }
+
    /* Try creating DIMENSIONS GROUP i.e. /minc-2.0/dimensions
     */
   grp_dimensions_id = H5Gopen(file_id, "/minc-2.0/dimensions");