trk-io 0.11.0

TrackVis (*.trk) reader and writer
Documentation
extern crate docopt;
extern crate nifti;
extern crate trk_io;

use std::path::Path;
use std::str;

use docopt::Docopt;
use nifti::{InMemNiftiObject, NiftiObject};
use trk_io::affine_nifti::get_nifti_affine;

static USAGE: &'static str = "
Print a Nifti (.nii | .nii.gz) header in a readable way

Usage:
  nifti_header <input> [options]
  nifti_header (-h | --help)
  nifti_header (-v | --version)

Options:
  -h --help     Show this screen.
  -v --version  Show version.
";

fn main() {
    let version = String::from(env!("CARGO_PKG_VERSION"));
    let args = Docopt::new(USAGE)
        .and_then(|dopt| dopt.version(Some(version)).parse())
        .unwrap_or_else(|e| e.exit());
    let input = Path::new(args.get_str("<input>"));
    if !input.exists() {
        panic!("Input trk '{:?}' doesn't exist.", input);
    }

    let nifti_object = InMemNiftiObject::from_file(input).expect("The input file is unreadable.");
    let header = nifti_object.header();
    println!("sizeof_hdr: {}", header.sizeof_hdr);
    println!("data_type: {:?}", header.data_type);
    println!("db_name: {:?}", header.db_name);
    println!("extents: {}", header.extents);
    println!("session_error: {}", header.session_error);
    println!("regular: {}", header.regular);
    println!("dim_info: {}", header.dim_info);
    println!("dim: {:?}", header.dim);
    println!("intent_p1: {}", header.intent_p1);
    println!("intent_p2: {}", header.intent_p2);
    println!("intent_p3: {}", header.intent_p3);
    println!("intent_code: {}", header.intent_code);
    println!("datatype: {}", header.datatype);
    println!("bitpix: {}", header.bitpix);
    println!("slice_start: {}", header.slice_start);
    println!("pixdim: {:?}", header.pixdim);
    println!("vox_offset: {}", header.vox_offset);
    println!("scl_slope: {}", header.scl_slope);
    println!("scl_inter: {}", header.scl_inter);
    println!("slice_end: {}", header.slice_end);
    println!("slice_code: {}", header.slice_code);
    println!("xyzt_units: {}", header.xyzt_units);
    println!("cal_max: {}", header.cal_max);
    println!("cal_min: {}", header.cal_min);
    println!("slice_duration: {}", header.slice_duration);
    println!("toffset: {}", header.toffset);
    println!("glmax: {}", header.glmax);
    println!("glmin: {}", header.glmin);
    println!("descrip: {:?}", header.descrip);
    println!("aux_file: {:?}", header.aux_file);
    println!("qform_code: {}", header.qform_code);
    println!("sform_code: {}", header.sform_code);
    println!("quatern_b: {}", header.quatern_b);
    println!("quatern_c: {}", header.quatern_c);
    println!("quatern_d: {}", header.quatern_d);
    println!("quatern_x: {}", header.quatern_x);
    println!("quatern_y: {}", header.quatern_y);
    println!("quatern_z: {}", header.quatern_z);
    println!("srow_x: {:?}", header.srow_x);
    println!("srow_y: {:?}", header.srow_y);
    println!("srow_z: {:?}", header.srow_z);
    println!("intent_name: {:?}", header.intent_name);
    println!("magic: {:?}", header.magic);
    println!("endianness: {:?}", header.endianness);
    let affine = get_nifti_affine(header);
    println!("tranform{}", affine);
    println!("inversed tranform{}", affine.try_inverse().unwrap());
}