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>

394 lines (354 loc) 11.8 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 _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; var _models = require('../models/models.base'); var _models2 = _interopRequireDefault(_models); 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 ***/ /** * Frame object. * * @module models/frame */ var ModelsFrame = function (_ModelsBase) { _inherits(ModelsFrame, _ModelsBase); function ModelsFrame() { _classCallCheck(this, ModelsFrame); var _this = _possibleConstructorReturn(this, (ModelsFrame.__proto__ || Object.getPrototypeOf(ModelsFrame)).call(this)); _this._sopInstanceUID = null; _this._url = null; _this._stackID = -1; _this._rows = 0; _this._columns = 0; _this._dimensionIndexValues = []; _this._imagePosition = null; _this._imageOrientation = null; _this._rightHanded = true; _this._sliceThickness = 1; _this._spacingBetweenSlices = null; _this._pixelRepresentation = 0; _this._pixelType = 0; _this._pixelSpacing = null; _this._pixelAspectRatio = null; _this._pixelData = null; _this._instanceNumber = null; _this._windowCenter = null; _this._windowWidth = null; _this._rescaleSlope = null; _this._rescaleIntercept = null; _this._bitsAllocated = 8; _this._minMax = null; _this._dist = null; _this._index = -1; _this._referencedSegmentNumber = -1; return _this; } _createClass(ModelsFrame, [{ key: 'validate', value: function validate(model) { if (!(_get(ModelsFrame.prototype.__proto__ || Object.getPrototypeOf(ModelsFrame.prototype), 'validate', this).call(this, model) && typeof model.cosines === 'function' && typeof model.spacingXY === 'function' && model.hasOwnProperty('_sopInstanceUID') && model.hasOwnProperty('_dimensionIndexValues') && model.hasOwnProperty('_imageOrientation') && model.hasOwnProperty('_imagePosition'))) { return false; } return true; } /** * Merge current frame with provided frame. * * Frames can be merged (i.e. are identical) if following are equals: * - dimensionIndexValues * - imageOrientation * - imagePosition * - instanceNumber * - sopInstanceUID * * @returns {boolean} True if frames could be merge. False if not. */ }, { key: 'merge', value: function merge(frame) { if (!this.validate(frame)) { return false; } if (this._compareArrays(this._dimensionIndexValues, frame.dimensionIndexValues) && this._compareArrays(this._imageOrientation, frame.imageOrientation) && this._compareArrays(this._imagePosition, frame.imagePosition) && this._instanceNumber === frame.instanceNumber && this._sopInstanceUID === frame.sopInstanceUID) { return true; } else { return false; } } /** * Generate X, y and Z cosines from image orientation * Returns default orientation if _imageOrientation was invalid. * * @returns {array} Array[3] containing cosinesX, Y and Z. */ }, { key: 'cosines', value: function cosines() { var cosines = [new THREE.Vector3(1, 0, 0), new THREE.Vector3(0, 1, 0), new THREE.Vector3(0, 0, 1)]; if (this._imageOrientation && this._imageOrientation.length === 6) { var xCos = new THREE.Vector3(this._imageOrientation[0], this._imageOrientation[1], this._imageOrientation[2]); var yCos = new THREE.Vector3(this._imageOrientation[3], this._imageOrientation[4], this._imageOrientation[5]); if (xCos.length() > 0 && yCos.length() > 0) { cosines[0] = xCos; cosines[1] = yCos; cosines[2] = new THREE.Vector3(0, 0, 0).crossVectors(cosines[0], cosines[1]).normalize(); } } else { window.console.log('No valid image orientation for frame'); window.console.log(this); window.console.log('Returning default orientation.'); } if (!this._rightHanded) { cosines[2].negate(); } return cosines; } }, { key: 'spacingXY', value: function spacingXY() { var spacingXY = [1.0, 1.0]; if (this.pixelSpacing) { spacingXY[0] = this.pixelSpacing[0]; spacingXY[1] = this.pixelSpacing[1]; } else if (this.pixelAspectRatio) { spacingXY[0] = 1.0; spacingXY[1] = 1.0 * this.pixelAspectRatio[1] / this.pixelAspectRatio[0]; } return spacingXY; } }, { key: 'value', value: function value(column, row) { return this.pixelData[column + this._columns * row]; } /** * Compare 2 arrays. * * 2 null arrays return true. * Do no perform strict type checking. * * @returns {boolean} True if arrays are identicals. False if not. */ }, { key: '_compareArrays', value: function _compareArrays(reference, target) { // could both be null if (reference === target) { return true; } // if not null.... if (reference && target && reference.join() === target.join()) { return true; } return false; } }, { key: 'rows', get: function get() { return this._rows; }, set: function set(rows) { this._rows = rows; } }, { key: 'columns', get: function get() { return this._columns; }, set: function set(columns) { this._columns = columns; } }, { key: 'spacingBetweenSlices', get: function get() { return this._spacingBetweenSlices; }, set: function set(spacingBetweenSlices) { this._spacingBetweenSlices = spacingBetweenSlices; } }, { key: 'sliceThickness', get: function get() { return this._sliceThickness; }, set: function set(sliceThickness) { this._sliceThickness = sliceThickness; } }, { key: 'imagePosition', get: function get() { return this._imagePosition; }, set: function set(imagePosition) { this._imagePosition = imagePosition; } }, { key: 'imageOrientation', get: function get() { return this._imageOrientation; }, set: function set(imageOrientation) { this._imageOrientation = imageOrientation; } }, { key: 'windowWidth', get: function get() { return this._windowWidth; }, set: function set(windowWidth) { this._windowWidth = windowWidth; } }, { key: 'windowCenter', get: function get() { return this._windowCenter; }, set: function set(windowCenter) { this._windowCenter = windowCenter; } }, { key: 'rescaleSlope', get: function get() { return this._rescaleSlope; }, set: function set(rescaleSlope) { this._rescaleSlope = rescaleSlope; } }, { key: 'rescaleIntercept', get: function get() { return this._rescaleIntercept; }, set: function set(rescaleIntercept) { this._rescaleIntercept = rescaleIntercept; } }, { key: 'bitsAllocated', get: function get() { return this._bitsAllocated; }, set: function set(bitsAllocated) { this._bitsAllocated = bitsAllocated; } }, { key: 'dist', get: function get() { return this._dist; }, set: function set(dist) { this._dist = dist; } }, { key: 'pixelSpacing', get: function get() { return this._pixelSpacing; }, set: function set(pixelSpacing) { this._pixelSpacing = pixelSpacing; } }, { key: 'pixelAspectRatio', get: function get() { return this._pixelAspectRatio; }, set: function set(pixelAspectRatio) { this._pixelAspectRatio = pixelAspectRatio; } }, { key: 'minMax', get: function get() { return this._minMax; }, set: function set(minMax) { this._minMax = minMax; } }, { key: 'dimensionIndexValues', get: function get() { return this._dimensionIndexValues; }, set: function set(dimensionIndexValues) { this._dimensionIndexValues = dimensionIndexValues; } }, { key: 'instanceNumber', get: function get() { return this._instanceNumber; }, set: function set(instanceNumber) { this._instanceNumber = instanceNumber; } }, { key: 'pixelData', get: function get() { return this._pixelData; }, set: function set(pixelData) { this._pixelData = pixelData; } }, { key: 'sopInstanceUID', set: function set(sopInstanceUID) { this._sopInstanceUID = sopInstanceUID; }, get: function get() { return this._sopInstanceUID; } }, { key: 'pixelRepresentation', get: function get() { return this._pixelRepresentation; }, set: function set(pixelRepresentation) { this._pixelRepresentation = pixelRepresentation; } }, { key: 'pixelType', get: function get() { return this._pixelType; }, set: function set(pixelType) { this._pixelType = pixelType; } }, { key: 'url', get: function get() { return this._url; }, set: function set(url) { this._url = url; } }, { key: 'referencedSegmentNumber', get: function get() { return this._referencedSegmentNumber; }, set: function set(referencedSegmentNumber) { this._referencedSegmentNumber = referencedSegmentNumber; } }, { key: 'rightHanded', get: function get() { return this._rightHanded; }, set: function set(rightHanded) { this._rightHanded = rightHanded; } }, { key: 'index', get: function get() { return this._index; }, set: function set(index) { this._index = index; } }]); return ModelsFrame; }(_models2.default); exports.default = ModelsFrame; module.exports = exports['default'];