Beispiel #1
0
int write_minc(char *filename, float *image, image_metadata *meta,VIO_BOOL binary_mask){
  VIO_Volume volume;
  int i,j,k,index;
  float min=FLT_MAX,max=FLT_MIN;
  VIO_Real dummy[3];

  if(binary_mask)
  {
    volume = create_volume(3,NULL,NC_BYTE,FALSE,0.0,1.0);
    printf("Writing a binary volume...\n");
  }
  else 
    volume = create_volume(3,NULL,NC_FLOAT,FALSE,FLT_MIN,FLT_MAX);
  
  if(!volume)
    return STATUS_ERR;
  
  if(!binary_mask)
  {
    for (i=0;i<meta->length[0];i++){
      for (j=0;j<meta->length[1];j++){
        for (k=0;k<meta->length[2];k++){	  
          index=i*meta->length[2]*meta->length[1] + j*meta->length[2] + k;
          min=MIN(min,image[index]);
          max=MAX(max,image[index]);
        }
      }
    }
    set_volume_real_range(volume,min,max);
  } else {
    set_volume_real_range(volume,0.0,1.0);
  }
  
  set_volume_sizes(volume,meta->length);
  dummy[0]=meta->start[0];
  dummy[1]=meta->start[1];
  dummy[2]=meta->start[2];
  set_volume_starts(volume,dummy);
  dummy[0]=meta->step[0];
  dummy[1]=meta->step[1];
  dummy[2]=meta->step[2];
  set_volume_separations(volume,dummy);

  alloc_volume_data(volume);
    
  get_volume(image, volume, meta->length);

  if(!binary_mask)
    output_volume( filename, NC_FLOAT,FALSE,min, max,volume,meta->history,(minc_output_options *)NULL);
  else
    output_volume( filename, NC_BYTE,FALSE,0, 1.0,volume,meta->history,(minc_output_options *)NULL);
    
  delete_volume(volume);

  return STATUS_OK;
}
Beispiel #2
0
/* create a new disk volume */
NTSTATUS add_volume( const char *udi, const char *device, const char *mount_point,
                     enum device_type type, const GUID *guid )
{
    struct volume *volume;
    NTSTATUS status = STATUS_SUCCESS;

    TRACE( "adding %s device %s mount %s type %u uuid %s\n", debugstr_a(udi),
           debugstr_a(device), debugstr_a(mount_point), type, debugstr_guid(guid) );

    EnterCriticalSection( &device_section );
    LIST_FOR_EACH_ENTRY( volume, &volumes_list, struct volume, entry )
        if (volume->udi && !strcmp( udi, volume->udi ))
        {
            grab_volume( volume );
            goto found;
        }

    /* udi not found, search for a non-dynamic volume */
    if ((volume = find_matching_volume( udi, device, mount_point, type ))) set_volume_udi( volume, udi );
    else status = create_volume( udi, type, &volume );

found:
    if (!status) status = set_volume_info( volume, NULL, device, mount_point, type, guid );
    if (volume) release_volume( volume );
    LeaveCriticalSection( &device_section );
    return status;
}
Beispiel #3
0
static partition_result_t
create_udfs_vnodes(partition_private_t *partition_privatep)
{
	partition_result_t	partition_result;

	debug(2, "entering create_udfs_vnodes()\n");

	partition_result = PARTITION_SUCCESS;
	partition_result = create_pathnames(partition_privatep);
	if (partition_result == PARTITION_SUCCESS) {
		partition_result = create_volume(partition_privatep);
	}
	if (partition_result == PARTITION_SUCCESS) {
		partition_result = create_vvnodes(partition_privatep);
	}
	if (partition_result == PARTITION_SUCCESS) {
		correct_pathnames(partition_privatep);
	}
	if ((partition_result == PARTITION_SUCCESS) &&
		(partition_privatep->location == TOP)) {
		partition_result = create_symlink(partition_privatep);
	}
	debug(2, "leaving create_udfs_vnodes(), result code = %s\n",
		partition_result_codes[partition_result]);

	return (partition_result);
}
Beispiel #4
0
/* create the disk device for a given volume */
static NTSTATUS create_dos_device( struct volume *volume, const char *udi, int letter,
                                   enum device_type type, struct dos_drive **drive_ret )
{
    struct dos_drive *drive;
    NTSTATUS status;

    if (!(drive = RtlAllocateHeap( GetProcessHeap(), 0, sizeof(*drive) ))) return STATUS_NO_MEMORY;
    drive->drive = letter;
    drive->mount = NULL;

    if (volume)
    {
        if (udi) set_volume_udi( volume, udi );
        drive->volume = grab_volume( volume );
        status = STATUS_SUCCESS;
    }
    else status = create_volume( udi, type, &drive->volume );

    if (status == STATUS_SUCCESS)
    {
        list_add_tail( &drives_list, &drive->entry );
        *drive_ret = drive;
    }
    else RtlFreeHeap( GetProcessHeap(), 0, drive );

    return status;
}
Beispiel #5
0
int main(int argc, char const *argv[]) {
    int i,
        s,
        fc,
        fs,
        res;

    const char * n;

    /* Checking arguments */
    s = fc = fs = -1;
    n = NULL;

    if (argc < 5) {
        usage(argv[0]);
    }

    for (i = 1; i < argc; i++) {
        if (!strcmp("-s", argv[i])) {
            s = strtol(argv[++i], NULL, 10);
        } else if (!strcmp("-fc", argv[i])) {
            fc = strtol(argv[++i], NULL, 10);
        } else if (!strcmp("-fs", argv[i])) {
            fs = strtol(argv[++i], NULL, 10);
        } else if (!strcmp("-n", argv[i])) {
            n = argv[++i];
        } else {
            usage(argv[0]);
        }
    }

    if (s == -1 || fc == -1) {
        usage(argv[0]);
    }

    /* Checking for idiotic input */
    if (fc == 0 && fs == 0) {
        fprintf(stderr, "Wrong input: cannot write on the Master Boot Record, use other values than (0, 0).\n");
    }

    /* Default values */
    if (fs == -1) {
        fs = 0;
    }

    /* Start modifying the mbr */
    read_mbr();

    /* Creating a new volume */
    res = create_volume(s, fc, fs, n);

    display_all_volume_name();

    /* End of all modifications, saving them */
    save_mbr();

    return res;
}
Beispiel #6
0
/* Create a RAID-5 volume. */
void
gvinum_raid5(int argc, char **argv)
{

	if (argc < 2) {
		warnx("usage:\traid5 [-fv] [-s stripesize] [-n name] drives\n");
		return;
	}
	create_volume(argc, argv, "raid5");
}
Beispiel #7
0
/* Create a mirrored volume. */
void
gvinum_mirror(int argc, char **argv)
{

	if (argc < 2) {
		warnx("usage\tmirror [-fsv] [-n name] drives\n");
		return;
	}
	create_volume(argc, argv, "mirror");
}
Beispiel #8
0
/* Create a concatenated volume. */
void
gvinum_concat(int argc, char **argv)
{

	if (argc < 2) {
		warnx("usage:\tconcat [-fv] [-n name] drives\n");
		return;
	}
	create_volume(argc, argv, "concat");
}
Beispiel #9
0
/* Create a striped volume. */
void
gvinum_stripe(int argc, char **argv)
{

	if (argc < 2) {
		warnx("usage:\tstripe [-fv] [-n name] drives\n");
		return;
	}
	create_volume(argc, argv, "stripe");
}
Beispiel #10
0
int main(int argc, char** argv) {
  int i,l;
  unsigned int cylinder, sector, size;
  enum vol_type_e type;
  if (argc != 5) {
    printf("Usage:\n\tcreate_vol <cylinder (0 to 15)> <sector (0 to 15)> <size> <type: ANNEXE|BASE|OTHER>\n");
    exit(EXIT_FAILURE);
  }

  // Récupération des arguments
  cylinder = atoi(argv[1]);
  sector = atoi(argv[2]);
  size = atoi(argv[3]);
  if (!strcmp(argv[4],"BASE")) {
    type = BASE;
  }
  else if (!strcmp(argv[4],"ANNEXE")) {
    type = ANNEXE;
  }
  else if (!strcmp(argv[4],"OTHER")) {
    type = OTHER;
  }
  else {
    fprintf(stderr, "Type inconnu (ANNEXE|BASE|OTHER)\n");
    exit(EXIT_FAILURE);
  }
  // Initialisation
  assert(init_hardware(HARDWARE_INI));
  for(i = 0; i < 15; i++)
    IRQVECTOR[i] = empty_it;

  l = create_volume(cylinder, sector, size, type);
  if (l < 0) {
    exit(EXIT_FAILURE);
  }

  return EXIT_SUCCESS;
}
Beispiel #11
0
VIOAPI  VIO_Status  start_volume_input(
    VIO_STR             filename,
    int                 n_dimensions,
    VIO_STR             dim_names[],
    nc_type             volume_nc_data_type,
    VIO_BOOL            volume_signed_flag,
    VIO_Real            volume_voxel_min,
    VIO_Real            volume_voxel_max,
    VIO_BOOL            create_volume_flag,
    VIO_Volume          *volume,
    minc_input_options  *options,
    volume_input_struct *input_info )
{
    VIO_Status          status;
    int                 d;
    VIO_STR             expanded_filename;
    minc_input_options  default_options;
    status = VIO_OK;

    if( options == (minc_input_options *) NULL )
    {
        set_default_minc_input_options( &default_options );
        options = &default_options;
    }
    
    if( create_volume_flag || *volume == (VIO_Volume) NULL )
    {
        if( n_dimensions < 1 || n_dimensions > VIO_MAX_DIMENSIONS )
        {
            n_dimensions = VIO_MAX_DIMENSIONS;
        }

        if( dim_names == (VIO_STR *) NULL )
            dim_names = get_default_dim_names( n_dimensions );

        *volume = create_volume( n_dimensions, dim_names, volume_nc_data_type,
                                 volume_signed_flag,
                                 volume_voxel_min, volume_voxel_max );
    }
    else if( n_dimensions != get_volume_n_dimensions( *volume ) &&
             volume_is_alloced( *volume ) )
    {
        free_volume_data( *volume );
    }

    expanded_filename = expand_filename( filename );

    if (filename_extension_matches( expanded_filename, FREE_ENDING ) ) {
        input_info->file_format = FREE_FORMAT;
    }
#ifdef LIBMINC_NIFTI_SUPPORT
    else if (filename_extension_matches( expanded_filename, "mgh" ) ||
             filename_extension_matches( expanded_filename, "mgz" )
             ) {
        input_info->file_format = MGH_FORMAT; /* FreeSurfer */
    }
    else if (filename_extension_matches( expanded_filename, "nii" ) ||
             filename_extension_matches( expanded_filename, "hdr" )) {
        input_info->file_format = NII_FORMAT; /* NIfTI-1 */
    }
    else if (filename_extension_matches( expanded_filename, "nhdr" ) ||
             filename_extension_matches( expanded_filename, "nrrd" )) {
        input_info->file_format = NRRD_FORMAT; /* NRRD */
    }
#endif /*LIBMINC_NIFTI_SUPPORT*/
    else {

#if defined(HAVE_MINC1) && defined(HAVE_MINC2)
      if(options->prefer_minc2_api) {
#endif

#if defined(HAVE_MINC2)
        input_info->file_format = MNC2_FORMAT;
#endif
        
#if defined(HAVE_MINC1) && defined(HAVE_MINC2)
      } else {
#endif
#ifdef HAVE_MINC1
        input_info->file_format = MNC_FORMAT;
#endif
#if defined(HAVE_MINC1) && defined(HAVE_MINC2)
      } 
#endif
    }
    switch( input_info->file_format )
    {
#ifdef HAVE_MINC1
    case  MNC_FORMAT:
        if( !file_exists( expanded_filename ) )
        {
            file_exists_as_compressed( expanded_filename,
                                              &expanded_filename );
        }

        input_info->minc_file = initialize_minc_input( expanded_filename,
                                                       *volume, options );
        if( input_info->minc_file == (Minc_file) NULL )
            status = VIO_ERROR;
        else
        {
            for_less( d, 0, VIO_MAX_DIMENSIONS )
                input_info->axis_index_from_file[d] = d;
        }

        break;
#endif /*HAVE_MINC1*/

#ifdef HAVE_MINC2
      case  MNC2_FORMAT:
        input_info->minc_file = initialize_minc2_input( expanded_filename,
                                                       *volume, options );
        if( input_info->minc_file == (Minc_file) NULL )
            status = VIO_ERROR;
        else
        {
            for_less( d, 0, VIO_MAX_DIMENSIONS )
            input_info->axis_index_from_file[d] = d;
        }
        break;
#endif /*HAVE_MINC2*/
    case  FREE_FORMAT:
        status = initialize_free_format_input( expanded_filename,
                                               *volume, input_info );
        break;
        
#ifdef LIBMINC_NIFTI_SUPPORT
      case MGH_FORMAT:
        status = initialize_mgh_format_input( expanded_filename,
                                              *volume, input_info );
        break;
      case NII_FORMAT:
        status = initialize_nifti_format_input( expanded_filename,
                                                *volume, input_info );
        break;
      case NRRD_FORMAT:
        status = initialize_nrrd_format_input( expanded_filename,
                                               *volume, input_info );
        break;
#endif /*LIBMINC_NIFTI_SUPPORT*/
      default:
        /*Unsupported file format*/
        status = VIO_ERROR;
        break;
    }

    if( status != VIO_OK && create_volume_flag )
        delete_volume( *volume );

    delete_string( expanded_filename );

    return( status );
}
int main(int argc, char *argv[]) {
  int v1, v2, v3, v4;
  int sizes[VIO_MAX_DIMENSIONS], grid_sizes[4];
  int n_concat_transforms, i;
  VIO_STR arg_string;
  char *input_volume_name;
  char *input_xfm;
  VIO_STR outfile;
  VIO_Real w1, w2, w3;
  VIO_Real nw1, nw2, nw3;
  VIO_Real original[3], transformed[3];
  VIO_Real value;
  VIO_Real cosine[3];
  VIO_Real original_separation[3], grid_separation[4];
  VIO_Real original_starts[3], grid_starts[4];
  VIO_Volume eval_volume, new_grid;
  VIO_General_transform xfm, *voxel_to_world;
  VIO_STR *dimnames, dimnames_grid[4];
  VIO_progress_struct progress;
  
  arg_string = time_stamp(argc, argv);

  /* Check arguments   */
  if(ParseArgv(&argc, argv, argTable, 0) || (argc != 4)){
    fprintf(stderr, "\nUsage: %s [options] input.mnc input.xfm output_grid.mnc\n", argv[0]);
    fprintf(stderr, "       %s -help\n\n", argv[0]);
    exit(EXIT_FAILURE);
  }

  input_volume_name = argv[1];
  input_xfm = argv[2];
  outfile = argv[3];

  /* check for the infile and outfile */
  if(access(input_volume_name, F_OK) != 0){
    fprintf(stderr, "%s: Couldn't find %s\n\n", argv[0], input_volume_name);
    exit(EXIT_FAILURE);
  }
  if(access(input_xfm, F_OK) != 0) {
    fprintf(stderr, "%s: Couldn't find %s\n\n", argv[0], input_xfm);
    exit(EXIT_FAILURE);
  }
  if(access(outfile, F_OK) == 0 && !clobber){
    fprintf(stderr, "%s: %s exists! (use -clobber to overwrite)\n\n", argv[0], outfile);
    exit(EXIT_FAILURE);
  }

  /*--- input the volume */
  /*
  if( input_volume( input_volume_name, 3, NULL, MI_ORIGINAL_TYPE, 
                    FALSE, 0.0, 0.0, TRUE, &eval_volume,(minc_input_options *) NULL ) != OK )
    return( 1 );
  */

  if (input_volume_header_only( input_volume_name, 3, NULL, &eval_volume,(minc_input_options *) NULL ) != VIO_OK ) { 
    return( 1 );
  }

  /* get information about the volume */
  get_volume_sizes( eval_volume, sizes );
  voxel_to_world = get_voxel_to_world_transform(eval_volume);
  dimnames = get_volume_dimension_names(eval_volume);
  get_volume_separations(eval_volume, original_separation);
  get_volume_starts(eval_volume, original_starts);

  /* create new 4D volume, last three dims same as other volume,
     first dimension being the vector dimension. */
  for(i=1; i < 4; i++) {
    dimnames_grid[i] = dimnames[i-1];
    grid_separation[i] = original_separation[i-1];
    grid_sizes[i] = sizes[i-1];
    grid_starts[i] = original_starts[i-1];
  }
  dimnames_grid[0] = "vector_dimension";
  grid_sizes[0] = 3;
  grid_separation[0] = 1;
  grid_starts[0] = 0;

  new_grid = create_volume(4, dimnames_grid, NC_SHORT, FALSE, 0.0, 0.0);

  //set_voxel_to_world_transform(new_grid, voxel_to_world);
  // initialize the new grid volume, otherwise the output will be
  // garbage...
  set_volume_real_range(new_grid, -100, 100);
  set_volume_sizes(new_grid, grid_sizes);

  set_volume_separations(new_grid, grid_separation);
  set_volume_starts(new_grid, grid_starts);
  /*
  for (i=0; i < 3; i++) {
    get_volume_direction_cosine(eval_volume, i, cosine);
    set_volume_direction_cosine(new_grid, i+1, cosine);
  }
  */

  alloc_volume_data(new_grid);

  /* get the transforms */
  if( input_transform_file( input_xfm, &xfm ) != VIO_OK )
    return( 1 );

  /* see how many transforms will be applied */
  n_concat_transforms = get_n_concated_transforms( &xfm );
  printf("Number of transforms to be applied: %d\n", n_concat_transforms);

  initialize_progress_report(&progress, FALSE, sizes[0], "Processing");


  /* evaluate the transform at every voxel, keep the displacement
     in the three cardinal directions */
  for( v1 = 0;  v1 < sizes[0];  ++v1 ) {
    update_progress_report(&progress, v1 + 1);
    for( v2 = 0;  v2 < sizes[1];  ++v2 ) {
      for( v3 = 0;  v3 < sizes[2];  ++v3 ) {
        convert_3D_voxel_to_world(eval_volume, 
                                  v1, v2, v3, 
                                  &original[0], &original[1], &original[2]);
        general_transform_point(&xfm, 
                                original[0], original[1], original[2], 
                                &transformed[0], &transformed[1], &transformed[2]);
        for(i=0; i < 3; i++) {
          value = transformed[i] - original[i];
          set_volume_real_value(new_grid, i, v1, v2, v3, 0, value);
        }
      }
    }
  }

  terminate_progress_report(&progress);

  printf("Outputting volume.\n");

  output_volume(outfile, MI_ORIGINAL_TYPE, TRUE, 0.0, 0.0, new_grid, arg_string, NULL);

  return(0);

}
static void append_new_default_deformation_field(Arg_Data *globals)
{

  VIO_Volume
    new_field;
  VIO_Real
    zero,
    st[VIO_MAX_DIMENSIONS],
    wst[VIO_MAX_DIMENSIONS],
    step[VIO_MAX_DIMENSIONS],
    XYZstart[ VIO_MAX_DIMENSIONS ],
    XYZstep[ VIO_MAX_DIMENSIONS ],
    voxel[VIO_MAX_DIMENSIONS],
    point[VIO_N_DIMENSIONS],
    dir[3][3];

  int
    index[VIO_MAX_DIMENSIONS],
    xyzv[VIO_MAX_DIMENSIONS],
    i,
    count[VIO_MAX_DIMENSIONS],
    XYZcount[VIO_MAX_DIMENSIONS],
    count_extended[VIO_MAX_DIMENSIONS];

  VIO_General_transform
    *grid_trans;

   VectorR
    XYZdirections[ VIO_MAX_DIMENSIONS ];

  /* build a vector volume to store the Grid VIO_Transform */

   /*  ALLOC(new_field,1); not needed since create volume allocs it
       internally and returns a pointer*/

  if (globals->flags.debug) { print ("In append_new_default_deformation_field...\n"); }

  new_field = create_volume(4, dim_name_vector_vol, NC_DOUBLE, TRUE, 0.0, 0.0);

  get_volume_XYZV_indices(new_field, xyzv);

                                /* get the global voxel count and voxel size */
  for(i=0; i<VIO_N_DIMENSIONS; i++) {
    count[xyzv[i]] = globals->count[i];
    count_extended[xyzv[i]] = count[xyzv[i]];
    step[xyzv[i]]  = globals->step[i];
  }
                                /* add info for the vector dimension */
  count[xyzv[VIO_Z+1]] = 3;
  count_extended[xyzv[VIO_Z+1]] = 3;
  step[xyzv[VIO_Z+1]] = 0.0;


  set_volume_sizes(       new_field, count);
  set_volume_separations( new_field, step);
  /*
     set_volume_voxel_range( new_field, -MY_MAX_VOX, MY_MAX_VOX);
     set_volume_real_range(  new_field, -1.0*globals->trans_info.max_def_magnitude, globals->trans_info.max_def_magnitude); no longer needed, now using floats */


  for(i=0; i<VIO_N_DIMENSIONS; i++) {
    dir[VIO_X][i]=globals->directions[VIO_X].coords[i];
    dir[VIO_Y][i]=globals->directions[VIO_Y].coords[i];
    dir[VIO_Z][i]=globals->directions[VIO_Z].coords[i];

  }


  set_volume_direction_cosine(new_field,xyzv[VIO_X],dir[VIO_X]);
  set_volume_direction_cosine(new_field,xyzv[VIO_Y],dir[VIO_Y]);
  set_volume_direction_cosine(new_field,xyzv[VIO_Z],dir[VIO_Z]);


  for(i=0; i<VIO_MAX_DIMENSIONS; i++)  /* set the voxel origin, used in the vol def */
    voxel[i] = 0.0;

  set_volume_translation( new_field, voxel, globals->start);



  if (globals->flags.debug) {
    print("in append new def, the start is: %8.3f %8.3f %8.3f\n", globals->start[VIO_X], globals->start[VIO_Y], globals->start[VIO_Z]);
  }

                   /* now pad the volume along the spatial axis
                      to ensure good coverage of the data space
                      with the deformation field */

  for(i=0; i<VIO_N_DIMENSIONS; i++) {
    if (globals->count[i]>1) {
      voxel[xyzv[i]] = -2.5;
      count_extended[xyzv[i]] = globals->count[i]+5;
    }
    else {
      voxel[xyzv[i]] = 0.0;
      count_extended[xyzv[i]] = 1;
    }
  }

  if (globals->flags.debug) {
    print("in append_new_default_deformation_field:\n\tcount_extended= %d %d %d %d\n",
           count_extended[0],count_extended[1],count_extended[2],count_extended[3]);
  }

  set_volume_sizes(new_field, count_extended);
  for(i=0; i<VIO_MAX_DIMENSIONS; i++) count[i] = count_extended[i];

              /* reset the first voxel position with the new origin */
  convert_voxel_to_world(new_field, voxel,
                         &(point[VIO_X]), &(point[VIO_Y]), &(point[VIO_Z]));
  for(i=0; i<VIO_MAX_DIMENSIONS; i++) voxel[i] = 0;

  set_volume_translation(new_field, voxel, point);


  if (globals->flags.debug) {
    print (" point: %8.3f %8.3f %8.3f \n", point[VIO_X], point[VIO_Y], point[VIO_Z]);

    get_volume_starts(new_field, st);
    print (" start: %8.3f %8.3f %8.3f \n", st[xyzv[VIO_X]], st[xyzv[VIO_Y]], st[xyzv[VIO_Z]]);

    voxel[0] = 0;
    voxel[1] = 0;
    voxel[2] = 0;
    get_volume_translation(new_field, voxel, wst);
    print (" wstrt: %8.3f %8.3f %8.3f \n", wst[VIO_X], wst[VIO_Y], wst[VIO_Z]);
    print (" voxel: %8.3f %8.3f %8.3f \n", voxel[xyzv[VIO_X]], voxel[xyzv[VIO_Y]], voxel[xyzv[VIO_Z]]);


    for(i=0; i<3; i++) {
      get_volume_direction_cosine(new_field,xyzv[i], wst);
      print (" dirs: %8.3f %8.3f %8.3f \n", wst[VIO_X], wst[VIO_Y], wst[VIO_Z]);
    }



  }


              /* allocate space for the deformation field data */
  alloc_volume_data(new_field);

              /* Initilize the field to zero deformation */

  /* zero = CONVERT_VALUE_TO_VOXEL(new_field, 0.0); not needed, defs are now doubles */

  for(index[0]=0; index[0]<count[0]; index[0]++)
    for(index[1]=0; index[1]<count[1]; index[1]++)
      for(index[2]=0; index[2]<count[2]; index[2]++)
        for(index[3]=0; index[3]<count[3]; index[3]++)
          {
            SET_VOXEL(new_field, index[0],index[1],index[2],index[3],0, 0.0);  /* was set to 'zero', but now as a double,can be set to 0.0 */
          }

              /* build the new GRID_TRANSFORM */

  ALLOC(grid_trans, 1);

  create_grid_transform(grid_trans, new_field, NULL);

              /* append the deforamation to the current transformation */
  concat_general_transforms(globals->trans_info.transformation, grid_trans,
                            globals->trans_info.transformation);

  delete_volume(new_field);
  delete_general_transform(grid_trans);




}
Beispiel #14
0
int
main(int argc, char *argv[])
{
    struct tcplay_opts *opts;
    int ch, error;
    int info_vol = 0, map_vol = 0,
        unmap_vol = 0, info_map = 0,
        create_vol = 0, modify_vol = 0;

    if ((error = tc_play_init()) != 0) {
        fprintf(stderr, "Initialization failed, exiting.");
        exit(EXIT_FAILURE);
    }

    atexit(check_and_purge_safe_mem);
    signal(SIGUSR1, sig_handler);
    signal(SIGINFO, sig_handler);

    if ((opts = opts_init()) == NULL) {
        fprintf(stderr, "Initialization failed (opts), exiting.");
        exit(EXIT_FAILURE);
    }

    opts->interactive = 1;

    while ((ch = getopt_long(argc, argv, "a:b:cd:ef:ghij:k:m:s:tu:vwx:y:zC:",
        longopts, NULL)) != -1) {
        switch(ch) {
        case 'a':
            if (opts->prf_algo != NULL)
                usage();
            if ((opts->prf_algo = check_prf_algo(optarg, 0)) == NULL) {
                if (strcmp(optarg, "help") == 0)
                    exit(EXIT_SUCCESS);
                else
                    usage();
                /* NOT REACHED */
            }
            break;
        case 'b':
            if (opts->cipher_chain != NULL)
                usage();
            if ((opts->cipher_chain = check_cipher_chain(optarg, 0)) == NULL) {
                if (strcmp(optarg, "help") == 0)
                    exit(EXIT_SUCCESS);
                else
                    usage();
                /* NOT REACHED */
            }
            break;
        case 'c':
            create_vol = 1;
            break;
        case 'C':
            opts->custom_iterations = atoi(optarg);
            break;
        case 'd':
            _set_str_opt(dev);
            break;
        case 'e':
            opts->protect_hidden = 1;
            break;
        case 'f':
            if ((error = opts_add_keyfile_hidden(opts, optarg)) != 0) {
                fprintf(stderr, "Could not add keyfile: %s\n", optarg);
                exit(EXIT_FAILURE);
            }
            break;
        case 'g':
            opts->hidden = 1;
            break;
        case 'i':
            info_vol = 1;
            break;
        case 'j':
            info_map = 1;
            _set_str_opt(map_name);
            break;
        case 'k':
            if ((error = opts_add_keyfile(opts, optarg)) != 0) {
                fprintf(stderr, "Could not add keyfile: %s\n", optarg);
                exit(EXIT_FAILURE);
            }
            break;
        case 'm':
            map_vol = 1;
            _set_str_opt(map_name);
            break;
        case 's':
            opts->flags |= TC_FLAG_SYS;
            _set_str_opt(sys_dev);
            break;
        case 't':
            opts->flags |= TC_FLAG_ALLOW_TRIM;
            break;
        case 'u':
            unmap_vol = 1;
            _set_str_opt(map_name);
            break;
        case 'v':
            printf("tcplay v%d.%d\n", MAJ_VER, MIN_VER);
            exit(EXIT_SUCCESS);
            /* NOT REACHED */
        case 'w':
            fprintf(stderr, "WARNING: Using urandom as source of "
                "entropy for key material is a really bad idea.\n");
            opts->weak_keys_and_salt = 1;
            break;
        case 'x':
            if (opts->h_prf_algo != NULL)
                usage();
            if ((opts->h_prf_algo = check_prf_algo(optarg, 0)) == NULL) {
                if (strcmp(optarg, "help") == 0)
                    exit(EXIT_SUCCESS);
                else
                    usage();
                /* NOT REACHED */
            }
            break;
        case 'y':
            if (opts->h_cipher_chain != NULL)
                usage();
            if ((opts->h_cipher_chain = check_cipher_chain(optarg, 0)) == NULL) {
                if (strcmp(optarg, "help") == 0)
                    exit(EXIT_SUCCESS);
                else
                    usage();
                /* NOT REACHED */
            }
            break;
        case 'z':
            opts->secure_erase = 0;
            break;
        case FLAG_LONG_FDE:
            opts->flags |= TC_FLAG_FDE;
            break;
        case FLAG_LONG_USE_BACKUP:
            opts->flags |= TC_FLAG_BACKUP;
            break;
        case FLAG_LONG_USE_HDR_FILE:
            opts->flags |= TC_FLAG_HDR_FROM_FILE;
            _set_str_opt(hdr_file_in);
            break;
        case FLAG_LONG_USE_HHDR_FILE:
            opts->flags |= TC_FLAG_H_HDR_FROM_FILE;
            _set_str_opt(h_hdr_file_in);
            break;
        case FLAG_LONG_MOD:
            modify_vol = 1;
            break;
        case FLAG_LONG_MOD_KF:
            if ((error = opts_add_keyfile_new(opts, optarg)) != 0) {
                fprintf(stderr, "Could not add keyfile: %s\n", optarg);
                exit(EXIT_FAILURE);
            }
            break;
        case FLAG_LONG_MOD_PRF:
            if (opts->new_prf_algo != NULL)
                usage();
            if ((opts->new_prf_algo = check_prf_algo(optarg, 0)) == NULL) {
                if (strcmp(optarg, "help") == 0)
                    exit(EXIT_SUCCESS);
                else
                    usage();
                /* NOT REACHED */
            }
            break;
        case FLAG_LONG_MOD_NONE:
            opts->new_prf_algo = NULL;
            opts->flags |= TC_FLAG_ONLY_RESTORE;
            opts->flags |= TC_FLAG_BACKUP;
            break;
        case FLAG_LONG_MOD_TO_FILE:
            opts->flags |= TC_FLAG_SAVE_TO_FILE;
            _set_str_opt(hdr_file_out);
            break;
        case FLAG_LONG_NO_RETRIES:
            opts->retries = 1;
            break;
        case 'h':
        case '?':
        default:
            usage();
            /* NOT REACHED */
        }
    }

    argc -= optind;
    argv += optind;

    /* Check arguments */
    if (!(((map_vol || info_vol || create_vol || modify_vol) && opts->dev != NULL) ||
        ((unmap_vol || info_map) && opts->map_name != NULL)) ||
        (TC_FLAG_SET(opts->flags, SYS) && TC_FLAG_SET(opts->flags, FDE)) ||
        (map_vol + info_vol + create_vol + unmap_vol + info_map + modify_vol > 1) ||
        (opts->hidden && !create_vol) ||
        (TC_FLAG_SET(opts->flags, SYS) && (opts->sys_dev == NULL)) ||
        (TC_FLAG_SET(opts->flags, ONLY_RESTORE) && (opts->n_newkeyfiles > 0 || opts->new_prf_algo != NULL)) ||
        (TC_FLAG_SET(opts->flags, BACKUP) && (opts->sys_dev != NULL || TC_FLAG_SET(opts->flags, FDE))) ||
        (map_vol && (opts->map_name == NULL)) ||
        (unmap_vol && (opts->map_name == NULL)) ||
        (!modify_vol && opts->n_newkeyfiles > 0) ||
        (!modify_vol && opts->new_prf_algo != NULL) ||
        (!modify_vol && TC_FLAG_SET(opts->flags, ONLY_RESTORE)) ||
        (!modify_vol && TC_FLAG_SET(opts->flags, SAVE_TO_FILE)) ||
        (!(opts->protect_hidden || create_vol) && opts->n_hkeyfiles > 0)) {
        usage();
        /* NOT REACHED */
    }

    /* Create a new volume */
    if (create_vol) {
        error = create_volume(opts);
        if (error) {
            tc_log(1, "could not create new volume on %s\n", opts->dev);
        }
    } else if (info_map) {
        error = info_mapped_volume(opts);
    } else if (info_vol) {
        error = info_volume(opts);
    } else if (map_vol) {
        error = map_volume(opts);
    } else if (unmap_vol) {
        error = dm_teardown(opts->map_name, NULL);
    } else if (modify_vol) {
        error = modify_volume(opts);
    }

    return error;
}
Beispiel #15
0
int
main(int argc, char *argv[])
{
	const char *dev = NULL, *sys_dev = NULL, *map_name = NULL;
	const char *keyfiles[MAX_KEYFILES];
	const char *h_keyfiles[MAX_KEYFILES];
	int nkeyfiles;
	int n_hkeyfiles;
	int ch, error;
	int sflag = 0, info_vol = 0, map_vol = 0, protect_hidden = 0,
	    create_vol = 0, contain_hidden = 0, use_secure_erase = 1;
	struct pbkdf_prf_algo *prf = NULL;
	struct tc_cipher_chain *cipher_chain = NULL;
	struct pbkdf_prf_algo *h_prf = NULL;
	struct tc_cipher_chain *h_cipher_chain = NULL;

	if ((error = tc_play_init()) != 0) {
		fprintf(stderr, "Initialization failed, exiting.");
		exit(1);
	}

	atexit(check_and_purge_safe_mem);
	signal(SIGUSR1, sig_handler);
	signal(SIGINFO, sig_handler);

	nkeyfiles = 0;
	n_hkeyfiles = 0;

	while ((ch = getopt_long(argc, argv, "a:b:cd:ef:ghik:m:s:vx:y:z",
	    longopts, NULL)) != -1) {
		switch(ch) {
		case 'a':
			if (prf != NULL)
				usage();
			if ((prf = check_prf_algo(optarg, 0)) == NULL) {
				if (strcmp(optarg, "help") == 0)
					exit(0);
				else
					usage();
				/* NOT REACHED */
			}
			break;
		case 'b':
			if (cipher_chain != NULL)
				usage();
			if ((cipher_chain = check_cipher_chain(optarg, 0)) == NULL) {
				if (strcmp(optarg, "help") == 0)
					exit(0);
				else
					usage();
				/* NOT REACHED */
			}
			break;
		case 'c':
			create_vol = 1;
			break;
		case 'd':
			if (sflag) usage();
			dev = optarg;
			break;
		case 'e':
			protect_hidden = 1;
			break;
		case 'f':
			h_keyfiles[n_hkeyfiles++] = optarg;
			break;
		case 'g':
			contain_hidden = 1;
			break;
		case 'i':
			info_vol = 1;
			break;
		case 'k':
			keyfiles[nkeyfiles++] = optarg;
			break;
		case 'm':
			map_vol = 1;
			map_name = optarg;
			break;
		case 's':
			if (dev) usage();
			sflag = 1;
			sys_dev = optarg;
			dev = optarg;
			break;
		case 'v':
			printf("tcplay v%d.%d\n", MAJ_VER, MIN_VER);
			exit(0);
			/* NOT REACHED */
		case 'x':
			if (h_prf != NULL)
				usage();
			if ((h_prf = check_prf_algo(optarg, 0)) == NULL) {
				if (strcmp(optarg, "help") == 0)
					exit(0);
				else
					usage();
				/* NOT REACHED */
			}
			break;
		case 'y':
			if (h_cipher_chain != NULL)
				usage();
			if ((h_cipher_chain = check_cipher_chain(optarg, 0)) == NULL) {
				if (strcmp(optarg, "help") == 0)
					exit(0);
				else
					usage();
				/* NOT REACHED */
			}
			break;

		case 'z':
			use_secure_erase = 0;
			break;
		case 'h':
		case '?':
		default:
			usage();
			/* NOT REACHED */
		}
	}

	argc -= optind;
	argv += optind;

	/* Check arguments */
	if (!((map_vol || info_vol || create_vol) && dev != NULL) ||
	    (map_vol && info_vol) ||
	    (map_vol && create_vol) ||
	    (create_vol && info_vol) ||
	    (contain_hidden && !create_vol) ||
	    (sflag && (sys_dev == NULL)) ||
	    (map_vol && (map_name == NULL)) ||
	    (!(protect_hidden || create_vol) && n_hkeyfiles > 0)) {
		usage();
		/* NOT REACHED */
	}

	/* Create a new volume */
	if (create_vol) {
		error = create_volume(dev, contain_hidden, keyfiles, nkeyfiles,
		    h_keyfiles, n_hkeyfiles, prf, cipher_chain, h_prf,
		    h_cipher_chain, NULL, NULL,
		    0, 1 /* interactive */,
		    use_secure_erase);
		if (error) {
			tc_log(1, "could not create new volume on %s\n", dev);
		}
	} else if (info_vol) {
		error = info_volume(dev, sflag, sys_dev, protect_hidden,
		    keyfiles, nkeyfiles, h_keyfiles, n_hkeyfiles, NULL, NULL,
		    1 /* interactive */, DEFAULT_RETRIES, 0);
	} else if (map_vol) {
		error = map_volume(map_name,
		    dev, sflag, sys_dev, protect_hidden,
		    keyfiles, nkeyfiles, h_keyfiles, n_hkeyfiles, NULL, NULL,
		    1 /* interactive */, DEFAULT_RETRIES, 0);
	}

	return error;
}
Beispiel #16
0
int main(int argc, char **argv)
{
	ps8_t volume_name = NULL;
	u128 volume_size = 0;
	u128 cluster_size = 0;
	struct mfs_volume* volume = NULL;
	static int auto_create_loopback_flag = 0;

  while(1) 
	{
		int c;
		static const struct option long_options[] = 
		{
		  { "auto", 				no_argument, 				&auto_create_loopback_flag, 	1		},
			{ "name", 				required_argument, 	NULL, 												'n' },
			{ "size", 				required_argument, 	NULL, 												's' },
			{ "clustersize", 	required_argument,	NULL, 												'c' },
			{ NULL, 					0, 									NULL, 												0		}
		};
		c = getopt_long(argc, argv, "n:s:c:", long_options, NULL);

		if (c < 0)
			break;

		switch(c) 
		{
			case 0:
				break;
			case 'n':
				volume_name = strdup(optarg);
				break;
			case 's':
				volume_size = parse_size(optarg);
				break;
			case 'c':
				cluster_size = parse_size(optarg);
				break;
			case GETOPT_VAL_HELP:
			default:
				print_usage(c != GETOPT_VAL_HELP);
		}
	}

  if (auto_create_loopback_flag) 
	{
  	if (volume_name == NULL) 
		{
			printf("ERROR: Set the volume name\n");
			exit(1);
		}

		if (volume_size <= 0) 
		{
			printf("ERROR: Set the correct volume size\n");
			exit(1);
		}

		volume = create_loopback(volume_name);

	} 
	else 
	{
		char* device_name = argv[optind];

		if (device_name == NULL) 
		{
			printf("ERROR: Set the correct device name\n");
			exit(1);
		}

		volume = open_device(device_name, &volume_size);
	}

  if (cluster_size <= 0) 
	{
		printf("ERROR: Set the correct cluster size\n");
		exit(1);
	}

	create_volume(volume, volume_name, volume_size, cluster_size);
	if (volume != NULL) 
	{
		print_volume_status(volume);
		free_volume(volume);
	}

	return 0;
}
Beispiel #17
0
int main(int argc, char *argv[])
{
   char   **infiles;
   int      n_infiles;
   char    *out_fn;
   char    *history;
   VIO_progress_struct progress;
   VIO_Volume   totals, weights;
   int      i, j, k, v;
   double   min, max;
   double   w_min, w_max;
   long     num_missed;
   double   weight, value;
   double   initial_weight;

   VIO_Real     dummy[3];

   int      sizes[MAX_VAR_DIMS];
   double   starts[MAX_VAR_DIMS];
   double   steps[MAX_VAR_DIMS];
   
   long     t = 0;

   /* start the time counter */
   current_realtime_seconds();
   
   /* get the history string */
   history = time_stamp(argc, argv);

   /* get args */
   if(ParseArgv(&argc, argv, argTable, 0) || (argc < 3)){
      fprintf(stderr,
              "\nUsage: %s [options] <in1.mnc> [<in2.mnc> [...]] <out.mnc>\n", argv[0]);
      fprintf(stderr,
              "       %s [options] -arb_path pth.conf <infile.raw> <out.mnc>\n", argv[0]);
      fprintf(stderr, "       %s -help\n\n", argv[0]);
      exit(EXIT_FAILURE);
      }

   /* get file names */
   n_infiles = argc - 2;
   infiles = (char **)malloc(sizeof(char *) * n_infiles);
   for(i = 0; i < n_infiles; i++){
      infiles[i] = argv[i + 1];
      }
   out_fn = argv[argc - 1];

   /* check for infiles and outfile */
   for(i = 0; i < n_infiles; i++){
      if(!file_exists(infiles[i])){
         fprintf(stderr, "%s: Couldn't find input file %s.\n\n", argv[0], infiles[i]);
         exit(EXIT_FAILURE);
         }
      }
   if(!clobber && file_exists(out_fn)){
      fprintf(stderr, "%s: %s exists, -clobber to overwrite.\n\n", argv[0], out_fn);
      exit(EXIT_FAILURE);
      }

   /* check for weights_fn if required */
   if(weights_fn != NULL){
      if(!clobber && file_exists(weights_fn)){
         fprintf(stderr, "%s: %s exists, -clobber to overwrite.\n\n", argv[0],
                 weights_fn);
         exit(EXIT_FAILURE);
         }
      }

   /* set up parameters for reconstruction */
   if(out_dtype == NC_UNSPECIFIED){
      out_dtype = in_dtype;
      }
   if(out_is_signed == DEF_BOOL){
      out_is_signed = in_is_signed;
      }

   /* check vector dimension size */
   if(vect_size < 1){
      fprintf(stderr, "%s: -vector (%d) must be 1 or greater.\n\n", argv[0], vect_size);
      exit(EXIT_FAILURE);
      }

   /* check sigma */
   if(regrid_sigma[0] <= 0 || regrid_sigma[1] <= 0 || regrid_sigma[2] <= 0 ){
      fprintf(stderr, "%s: -sigma must be greater than 0\n\n", argv[0]);
      exit(EXIT_FAILURE);
      }

   /* read in the output file config from a file is specified */
   if(out_config_fn != NULL){
      int      ext_args_c;
      char    *ext_args[32];           /* max possible is 32 arguments */

      ext_args_c = read_config_file(out_config_fn, ext_args);
      if(ParseArgv(&ext_args_c, ext_args, argTable,
                   ARGV_DONT_SKIP_FIRST_ARG | ARGV_NO_LEFTOVERS | ARGV_NO_DEFAULTS)){
         fprintf(stderr, "\nError in parameters in %s\n", out_config_fn);
         exit(EXIT_FAILURE);
         }
      }

   if(verbose){
      fprintf_vol_def(stdout, &out_inf);
      }

   /* transpose the geometry arrays */
   /* out_inf.*[] are in world xyz order, perm[] is the permutation
      array to map world xyz to the right voxel order in the volume */
   for(i = 0; i < WORLD_NDIMS; i++){
      sizes[i] = out_inf.nelem[perm[i]];  /* sizes, starts, steps are in voxel volume order. */
      starts[i] = out_inf.start[perm[i]];
      steps[i] = out_inf.step[perm[i]];
      }
   sizes[WORLD_NDIMS] = vect_size;

   /* create the totals volume */
   totals = create_volume((vect_size > 1) ? 4 : 3,
                          (vect_size > 1) ? std_dimorder_v : std_dimorder,
                          out_dtype, out_is_signed, 0.0, 0.0);
   set_volume_sizes(totals, sizes);
   set_volume_starts(totals, starts);
   set_volume_separations(totals, steps);
   for(i = 0; i < WORLD_NDIMS; i++){
      /* out_inf.dircos is in world x,y,z order, we have to use the perm array to 
         map each direction to the right voxel axis. */
      set_volume_direction_cosine(totals, i, out_inf.dircos[perm[i]]);
      }
   alloc_volume_data(totals);

   /* create the "weights" volume */
   weights = create_volume(3, std_dimorder, out_dtype, out_is_signed, 0.0, 0.0);
   set_volume_sizes(weights, sizes);
   set_volume_starts(weights, starts);
   set_volume_separations(weights, steps);
   for(i = 0; i < WORLD_NDIMS; i++){
      set_volume_direction_cosine(weights, i, out_inf.dircos[perm[i]]);
      }
   alloc_volume_data(weights);

   /* down below in regrid_loop, Andrew makes a nasty direct reference to the
      voxel_to_world transformation in the volume.  This
      transformation is not necessarily up to date, particularly when
      non-default direction cosines are used.  In volume_io, the
      direction cosines are set and a FLAG is also set to indicate
      that the voxel-to-world xform is not up to date.  If the stanrd
      volume_io general transform code is used, it checks internally
      to see if the matrix is up to date, and if not it is recomputed.

      So here, we'll (LC + MK) force an update by calling a general
      transform.  */

//   convert_world_to_voxel(weights, (Real) 0, (Real) 0, (Real) 0, dummy);
//   convert_world_to_voxel(totals, (Real) 0, (Real) 0, (Real) 0, dummy);

   fprintf(stderr, "2Sizes: [%d:%d:%d] \n", sizes[perm[0]], sizes[perm[1]], sizes[perm[2]]);
   
   /* initialize weights to be arbitray large value if using NEAREST */
   /* volume interpolation else initialize all to zero */
   if(regrid_type == NEAREST_FUNC && ap_coord_fn == NULL){
      initial_weight = LARGE_INITIAL_WEIGHT;
      }
   else{
      initial_weight = 0.0;
      }
   
   /* initialize weights and totals */   
   for(k = sizes[Z_IDX]; k--;){
      for(j = sizes[Y_IDX]; j--;){
         for(i = sizes[X_IDX]; i--;){
            set_volume_real_value(weights, k, j, i, 0, 0, initial_weight);
            for(v = vect_size; v--;){
               set_volume_real_value(totals, k, j, i, v, 0, 0.0);
               }
            }
         }
      }

   /* if regridding via an arbitrary path */
   if(ap_coord_fn != NULL){

      if(n_infiles > 1){
         fprintf(stderr, "%s: arb_path only works for one input file (so far).\n\n",
                 argv[0]);
         exit(EXIT_FAILURE);
         }

      /* print some pretty output */
      if(verbose){
         fprintf(stdout, " | Input data:      %s\n", infiles[0]);
         fprintf(stdout, " | Arb path:        %s\n", ap_coord_fn);
         fprintf(stdout, " | Output range:    [%g:%g]\n", out_range[0], out_range[1]);
         fprintf(stdout, " | Output file:     %s\n", out_fn);
         }

      regrid_arb_path(ap_coord_fn, infiles[0], max_buffer_size_in_kb,
                      &totals, &weights, vect_size, regrid_range[0], regrid_range[1]);
      }

   /* else if regridding via a series of input minc file(s) */
   else {
      for(i = 0; i < n_infiles; i++){
         if(verbose){
            fprintf(stdout, " | Input file:      %s\n", infiles[i]);
            }
         regrid_minc(infiles[i], max_buffer_size_in_kb,
                     &totals, &weights, vect_size, regrid_range[0], regrid_range[1]);
         }
      }

   /* initialise min and max counters and divide totals/weights */
   num_missed = 0;
   min = get_volume_real_value(totals, 0, 0, 0, 0, 0);
   max = get_volume_real_value(totals, 0, 0, 0, 0, 0);
   w_min = get_volume_real_value(weights, 0, 0, 0, 0, 0);
   w_max = get_volume_real_value(weights, 0, 0, 0, 0, 0);
   initialize_progress_report(&progress, FALSE, out_inf.nelem[Z_IDX], "Dividing through");
   
   for(i = sizes[perm[0]]; i--;){
      for(j = sizes[perm[1]]; j--;){
         for(k = sizes[perm[2]]; k--;){
            weight = get_volume_real_value(weights, k, j, i, 0, 0);
            if(weight < w_min){
               w_min = weight;
               }
            else if(weight > w_max){
               w_max = weight;
               }
            
            if(weight != 0){
               for(v = vect_size; v--;){
                  value = get_volume_real_value(totals, k, j, i, v, 0) / weight;
                  if(value < min){
                     min = value;
                     }
                  else if(value > max){
                     max = value;
                     }
                  
                  set_volume_real_value(totals, k, j, i, v, 0, value);
                  }
               }
            else {
               num_missed++;
               }
            }
         }
      update_progress_report(&progress, k + 1);
      }
   terminate_progress_report(&progress);

   /* set the volumes range */
   if(verbose){
      fprintf(stdout, " + data range:   [%g:%g]\n", min, max);
      fprintf(stdout, " + weight range: [%g:%g]\n", w_min, w_max);
      }
   set_volume_real_range(totals, min, max);
   set_volume_real_range(weights, w_min, w_max);

   if(num_missed > 0 && verbose){
      int      nvox;

      nvox = out_inf.nelem[X_IDX] * out_inf.nelem[Y_IDX] * out_inf.nelem[Z_IDX];
      fprintf(stdout,
              "\n-regrid_radius possibly too small, no data in %ld/%d[%2.2f%%] voxels\n\n",
              num_missed, nvox, ((float)num_missed / nvox * 100));
      }

   /* rescale data if required */
   if(out_range[0] != -DBL_MAX && out_range[1] != DBL_MAX){
      double   o_min, o_max;

      /* get the existing range */
      get_volume_real_range(totals, &o_min, &o_max);

      /* rescale it */
      scale_volume(&totals, o_min, o_max, out_range[0], out_range[1]);
      }

   /* output the result */
   if(verbose){
      fprintf(stdout, " | Outputting %s...\n", out_fn);
      }
   if(output_volume(out_fn, out_dtype, out_is_signed,
                    0.0, 0.0, totals, history, NULL) != VIO_OK){
      fprintf(stderr, "Problems outputing: %s\n\n", out_fn);
      }

   /* output weights volume if required */
   if(weights_fn != NULL){
      if(verbose){
         fprintf(stdout, " | Outputting %s...\n", weights_fn);
         }
      if(output_volume(weights_fn, out_dtype, out_is_signed,
                       0.0, 0.0, weights, history, NULL) != VIO_OK){
         fprintf(stderr, "Problems outputting: %s\n\n", weights_fn);
         }
      }

   delete_volume(totals);
   delete_volume(weights);
   
   t = current_realtime_seconds();
   printf("Total reconstruction time: %ld hours %ld minutes %ld seconds\n", t/3600, (t/60)%60, t%60);
   
   return (EXIT_SUCCESS);
   }
Beispiel #18
0
int
main(int argc, char *argv[])
{
	const char *dev = NULL, *sys_dev = NULL, *map_name = NULL;
	const char *keyfiles[MAX_KEYFILES];
	const char *h_keyfiles[MAX_KEYFILES];
	int nkeyfiles;
	int n_hkeyfiles;
	int ch, error;
	int flags = 0;
	int info_vol = 0, map_vol = 0, protect_hidden = 0,
	    unmap_vol = 0, info_map = 0,
	    create_vol = 0, contain_hidden = 0, use_secure_erase = 1,
	    use_weak_keys = 0;
	struct pbkdf_prf_algo *prf = NULL;
	struct tc_cipher_chain *cipher_chain = NULL;
	struct pbkdf_prf_algo *h_prf = NULL;
	struct tc_cipher_chain *h_cipher_chain = NULL;

	if ((error = tc_play_init()) != 0) {
		fprintf(stderr, "Initialization failed, exiting.");
		exit(EXIT_FAILURE);
	}

	atexit(check_and_purge_safe_mem);
	signal(SIGUSR1, sig_handler);
	signal(SIGINFO, sig_handler);

	nkeyfiles = 0;
	n_hkeyfiles = 0;

	while ((ch = getopt_long(argc, argv, "a:b:cd:ef:ghij:k:m:s:u:vwx:y:z",
	    longopts, NULL)) != -1) {
		switch(ch) {
		case 'a':
			if (prf != NULL)
				usage();
			if ((prf = check_prf_algo(optarg, 0)) == NULL) {
				if (strcmp(optarg, "help") == 0)
					exit(EXIT_SUCCESS);
				else
					usage();
				/* NOT REACHED */
			}
			break;
		case 'b':
			if (cipher_chain != NULL)
				usage();
			if ((cipher_chain = check_cipher_chain(optarg, 0)) == NULL) {
				if (strcmp(optarg, "help") == 0)
					exit(EXIT_SUCCESS);
				else
					usage();
				/* NOT REACHED */
			}
			break;
		case 'c':
			create_vol = 1;
			break;
		case 'd':
			dev = optarg;
			break;
		case 'e':
			protect_hidden = 1;
			break;
		case 'f':
			h_keyfiles[n_hkeyfiles++] = optarg;
			break;
		case 'g':
			contain_hidden = 1;
			break;
		case 'i':
			info_vol = 1;
			break;
		case 'j':
			info_map = 1;
			map_name = optarg;
			break;
		case 'k':
			keyfiles[nkeyfiles++] = optarg;
			break;
		case 'm':
			map_vol = 1;
			map_name = optarg;
			break;
		case 's':
			flags |= TC_FLAG_SYS;
			sys_dev = optarg;
			break;
		case 'u':
			unmap_vol = 1;
			map_name = optarg;
			break;
		case 'v':
			printf("tcplay v%d.%d\n", MAJ_VER, MIN_VER);
			exit(EXIT_SUCCESS);
			/* NOT REACHED */
		case 'w':
			fprintf(stderr, "WARNING: Using urandom as source of "
			    "entropy for key material is a really bad idea.\n");
			use_weak_keys = 1;
			break;
		case 'x':
			if (h_prf != NULL)
				usage();
			if ((h_prf = check_prf_algo(optarg, 0)) == NULL) {
				if (strcmp(optarg, "help") == 0)
					exit(EXIT_SUCCESS);
				else
					usage();
				/* NOT REACHED */
			}
			break;
		case 'y':
			if (h_cipher_chain != NULL)
				usage();
			if ((h_cipher_chain = check_cipher_chain(optarg, 0)) == NULL) {
				if (strcmp(optarg, "help") == 0)
					exit(EXIT_SUCCESS);
				else
					usage();
				/* NOT REACHED */
			}
			break;
		case 'z':
			use_secure_erase = 0;
			break;
		case FLAG_LONG_FDE:
			flags |= TC_FLAG_FDE;
			break;
		case FLAG_LONG_USE_BACKUP:
			flags |= TC_FLAG_BACKUP;
			break;
		case 'h':
		case '?':
		default:
			usage();
			/* NOT REACHED */
		}
	}

	argc -= optind;
	argv += optind;

	/* Check arguments */
	if (!(((map_vol || info_vol || create_vol) && dev != NULL) ||
	    ((unmap_vol || info_map) && map_name != NULL)) ||
	    (TC_FLAG_SET(flags, SYS) && TC_FLAG_SET(flags, FDE)) ||
	    (map_vol && info_vol) ||
	    (map_vol && create_vol) ||
	    (unmap_vol && map_vol) ||
	    (unmap_vol && info_vol) ||
	    (unmap_vol && create_vol) ||
	    (create_vol && info_vol) ||
	    (contain_hidden && !create_vol) ||
	    (TC_FLAG_SET(flags, SYS) && (sys_dev == NULL)) ||
	    (map_vol && (map_name == NULL)) ||
	    (unmap_vol && (map_name == NULL)) ||
	    (!(protect_hidden || create_vol) && n_hkeyfiles > 0)) {
		usage();
		/* NOT REACHED */
	}

	/* Create a new volume */
	if (create_vol) {
		error = create_volume(dev, contain_hidden, keyfiles, nkeyfiles,
		    h_keyfiles, n_hkeyfiles, prf, cipher_chain, h_prf,
		    h_cipher_chain, NULL, NULL,
		    0, 1 /* interactive */,
		    use_secure_erase, use_weak_keys);
		if (error) {
			tc_log(1, "could not create new volume on %s\n", dev);
		}
	} else if (info_map) {
		error = info_mapped_volume(map_name, 1 /* interactive */);
	} else if (info_vol) {
		error = info_volume(dev, flags, sys_dev, protect_hidden,
		    keyfiles, nkeyfiles, h_keyfiles, n_hkeyfiles, NULL, NULL,
		    1 /* interactive */, DEFAULT_RETRIES, 0);
	} else if (map_vol) {
		error = map_volume(map_name,
		    dev, flags, sys_dev, protect_hidden,
		    keyfiles, nkeyfiles, h_keyfiles, n_hkeyfiles, NULL, NULL,
		    1 /* interactive */, DEFAULT_RETRIES, 0);
	} else if (unmap_vol) {
		error = dm_teardown(map_name, NULL);
	}

	return error;
}
static void resample_the_deformation_field(Arg_Data *globals)
{

  VIO_Volume
    existing_field,
    new_field;
  VIO_Real
    vector_val[3],
    XYZstart[ VIO_MAX_DIMENSIONS ],
    wstart[ VIO_MAX_DIMENSIONS ],
    start[    VIO_MAX_DIMENSIONS ],
    XYZstep[  VIO_MAX_DIMENSIONS ],
    step[     VIO_MAX_DIMENSIONS ],
    step2[    VIO_MAX_DIMENSIONS ],
    s1[       VIO_MAX_DIMENSIONS ],
    voxel[    VIO_MAX_DIMENSIONS ],
    dir[3][3];
  int
    i,
    siz[      VIO_MAX_DIMENSIONS ],
    index[    VIO_MAX_DIMENSIONS ],
    xyzv[     VIO_MAX_DIMENSIONS ],
    XYZcount[ VIO_MAX_DIMENSIONS ],
    count[    VIO_MAX_DIMENSIONS ];
  VIO_General_transform
    *non_lin_part;
  VectorR
    XYZdirections[ VIO_MAX_DIMENSIONS ];
  VIO_Real
    del_x, del_y, del_z, wx, wy,wz;
  VIO_progress_struct
    progress;
  char
    **data_dim_names;


                                /* get the nonlinear part
                                   of the transformation           */

  existing_field = (VIO_Volume)NULL;
  non_lin_part = get_nth_general_transform(globals->trans_info.transformation,
                                           get_n_concated_transforms(
                                               globals->trans_info.transformation)
                                           -1);

  if (get_transform_type( non_lin_part ) == GRID_TRANSFORM){
    existing_field = (VIO_Volume)(non_lin_part->displacement_volume);
  }
  else {
    for(i=0; i<get_n_concated_transforms(globals->trans_info.transformation); i++)
      print ("Transform %d is of type %d\n",i,
             get_transform_type(
                get_nth_general_transform(globals->trans_info.transformation,
                                i) ));

    print_error_and_line_num("Cannot find the deformation field transform to resample",
                             __FILE__, __LINE__);
  }

  /* build a vector volume to store the Grid VIO_Transform */

  new_field = create_volume(4, dim_name_vector_vol, NC_DOUBLE, TRUE, 0.0, 0.0);

  get_volume_XYZV_indices(new_field, xyzv);

  for(i=0; i<VIO_N_DIMENSIONS; i++)
    step2[i] = globals->step[i];
                                /* get new start, count, step and directions,
                                   all returned in X, Y, Z order.          */

  set_up_lattice(existing_field, step2, XYZstart, wstart, XYZcount, XYZstep, XYZdirections);

                                /* reset count and step to be in volume order */
  for(i=0; i<VIO_N_DIMENSIONS; i++) {
    start[      i  ] = wstart[ i ];
    count[ xyzv[i] ] = XYZcount[ i ];
    step[  xyzv[i] ] = XYZstep[  i ];
  }

                                /* add info for the vector dimension */
  count[xyzv[VIO_Z+1]] = 3;
  step[xyzv[VIO_Z+1]] = 0.0;

         /* use the sign of the step returned to set the true step size */
  for(i=0; i<VIO_N_DIMENSIONS; i++) {
    if (step[xyzv[i]]<0)
      step[xyzv[i]] = -1.0 * fabs(globals->step[i]);
    else
      step[xyzv[i]] = fabs(globals->step[i]);
  }

  for(i=0; i<VIO_MAX_DIMENSIONS; i++)  /* set the voxel origin, used in the vol def */
    voxel[i] = 0.0;

  set_volume_sizes(       new_field, count);
  set_volume_separations( new_field, step);

  /*  set_volume_voxel_range( new_field, -MY_MAX_VOX, MY_MAX_VOX);
      set_volume_real_range(  new_field, -1.0*globals->trans_info.max_def_magnitude, globals->trans_info.max_def_magnitude);  - no longer needed, because now using doubles*/

  set_volume_translation( new_field, voxel, start);

  for(i=0; i<VIO_N_DIMENSIONS; i++) {
    dir[VIO_X][i]=XYZdirections[VIO_X].coords[i];
    dir[VIO_Y][i]=XYZdirections[VIO_Y].coords[i];
    dir[VIO_Z][i]=XYZdirections[VIO_Z].coords[i];

  }


  set_volume_direction_cosine(new_field,xyzv[VIO_X],dir[VIO_X]);
  set_volume_direction_cosine(new_field,xyzv[VIO_Y],dir[VIO_Y]);
  set_volume_direction_cosine(new_field,xyzv[VIO_Z],dir[VIO_Z]);


                                /* make sure that the vector dimension
                                   is named! */
  data_dim_names = get_volume_dimension_names(new_field);

  if( strcmp( data_dim_names[ xyzv[VIO_Z+1] ] , MIvector_dimension ) != 0 ) {
    ALLOC((new_field)->dimension_names[xyzv[VIO_Z+1]], \
          strlen(MIvector_dimension  ) + 1 );
    (void) strcpy( (new_field)->dimension_names[xyzv[VIO_Z+1]], MIvector_dimension );
  }

  delete_dimension_names(new_field, data_dim_names);

  if (globals->flags.debug) {
    print ("in resample_deformation_field:\n");
    print ("xyzv[axes] = %d, %d, %d, %d\n",xyzv[VIO_X],xyzv[VIO_Y],xyzv[VIO_Z],xyzv[VIO_Z+1]);

    get_volume_sizes(new_field, siz);
    get_volume_separations(new_field, s1);
    print ("seps: %7.3f %7.3f %7.3f %7.3f %7.3f \n",s1[0],s1[1],s1[2],s1[3],s1[4]);
    print ("size: %7d %7d %7d %7d %7d \n",siz[0],siz[1],siz[2],siz[3],siz[4]);
  }

  alloc_volume_data(new_field);

  if (globals->flags.verbose>0)
    initialize_progress_report( &progress, FALSE, count[xyzv[VIO_X]],
                               "Interpolating new field" );

  /* now resample the values from the input deformation */

  for(i=0; i<VIO_MAX_DIMENSIONS; i++) {
    voxel[i] = 0.0;
    index[i] = 0;
  }

  for(index[xyzv[VIO_X]]=0; index[xyzv[VIO_X]]<count[xyzv[VIO_X]]; index[xyzv[VIO_X]]++) {
    voxel[xyzv[VIO_X]] = (VIO_Real)index[xyzv[VIO_X]];

    for(index[xyzv[VIO_Y]]=0; index[xyzv[VIO_Y]]<count[xyzv[VIO_Y]]; index[xyzv[VIO_Y]]++) {
      voxel[xyzv[VIO_Y]] = (VIO_Real)index[xyzv[VIO_Y]];

      for(index[xyzv[VIO_Z]]=0; index[xyzv[VIO_Z]]<count[xyzv[VIO_Z]]; index[xyzv[VIO_Z]]++) {
        voxel[xyzv[VIO_Z]] = (VIO_Real)index[xyzv[VIO_Z]];

        convert_voxel_to_world(new_field, voxel, &wx,&wy,&wz);


           grid_transform_point(non_lin_part, wx, wy, wz,
                             &del_x, &del_y, &del_z);



                                /* get just the deformation part */
        del_x = del_x - wx;
        del_y = del_y - wy;
        del_z = del_z - wz;


/*        del_x = del_y = del_z = 0.0;
*/
        vector_val[0] = CONVERT_VALUE_TO_VOXEL(new_field, del_x);
        vector_val[1] = CONVERT_VALUE_TO_VOXEL(new_field, del_y);
        vector_val[2] = CONVERT_VALUE_TO_VOXEL(new_field, del_z);

        for(index[xyzv[VIO_Z+1]]=0; index[xyzv[VIO_Z+1]]<3; index[xyzv[VIO_Z+1]]++) {
          SET_VOXEL(new_field, \
                    index[0], index[1], index[2], index[3], index[4], \
                    vector_val[ index[ xyzv[ VIO_Z+1] ] ]);
        }


      }
    }
    if (globals->flags.verbose>0)
      update_progress_report( &progress,index[xyzv[VIO_X]]+1);
  }
  if (globals->flags.verbose>0)
    terminate_progress_report( &progress );

                 /* delete and free up old data */
  delete_volume(non_lin_part->displacement_volume);
               /* set new volumes into transform */
  non_lin_part->displacement_volume = new_field;

}