问题
I'm using xtk to read remote NIfTI volumes into an application. My sole objective is to obtain a volume object so I can extract its data; I don't need to render anything. The examples I've seen all initialize a renderer and attach a volume before accessing its contents. E.g. (from http://jsfiddle.net/QxMSt/5/):
var r = new X.renderer3D();
r.init();
var v = new X.volume();
v.file = 'http://www.cogitatum.org/mprage003.nii.gz';
r.add(v);
r.render();
r.onShowtime = function() {
r.destroy();
// get the image data
var data = v.image;
}
This works very nicely, but I'd rather not have to go to the trouble of creating a renderer for nothing, and would also prefer not to require WebGL support. Is there any way to initialize the volume and access its properties without rendering? I've looked through the codebase but don't see any place an onLoad() event or comparable is fired at the moment, though X.loader clearly tracks loading completion internally. It looks as though setting the volume's file property is sufficient to trigger volume loading, but I don't see any way to pass a callback function that gets triggered on completion. Any suggestions?
回答1:
Unfortunately this is currently the only solution. The file loading starts when adding the object to the renderer.
To avoid the WebGL requirement, just use a X.renderer2D
.
A separate and generic i/o library externally from XTK is planned and should be available in the next couple of weeks.
回答2:
I also need just the volume information, so what I did is:
var filename = "../data/data.nrrd";
var volume = new X.volume();
volume.file = filename;
var request = new XMLHttpRequest();
request.open("GET", filename, true);
request.responseType = 'arraybuffer';
request.onload=function()
{
var _data = request.response;
volume._filedata = _data;
var loader = new X.loader();
loader.load(volume, volume);
loader.complete = function()
{
volumeImage = volume.image;
// process volumeImage
}
}
request.send(null);
来源:https://stackoverflow.com/questions/16950718/load-volume-in-xtk-without-initializing-a-renderer