Skip to content

Commit

Permalink
script to generate an xfm file for some input vector field
Browse files Browse the repository at this point in the history
  • Loading branch information
mcvaneede committed Jan 6, 2017
1 parent d341aeb commit e14cc15
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions perl/make_xfm_for_grid.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/perl

# generates an xfm file for a provided grid file

use strict;
use warnings;

use File::Spec;
use MNI::Startup;
use Getopt::Tabular;
use MNI::Spawn;
use MNI::FileUtilities qw(test_file check_output_dirs);

my $usage = "
$0 [options] deformation_grid.mnc output_xfm_for_grid.xfm\n";


# handle arguments
my @left_over_args;
my @arg_table =
( @DefaultArgs,
);

GetOptions(\@arg_table, \@ARGV, \@left_over_args) or die "\n";


my $deformation_grid = shift @left_over_args or die $usage;
my $output_xfm = shift @left_over_args or die $usage;

if(-f $output_xfm and not $Clobber) {
die "Error: output xfm file already exists and -clobber not specified: $output_xfm.\n";
}

if(not -f $deformation_grid){
die "Error: deformation grid does not exist: $deformation_grid.\n";
}

# save the realpath to the grid, otherwise it won't necessarily work
my $deformation_grid_abs_path = File::Spec->rel2abs( $deformation_grid );

# write to the output
open(OUTPUT, "> $output_xfm");
print OUTPUT "MNI Transform File\n";
print OUTPUT "% created by $0 with grid $deformation_grid\n";
print OUTPUT "Transform_Type = Grid_Transform;\n";
print OUTPUT "Displacement_Volume = $deformation_grid_abs_path;\n";

0 comments on commit e14cc15

Please sign in to comment.