| Crates.io | trk-io |
| lib.rs | trk-io |
| version | 0.30.0 |
| created_at | 2017-12-03 19:06:29.638735+00 |
| updated_at | 2025-06-19 17:37:25.880282+00 |
| description | TrackVis (*.trk) reader and writer |
| homepage | |
| repository | https://github.com/imeka/trk-io |
| max_upload_size | |
| id | 41591 |
| size | 137,421 |
trk-io implements a TrackVis (.trk) reader and writer.
TrackVis files. Handles affine transformation as
nibabel.streamlines and MI-Brain would.nibabel.streamlines.nifti-rs crate, which can then be used to create a
trk header from a NiftiHeader, like you would do in nibabelReader can read all streamlines at once or can be used as a generator.trk_color.rs.nibabel.streamlines architecture (all 3D points are in a single
Vec![Point3D]). Currently, this is only useful for performance, but it may
lead to easier changes when and if we support BLAS.examples/*.rs. It's a good way to learn how
to use this library.// Read complete streamlines to memory
let tractogram = Reader::new("bundle.trk").unwrap().read_all();
for streamline in &tractogram.streamlines {
println!("Nb points: {}", streamline.len());
for point in streamline {
println!("{}", point);
}
}
// Simple read/write. Using a generator, so it will load only
// one streamline in memory.
let reader = Reader::new("full_brain.trk").unwrap();
let mut writer = Writer::new(
"copy.trk", Some(reader.header.clone()));
for tractogram_item in reader.into_iter() {
// tractogram_item is a TractogramItem, which is a tuple of
// (streamline, scalars, properties).
writer.write(tractogram_item);
}
// The new file will be completed only at the end of the scope. The
// 'n_count' field is written in the destructor because we don't
// know how many streamlines the user will write.
There's still a lot of work to do but it should work perfectly for simple use cases. In particular, future versions should be able to:
ops.Range, e.g. streamlines[0..10]Your help is much appreciated. Consider filing an issue in case something is missing for your use case to work. Pull requests are also welcome.