ami-cjs.js
Version:
<p align="center"> <img src="https://cloud.githubusercontent.com/assets/214063/23213764/78ade038-f90c-11e6-8208-4fcade5f3832.png" width="60%"> </p>
474 lines (419 loc) • 15.1 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _geometries = require('../geometries/geometries.slice');
var _geometries2 = _interopRequireDefault(_geometries);
var _shadersData = require('../shaders/shaders.data.uniform');
var _shadersData2 = _interopRequireDefault(_shadersData);
var _shadersData3 = require('../shaders/shaders.data.vertex');
var _shadersData4 = _interopRequireDefault(_shadersData3);
var _shadersData5 = require('../shaders/shaders.data.fragment');
var _shadersData6 = _interopRequireDefault(_shadersData5);
var _helpersMaterial = require('../helpers/helpers.material.mixin');
var _helpersMaterial2 = _interopRequireDefault(_helpersMaterial);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** * Imports ***/
/**
* @module helpers/slice
*/
var HelpersSlice = function (_HelpersMaterialMixin) {
_inherits(HelpersSlice, _HelpersMaterialMixin);
function HelpersSlice(stack) {
var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var position = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new THREE.Vector3(0, 0, 0);
var direction = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new THREE.Vector3(0, 0, 1);
var aabbSpace = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'IJK';
_classCallCheck(this, HelpersSlice);
// private vars
var _this = _possibleConstructorReturn(this, (HelpersSlice.__proto__ || Object.getPrototypeOf(HelpersSlice)).call(this));
//
_this._stack = stack;
// image settings
// index only used to grab window/level and intercept/slope
_this._invert = _this._stack.invert;
_this._lut = 'none';
_this._lutTexture = null;
// if auto === true, get from index
// else from stack which holds the default values
_this._intensityAuto = true;
_this._interpolation = 1; // default to trilinear interpolation
// starts at 0
_this._index = index;
_this._windowWidth = null;
_this._windowCenter = null;
_this._rescaleSlope = null;
_this._rescaleIntercept = null;
_this._canvasWidth = 0;
_this._canvasHeight = 0;
_this._borderColor = null;
// Object3D settings
// shape
_this._planePosition = position;
_this._planeDirection = direction;
// change aaBBSpace changes the box dimensions
// also changes the transform
// there is also a switch to move back mesh to LPS space automatically
_this._aaBBspace = aabbSpace; // or LPS -> different transforms, esp for the geometry/mesh
_this._material = null;
_this._textures = [];
_this._shadersFragment = _shadersData6.default;
_this._shadersVertex = _shadersData4.default;
_this._uniforms = _shadersData2.default.uniforms();
_this._geometry = null;
_this._mesh = null;
_this._visible = true;
// update dimensions, center, etc.
// depending on aaBBSpace
_this._init();
// update object
_this._create();
return _this;
}
// getters/setters
_createClass(HelpersSlice, [{
key: '_init',
value: function _init() {
if (!this._stack || !this._stack._prepared || !this._stack._packed) {
return;
}
if (this._aaBBspace === 'IJK') {
this._halfDimensions = this._stack.halfDimensionsIJK;
this._center = new THREE.Vector3(this._stack.halfDimensionsIJK.x - 0.5, this._stack.halfDimensionsIJK.y - 0.5, this._stack.halfDimensionsIJK.z - 0.5);
this._toAABB = new THREE.Matrix4();
} else {
// LPS
var aaBBox = this._stack.AABBox();
this._halfDimensions = aaBBox.clone().multiplyScalar(0.5);
this._center = this._stack.centerAABBox();
this._toAABB = this._stack.lps2AABB;
}
}
// private methods
}, {
key: '_create',
value: function _create() {
if (!this._stack || !this._stack.prepared || !this._stack.packed) {
return;
}
// Convenience vars
try {
this._geometry = new _geometries2.default(this._halfDimensions, this._center, this._planePosition, this._planeDirection, this._toAABB);
} catch (e) {
window.console.log(e);
window.console.log('invalid slice geometry - exiting...');
return;
}
if (!this._geometry.vertices) {
return;
}
if (!this._material) {
//
this._uniforms.uTextureSize.value = this._stack.textureSize;
this._uniforms.uDataDimensions.value = [this._stack.dimensionsIJK.x, this._stack.dimensionsIJK.y, this._stack.dimensionsIJK.z];
this._uniforms.uWorldToData.value = this._stack.lps2IJK;
this._uniforms.uNumberOfChannels.value = this._stack.numberOfChannels;
this._uniforms.uPixelType.value = this._stack.pixelType;
this._uniforms.uBitsAllocated.value = this._stack.bitsAllocated;
this._uniforms.uPackedPerPixel.value = this._stack.packedPerPixel;
// compute texture if material exist
this._prepareTexture();
this._uniforms.uTextureContainer.value = this._textures;
this._createMaterial({
side: THREE.DoubleSide
});
}
// update intensity related stuff
this.updateIntensitySettings();
this.updateIntensitySettingsUniforms();
// create the mesh!
this._mesh = new THREE.Mesh(this._geometry, this._material);
if (this._aaBBspace === 'IJK') {
this._mesh.applyMatrix(this._stack.ijk2LPS);
}
this._mesh.visible = this._visible;
// and add it!
this.add(this._mesh);
}
}, {
key: 'updateIntensitySettings',
value: function updateIntensitySettings() {
// if auto, get from frame index
if (this._intensityAuto) {
this.updateIntensitySetting('windowCenter');
this.updateIntensitySetting('windowWidth');
this.updateIntensitySetting('rescaleSlope');
this.updateIntensitySetting('rescaleIntercept');
} else {
if (this._windowCenter === null) {
this._windowCenter = this._stack.windowCenter;
}
if (this.__windowWidth === null) {
this._windowWidth = this._stack.windowWidth;
}
if (this._rescaleSlope === null) {
this._rescaleSlope = this._stack.rescaleSlope;
}
if (this._rescaleIntercept === null) {
this._rescaleIntercept = this._stack.rescaleIntercept;
}
}
}
}, {
key: 'updateIntensitySettingsUniforms',
value: function updateIntensitySettingsUniforms() {
// compensate for the offset to only pass > 0 values to shaders
// models > models.stack.js : _packTo8Bits
var offset = 0;
if (this._stack._minMax[0] < 0) {
offset -= this._stack._minMax[0];
}
// set slice window center and width
this._uniforms.uRescaleSlopeIntercept.value = [this._rescaleSlope, this._rescaleIntercept];
this._uniforms.uWindowCenterWidth.value = [offset + this._windowCenter, this._windowWidth];
// invert
this._uniforms.uInvert.value = this._invert === true ? 1 : 0;
// interpolation
this._uniforms.uInterpolation.value = this._interpolation;
// lut
if (this._lut === 'none') {
this._uniforms.uLut.value = 0;
} else {
this._uniforms.uLut.value = 1;
this._uniforms.uTextureLUT.value = this._lutTexture;
}
}
}, {
key: 'updateIntensitySetting',
value: function updateIntensitySetting(setting) {
if (this._stack.frame[this._index] && this._stack.frame[this._index][setting]) {
this['_' + setting] = this._stack.frame[this._index][setting];
} else {
this['_' + setting] = this._stack[setting];
}
}
}, {
key: '_update',
value: function _update() {
// update slice
if (this._mesh) {
this.remove(this._mesh);
this._mesh.geometry.dispose();
this._mesh.geometry = null;
// we do not want to dispose the texture!
// this._mesh.material.dispose();
// this._mesh.material = null;
this._mesh = null;
}
this._create();
}
}, {
key: 'cartesianEquation',
value: function cartesianEquation() {
// Make sure we have a geometry
if (!this._geometry || !this._geometry.vertices || this._geometry.vertices.length < 3) {
return new THREE.Vector4();
}
var vertices = this._geometry.vertices;
var dataToWorld = this._stack.ijk2LPS;
var p1 = new THREE.Vector3(vertices[0].x, vertices[0].y, vertices[0].z).applyMatrix4(dataToWorld);
var p2 = new THREE.Vector3(vertices[1].x, vertices[1].y, vertices[1].z).applyMatrix4(dataToWorld);
var p3 = new THREE.Vector3(vertices[2].x, vertices[2].y, vertices[2].z).applyMatrix4(dataToWorld);
var v1 = new THREE.Vector3();
var v2 = new THREE.Vector3();
var normal = v1.subVectors(p3, p2).cross(v2.subVectors(p1, p2)).normalize();
return new THREE.Vector4(normal.x, normal.y, normal.z, -normal.dot(p1));
}
}, {
key: 'stack',
get: function get() {
return this._stack;
},
set: function set(stack) {
this._stack = stack;
}
}, {
key: 'windowWidth',
get: function get() {
return this._windowWidth;
},
set: function set(windowWidth) {
this._windowWidth = windowWidth;
this.updateIntensitySettingsUniforms();
}
}, {
key: 'windowCenter',
get: function get() {
return this._windowCenter;
},
set: function set(windowCenter) {
this._windowCenter = windowCenter;
this.updateIntensitySettingsUniforms();
}
}, {
key: 'rescaleSlope',
get: function get() {
return this._rescaleSlope;
},
set: function set(rescaleSlope) {
this._rescaleSlope = rescaleSlope;
this.updateIntensitySettingsUniforms();
}
}, {
key: 'rescaleIntercept',
get: function get() {
return this._rescaleIntercept;
},
set: function set(rescaleIntercept) {
this._rescaleIntercept = rescaleIntercept;
this.updateIntensitySettingsUniforms();
}
}, {
key: 'invert',
get: function get() {
return this._invert;
},
set: function set(invert) {
this._invert = invert;
this.updateIntensitySettingsUniforms();
}
}, {
key: 'lut',
get: function get() {
return this._lut;
},
set: function set(lut) {
this._lut = lut;
}
}, {
key: 'lutTexture',
get: function get() {
return this._lutTexture;
},
set: function set(lutTexture) {
this._lutTexture = lutTexture;
this.updateIntensitySettingsUniforms();
}
}, {
key: 'intensityAuto',
get: function get() {
return this._intensityAuto;
},
set: function set(intensityAuto) {
this._intensityAuto = intensityAuto;
this.updateIntensitySettings();
this.updateIntensitySettingsUniforms();
}
}, {
key: 'interpolation',
get: function get() {
return this._interpolation;
},
set: function set(interpolation) {
this._interpolation = interpolation;
this.updateIntensitySettingsUniforms();
this._updateMaterial();
}
}, {
key: 'index',
get: function get() {
return this._index;
},
set: function set(index) {
this._index = index;
this._update();
}
}, {
key: 'planePosition',
set: function set(position) {
this._planePosition = position;
this._update();
},
get: function get() {
return this._planePosition;
}
}, {
key: 'planeDirection',
set: function set(direction) {
this._planeDirection = direction;
this._update();
},
get: function get() {
return this._planeDirection;
}
}, {
key: 'halfDimensions',
set: function set(halfDimensions) {
this._halfDimensions = halfDimensions;
},
get: function get() {
return this._halfDimensions;
}
}, {
key: 'center',
set: function set(center) {
this._center = center;
},
get: function get() {
return this._center;
}
}, {
key: 'aabbSpace',
set: function set(aabbSpace) {
this._aaBBspace = aabbSpace;
this._init();
},
get: function get() {
return this._aaBBspace;
}
}, {
key: 'mesh',
set: function set(mesh) {
this._mesh = mesh;
},
get: function get() {
return this._mesh;
}
}, {
key: 'geometry',
set: function set(geometry) {
this._geometry = geometry;
},
get: function get() {
return this._geometry;
}
}, {
key: 'canvasWidth',
set: function set(canvasWidth) {
this._canvasWidth = canvasWidth;
this._uniforms.uCanvasWidth.value = this._canvasWidth;
},
get: function get() {
return this._canvasWidth;
}
}, {
key: 'canvasHeight',
set: function set(canvasHeight) {
this._canvasHeight = canvasHeight;
this._uniforms.uCanvasHeight.value = this._canvasHeight;
},
get: function get() {
return this._canvasHeight;
}
}, {
key: 'borderColor',
set: function set(borderColor) {
this._borderColor = borderColor;
this._uniforms.uBorderColor.value = new THREE.Color(borderColor);
},
get: function get() {
return this._borderColor;
}
}]);
return HelpersSlice;
}((0, _helpersMaterial2.default)(THREE.Object3D));
exports.default = HelpersSlice;
module.exports = exports['default'];