Frage

i think i'm getting familiar with this library.

1) i want to do a volume rendering like in lesson 10

i want to check whether the user pressed "v" and run a function

this is what i have tried:

window.onload = function() {

    var r = new X.renderer3D();
    r.init();

    var volume = new X.volume();
    volume.file = 'http://lessons.goXTK.com/data/avf.nrrd';
    var vr = false;

    function vRender() {
        if (vr) {
            volume.volumeRendering = true;
            volume.opacity = 0.15;
            r.render();
        }
    }


    r.interactor.onKey = function(event) {
        if (event.keyCode == 86) {
            vr = true;
            vRender();
        }
    }

    r.add(volume);
    r.camera.position = [120, 80, 160];
    r.render();

};

2) how can i grab one of the slice-layers or disable two of the three axis? does it work in a similar way like what i've tried?

var volume = new X.volume();
volume.file = 'http://lessons.goXTK.com/data/avf.nrrd';

volume.sliceX.visible = false;
volume.sliceZ.visible = false;

any help would be appreciated!

War es hilfreich?

Lösung

2)

Yes, it is possible in a similiar way. Check out the JSFiddle

http://jsfiddle.net/haehn/qxMtk/

The difference is that volume._sliceX is not available (not exported during compilation) so you have to go through the children. Each X.volume has 3 children 0,1,2 which are the X,Y,Z slices.

Also, the volume has to be created (which happens during parsing initiated by r.render()) before you can access the children so we have to do the stuff in onShowtime or after.

Andere Tipps

1) I just tried your code and it almost works perfectly. (Unfortunately onKey events don't work in JSFiddle so I can't post a fiddle).

I just added the volume.modified() line to fire a X.event.ModifiedEvent and make sure the switch between slicing and volume rendering happens properly.

  function vRender() {

    if (vr) {

      volume.volumeRendering = true;
      volume.opacity = 0.15;
      **volume.modified();**
      r.render();
    }
  }


  r.interactor.onKey = function(event) {

    if (event.keyCode == 86) {
      vr = true;
      vRender();
    }
  };
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top