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>
181 lines (147 loc) • 5.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
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 _core = require('./core.validators');
var _core2 = _interopRequireDefault(_core);
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"); } }
var URL = require('url');
/**
* General purpose functions.
*
* @module core/utils
*/
var CoreUtils = function () {
function CoreUtils() {
_classCallCheck(this, CoreUtils);
}
_createClass(CoreUtils, null, [{
key: 'bbox',
/**
* Generate a bouding box object.
* @param {THREE.Vector3} center - Center of the box.
* @param {THREE.Vector3} halfDimensions - Half Dimensions of the box.
* @return {Object} The bounding box object. {Object.min} is a {THREE.Vector3}
* containing the min bounds. {Object.max} is a {THREE.Vector3} containing the
* max bounds.
* @return {boolean} False input NOT valid.
* @example
* // Returns
* //{ min: { x : 0, y : 0, z : 0 },
* // max: { x : 2, y : 4, z : 6 }
* //}
* VJS.Core.Utils.bbox(
* new THREE.Vector3(1, 2, 3), new THREE.Vector3(1, 2, 3));
*
* //Returns false
* VJS.Core.Utils.bbox(new THREE.Vector3(), new THREE.Matrix4());
*
*/
value: function bbox(center, halfDimensions) {
// make sure we have valid inputs
if (!(_core2.default.vector3(center) && _core2.default.vector3(halfDimensions))) {
window.console.log('Invalid center or plane halfDimensions.');
return false;
}
// make sure half dimensions are >= 0
if (!(halfDimensions.x >= 0 && halfDimensions.y >= 0 && halfDimensions.z >= 0)) {
window.console.log('halfDimensions must be >= 0.');
window.console.log(halfDimensions);
return false;
}
// min/max bound
var min = center.clone().sub(halfDimensions);
var max = center.clone().add(halfDimensions);
return {
min: min,
max: max
};
}
/**
* Find min/max values in an array
* @param {Array} data
* @return {Array}
*/
}, {
key: 'minMax',
value: function minMax() {
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var minMax = [65535, -32768];
var numPixels = data.length;
for (var index = 0; index < numPixels; index++) {
var spv = data[index];
minMax[0] = Math.min(minMax[0], spv);
minMax[1] = Math.max(minMax[1], spv);
}
return minMax;
}
/**
* Check HTMLElement
* @param {HTMLElement} obj
* @return {boolean}
*/
}, {
key: 'isElement',
value: function isElement(obj) {
try {
// Using W3 DOM2 (works for FF, Opera and Chrom)
return obj instanceof HTMLElement;
} catch (e) {
// Browsers not supporting W3 DOM2 don't have HTMLElement and
// an exception is thrown and we end up here. Testing some
// properties that all elements have. (works on IE7)
return (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && obj.nodeType === 1 && _typeof(obj.style) === 'object' && _typeof(obj.ownerDocument) === 'object';
}
}
/**
* Check string
* @param {String} str
* @return {Boolean}
*/
}, {
key: 'isString',
value: function isString(str) {
return typeof str === 'string' || str instanceof String;
}
/**
* Parse url
* @param {*} url
* @return {Object}
*/
}, {
key: 'parseUrl',
value: function parseUrl(url) {
//
var data = {};
data.filename = '';
data.extension = '';
data.pathname = '';
data.query = '';
var parsedUrl = URL.parse(url);
data.pathname = parsedUrl.pathname;
data.query = parsedUrl.query;
// get file name
data.filename = data.pathname.split('/').pop();
// find extension
var splittedName = data.filename.split('.');
if (splittedName.length <= 1) {
data.extension = 'dicom';
} else {
data.extension = data.filename.split('.').pop();
}
if (!isNaN(data.extension)) {
data.extension = 'dicom';
}
if (data.query && data.query.includes('contentType=application%2Fdicom')) {
data.extension = 'dicom';
}
return data;
}
}]);
return CoreUtils;
}();
exports.default = CoreUtils;
module.exports = exports['default'];