FNNDSC / ami

AMI Medical Imaging (AMI) JS ToolKit
https://fnndsc.github.io/ami/#viewers_upload
MIT License
719 stars 213 forks source link

[feature] Status of TRK Fiber loading #182

Open aalises opened 7 years ago

aalises commented 7 years ago

Hello,

I would like to ask which is the current status of the TRK Fiber loader for ami.js , is it usable? can you load a TRK model in a 3D view (for instance in the quadview_example 3D view)?. If so, how would you use it?

Thank you!

NicolasRannou commented 7 years ago

hi @aalises, I didn't try it for a long time, it was working but may need to be adjusted (syntax is not valid in AMI anymore). It was a first proof of concept implementation based on THREEJS.

AFAIR it was generating 1 geometry per track, which then had to be converted into a line mesh in THREEJS.

However it would ideally be more independent from THREEJS and have a similar API as loaders.volume (i.e. extend loaders.base if possible).

So as a first step I would refactor https://github.com/FNNDSC/ami/blob/dev/src/loaders/loaders.trk.js into a proper es6 class, similar to loaders.volume.

An alternative approach it to make a "pure" THREEJS TRK Loader and submit it to the THREEJS team!

WDYT?

Thanks!

aalises commented 7 years ago

Hello! Right now I do not have a lot of time to look into it but I think it would be great to have it working again. How would you use it in the current state (e.g inside an application)? I am not familiar with the sintax of the class tbh....

Making it similar to the loaders.volume would be great of course! But I do not know how difficult it would be or if a lot of things should be changed...

Cheers!

NicolasRannou commented 7 years ago

In its current state you can you it as: http://jsfiddle.net/16fnyb8k/14/

Some notes: 1- TRK Loader has to be loaded after THREEJS as it relies on some THREEJS functions 2- TRK Loader doesn't expose all the data yet so may need some addition to expose IJK to LPS transforms 3- In the fiddle all tracks are intependent mesh, which is useful if you want to show/hide each of them on demand, but bad for performance. You may want to merge all tracks into a single object!

NicolasRannou commented 7 years ago

https://github.com/FNNDSC/ami/blob/dev/src/loaders/loaders.trk.js#L411

return {
  header: header,
  tracks: tracks,
}

would give you access to the VOX_TO_RAS transform that should be all what you need to transform tracks from data to LPS world coordinates.

In addition, you will have to transform from RAS to LPS space:

    var RASToLPS = new THREE.Matrix4();
    RASToLPS.set(-1, 0, 0, 0,
                  0, -1, 0, 0,
                  0, 0, 1, 0,
                  0, 0, 0, 1);
    mesh.applyMatrix(RASToLPS);
    scene.add(mesh);

If you have 2 datasets available online (nifti/dicom + matching trk), I'd love to add a small demo in AMI!

aalises commented 7 years ago

Hi! thanks for the review and the fiddle, looks good! Of course, you can use this data to add a small demo in AMI, looking forward to it :+1: : T1 MRI NIFTI data Associated TRK

NicolasRannou commented 7 years ago

wip: http://jsfiddle.net/16fnyb8k/34/

something is a bit weird with the transform I guess from the TRK file (missing origin) so I use the transform from the stack to transform the fibers to the right location.

and it is a bit slow, not sure which is best way to improve yet

NicolasRannou commented 7 years ago

couple of ideas to improve perf: 1- merge all geometries 2- show less geometries (threshold by fiber length) 3- merge geometries by length 4- use bufferGeometry instead of geometry

NicolasRannou commented 7 years ago

Much faster implementation (dirty but you will get the idea) http://jsfiddle.net/16fnyb8k/61/

NicolasRannou commented 7 years ago

As a note - fiddle doesn't work on mobile for some reason