UNPKG

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>

155 lines (124 loc) 6.13 kB
'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 _shadersVr = require('../shaders/shaders.vr.uniform'); var _shadersVr2 = _interopRequireDefault(_shadersVr); var _shadersVr3 = require('../shaders/shaders.vr.vertex'); var _shadersVr4 = _interopRequireDefault(_shadersVr3); var _shadersVr5 = require('../shaders/shaders.vr.fragment'); var _shadersVr6 = _interopRequireDefault(_shadersVr5); 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/volumerendering */ var HelpersVolumeRendering = function (_HelpersMaterialMixin) { _inherits(HelpersVolumeRendering, _HelpersMaterialMixin); function HelpersVolumeRendering(stack) { _classCallCheck(this, HelpersVolumeRendering); var _this = _possibleConstructorReturn(this, (HelpersVolumeRendering.__proto__ || Object.getPrototypeOf(HelpersVolumeRendering)).call(this)); // _this._stack = stack; _this._textures = []; _this._shadersFragment = _shadersVr6.default; _this._shadersVertex = _shadersVr4.default; _this._uniforms = _shadersVr2.default.uniforms(); _this._material = null; _this._geometry = null; _this._interpolation = 1; // default to trilinear interpolation _this._create(); return _this; } _createClass(HelpersVolumeRendering, [{ key: '_create', value: function _create() { this._prepareStack(); this._prepareTexture(); this._prepareMaterial(); this._prepareGeometry(); this._mesh = new THREE.Mesh(this._geometry, this._material); this.add(this._mesh); } }, { key: '_prepareStack', value: function _prepareStack() { if (!this._stack.prepared) { this._stack.prepare(); } if (!this._stack.packed) { this._stack.pack(); } } }, { key: '_prepareMaterial', value: function _prepareMaterial() { // 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]; } // uniforms this._uniforms = _shadersVr2.default.uniforms(); this._uniforms.uWorldBBox.value = this._stack.worldBoundingBox(); this._uniforms.uTextureSize.value = this._stack.textureSize; this._uniforms.uTextureContainer.value = this._textures; 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; this._uniforms.uWindowCenterWidth.value = [offset + this._stack.windowCenter, this._stack.windowWidth * 0.8]; this._uniforms.uRescaleSlopeIntercept.value = [this._stack.rescaleSlope, this._stack.rescaleIntercept]; this._uniforms.uDataDimensions.value = [this._stack.dimensionsIJK.x, this._stack.dimensionsIJK.y, this._stack.dimensionsIJK.z]; this._uniforms.uInterpolation.value = this._interpolation; this._createMaterial({ side: THREE.FrontSide, transparent: true }); } }, { key: '_prepareGeometry', value: function _prepareGeometry() { var worldBBox = this._stack.worldBoundingBox(); var centerLPS = this._stack.worldCenter(); this._geometry = new THREE.BoxGeometry(worldBBox[1] - worldBBox[0], worldBBox[3] - worldBBox[2], worldBBox[5] - worldBBox[4]); this._geometry.applyMatrix(new THREE.Matrix4().makeTranslation(centerLPS.x, centerLPS.y, centerLPS.z)); } }, { key: 'uniforms', get: function get() { return this._uniforms; }, set: function set(uniforms) { this._uniforms = uniforms; } }, { key: 'stack', get: function get() { return this._stack; }, set: function set(stack) { this._stack = stack; } }, { key: 'interpolation', get: function get() { return this._interpolation; }, set: function set(interpolation) { this._interpolation = interpolation; this._uniforms.uInterpolation.value = this._interpolation; this._updateMaterial(); } }]); return HelpersVolumeRendering; }((0, _helpersMaterial2.default)(THREE.Object3D)); exports.default = HelpersVolumeRendering; module.exports = exports['default'];