imeka / trk-io Goto Github PK
View Code? Open in Web Editor NEWTrackVis (*.trk) reader and writer
License: BSD 2-Clause "Simplified" License
TrackVis (*.trk) reader and writer
License: BSD 2-Clause "Simplified" License
"s/p" means "scalars and/or properties"
People calling read_all
wants everything in one shot and they don't care about memory consumption. Hence we can change the definition of read_all
to
pub fn read_all(
&mut self,
bool return_all
) -> (Streamlines, Scalars, Properties) {
So, always return (streamlines, vec![], vec![])
when return_all=false
. An empty vec![]
doesn't allocate. The reading time should mostly stay the same when false
. The usage stays pleasant
let (streamlines, _, _) = writer.read_all(false);
let (streamlines, scalars, properties) = writer.read_all(true);
Of course we modify write_all
to receive those 3 arguments. They really should fit!
NiBabel::TractogramItem
and iteration make sense to me. In NiBabel, they return a struct on iteration, something like
struct TractogramItem {
streamline, scalars, properties
}
for item in streamlines {
// Read only streamlines, or zip, or ?
for p in item.streamline { ... }
}
I wonder though if we should offer 2 iterators.
I'm not sure about the naming. Maybe we should rename the fast one to iter_points()
and keep the standard iter
for the complete one? If we only offer one, it should be the complete one, of course.
s/p are f32
. We can't avoid that and it's in fact ok. It's less fun for "grouped" s/p like colors. We should offer a tool to manage colors in a non-terrible way. Nothing complicated, just a method that try to find which properties are the color then returns an iterator of tuple(r, g, b)
. I want something like
for (p, color, torsion) in streamline.iter()
.zip(scalars.colors())
.zip(scalars["torsion"]) { ... }
We currently have 3 write methods: write_all
(already been discussed), write
and write_from_iter
. They both write a single streamline. We can either change their signatures to receive 2 Option<>
OR double them to have a "points" version and a "points and s/p" version.
Here's a read + add colors example that will crash if there's already one or more s/p
let reader = Reader::new("full_brain.trk");
let mut header = reader.header.clone();
header.add_scalar("color_x");
header.add_scalar("color_y");
header.add_scalar("color_z");
let mut writer = Writer::new("copy.trk", Some(header));
for item in streamlines {
let nb_points = item.streamline.len();
let mut r = Vec::with_capacity(nb_points);
let mut g = Vec::with_capacity(nb_points);
let mut b = Vec::with_capacity(nb_points);
... Fill r, g and b with the coloring method you want ...
writer.write(item.streamline, vec![r, g, b], vec![]);
}
TBH, I'm not too sure about the write_from_iter
. Maybe it should stay exactly as it is. Maybe not. I'll probably have an opinion when I code it or when I use it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.