Permalink
Browse files

* support negative value

* new resolutionFactor on volume to increase resolution of slices
(hack-ish)
* hide mouse pointer on 2D picking since it is misleading
(tip of cursor is not real picking location)
* fix compilation warnings from merge
  • Loading branch information...
NicolasRannou committed Jan 14, 2015
1 parent 3d01acc commit 4040f0e4201bba1ffe80ee81e4086ce0de0213c5
Showing with 72 additions and 47 deletions.
  1. +22 −15 io/parser.js
  2. +2 −9 io/parserNII.js
  3. +37 −3 objects/volume.js
  4. +9 −18 visualization/renderer2D.js
  5. +2 −2 visualization/shaders.js
View
@@ -770,6 +770,7 @@ X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color
// GET INTERSECTION BOUNDING BOX/PLANE
// ------------------------------------------
//_bbox is only this slice bounding box
var _solutions = X.parser.intersectionBBoxPlane(_bbox,_sliceOrigin, _sliceNormal);
var _solutionsIn = _solutions[0];
@@ -808,11 +809,11 @@ X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color
var _RASCenter = goog.vec.Vec4.createFloat32();
goog.vec.Mat4.multMat(_XYToRAS,_xyCenter, _RASCenter);
// var _wmin = Math.floor(_xyBBox[0]);
// var _wmax = Math.ceil(_xyBBox[1]);
window.console.log(_xyBBox);
var _wmin = _xyBBox[0];
var _wmax = _xyBBox[1];
var _wmin = Math.floor(_xyBBox[0]);
var _wmax = Math.ceil(_xyBBox[1]);
// window.console.log(_xyBBox);
// var _wmin = _xyBBox[0];
// var _wmax = _xyBBox[1];
// if the slice only has to intersections with the volume BBox
// (can happens if the slice is right on the edge of the volume)
@@ -824,10 +825,11 @@ X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color
var _swidth = _wmax - _wmin;
// var _hmin = Math.floor(_xyBBox[2]);
// var _hmax = Math.ceil(_xyBBox[3]);
var _hmin = _xyBBox[2];
var _hmax = _xyBBox[3];
var _hmin = Math.floor(_xyBBox[2]);
var _hmax = Math.ceil(_xyBBox[3]);
// var _hmin = _xyBBox[2];
// var _hmax = _xyBBox[3];
// if the slice only has to intersections with the volume BBox
// (can happens if the slice is right on the edge of the volume)
if(_hmin == _hmax){
@@ -841,6 +843,7 @@ X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color
var _resX = _sliceXYSpacing[0];
var _resY = _sliceXYSpacing[1];
// not sure why?
var _epsilon = 0.0000001;
// How many pixels are we expecting the raw data
@@ -897,8 +900,6 @@ X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color
(0 <= _k) && (_k < object._dimensions[2] )) {
// map to 0 if necessary
var pixval = _IJKVolume[_k][_j][_i];
var pixelValue_r = 0;
var pixelValue_g = 0;
@@ -967,6 +968,7 @@ X.parser.reslice2 = function(_sliceOrigin, _sliceXYSpacing, _sliceNormal, _color
sliceXY._heightSpacing = _resY;
sliceXY._height = _sheight;
sliceXY._center = [_RASCenter[0], _RASCenter[1], _RASCenter[2]];
// ADD SPACING OFFSET to center so it matches meshes/tracts perfectly
sliceXY._front = [_sliceNormal[0], _sliceNormal[1], _sliceNormal[2]];
sliceXY._right= [_rright[0], _rright[1], _rright[2]];
sliceXY._up = [_rup[0], _rup[1], _rup[2]];
@@ -1045,14 +1047,19 @@ X.parser.prototype.updateSliceInfo = function(_index, _sliceOrigin, _sliceNormal
// scale
goog.vec.Vec4.scale(_sliceNormal,_xySpacing[2],_sliceDirection);
if(Math.abs(_xySpacing[0]) < 0.5){
_xySpacing[0] = 0.5;
// by default the minimum in plane spacing is 0.1
if(Math.abs(_xySpacing[0]) < 0.1){
_xySpacing[0] = 0.1;
}
if(Math.abs(_xySpacing[1]) < 0.5){
_xySpacing[1] = 0.5;
if(Math.abs(_xySpacing[1]) < 0.1){
_xySpacing[1] = 0.1;
}
// increase resolution if needed
_xySpacing[0] /= object._resolutionFactor;
_xySpacing[1] /= object._resolutionFactor;
object._childrenInfo[_index]._sliceXYSpacing = [Math.abs(_xySpacing[0]), Math.abs(_xySpacing[1])];
object._childrenInfo[_index]._sliceSpacing = _xySpacing[2];
object._childrenInfo[_index]._sliceDirection = _sliceDirection;
View
@@ -79,11 +79,9 @@ X.parserNII.prototype.parse = function(container, object, data, flag) {
try {
// first, try to decompress the datastream
// here we start the unzipping and get a typed Uint8Array back
var inflate = new Zlib.Gunzip(new Uint8Array(_data));
_data = inflate.decompress();
// .. and use the underlying array buffer
_data = _data.buffer;
var inflate = new Zlib.Gunzip(new Uint8Array(_data));
_data = inflate.decompress().buffer;
// check endianness
if (!this.verifyNII(_data)) {
@@ -102,8 +100,6 @@ X.parserNII.prototype.parse = function(container, object, data, flag) {
// grab the min, max intensities
var min = MRI.min;
var max = MRI.max;
window.console.log(min);
window.console.log(max);
// attach the scalar range to the volume
object._min = object._windowLow = min;
@@ -487,12 +483,9 @@ X.parserNII.prototype.parseStream = function(data) {
}
// get the min and max intensities
window.console.log(MRI.data);
var min_max = this.arrayMinMax(MRI.data);
MRI.min = min_max[0];
MRI.max = min_max[1];
window.console.log(min_max[0]);
window.console.log(min_max[1]);
return MRI;
View
@@ -256,6 +256,16 @@ X.volume = function(volume) {
*/
this._reslicing = true;
/**
* The resolution factor.
* It lets us artificialy increasing the resolution of the slice,
* by decreasing the in slice spacing.
*
* @type {!number}
* @protected
*/
this._resolutionFactor = 1;
/**
* The max intensity in the image
*
@@ -1069,9 +1079,7 @@ X.volume.prototype.__defineGetter__('reslicing', function() {
/**
* Set the borders flag. Must be called before the volume gets created
* internally. After that, the borders can be modified using the children of
* each slice.
* Set the reslicing flag for this volume.
*
* @param {boolean}
* reslicing TRUE to enable reslicing, FALSE to disable it.
@@ -1083,6 +1091,32 @@ X.volume.prototype.__defineSetter__('reslicing', function(reslicing) {
});
/**
* Return the resolution factor.
*
* @return {number} Default is 1.
* @public
*/
X.volume.prototype.__defineGetter__('resolutionFactor', function() {
return this._resolutionFactor;
});
/**
* Set the resolution factor for this volume.
* Must be set before the volume is loaded.
*
* @param {number} resolutionFactor Default is 1.
* @public
*/
X.volume.prototype.__defineSetter__('resolutionFactor', function(resolutionFactor) {
this._resolutionFactor = resolutionFactor;
});
/**
* Set value of normal X of slice X.
*
@@ -798,7 +798,6 @@ X.renderer2D.prototype.onSliceNavigation = function() {
*/
X.renderer2D.prototype.xy2ijk = function(x, y) {
window.console.log(x + ' - ' + y);
// un-zoom and un-offset
// there get coordinates in a normla view
@@ -844,11 +843,8 @@ X.renderer2D.prototype.xy2ijk = function(x, y) {
var _y = -1 * _view[13]; // we need to flip y here
// .. and zoom
this._normalizedScale = Math.max(_view[14], 0.6);
var _center = [this._width / 2, this._height / 2];
window.console.log(_center);
// the slice dimensions in canvas coordinates
var _sliceWidthScaled = _sliceWidth * _sliceWSpacing *
this._normalizedScale;
@@ -897,19 +893,15 @@ X.renderer2D.prototype.xy2ijk = function(x, y) {
}
window.console.log(_x + ' - ' + _y);
// map indices to xy coordinates
_x = _currentSlice._wmin + _x*_currentSlice._widthSpacing - _currentSlice._widthSpacing/2;
_y = _currentSlice._hmin + _y*_currentSlice._heightSpacing - _currentSlice._heightSpacing/2;
_x = _currentSlice._wmin + _x*_currentSlice._widthSpacing;// - _currentSlice._widthSpacing/2;
_y = _currentSlice._hmin + _y*_currentSlice._heightSpacing;// - _currentSlice._heightSpacing/2;
var _xyz = goog.vec.Vec4.createFloat32FromValues(_x, _y, _z, 1);
var _ijk = goog.vec.Mat4.createFloat32();
goog.vec.Mat4.multVec4(_currentSlice._XYToIJK, _xyz, _ijk);
window.console.log('IJK');
window.console.log(_currentSlice._widthSpacing);
window.console.log(_currentSlice._heightSpacing);
window.console.log(_ijk[0], _ijk[1], _ijk[2]);
_ijk = [Math.floor(_ijk[0]),Math.floor(_ijk[1]),Math.floor(_ijk[2])];
// why < 0??
var _ras = goog.vec.Mat4.createFloat32();
goog.vec.Mat4.multVec4(_currentSlice._XYToRAS, _xyz, _ras);
@@ -956,9 +948,9 @@ X.renderer2D.prototype.xy2ijk = function(x, y) {
_iz = 0;
}
window.console.log(_dx/_volume._childrenInfo[0]._sliceSpacing);
window.console.log(_dy/_volume._childrenInfo[1]._sliceSpacing);
window.console.log(_dz/_volume._childrenInfo[2]._sliceSpacing);
// window.console.log(_dx/_volume._childrenInfo[0]._sliceSpacing);
// window.console.log(_dy/_volume._childrenInfo[1]._sliceSpacing);
// window.console.log(_dz/_volume._childrenInfo[2]._sliceSpacing);
return [[_ix, _iy, _iz], [_ijk[0], _ijk[1], _ijk[2]], [_ras[0], _ras[1], _ras[2]]];
}
@@ -1009,10 +1001,10 @@ X.renderer2D.prototype.render_ = function(picking, invoked) {
// spacing
this._sliceWidthSpacing = this._slices[parseInt(_currentSlice, 10)]._widthSpacing;
this._sliceHeightSpacing = this._slices[parseInt(_currentSlice, 10)]._heightSpacing;
// .. and store the dimensions
this._sliceWidth = _width2;
this._sliceHeight = _height2;
//
// grab the camera settings
@@ -1031,7 +1023,7 @@ X.renderer2D.prototype.render_ = function(picking, invoked) {
// transform the canvas according to the view matrix
// .. this includes zoom
this._normalizedScale = Math.max(_view[14], 0.1);
this._normalizedScale = Math.max(_view[14], 0.0001);
this._context.setTransform(this._normalizedScale, 0, 0, this._normalizedScale, 0, 0);
@@ -1307,7 +1299,6 @@ X.renderer2D.prototype.render_ = function(picking, invoked) {
// check if we are over the slice
var ijk = this.xy2ijk(_mousePosition[0], _mousePosition[1]);
window.console.log(ijk);
if (ijk) {
// // we are over the slice
View
@@ -242,8 +242,8 @@ X.shaders = function() {
t2 += ' }\n';
// threshold functionality for 1-channel volumes
t2 += ' if (volumeTexture) {\n';
t2 += ' float _volumeLowerThreshold = (volumeLowerThreshold / volumeScalarMax);\n';
t2 += ' float _volumeUpperThreshold = (volumeUpperThreshold / volumeScalarMax);\n';
t2 += ' float _volumeLowerThreshold = (volumeLowerThreshold - volumeScalarMin)/ (volumeScalarMax - volumeScalarMin);\n';
t2 += ' float _volumeUpperThreshold = (volumeUpperThreshold - volumeScalarMin)/ (volumeScalarMax - volumeScalarMin);\n';
t2 += ' if (texture1.r < _volumeLowerThreshold ||\n';
t2 += ' texture1.r > _volumeUpperThreshold ||\n';
t2 += ' texture1.a == 0.0 ) {\n';

0 comments on commit 4040f0e

Please sign in to comment.