0

i have two volumes (.nrrd) of different qualities. the user can browse through the layers. if a key is pressed i want to load the slice of the volume with better quality.

my volume is similar to this one: lesson 10 xtk

i've found:

volume.children[2].children[0].children[0].texture.file = "http://path/to/file.ext";

but if i apply some kind of file (.jpg, .dcm) nothing happens.

is this the right approach to change the slice to go inside the children and change the texture?

or shall i load the selected slice seperate as an object and apply it to the "lower-quality-volume" somehow?


edit: this is what i tried so far (i get errors with dcms but not with jpgs):

if (event.keyCode == 83) {  // "s"-button
    volume.children[2].children[0].children[0].texture.file = "http://localhost:3000/112.jpg";
    volume.children[2].children[0].children[0].modified();
    r.render();
}

edit2: this is whats in my r.onShowtime = function() {}

volume.children[2].children[0].texture.file = 'http://localhost:3000/112.jpg';
volume.children[2].children[0].visible = true; // to activate the first layer
volume.children[2].children[0].modified();
console.log(volume.children[2].children[0].visible +" "+ volume.children[2].children[0].texture.file);

it outputs "true hostname/112.jpg"

when i inspect the .jpg in firebug the header is ok but the answer is "null"

when i inspect console.log(volume.children[2].children[0]); with firebug

.texture.file is set to hostname/112.jpg

when i go to "network" the .jpg has been transfered successfully

enter image description here

enter image description here


enter image description here

please notice that 112.jpg and level.jpg are the same. the first one is getting loaded in r.onShowtime and the other one is loaded at a keypressed event.


EDIT 3: volume.children[2].children[0] is of the type "X.slice", isn't it?

here is my approach: jsFiddle

and this is my actual issue and still not working: jsFiddle

p0rter
  • 961
  • 2
  • 13
  • 28
  • why is the answer "null"? i can click on the link and the image appears. do i have to wait for an image-loaded-event or something? – p0rter Jun 19 '12 at 14:30
  • alright i tried to bind it to an image.onload like here: http://stackoverflow.com/questions/5933230/javascript-image-onload but it didn't change the behavior – p0rter Jun 20 '12 at 13:55

1 Answers1

1

Mhh..

I think a call to object.modified() is missing in the file setter (and in others setters from inject classes). Let's see when Haehn will come if he wants to change something internaly, but for the moment could you try to call it by yourself ?

You can try to add after the modification of texture :

volume.children[2].children[0].children[0].modified();

And if it doesn't work, in addition :

renderer.render();

Edit : It's strange, I did a similar code and it did something. Can you please try something like that with opening your javascript console (Firefox, Chrome,... has one) and tell me the error you get ?

 renderer.onShowtime = {
   for (var i=0 ; i< volume.children[2].children.length ; i++) {
     volume.children[2].children[i].texture.file="myimage.jpeg";
     volume.children[2].children[i].modified();
   }
 }

It is important you call it in the onShowtime, because before the volume is not loaded, and so slicesX, slicesY... don't exist.

Edit2 : Hey,

Thanks to the informations you added I think I've got the point ! In the render() method of our renderer3D there is a test on texture._dirty flag, that you cannot change from outside the framework. In addition the 1st rendering with a texture make that flag false, and loading a new texture doesn't seem to set that flag back to true in the current XTK. So, I think, we have to add it in the loader.load(texture, object) method. I'll make an issue on Github and see what Haehn thinks of it !

Ricola3D
  • 2,402
  • 17
  • 16
  • thank you. i added it to my code but it did not change the texture/slice. – p0rter Jun 19 '12 at 11:38
  • 1
    actually i don't understand why there is another ".children"-array. there is volume -> axis -> slice. so according to that i have to change the texture in **volume.children[2].children[0]** don't i? but that didn't work either... – p0rter Jun 19 '12 at 12:35
  • 1
    The 3rd call to children actualy calls the borders of the slice : Volume>axis>slice>borders. See my post edit, I need more informations ! – Ricola3D Jun 19 '12 at 14:01
  • could it be possible that there is no setter for .texture? would adding a setter close my issue? http://api.goxtk.com/slice.html – p0rter Jun 19 '12 at 14:47
  • About Edit2 : Mhh.. The XTK loader uses an XHR (XMLHttpRequest) to get the file from the server, and there is a same origin policy for such requests by default. Unfortunately Firefox just blocks the response (and says exactly what you wrote, no error), do you have any other browser to test it ? For example Chrome is far more explicit. But it is strange, X.loader should throw an error "Loading failed"... Are you running your tests in localhost ? With wamp or equivalent ? – Ricola3D Jun 20 '12 at 09:59
  • same issue. i'm running ruby w rails on my localhost and i always test with firebug and in chrome. i provided a screenshot of chrome network console and two screens of firebug... – p0rter Jun 20 '12 at 11:16
  • could you please show a working example where you can apply e.g. a .jpg to a slice? jsfiddle or something? that would be awesome because by now i really dont't know what i'm doing wrong! – p0rter Jun 20 '12 at 11:28
  • wow thank's alot...it would be really great if you could change this because it's the most important step for my work at the moment. thanks for your support! – p0rter Jun 20 '12 at 15:27
  • guys, it makes me really happy that you guys are studying the internals, find bugs and enable features!! I can look at it also next week when I am back from vacay. – haehn Jun 21 '12 at 22:53
  • I merged the pull request from @Ricola3D but it seems not to make it work. Any comments? – haehn Jun 25 '12 at 17:58
  • i can say it has nothing do to with the XHR (or same origin policy). if it is possible to render a cube and texture it, where is the difference to a single slice? the volume contains many "slices". and the slice has the same property for texture like the cube. (see my EDIT3) – p0rter Jun 26 '12 at 13:02
  • here is the solution: https://github.com/xtk/X/commit/131cb894e271a606f0e5c546e648c9d49c1ea494 – p0rter Aug 21 '12 at 09:12