xtkvolume-rendering

The volume disappears when the slice X normals are changed


I want to fuse the lesson 10 and 17 to visualize the volume, the canonical Slices (like in the lesson 10) and the reslice of the sliceX (lesson 17). To do that, I modified the lesson 10 code.

The problems detected are:

  1. The Slice X appears when the volume rendering is enabled.
  2. The volume DISAPPEARs!!!!
  3. Appears only the X Slice on the screen when the volume rendering is enabled.

The problems appears when:

The problems appears on the volume visualization. when we change between Volume visualization and slice visualization, then when we are on the volume visualization we need to move the volume and then the errors will appear.

The specific error is on line 1385 of the volume.js (of the master branch downloaded yesterday, commit 318986e6b1d4a195a78b87f81a082ca249cbd866)...the screen shot : https://mega.co.nz/#!d8hVCIhY!TWegqY2pRPcvl09CyMocJYeZu55sDOc_xRCiAed2Jhg

Error: Uncaught TypeError: Cannot set property '_visible' of undefined volume.js:1385

    for (i = 0; i < _numberOfSlices; i++) {
       //THE ERROR IS IN THE NEXT LINE
        _child._children[i]._visible = true;

    }

WHAT I DO.... I modified the Lesson 10 in the next way:

1. Adding X Slice normals controls. To modify the xNormX, xNormY and xNormZ we use code from the lesson 17:

var slicegui = gui.addFolder('Slice X Orientation');
var sliceXNXController = slicegui.add(volume, 'xNormX', -1.00,1.00).name('Normal X Dir.').listen();
var sliceXNYController = slicegui.add(volume, 'xNormY', -1.00,1.00).name('Normal Y Dir.').listen();
var sliceXNZController = slicegui.add(volume, 'xNormZ', -1.00,1.00).name('Normal Z Dir.').listen();
normalChange = function(value){
    volume.sliceInfoChanged(0);
    sliceXController.max(volume.range[0] - 1);
}
sliceXNXController.onChange(normalChange);
sliceXNYController.onChange(normalChange);
sliceXNZController.onChange(normalChange);
slicegui.open();

2. Adding Listen() to sliceXController to allow auto update when we modify the normals:

var sliceXController = volumegui.add(volume, 'indexX', 0.00, volume.range[0] - 1).listen();

3. Adding code for store and restore the normals and the sliceX index When the user change the volumeRendering.

//Store the initial normals
var _xNormX_initial = volume.xNormX; 
var _xNormY_initial = volume.yNormX;
var _xNormZ_initial = volume.zNormX;
//Store the user defined normals
var _xNormX_current = null; 
var _xNormY_current = null;
var _xNormZ_current = null;

//store the initial indexX slice
var _indexX_initial = volume.indexX;
//store the user defined indexX slice
var _indexX_current = null;

//IF volumeRendering  change we catch the event
vrController.onChange(function(value) {
  if (value == true) {
    //Store the user defined normals
    _xNormX_current = volume.xNormX;
    _xNormY_current = volume.xNormY;
    _xNormZ_current = volume.xNormZ;
    //store  user defined indexX slice
    _indexX_current = volume.indexX;

    //set the initials normals
    volume.xNormX = _xNormX_initial;
    volume.xNormY = _xNormY_initial;
    volume.xNormZ = _xNormZ_initial;  
    //Set the initial indexX slice
    volume.indexX = _indexX_initial;                
  }else{
    //Go back to the  user defined normals
    volume.xNormX = _xNormX_current;
    volume.xNormY = _xNormY_current;
    volume.xNormZ = _xNormZ_current;
    //Go back to the  user defined indexX slice
    volume.indexX = _indexX_current;
  }
  volume.sliceInfoChanged(0);
});

I hope can you help me. Thanks in advance!!!


I share a video when I show the error(mp4 and webm), The full source code of the lesson 10 modified (It needs to be stored on "X-master\testing\visualization") and The screen shots of the errors

https://mega.co.nz/#F!I8pxgBqa!M0ZCBUTWXlcIDtYqvboo3w


EDIT 1, Problem Solved: For uncompiled XTK, I use this code:

//Modify Normals
volume.xNormX = _xNormX_current;
volume.xNormY = _xNormY_current;
volume.xNormZ = _xNormZ_current;
//Rebuild the sliceX data
volume.sliceInfoChanged(0);
//reset the "volume._volumeRenderingCache", thanks Nicolas :)
//this is the trick
volume._volumeRenderingCache = [];
//Modify the indexX slice
volume.indexX = _indexX_current;

The functional code is here(demo_ok.js): mega.co.nz/#!R1p0lKAC!C806T7tLTpQTdBN7mJBRS0_ANWa4fqv3wvJtZR_kMg4


Solution

  • Did you try to reset the "volume._volumeRenderingCache" after modifying the slice normal?

    something like:

    ...
    volume.sliceInfoChanged(0);
    volume._volumeRenderingCache = [];
    ...
    

    if it does work with the uncompiled XTK, we can add getters/setters to access this variable from the compiled XTK.

    Does it make sense?

    Thanks