FNNDSC / ami

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

Translate slice in viewers_compare example #256

Open llafitte007 opened 6 years ago

llafitte007 commented 6 years ago

Hi, Based on the example of viewers-compare (https://github.com/FNNDSC/ami/tree/dev/examples/viewers_compare) I try to perform a translation 2d on one of two slice in the scene.

According to this issue https://github.com/FNNDSC/ami/issues/125 , I try to transpose the transalation for my case like :

`

    let shiftFolder = gui.addFolder('Shift');
    let modeMix = shiftFolder.add(uniformsLayerMix.uMixMode, 'value', 0, 2).step(1).listen();

    let shiftxMix = shiftFolder.add(appParams, 'dx', -stack2.dimensionsIJK.x, stack2.dimensionsIJK.x).step(1).listen();
    shiftxMix.onChange(function(value) {

        let pos = parseInt((stack2.dimensionsIJK.x / 2)) + value;
        let mat = new THREE.Matrix4().makeTranslation(value, 0, 0);

        stackHelper2.stack.regMatrix = mat;
        stackHelper2.stack.computeIJK2LPS();

        stackHelper2.slice._uniforms.uWorldToData.value = stackHelper2.stack.lps2IJK;
        stackHelper2.slice.planePosition.x = pos;
        stackHelper2.slice._update();

        updateLayer1();
        updateLayerMix();
    });

` I use a stackHelper2 initialized like default stackHelper in code, and passed to buildGUI function to add a dx slider change the translation x value.

With this code, I have the following result when I changed the dx slider value :

capture du 2018-03-07 18 27 58

The geometry of slice seems to be translate but not the inner texture, do you have any idea ?

I can share more code if necessary

NicolasRannou commented 6 years ago

It is a bit hard to say from the code but I would say that should not be needed:

stackHelper2.slice.planePosition.x = pos;

Otherwise the Slice from StackHelper2 should be translated as you want.

If you use 2 different geometries (from StackHelpers 1 and 2), the mix Layer may not work as expected (basically in the mix layer it may look like nothing was translated - could that be something you noticed?)

llafitte007 commented 6 years ago

As you say, the stackHelper2.slice update lines is not necessary...

For the mix layer, it "see" a translation of stackHelper2 as you can see on previous scrennshot, but the translation is not on image but on its geometry.

Maybe another way to make this translation easilest, is to apply it on the data shader ? do you think this is achievable by this way adding parameter for shader (by this trick, I will not change stackhelper and layer or mix shaders)

NicolasRannou commented 6 years ago

I'll try to test in the viewers_compare example asap to see if I can figure it out.

llafitte007 commented 6 years ago

Sorry to come back to you, but after several other inconclusive tests I still can not :( ! Have you had time to take a look at my problem ?

Would anyone else have an idea ?