diff --git a/core/texture.js b/core/texture.js index 5f1100d34..b42ec8553 100644 --- a/core/texture.js +++ b/core/texture.js @@ -104,6 +104,8 @@ X.texture = function() { * @protected */ this._grayscale = false; + + this._needs_update = false; // inject functionality inject(this, new X.loadable()); // this object is loadable from a file @@ -113,6 +115,19 @@ X.texture = function() { goog.inherits(X.texture, X.base); +/** + * Get the raw data of this texture. + * + * @return {?Object} The raw data array (Uint8Array). + */ +X.texture.prototype.__defineGetter__('rawData', function() { + + return this._rawData; + +}); + + + /** * Set the raw data of this texture. * @@ -168,4 +183,14 @@ X.texture.prototype.__defineSetter__('grayscale', function(grayscale) { }); +X.texture.prototype.updateTexture = function(data) { + + this._rawData = data; + this._needs_update = true; + + this._dirty = true; + +}; + goog.exportSymbol('X.texture', X.texture); +goog.exportSymbol('X.texture.prototype.updateTexture', X.texture.prototype.updateTexture); diff --git a/io/interactor.js b/io/interactor.js index 96c110a40..d0318092b 100644 --- a/io/interactor.js +++ b/io/interactor.js @@ -363,17 +363,17 @@ X.interactor.prototype.init = function() { this._element.oncontextmenu = null; } - if (this._config['KEYBOARD_ENABLED']) { + // if (this._config['KEYBOARD_ENABLED']) { - // the google closure way did not work, so let's do it this way.. - window.onkeydown = this.onKey_.bind(this); + // // the google closure way did not work, so let's do it this way.. + // window.onkeydown = this.onKey_.bind(this); - } else { + // } else { - // remove the keyboard observer - window.onkeydown = null; + // // remove the keyboard observer + // window.onkeydown = null; - } + // } // touch events if (this._config['TOUCH_ENABLED']) { @@ -561,13 +561,13 @@ X.interactor.prototype.onMouseMovementOutside_ = function(event) { // reset the click flags this._mouseInside = false; - if (this._config['KEYBOARD_ENABLED']) { + // if (this._config['KEYBOARD_ENABLED']) { - // if we observe the keyboard, remove the observer here - // this is necessary if there are more than one renderer in the document - window.onkeydown = null; + // // if we observe the keyboard, remove the observer here + // // this is necessary if there are more than one renderer in the document + // window.onkeydown = null; - } + // } this._leftButtonDown = false; this._middleButtonDown = false; @@ -940,13 +940,13 @@ X.interactor.prototype.onMouseMovementInside_ = function(event) { this._mouseInside = true; - if (this._config['KEYBOARD_ENABLED'] && window.onkeydown == null) { + // if (this._config['KEYBOARD_ENABLED'] && window.onkeydown == null) { - // we re-gained the focus, enable the keyboard observer again! - window.onkeydown = this.onKey_.bind(this); + // // we re-gained the focus, enable the keyboard observer again! + // window.onkeydown = this.onKey_.bind(this); - } + // } // prevent any other actions by the browser (f.e. scrolling, selection..) event.preventDefault(); diff --git a/io/parser.js b/io/parser.js index 3dbce8e22..d7174311a 100644 --- a/io/parser.js +++ b/io/parser.js @@ -830,11 +830,11 @@ X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color var _resX = _sliceXYSpacing[0]; var _resY = _sliceXYSpacing[1]; - var _epsilon = 0.0000001; + var _epsilon = 0.000;//0001; // How many pixels are we expecting the raw data - var _cswidth = Math.ceil(_swidth/_resX); - var _csheight = Math.ceil(_sheight/_resY); + var _cswidth = Math.ceil(_swidth/_resX)+1; + var _csheight = Math.ceil(_sheight/_resY)+1; var _csize = _cswidth*_csheight; var textureSize = 4 * _csize; @@ -910,8 +910,15 @@ X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color pixelValue_b = 255 * lookupValue[3]; pixelValue_a = 255 * lookupValue[4]; - } - else { + } else if(object._32bit) { + + // 32 bit textures + pixelValue_r = pixval[0]; + pixelValue_g = pixval[1]; + pixelValue_b = pixval[2]; + pixelValue_a = pixval[3]; + + } else { pixelValue_r = pixelValue_g = pixelValue_b = 255 * (pixval / object._max); pixelValue_a = 255; @@ -1118,7 +1125,7 @@ X.parser.prototype.updateSliceInfo = function(_index, _sliceOrigin, _sliceNormal * object The X.volume to fill. * @return {!Array} The volume data as a 3D Array. */ -X.parser.prototype.reslice = function(object) { +X.parser.prototype.reslice_old = function(object) { // ------------------------------------------ // CREATE IJK VOLUMES @@ -1126,13 +1133,16 @@ X.parser.prototype.reslice = function(object) { // Step 1: create 2 IJK volumes // 1 full res, 1 normalized [0-255] - - var _IJKVolumes = X.parser.createIJKVolume(object._data, object._dimensions, object._max); + // if (object._32bit) { + // var _IJKVolumes = X.parser.createIJKVolume32(object._data, object._dimensions, object._max); + // } else { + // var _IJKVolumes = X.parser.createIJKVolume(object._data, object._dimensions, object._max); + // real volume - object._IJKVolume = _IJKVolumes[0]; - // normalized volume - object._IJKVolumeN = _IJKVolumes[1]; - X.TIMER(this._classname + '.reslice'); + // object._IJKVolume = _IJKVolumes[0]; + // // normalized volume + // object._IJKVolumeN = _IJKVolumes[1]; + X.TIMER(this._classname + '.reslice_old'); // ------------------------------------------ // SETUP LABEL MAPS AND COLOR TABLES @@ -1196,16 +1206,16 @@ X.parser.prototype.reslice = function(object) { _sliceOrigin[1] = object._childrenInfo[0]._solutionsLine[0][0][1] + object._childrenInfo[0]._sliceDirection[1]*Math.floor(object._childrenInfo[0]._nb/2); _sliceOrigin[2] = object._childrenInfo[0]._solutionsLine[0][0][2] + object._childrenInfo[0]._sliceDirection[2]*Math.floor(object._childrenInfo[0]._nb/2); - var _slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[0]._sliceXYSpacing, object._childrenInfo[0]._sliceNormal, object._childrenInfo[0]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable); + //var _slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[0]._sliceXYSpacing, object._childrenInfo[0]._sliceNormal, object._childrenInfo[0]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable); if (object.hasLabelMap) { // if this object has a labelmap, // we have it loaded at this point (for sure) // ..so we can attach it as the second texture to this slice - _slice._labelmap = object._labelmap._children[0]._children[Math.floor(object._childrenInfo[0]._nb/2)]._texture; + //_slice._labelmap = object._labelmap._children[0]._children[Math.floor(object._childrenInfo[0]._nb/2)]._texture; } - object._children[0]._children[Math.floor(object._childrenInfo[0]._nb/2)] = _slice; + //object._children[0]._children[Math.floor(object._childrenInfo[0]._nb/2)] = _slice; object._indexX = Math.floor(object._childrenInfo[0]._nb/2); object._indexXold = Math.floor(object._childrenInfo[0]._nb/2); @@ -1243,16 +1253,16 @@ X.parser.prototype.reslice = function(object) { _sliceOrigin[1] = object._childrenInfo[1]._solutionsLine[0][0][1] + object._childrenInfo[1]._sliceDirection[1]*Math.floor(object._childrenInfo[1]._nb/2); _sliceOrigin[2] = object._childrenInfo[1]._solutionsLine[0][0][2] + object._childrenInfo[1]._sliceDirection[2]*Math.floor(object._childrenInfo[1]._nb/2); - _slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[1]._sliceXYSpacing, object._childrenInfo[1]._sliceNormal, object._childrenInfo[1]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable); + //_slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[1]._sliceXYSpacing, object._childrenInfo[1]._sliceNormal, object._childrenInfo[1]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable); if (object.hasLabelMap) { // if this object has a labelmap, // we have it loaded at this point (for sure) // ..so we can attach it as the second texture to this slice - _slice._labelmap = object._labelmap._children[1]._children[Math.floor(object._childrenInfo[1]._nb/2)]._texture; + //_slice._labelmap = object._labelmap._children[1]._children[Math.floor(object._childrenInfo[1]._nb/2)]._texture; } - object._children[1]._children[Math.floor(object._childrenInfo[1]._nb/2)] = _slice; + //object._children[1]._children[Math.floor(object._childrenInfo[1]._nb/2)] = _slice; object._indexY = Math.floor(object._childrenInfo[1]._nb/2); object._indexYold = Math.floor(object._childrenInfo[1]._nb/2); @@ -1289,22 +1299,207 @@ X.parser.prototype.reslice = function(object) { _sliceOrigin[1] = object._childrenInfo[2]._solutionsLine[0][0][1] + object._childrenInfo[2]._sliceDirection[1]*Math.floor(object._childrenInfo[2]._nb/2); _sliceOrigin[2] = object._childrenInfo[2]._solutionsLine[0][0][2] + object._childrenInfo[2]._sliceDirection[2]*Math.floor(object._childrenInfo[2]._nb/2); - _slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[2]._sliceXYSpacing, object._childrenInfo[2]._sliceNormal, object._childrenInfo[2]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable); + //_slice = X.parser.reslice2(_sliceOrigin, object._childrenInfo[2]._sliceXYSpacing, object._childrenInfo[2]._sliceNormal, object._childrenInfo[2]._color, object._BBox, object._IJKVolume, object, object.hasLabelMap, object._colorTable); if (object.hasLabelMap) { // if this object has a labelmap, // we have it loaded at this point (for sure) // ..so we can attach it as the second texture to this slice - _slice._labelmap = object._labelmap._children[2]._children[Math.floor(object._childrenInfo[2]._nb/2)]._texture; + //_slice._labelmap = object._labelmap._children[2]._children[Math.floor(object._childrenInfo[2]._nb/2)]._texture; } - object._children[2]._children[Math.floor(object._childrenInfo[2]._nb/2)] = _slice; + //object._children[2]._children[Math.floor(object._childrenInfo[2]._nb/2)] = _slice; object._indexZ = Math.floor(object._childrenInfo[2]._nb/2); object._indexZold = Math.floor(object._childrenInfo[2]._nb/2); - X.TIMERSTOP(this._classname + '.reslice'); + + if (object._indexZ % 2 != 0) { + object._indexZ -= 1; + object._indexZold -= 1; + } + + X.TIMERSTOP(this._classname + '.reslice_old'); - return object._IJKVolume; + //return object._IJKVolume; }; +X.parser.prototype.reslice = function(object) { + + X.TIMER(this._classname + '.reslice'); + + var data = object._data; + + var bytes_per_value = object._32bit ? 4 : 1; + + var grayscale = (bytes_per_value == 1); + + var dim_x = object._dimensions[0]; + var dim_y = object._dimensions[1]; + var dim_z = object._dimensions[2]; + + var texture_dim_x = dim_x; + var texture_dim_y = dim_y; + var texture_dim_z = dim_z; + + var x_y_sample_rate = object._x_y_sample_rate; + var z_sample_rate = object._z_sample_rate; + + // if (!grayscale) { + // var texture_dim_x = Math.pow(2,Math.ceil(Math.log(dim_x)/Math.log(2))); + // var texture_dim_y = Math.pow(2,Math.ceil(Math.log(dim_y)/Math.log(2))); + // var texture_dim_z = Math.pow(2,Math.ceil(Math.log(dim_z)/Math.log(2))); + // } + + var spacing_x = object._spacing[0]; + var spacing_y = object._spacing[1]; + var spacing_z = object._spacing[2]; + + var data_length = dim_x * dim_y * dim_z * bytes_per_value; + + var nb_pix_per_z = dim_x * dim_y; + + var slices_x = new Array(dim_x); + var slices_y = new Array(dim_y); + var slices_z = new Array(dim_z); + + var labelmap = object._labelmap; + + // allocate slices x y z + for (var x=0; x