Mercurial > hg > minc-tools
changeset 1624:5f7662ae7a55
*** empty log message ***
author | baghdadi <baghdadi> |
---|---|
date | Wed, 14 Jan 2004 16:53:04 +0000 |
parents | 8c3fa53243a2 |
children | 17877968b6a7 |
files | libsrc2/dimension.c libsrc2/minc2.h libsrc2/minc2_private.h libsrc2/volume.c |
diffstat | 4 files changed, 118 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/libsrc2/dimension.c +++ b/libsrc2/dimension.c @@ -129,10 +129,12 @@ } - /* Explicitly allocate storage for name + /* Duplicate the dimension name */ handle->name = strdup(name); - + /* Set the dimension comment to NULL unless otherwise + */ + handle->comments = NULL; switch (class) { case MI_DIMCLASS_ANY: handle->class = MI_DIMCLASS_ANY; @@ -143,21 +145,25 @@ 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) { 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) { handle->direction_cosines[MI2_X] = 0.0; handle->direction_cosines[MI2_Y] = 0.0; handle->direction_cosines[MI2_Z] = 1.0; + handle->comments = strdup("Z increases from patient inferior to superior"); } else { handle->direction_cosines[MI2_X] = 1.0; handle->direction_cosines[MI2_Y] = 0.0; handle->direction_cosines[MI2_Z] = 0.0; + handle->comments = NULL; } break; case MI_DIMCLASS_TIME: @@ -201,20 +207,21 @@ /* "attr" can only be one of the following , MI_DIMATTR_ALL is not valid for this function */ + handle->offsets = NULL; switch (attr) { case MI_DIMATTR_REGULARLY_SAMPLED: handle->attr = MI_DIMATTR_REGULARLY_SAMPLED; handle->sampling_flag = 1; - handle->offsets = NULL; + handle->widths = NULL; break; case MI_DIMATTR_NOT_REGULARLY_SAMPLED: handle->attr = MI_DIMATTR_NOT_REGULARLY_SAMPLED; handle->sampling_flag = 0; - handle->offsets = (double *) malloc(length *sizeof(double)); + handle->widths = (double *) malloc(length *sizeof(double)); for (i=0; i< length; i++) { - handle->offsets[i] = 0; + handle->widths[i] = 1.0; } break; @@ -649,6 +656,42 @@ return (MI_NOERROR); } +/*! Set the comments attribute for a given dimension. + */ + +int +miset_dimension_description(midimhandle_t dimension, const char *comments) +{ + + if (dimension == NULL || comments == NULL) { + return (MI_ERROR); + } + + if ((strlen(comments) + 1) <= MI2_CHAR_LENGTH) { + dimension->comments = strdup(comments); + } + else { + return (MI_ERROR); + } + + return (MI_NOERROR); +} +/*! Get the comments attribute for a given dimension. + */ + +int +miget_dimension_description(midimhandle_t dimension, char **comments_ptr) +{ + + if (dimension == NULL) { + return (MI_ERROR); + } + + *comments_ptr = strdup(dimension->comments); + + return (MI_NOERROR); +} + /*! Get the identifier (name) of a MINC dimension. */ @@ -745,6 +788,7 @@ else { diff = array_length; } + /* Allocate space for the offsets if not already done. */ if (dimension->offsets == NULL) { @@ -1166,6 +1210,8 @@ midimhandle_t dim[4]; mivolumeprops_t props; double cosines[3]; + double offsets[3]; + double widths[3]; int n; midimhandle_t dimens[3]; /* Turn off automatic error reporting - we'll take care of this @@ -1191,6 +1237,10 @@ 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); if (r < 0) { TESTRPT("failed", r); @@ -1210,11 +1260,23 @@ if (r < 0) { TESTRPT("failed", r); } - r = miget_volume_dimensions(vol, MI_DIMCLASS_SPATIAL, 0, 0, 4, dimens); + 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);
--- a/libsrc2/minc2.h +++ b/libsrc2/minc2.h @@ -195,6 +195,8 @@ double direction_cosines[3]); extern int miset_dimension_direction_cosines(midimhandle_t dimension, const double direction_cosines[3]); +extern int miset_dimension_description(midimhandle_t dimension, const char *comments); +extern int miget_dimension_description(midimhandle_t dimension, char **comments_ptr); extern int miget_dimension_name(midimhandle_t dimension, char **name_ptr); extern int miset_dimension_name(midimhandle_t dimension, const char *name); extern int miget_dimension_offsets(midimhandle_t dimension, unsigned long array_length,
--- a/libsrc2/minc2_private.h +++ b/libsrc2/minc2_private.h @@ -76,6 +76,7 @@ char *units; double width; double *widths; + char *comments; mihandle_t volume_handle; };
--- a/libsrc2/volume.c +++ b/libsrc2/volume.c @@ -193,33 +193,40 @@ */ if (dimensions[i]->attr == MI_DIMATTR_NOT_REGULARLY_SAMPLED) { - fspc_id = H5Dget_space(dataset_id); - if (fspc_id < 0) { + if (dimensions[i]->offsets == NULL) { + printf(" OFFSETS MUST BE SPECIFIED FOR IRREGULARLY SAMPLED DIMENSIONS \n"); return (MI_ERROR); } - status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, dataspace_id, fspc_id, H5P_DEFAULT, dimensions[i]->offsets); - if (status < 0) { - return (MI_ERROR); - } - size = strlen(dimensions[i]->name) + 6; - if (size <= MI2_CHAR_LENGTH) { - name = malloc(size); - } else { - name = malloc(MI2_CHAR_LENGTH); + + fspc_id = H5Dget_space(dataset_id); + if (fspc_id < 0) { + return (MI_ERROR); + } + status = H5Dwrite(dataset_id, H5T_NATIVE_DOUBLE, dataspace_id, fspc_id, H5P_DEFAULT, dimensions[i]->offsets); + if (status < 0) { + return (MI_ERROR); + } + size = strlen(dimensions[i]->name) + 6; + if (size <= MI2_CHAR_LENGTH) { + name = malloc(size); + } + else { + name = malloc(MI2_CHAR_LENGTH); + } + strcpy(name, dimensions[i]->name); + strcat(name, "-width"); + dataset_width = H5Dcreate(grp_dimensions_id, name, H5T_NATIVE_DOUBLE, dataspace_id, H5P_DEFAULT); + fspc_id = H5Dget_space(dataset_width); + if (fspc_id < 0) { + return (MI_ERROR); + } + status = H5Dwrite(dataset_width, H5T_NATIVE_DOUBLE, dataspace_id, fspc_id, H5P_DEFAULT, dimensions[i]->widths); + if (status < 0) { + return (MI_ERROR); + } + H5Dclose(dataset_width); } - strcpy(name, dimensions[i]->name); - strcat(name, "-width"); - dataset_width = H5Dcreate(grp_dimensions_id, name, H5T_NATIVE_DOUBLE, dataspace_id, H5P_DEFAULT); - fspc_id = H5Dget_space(dataset_width); - if (fspc_id < 0) { - return (MI_ERROR); - } - status = H5Dwrite(dataset_width, H5T_NATIVE_DOUBLE, dataspace_id, fspc_id, H5P_DEFAULT, dimensions[i]->widths); - if (status < 0) { - return (MI_ERROR); - } - H5Dclose(dataset_width); } /* Create Dimension attribute "attr" */ @@ -341,7 +348,24 @@ H5Sclose(dataspace_id); /* Close attribute. */ H5Aclose(hdf_attr); + + /* Create Dimension attribute "comments" */ + dataspace_id = H5Screate(H5S_SCALAR); + hdf_type = H5Tcopy(H5T_C_S1); + H5Tset_size(hdf_type, MI2_CHAR_LENGTH); + hdf_attr = H5Acreate(dataset_id, "comments", hdf_type, dataspace_id, H5P_DEFAULT); + if (hdf_attr < 0) { + return (MI_ERROR); + } + H5Awrite(hdf_attr, hdf_type, dimensions[i]->comments); + + /* Close attribute dataspace. */ + H5Sclose(dataspace_id); + /* Close attribute. */ + H5Aclose(hdf_attr); + /* !!! DELETE DATA TYPE OBJECT !!! */ + H5Tclose(hdf_type); } /* Create image attribute "dimorder" */