void create_test_file(void) { int r; double start_values[3]= {-6.96, -12.453, -9.48}; double separations[3]= {0.09,0.09,0.09}; midimhandle_t hdim[NDIMS]; mihandle_t hvol; unsigned short *buf = ( unsigned short *) malloc(CX * CY * CZ * sizeof(unsigned short)); int i; long count[NDIMS]; long start[NDIMS]; miboolean_t flag=1; double min = -1.0; double max = 1.0; r = micreate_dimension("zspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &hdim[0]); r = micreate_dimension("yspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &hdim[1]); r = micreate_dimension("xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &hdim[2]); r = miset_dimension_starts(hdim, NDIMS, start_values); r = miset_dimension_separations(hdim, NDIMS, separations); r = micreate_volume("hyperslab-test2.mnc", NDIMS, hdim, MI_TYPE_USHORT, MI_CLASS_REAL, NULL, &hvol); /* set slice scaling flag to true */ r = miset_slice_scaling_flag(hvol, flag); r = micreate_volume_image(hvol); for (i = 0; i < CZ*CY*CX; i++) { buf[i] = (unsigned short) i * 0.01; } start[0] = start[1] = start[2] = 0; count[0] = CZ; count[1] = CY; count[2] = CX; r = miset_voxel_value_hyperslab(hvol, MI_TYPE_USHORT, start, count, buf); /* Set random values to slice min and max for slice scaling*/ start[0] =start[1]=start[2]=0; for (i=0; i < CZ; i++) { start[0] = i; min += 0.1; max += 0.1; r = miset_slice_range(hvol,start, 3, max, min); } r = miclose_volume(hvol); }
int create_2D_image(void) { int r,i; midimhandle_t hdim[NDIMS-1]; mihandle_t hvol; short *buf = (short *)malloc(CX * CY * sizeof(short)); double *offsets = (double *)malloc(CX * sizeof(double)); double start_values[NDIMS-1]={-1.01, -2.02}; miboolean_t flag=0; long count[NDIMS-1]; long start[NDIMS-1]; r = micreate_dimension("xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_NOT_REGULARLY_SAMPLED, CX, &hdim[0]); r = micreate_dimension("yspace", MI_DIMCLASS_USER, MI_DIMATTR_REGULARLY_SAMPLED, CY, &hdim[1]); for(i=0; i < CX; i++) { offsets[i] = (i * i) + 0.1; } r = miset_dimension_offsets(hdim[0], CX, 0, offsets); r = miset_dimension_separation(hdim[1], 0.06); r = miset_dimension_starts(hdim, NDIMS-1, start_values); r = micreate_volume("2D_image.mnc", NDIMS-1 , hdim, MI_TYPE_SHORT, MI_CLASS_REAL, NULL, &hvol); /* set slice scaling flag to true */ r = miset_slice_scaling_flag(hvol, flag); r = micreate_volume_image(hvol); for (i = 0; i < CX*CY; i++) { buf[i] = (short) i * 0.1; } start[0] = start[1] = 0; count[0] = CX; count[1] = CY; r = miset_voxel_value_hyperslab(hvol, MI_TYPE_SHORT, start, count, buf); r = miclose_volume(hvol); return r<0?1:0; }
static void create_test_file ( void ) { midimhandle_t hdim[NDIMS]; mihandle_t hvol; unsigned char *buf = malloc ( CZ * CX * CY * 3 ); int i; misize_t count[NDIMS]; misize_t start[NDIMS]; micreate_dimension ( "zspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &hdim[0] ); micreate_dimension ( "yspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &hdim[1] ); micreate_dimension ( "xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &hdim[2] ); micreate_dimension ( "vector_dimension", MI_DIMCLASS_RECORD, MI_DIMATTR_REGULARLY_SAMPLED, 3, &hdim[3] ); micreate_volume ( "example_vector2.mnc", NDIMS, hdim, MI_TYPE_BYTE, MI_CLASS_INT, NULL, &hvol ); micreate_volume_image ( hvol ); for ( i = 0; i < CZ * CY * CX * 3; i++ ) { buf[i] = ( unsigned char ) i; } start[0] = start[1] = start[2] = start[3] = 0; count[0] = CZ; count[1] = CY; count[2] = CX; count[3] = 3; miset_voxel_value_hyperslab ( hvol, MI_TYPE_BYTE, start, count, buf ); miclose_volume ( hvol ); }
/* ----------------------------- MNI Header ----------------------------------- @NAME : read_3Dvff_file_image @INPUT : hvol minc volume handle filename (vff filename) m2 minc2 variables (struct) vattrs vff attributes to be added to minc2.0 range (data min and max range) @OUTPUT : (nothing) @RETURNS : @DESCRIPTION: Function to read the 3D vff file image @METHOD : @GLOBALS : @CALLS : @CREATED : Jan 2007 (Leila Baghdadi) @MODIFIED : ---------------------------------------------------------------------------- */ void read_3Dvff_file_image(mihandle_t hvol, char *filename, struct mnc_vars m2, struct vff_attrs vattrs, double range[2]) { FILE *fp ; int i,counts,r; void *buffer; int number_of_bits = vattrs.bits/8; unsigned long start[MAX_VFF_DIMS]; /* MINC data starts */ unsigned long count[MAX_VFF_DIMS]; double valid_range[2]; range[0] = DBL_MAX; range[1] = -DBL_MAX; start[1] = 0; start[2] = 0; count[1] = m2.mnc_count[1]; count[2] = m2.mnc_count[0]; counts = m2.mnc_count[0]*m2.mnc_count[1]; /* open file */ fp = fopen(filename , "rb" ); if( fp == NULL ) { exit(EXIT_FAILURE); /* bad open? */ } // Set file position indicator to beginning of image r = fseek(fp,-counts * m2.mnc_count[2] * number_of_bits,SEEK_END); if ( r != 0) { printf(" fseek is reporting a problem!!\n"); exit(EXIT_FAILURE); } // allocate memory for one slice only buffer = malloc( counts * number_of_bits); CHKMEM(buffer); for (i = 0; i < m2.mnc_count[2]; i++) { // set start to the current slice start[0] = i; count[0] = 1; // read data one slice at a time r = fread(buffer,sizeof(char),counts * number_of_bits,fp); if ( r == 0) { printf(" fread is reporting a problem leila.\n"); exit(EXIT_FAILURE); } if (G.little_endian && vattrs.bits==16) { swab(buffer, buffer, counts * number_of_bits); } // write the slice r = miset_voxel_value_hyperslab(hvol, m2.mnc_type, start, count, buffer); if (r != 0) { TESTRPT("can not write data with hperslab function",r); exit(EXIT_FAILURE); } //calculate min and max of slice computeScalarRange(m2.mnc_type,valid_range,counts,buffer); if (valid_range[0] < range[0]) { range[0] = valid_range[0]; } if (valid_range[1] > range[1]) { range[1] = valid_range[1]; } } free(buffer); fclose(fp); }
int main(void) { mihandle_t vol; int r; midimhandle_t dim[NDIMS]; int n; misize_t coords[NDIMS]; misize_t count[NDIMS]; int i,j,k; double offset; unsigned int voxel; /* Write data one voxel at a time. */ for (i = 0; i < NDIMS; i++) { count[i] = 1; } r = micreate_dimension("time", MI_DIMCLASS_TIME, MI_DIMATTR_NOT_REGULARLY_SAMPLED, CT, &dim[0]); if (r < 0) { TESTRPT("failed", r); } for (i = 0; i < CT; i++) { offset = (i * i) + 100.0; r = miset_dimension_offsets(dim[0], 1, i, &offset); if (r < 0) { TESTRPT("failed", r); } } r = micreate_dimension("xspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &dim[1]); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_start(dim[1], XSTART); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_separation(dim[1], XSTEP); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("yspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &dim[2]); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_start(dim[2], YSTART); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_separation(dim[2], YSTEP); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("zspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &dim[3]); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_start(dim[3], ZSTART); if (r < 0) { TESTRPT("failed", r); } r = miset_dimension_separation(dim[3], ZSTEP); if (r < 0) { TESTRPT("failed", r); } r = micreate_volume("tst-dim.mnc", NDIMS, dim, MI_TYPE_UINT, MI_CLASS_REAL, NULL, &vol); if (r < 0) { TESTRPT("failed", r); } r = micreate_volume_image(vol); if (r < 0) { TESTRPT("failed", r); } check_dims(vol, dim); for (i = 0; i < CX; i++) { for (j = 0; j < CY; j++) { for (k = 0; k < CZ; k++) { coords[0] = 0; coords[1] = i; coords[2] = j; coords[3] = k; voxel = (i*10000)+(j*100)+k; r = miset_voxel_value_hyperslab(vol, MI_TYPE_UINT, coords, count, &voxel); if (r < 0) { TESTRPT("Error writing voxel", r); } } } } r = miclose_volume(vol); if (r < 0) { TESTRPT("failed", r); } /***** 03-Aug-2004: Added two tests for bugs reported by Leila */ r = miopen_volume("tst-dim.mnc", MI2_OPEN_RDWR, &vol); if (r < 0) { TESTRPT("failed", r); } r = miget_volume_dimension_count(vol, MI_DIMCLASS_ANY, MI_DIMATTR_REGULARLY_SAMPLED, &n); if (r < 0) { TESTRPT("failed", r); } if (n != NDIMS - 1) { TESTRPT("wrong result", n); } r = miget_volume_dimension_count(vol, MI_DIMCLASS_ANY, MI_DIMATTR_NOT_REGULARLY_SAMPLED, &n); if (r < 0) { TESTRPT("failed", r); } if (n != 1) { TESTRPT("wrong result", n); } r = miclose_volume(vol); if (r < 0) { TESTRPT("failed", r); } /* Test #2 - verify that we don't print anything scary if a user * closes a volume prematurely. */ r = micreate_dimension("xspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &dim[0]); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("yspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &dim[1]); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("zspace",MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &dim[2]); if (r < 0) { TESTRPT("failed", r); } r = micreate_volume("tst-vol.mnc", 3, dim, MI_TYPE_SHORT, MI_CLASS_LABEL, NULL, &vol); if (r < 0) { TESTRPT("failed", r); } r = miclose_volume(vol); if (r < 0) { TESTRPT("failed", r); } /** End of tests added 03-Aug-2004 **/ if (error_cnt != 0) { fprintf(stderr, "%d error%s reported\n", error_cnt, (error_cnt == 1) ? "" : "s"); } else { fprintf(stderr, "No errors\n"); } return (error_cnt); }
int main(int argc, char **argv) { mihandle_t vol; int r; midimhandle_t dim[NDIMS]; mivolumeprops_t props; int n; unsigned long coords[NDIMS]; unsigned long count[NDIMS]; int i,j,k; unsigned int voxel; printf("Creating volume...\n"); /* 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 = micreate_dimension("xspace",MI_DIMCLASS_SPATIAL,MI_DIMATTR_REGULARLY_SAMPLED, CX,&dim[0]); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("yspace",MI_DIMCLASS_SPATIAL,MI_DIMATTR_REGULARLY_SAMPLED, CY, &dim[1]); if (r < 0) { TESTRPT("failed", r); } r = micreate_dimension("zspace",MI_DIMCLASS_SPATIAL,MI_DIMATTR_REGULARLY_SAMPLED, CZ,&dim[2]); if (r < 0) { TESTRPT("failed", r); } r = micreate_volume("tst-multi.mnc", NDIMS, dim, MI_TYPE_UINT, MI_CLASS_REAL,props,&vol); if (r < 0) { TESTRPT("failed", r); } r = miset_volume_valid_range(vol, CX*10000.0 + CY*100 + CZ, 0.0); r = micreate_volume_image(vol); if (r < 0) { TESTRPT("failed", r); } r = miget_volume_dimension_count(vol, MI_DIMCLASS_SPATIAL, MI_DIMATTR_ALL, &n); if (r < 0) { TESTRPT("failed", r); } printf("Writing data...\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 = i*10000 + j*100 + k; r = miset_voxel_value_hyperslab(vol, MI_TYPE_UINT, coords, count, &voxel); if (r < 0) { TESTRPT("Error writing voxel", r); } } } } printf("Selecting half-size image\n"); r = miselect_resolution(vol, 1); if (r < 0) { TESTRPT("miselect_resolution failed", r); } /* OK, now try to read the lower-resolution hyperslab */ coords[0] = 0; coords[1] = 0; coords[2] = 0; count[0] = CX/2; count[1] = CY/2; count[2] = CZ/2; { unsigned int buffer[CX/2][CY/2][CZ/2]; r = miget_voxel_value_hyperslab(vol, MI_TYPE_UINT, coords, count, buffer); if (r < 0) { TESTRPT("failed", r); } } printf("Selecting quarter-size image\n"); r = miselect_resolution(vol, 2); if (r < 0) { TESTRPT("miselect_resolution failed", r); } /* OK, now try to read the lower-resolution hyperslab */ coords[0] = 0; coords[1] = 0; coords[2] = 0; count[0] = CX/4; count[1] = CY/4; count[2] = CZ/4; { unsigned int buffer[CX/4][CY/4][CZ/4]; r = miget_voxel_value_hyperslab(vol, MI_TYPE_UINT, coords, count, buffer); if (r < 0) { TESTRPT("failed", r); } } printf("Return to full resolution.\n"); r = miselect_resolution(vol, 0); /* Back to full resolution */ if (r < 0) { TESTRPT("miselect_resolution failed", r); } printf("Flush any remaining thumbnails.\n"); r = miflush_from_resolution(vol, 3); if (r < 0) { TESTRPT("failed", r); } r = miclose_volume(vol); if (r < 0) { TESTRPT("failed", r); } if (error_cnt != 0) { fprintf(stderr, "%d error%s reported\n", error_cnt, (error_cnt == 1) ? "" : "s"); } else { fprintf(stderr, "No errors\n"); } return (error_cnt); }
int main(void) { mihandle_t hvol; char *name; int result; midimhandle_t hdim[NDIMS]; misize_t coords[NDIMS]; misize_t count[NDIMS]; int i,j,k; struct test { int r; int g; int b; } voxel; /* Write data one voxel at a time. */ for (i = 0; i < NDIMS; i++) { count[i] = 1; } result = micreate_dimension("xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &hdim[0]); result = micreate_dimension("yspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &hdim[1]); result = micreate_dimension("zspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &hdim[2]); result = micreate_volume("tst-rec.mnc", NDIMS, hdim, MI_TYPE_UINT, MI_CLASS_UNIFORM_RECORD, NULL, &hvol); if (result < 0) { TESTRPT("Unable to create test file", result); } result = miset_record_field_name(hvol, 0, "Red"); if (result < 0) { TESTRPT("miset_record_field_name", result); } miset_record_field_name(hvol, 1, "Green"); miset_record_field_name(hvol, 2, "Blue"); miget_record_field_name(hvol, 1, &name); if (strcmp(name, "Green") != 0) { TESTRPT("Unexpected label for value 1", 0); } mifree_name(name); miget_record_field_name(hvol, 0, &name); if (strcmp(name, "Red") != 0) { TESTRPT("Unexpected label for value 0", 0); } mifree_name(name); miget_record_field_name(hvol, 2, &name); if (strcmp(name, "Blue") != 0) { TESTRPT("Unexpected label for value 2", 0); } mifree_name(name); result = micreate_volume_image(hvol); if (result < 0) { TESTRPT("micreate_volume_image failed", result); } 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(hvol, MI_TYPE_UNKNOWN, coords, count, &voxel); if (result < 0) { TESTRPT("Error writing voxel", result); } } } } 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; result = miget_voxel_value_hyperslab(hvol, MI_TYPE_UNKNOWN, coords, count, &voxel); if (result < 0) { TESTRPT("Error reading voxel", result); } if (voxel.r != i || voxel.g != j || voxel.b != k) { TESTRPT("Data mismatch", 0); } } } } miclose_volume(hvol); if (error_cnt != 0) { fprintf(stderr, "%d error%s reported\n", error_cnt, (error_cnt == 1) ? "" : "s"); } else { fprintf(stderr, "No errors\n"); } return (error_cnt); }
int create_4D_image(void) { int r; double start_values[NDIMS+1]={-6.96, -12.453, -9.48, 20.002}; double separations[NDIMS+1]={0.09,0.09,0.09, 1}; midimhandle_t hdim[NDIMS+1]; mihandle_t hvol; unsigned char *buf = (unsigned char *) malloc(CX * CU * CZ * CY * sizeof(unsigned char)); int i,j; long count[NDIMS+1]; long start[NDIMS+1]; miboolean_t flag=1; double min = -1.0; double max = 1.0; r = micreate_dimension("xspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CX, &hdim[0]); r = micreate_dimension("user", MI_DIMCLASS_USER, MI_DIMATTR_REGULARLY_SAMPLED, CU, &hdim[1]); r = micreate_dimension("zspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CZ, &hdim[2]); r = micreate_dimension("yspace", MI_DIMCLASS_SPATIAL, MI_DIMATTR_REGULARLY_SAMPLED, CY, &hdim[3]); r = miset_dimension_starts(hdim, NDIMS+1, start_values); r = miset_dimension_separations(hdim, NDIMS+1, separations); r = micreate_volume("4D_image.mnc", NDIMS+1, hdim, MI_TYPE_UBYTE, MI_CLASS_REAL, NULL, &hvol); /* set slice scaling flag to true */ r = miset_slice_scaling_flag(hvol, flag); r = micreate_volume_image(hvol); for (i = 0; i < CX*CU*CZ*CY; i++) { buf[i] = (unsigned char) i; } start[0] = start[1] = start[2] = start[3] = 0; count[0] = CX; count[1] = CU; count[2] = CZ; count[3] = CY; r = miset_voxel_value_hyperslab(hvol, MI_TYPE_UBYTE, start, count, buf); /* Set random values to slice min and max for slice scaling*/ start[0] =start[1]=start[2]=start[3]=0; for (i=0; i < CX; i++) { start[0] = i; for ( j=0; j < CU; j++) { start[1] = j; min += -0.1; max += 0.1; r = miset_slice_range(hvol,start,NDIMS+1 , max, min); } } r = miclose_volume(hvol); return r<0?1:0; }