Code Monkey home page Code Monkey logo

trk-io's People

Contributors

nilgoyette avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

czotti

trk-io's Issues

Scalars and properties

"s/p" means "scalars and/or properties"

Premises

  • s/p reading is not so complicated. In fact, it's already working. They are currently saved in the header.
  • s/p shouldn't be in the header. Their names fit there because it's actual header data, but the s/p themselves? I strongly doubt it.

Read all

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!

Iteration

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.

  • A fast one. The one we already have. It ignores all s/p and only returns the points.
  • A slow but complete one.

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.

Usage

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"]) { ... }

Saving on iteration

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.