Mercurial > hg > minc-tools
changeset 1886:f24d7e5d2b85
Fix allocation of volume structure
author | bert <bert> |
---|---|
date | Wed, 27 Oct 2004 19:31:38 +0000 |
parents | 63604aa11164 |
children | 22f2cfa11696 |
files | libsrc2/volume.c |
diffstat | 1 files changed, 29 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/libsrc2/volume.c +++ b/libsrc2/volume.c @@ -190,7 +190,33 @@ } } } - + +/** Create and initialize a MINC 2.0 volume structure. + */ +static mihandle_t +mialloc_volume_handle(void) +{ + mihandle_t handle = (mihandle_t) malloc(sizeof(struct mivolume)); + + if (handle != NULL) { + /* Clear the memory by default. */ + memset(handle, 0, sizeof(struct mivolume)); + + /* Set the defaults for the data structure */ + handle->scale_min = 0.0; + handle->scale_max = 1.0; + handle->image_id = -1; + handle->imax_id = -1; + handle->imin_id = -1; + handle->plist_id = -1; + handle->has_slice_scaling = FALSE; + handle->is_dirty = FALSE; + handle->dim_indices = NULL; + handle->selected_resolution = 0; + } + return (handle); +} + /** Create a volume with the specified name, dimensions, type, class, volume properties and retrieve the volume handle. \ingroup mi2Vol @@ -238,21 +264,14 @@ /* Allocate space for the volume handle */ - handle = (mihandle_t)malloc(sizeof(struct mivolume)); + handle = mialloc_volume_handle(); if (handle == NULL) { return (MI_ERROR); } /* Initialize some of the variables associated with the volume handle. */ - handle->is_dirty = FALSE; /* No writes yet. */ handle->mode = MI2_OPEN_RDWR; - handle->has_slice_scaling = FALSE; - handle->scale_min = 0.0; - handle->scale_max = 1.0; handle->number_of_dims = number_of_dimensions; - handle->image_id = -1; - handle->imax_id = -1; - handle->imin_id = -1; /* convert minc type to hdf type */ @@ -620,12 +639,6 @@ miset_volume_world_indices(handle); - /* Set the apparent order of dimensions to NULL - until user defines them. Switch is used to - avoid errors. - */ - handle->dim_indices = NULL; - /* Verify the volume type. */ switch (volume_type) { @@ -1018,14 +1031,13 @@ return (MI_ERROR); } /* Allocate space for the volume handle */ - handle = (mihandle_t) malloc(sizeof(struct mivolume)); + handle = mialloc_volume_handle(); if (handle == NULL) { return (MI_ERROR); } /* Set some varibales associated with the volume handle */ handle->hdf_id = file_id; handle->mode = mode; - handle->selected_resolution = 0; /* Get the volume class. */ @@ -1102,9 +1114,6 @@ /* Calculate the inverse transform */ miinvert_transform(handle->v2w_transform, handle->w2v_transform); - /* Initialize the selected resolution. */ - handle->selected_resolution = 0; - /* Open the image dataset */ handle->image_id = H5Dopen(file_id, "/minc-2.0/image/0/image"); if (handle->image_id < 0) {