├── .eslintignore ├── src ├── version.js ├── registerLoaders.js ├── externalModules.js ├── index.js ├── arrayBufferToImage.js ├── loadImage.js └── createImage.js ├── examples ├── Ultrasound.png ├── Renal_Cell_Carcinoma.jpg ├── cornerstone.min.css ├── index.html ├── cornerstoneMath.min.js └── cornerstone.min.js ├── .babelrc ├── config ├── webpack │ ├── index.js │ ├── webpack-dev.js │ ├── webpack-prod.js │ ├── merge.js │ ├── plugins │ │ └── banner.js │ └── webpack-base.js └── karma │ ├── karma-firefox.js │ ├── karma-extend.js │ ├── karma-watch.js │ ├── karma-chrome.js │ ├── karma-coverage.js │ ├── karma-coveralls.js │ └── karma-base.js ├── .gitignore ├── .npmignore ├── .travis.yml ├── test └── coverage_test.js ├── .jsdocrc ├── LICENSE ├── changelog.md ├── README.md ├── package.json └── .eslintrc.js /.eslintignore: -------------------------------------------------------------------------------- 1 | config/** 2 | -------------------------------------------------------------------------------- /src/version.js: -------------------------------------------------------------------------------- 1 | export default '2.1.1'; 2 | -------------------------------------------------------------------------------- /examples/Ultrasound.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornerstonejs/cornerstoneWebImageLoader/HEAD/examples/Ultrasound.png -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "es2015" 4 | ], 5 | "plugins": [ 6 | "transform-object-rest-spread" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /config/webpack/index.js: -------------------------------------------------------------------------------- 1 | const env = process.env.ENV || 'dev'; 2 | const config = require(`./webpack-${env}`); 3 | 4 | module.exports = config; -------------------------------------------------------------------------------- /examples/Renal_Cell_Carcinoma.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cornerstonejs/cornerstoneWebImageLoader/HEAD/examples/Renal_Cell_Carcinoma.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Directorties 2 | coverage/ 3 | dist/ 4 | documentation/ 5 | node_modules/ 6 | 7 | ## Files 8 | .idea 9 | .DS_Store 10 | npm-debug.log -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | ## All Non-Dist Directories 2 | config/ 3 | examples/ 4 | src/ 5 | test/ 6 | 7 | ## Root Files 8 | .babelrc 9 | .eslintignore 10 | .gitignore 11 | .jsdocrc 12 | .travis.yml 13 | karma.conf.js -------------------------------------------------------------------------------- /config/karma/karma-firefox.js: -------------------------------------------------------------------------------- 1 | const extendConfiguration = require('./karma-extend.js'); 2 | 3 | module.exports = function (config) { 4 | 'use strict'; 5 | config.set(extendConfiguration({ 6 | singleRun: true, 7 | browsers: ['Firefox'] 8 | })); 9 | }; 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | addons: 4 | chrome: stable 5 | 6 | node_js: 7 | - "node" 8 | 9 | cache: 10 | yarn: true 11 | directories: 12 | - node_modules 13 | 14 | after_success: 15 | cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js -------------------------------------------------------------------------------- /examples/cornerstone.min.css: -------------------------------------------------------------------------------- 1 | /*! cornerstone - v0.9.0 - 2016-02-03 | (c) 2014 Chris Hafey | https://github.com/chafey/cornerstone */.cornerstone-enabled-image{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default} -------------------------------------------------------------------------------- /src/registerLoaders.js: -------------------------------------------------------------------------------- 1 | import { loadImage } from './loadImage.js'; 2 | 3 | export default function (cornerstone) { 4 | // Register the http and https prefixes so we can use standard web urls directly 5 | cornerstone.registerImageLoader('http', loadImage); 6 | cornerstone.registerImageLoader('https', loadImage); 7 | } 8 | -------------------------------------------------------------------------------- /src/externalModules.js: -------------------------------------------------------------------------------- 1 | import registerLoaders from './registerLoaders.js'; 2 | 3 | let cornerstone; 4 | 5 | const external = { 6 | set cornerstone (cs) { 7 | cornerstone = cs; 8 | 9 | registerLoaders(cornerstone); 10 | }, 11 | get cornerstone () { 12 | return cornerstone; 13 | } 14 | }; 15 | 16 | export { external }; 17 | -------------------------------------------------------------------------------- /test/coverage_test.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-expressions */ 2 | import { expect } from 'chai'; 3 | 4 | import * as cornerstoneWebImageLoader from '../src/index.js'; 5 | 6 | describe('A test that pulls in all modules', function () { 7 | it('pulls in all modules', function () { 8 | expect(cornerstoneWebImageLoader).to.exist; 9 | }); 10 | }); 11 | -------------------------------------------------------------------------------- /config/webpack/webpack-dev.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const merge = require('./merge'); 3 | const baseConfig = require('./webpack-base'); 4 | 5 | const devConfig = { 6 | devServer: { 7 | hot: true, 8 | publicPath: '/dist/' 9 | }, 10 | plugins: [ 11 | new webpack.HotModuleReplacementPlugin({}) 12 | ] 13 | }; 14 | 15 | module.exports = merge(baseConfig, devConfig); 16 | -------------------------------------------------------------------------------- /config/karma/karma-extend.js: -------------------------------------------------------------------------------- 1 | const baseConfig = require('./karma-base.js'); 2 | 3 | module.exports = function (extendedConfig) { 4 | 'use strict'; 5 | // Overrides the base configuration for karma with the given properties 6 | for (var i in baseConfig) { 7 | if (typeof extendedConfig[i] === 'undefined') { 8 | extendedConfig[i] = baseConfig[i]; 9 | } 10 | } 11 | return extendedConfig; 12 | }; 13 | -------------------------------------------------------------------------------- /config/karma/karma-watch.js: -------------------------------------------------------------------------------- 1 | const extendConfiguration = require('./karma-extend.js'); 2 | 3 | module.exports = function (config) { 4 | 'use strict'; 5 | config.set(extendConfiguration({ 6 | browsers: ['ChromeHeadlessNoSandbox'], 7 | customLaunchers: { 8 | ChromeHeadlessNoSandbox: { 9 | base: 'ChromeHeadless', 10 | flags: ['--no-sandbox'] 11 | } 12 | } 13 | })); 14 | }; 15 | -------------------------------------------------------------------------------- /.jsdocrc: -------------------------------------------------------------------------------- 1 | { 2 | "source": { 3 | "include": "./src" 4 | }, 5 | "opts": { 6 | "template": "node_modules/docdash", 7 | "encoding": "utf8", 8 | "destination": "documentation/", 9 | "recurse": true, 10 | "verbose": true 11 | }, 12 | "templates": { 13 | "default": { 14 | "includeDate": false 15 | } 16 | }, 17 | "docdash": { 18 | "static": true, 19 | "sort": true 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /config/karma/karma-chrome.js: -------------------------------------------------------------------------------- 1 | const extendConfiguration = require('./karma-extend.js'); 2 | 3 | module.exports = function (config) { 4 | 'use strict'; 5 | config.set(extendConfiguration({ 6 | singleRun: true, 7 | browsers: ['ChromeHeadlessNoSandbox'], 8 | customLaunchers: { 9 | ChromeHeadlessNoSandbox: { 10 | base: 'ChromeHeadless', 11 | flags: ['--no-sandbox'] 12 | } 13 | } 14 | })); 15 | }; 16 | -------------------------------------------------------------------------------- /config/karma/karma-coverage.js: -------------------------------------------------------------------------------- 1 | const extendConfiguration = require('./karma-extend.js'); 2 | 3 | module.exports = function (config) { 4 | 'use strict'; 5 | config.set(extendConfiguration({ 6 | singleRun: true, 7 | reporters: ['progress', 'coverage'], 8 | browsers: ['ChromeHeadlessNoSandbox'], 9 | customLaunchers: { 10 | ChromeHeadlessNoSandbox: { 11 | base: 'ChromeHeadless', 12 | flags: ['--no-sandbox'] 13 | } 14 | } 15 | })); 16 | }; 17 | -------------------------------------------------------------------------------- /config/webpack/webpack-prod.js: -------------------------------------------------------------------------------- 1 | const merge = require('./merge'); 2 | const baseConfig = require('./webpack-base'); 3 | const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); 4 | 5 | const prodConfig = { 6 | output: { 7 | filename: '[name].min.js' 8 | }, 9 | mode: "production", 10 | optimization: { 11 | minimizer: [ 12 | new UglifyJSPlugin({ 13 | sourceMap: true 14 | }) 15 | ] 16 | } 17 | }; 18 | 19 | module.exports = merge(baseConfig, prodConfig); -------------------------------------------------------------------------------- /config/karma/karma-coveralls.js: -------------------------------------------------------------------------------- 1 | const extendConfiguration = require('./karma-extend.js'); 2 | 3 | module.exports = function (config) { 4 | 'use strict'; 5 | config.set(extendConfiguration({ 6 | singleRun: true, 7 | reporters: ['progress', 'coverage', 'coveralls'], 8 | browsers: ['ChromeHeadlessNoSandbox'], 9 | customLaunchers: { 10 | ChromeHeadlessNoSandbox: { 11 | base: 'ChromeHeadless', 12 | flags: ['--no-sandbox'] 13 | } 14 | } 15 | })); 16 | }; 17 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import arrayBufferToImage from './arrayBufferToImage.js'; 2 | import createImage from './createImage.js'; 3 | import { loadImage, configure } from './loadImage.js'; 4 | import { external } from './externalModules.js'; 5 | 6 | const cornerstoneWebImageLoader = { 7 | arrayBufferToImage, 8 | createImage, 9 | loadImage, 10 | configure, 11 | external 12 | }; 13 | 14 | export { 15 | arrayBufferToImage, 16 | createImage, 17 | loadImage, 18 | configure, 19 | external 20 | }; 21 | 22 | export default cornerstoneWebImageLoader; 23 | -------------------------------------------------------------------------------- /config/webpack/merge.js: -------------------------------------------------------------------------------- 1 | const _ = require('lodash'); 2 | 3 | // Merge two objects 4 | // Instead of merging array objects index by index (n-th source 5 | // item with n-th object item) it concatenates both arrays 6 | module.exports = function(object, source) { 7 | const clone = _.cloneDeep(object); 8 | const merged = _.mergeWith(clone, source, function(objValue, srcValue, key, object, source, stack) { 9 | if(objValue && srcValue && _.isArray(objValue) && _.isArray(srcValue)) { 10 | return _.concat(objValue, srcValue); 11 | } 12 | }); 13 | 14 | return merged; 15 | } -------------------------------------------------------------------------------- /config/webpack/plugins/banner.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const webpack = require('webpack'); 3 | const rootPath = process.cwd(); 4 | const pkgPath = path.join(rootPath, "package"); 5 | const pkg = require(pkgPath); 6 | 7 | const getCurrentDate = () => { 8 | const today = new Date(); 9 | const year = today.getFullYear(); 10 | const month = ('0' + (today.getMonth() + 1)).slice(-2); 11 | const date = ('0' + today.getDate()).slice(-2); 12 | 13 | return `${year}-${month}-${date}`; 14 | } 15 | 16 | const getBanner = () => { 17 | return `/*! ${pkg.name} - ${pkg.version} - ` + 18 | `${getCurrentDate()} ` + 19 | `| (c) 2016 Chris Hafey | ${pkg.homepage} */` 20 | } 21 | 22 | module.exports = () => { 23 | return new webpack.BannerPlugin({ 24 | banner: getBanner(), 25 | entryOnly: true, 26 | raw: true 27 | }); 28 | } -------------------------------------------------------------------------------- /src/arrayBufferToImage.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Convert array buffer to image. Returns a promise that resolves to an Image object for the bytes in arrayBuffer 3 | * 4 | * @param arrayBuffer - arrayBuffer with bytes for a web image (e.g. JPEG, PNG, etc) 5 | * @returns {Promise} Promise that resolves to an Image object 6 | */ 7 | export default function (arrayBuffer) { 8 | return new Promise((resolve, reject) => { 9 | const image = new Image(); 10 | const arrayBufferView = new Uint8Array(arrayBuffer); 11 | const blob = new Blob([arrayBufferView]); 12 | const urlCreator = window.URL || window.webkitURL; 13 | const imageUrl = urlCreator.createObjectURL(blob); 14 | 15 | image.src = imageUrl; 16 | image.onload = () => { 17 | resolve(image); 18 | urlCreator.revokeObjectURL(imageUrl); 19 | }; 20 | 21 | image.onerror = (error) => { 22 | urlCreator.revokeObjectURL(imageUrl); 23 | reject(error); 24 | }; 25 | }); 26 | } 27 | -------------------------------------------------------------------------------- /config/webpack/webpack-base.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const rootPath = process.cwd(); 3 | const context = path.join(rootPath, "src"); 4 | const outputPath = path.join(rootPath, 'dist'); 5 | const bannerPlugin = require('./plugins/banner'); 6 | 7 | module.exports = { 8 | mode: 'development', 9 | context, 10 | entry: { 11 | cornerstoneWebImageLoader: './index.js', 12 | }, 13 | target: 'web', 14 | output: { 15 | filename: '[name].js', 16 | library: '[name]', 17 | libraryTarget: 'umd', 18 | path: outputPath, 19 | umdNamedDefine: true 20 | }, 21 | devtool: 'source-map', 22 | externals: {}, 23 | module: { 24 | rules: [{ 25 | enforce: 'pre', 26 | test: /\.js$/, 27 | exclude: /(node_modules)/, 28 | loader: 'eslint-loader', 29 | options: { 30 | failOnError: true 31 | } 32 | }, { 33 | test: /\.js$/, 34 | exclude: /(node_modules)/, 35 | use: [{ 36 | loader: 'babel-loader' 37 | }] 38 | }] 39 | }, 40 | plugins: [ 41 | bannerPlugin() 42 | ] 43 | }; 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Chris Hafey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /config/karma/karma-base.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const webpackConfig = require('../webpack'); 3 | 4 | /* eslint no-process-env:0 */ 5 | process.env.CHROME_BIN = require('puppeteer').executablePath(); 6 | 7 | // Deleting output.library to avoid "Uncaught SyntaxError: Unexpected token /" error 8 | // when running testes (var test/foo_test.js = ...) 9 | delete webpackConfig.output.library; 10 | 11 | // Karma will build the dependecy tree by itself 12 | delete webpackConfig.entry; 13 | 14 | // Code coverage 15 | webpackConfig.module.rules.push({ 16 | test: /\.js$/, 17 | include: path.resolve('./src/'), 18 | loader: 'istanbul-instrumenter-loader', 19 | query: { 20 | esModules: true 21 | } 22 | }); 23 | 24 | module.exports = { 25 | basePath: '../../', 26 | frameworks: ['mocha'], 27 | reporters: ['progress', 'coverage'], 28 | files: [ 29 | 'node_modules/cornerstone-core/dist/cornerstone.js', 30 | 'test/**/*_test.js' 31 | ], 32 | 33 | plugins: [ 34 | 'karma-webpack', 35 | 'karma-mocha', 36 | 'karma-chrome-launcher', 37 | 'karma-firefox-launcher', 38 | 'karma-coverage' 39 | ], 40 | 41 | preprocessors: { 42 | 'src/**/*.js': ['webpack'], 43 | 'test/**/*_test.js': ['webpack'] 44 | }, 45 | 46 | webpack: webpackConfig, 47 | 48 | webpackMiddleware: { 49 | noInfo: false, 50 | stats: { 51 | chunks: false, 52 | timings: false, 53 | errorDetails: true 54 | } 55 | }, 56 | 57 | sauceLabs: { 58 | startConnect: true, 59 | testName: 'Cornerstone Web Image Loader' 60 | }, 61 | 62 | coverageReporter: { 63 | dir: './coverage', 64 | reporters: [ 65 | { type: 'html', subdir: 'html' }, 66 | { type: 'lcov', subdir: '.' }, 67 | { type: 'text', subdir: '.', file: 'text.txt' }, 68 | { type: 'text-summary', subdir: '.', file: 'text-summary.txt' } 69 | ] 70 | } 71 | }; 72 | -------------------------------------------------------------------------------- /src/loadImage.js: -------------------------------------------------------------------------------- 1 | import { external } from './externalModules.js'; 2 | import arrayBufferToImage from './arrayBufferToImage.js'; 3 | import createImage from './createImage.js'; 4 | 5 | // 6 | // This is a cornerstone image loader for web images such as PNG and JPEG 7 | // 8 | let options = { 9 | // callback allowing customization of the xhr (e.g. adding custom auth headers, cors, etc) 10 | beforeSend (/* xhr */) {} 11 | }; 12 | 13 | 14 | // Loads an image given a url to an image 15 | export function loadImage (imageId) { 16 | const cornerstone = external.cornerstone; 17 | 18 | const xhr = new XMLHttpRequest(); 19 | 20 | xhr.open('GET', imageId, true); 21 | xhr.responseType = 'arraybuffer'; 22 | options.beforeSend(xhr); 23 | 24 | xhr.onprogress = function (oProgress) { 25 | if (oProgress.lengthComputable) { 26 | // evt.loaded the bytes browser receive 27 | // evt.total the total bytes set by the header 28 | const loaded = oProgress.loaded; 29 | const total = oProgress.total; 30 | const percentComplete = Math.round((loaded / total) * 100); 31 | 32 | const eventData = { 33 | imageId, 34 | loaded, 35 | total, 36 | percentComplete 37 | }; 38 | 39 | cornerstone.triggerEvent(cornerstone.events, 'cornerstoneimageloadprogress', eventData); 40 | } 41 | }; 42 | 43 | const promise = new Promise((resolve, reject) => { 44 | xhr.onload = function () { 45 | const imagePromise = arrayBufferToImage(this.response); 46 | 47 | imagePromise.then((image) => { 48 | const imageObject = createImage(image, imageId); 49 | 50 | resolve(imageObject); 51 | }, reject); 52 | }; 53 | 54 | xhr.send(); 55 | }); 56 | 57 | const cancelFn = () => { 58 | xhr.abort(); 59 | }; 60 | 61 | return { 62 | promise, 63 | cancelFn 64 | }; 65 | } 66 | 67 | export function configure (opts) { 68 | options = opts; 69 | } 70 | -------------------------------------------------------------------------------- /src/createImage.js: -------------------------------------------------------------------------------- 1 | import { external } from './externalModules.js'; 2 | 3 | const canvas = document.createElement('canvas'); 4 | let lastImageIdDrawn; 5 | 6 | /** 7 | * creates a cornerstone Image object for the specified Image and imageId 8 | * 9 | * @param image - An Image 10 | * @param imageId - the imageId for this image 11 | * @returns Cornerstone Image Object 12 | */ 13 | export default function (image, imageId) { 14 | // extract the attributes we need 15 | const rows = image.naturalHeight; 16 | const columns = image.naturalWidth; 17 | 18 | function getPixelData () { 19 | const imageData = getImageData(); 20 | 21 | 22 | return imageData.data; 23 | } 24 | 25 | function getImageData () { 26 | let context; 27 | 28 | if (lastImageIdDrawn === imageId) { 29 | context = canvas.getContext('2d'); 30 | } else { 31 | canvas.height = image.naturalHeight; 32 | canvas.width = image.naturalWidth; 33 | context = canvas.getContext('2d'); 34 | context.drawImage(image, 0, 0); 35 | lastImageIdDrawn = imageId; 36 | } 37 | 38 | return context.getImageData(0, 0, image.naturalWidth, image.naturalHeight); 39 | } 40 | 41 | function getCanvas () { 42 | if (lastImageIdDrawn === imageId) { 43 | return canvas; 44 | } 45 | 46 | canvas.height = image.naturalHeight; 47 | canvas.width = image.naturalWidth; 48 | const context = canvas.getContext('2d'); 49 | 50 | context.drawImage(image, 0, 0); 51 | lastImageIdDrawn = imageId; 52 | 53 | return canvas; 54 | } 55 | 56 | // Extract the various attributes we need 57 | return { 58 | imageId, 59 | minPixelValue: 0, 60 | maxPixelValue: 255, 61 | slope: 1, 62 | intercept: 0, 63 | windowCenter: 128, 64 | windowWidth: 255, 65 | render: external.cornerstone.renderWebImage, 66 | getPixelData, 67 | getCanvas, 68 | getImage: () => image, 69 | rows, 70 | columns, 71 | height: rows, 72 | width: columns, 73 | color: true, 74 | rgba: false, 75 | columnPixelSpacing: undefined, 76 | rowPixelSpacing: undefined, 77 | invert: false, 78 | sizeInBytes: rows * columns * 4 79 | }; 80 | } 81 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 6 | 7 | ## [2.1.1] - 2018-12-05 8 | ### Added 9 | - Added default export named 'cornerstoneWebImageLoader' to the module 10 | 11 | ## [2.1.0] - 2018-04-11 12 | ### Changed 13 | - Updated Webpack to version 4 14 | - DIST folder is now removed from the repository 15 | 16 | ## [2.0.0] - 2017-12-08 17 | ### Changed 18 | 19 | - *Breaking Change!!!* Switches image loader return values to support the breaking change in Cornerstone Master (https://github.com/cornerstonejs/cornerstone/commit/9448755397da10a6de6f694d83123274cbd4b38e) which requires image loaders to return an object of the form { promise, cancelFn }. 20 | - *Breaking Change!!!* Removed jQuery events from triggerEvent, lower-cased all the event names (i.e. 'cornerstoneimageloadprogress'). 21 | - *Breaking Change!!!* Switched all Deferred usage to use Promises 22 | - Performance: Switch getPixelData to just return the canvas imageData.data. The previous loop to set alpha channel to 255 is unnecessary since we can now just set image.rgba = false. 23 | - Set image.rgba to false by default. Users can change this to have the image rendered with the alpha channel intact. 24 | - Switch event triggering to use cornerstone.triggerEvent 25 | - Switched this changelog to try to follow http://keepachangelog.com/en/1.0.0/ 26 | 27 | ## [1.0.0] 28 | 29 | - Updated to 1.0.0 because 0.8.5 introduced a breaking change with Cornerstone / jQuery injection. This doesn't break usage if you are using HTML script tags, but if you are using a module system, Cornerstone Web Image Loader may not properly find its dependencies. 30 | 31 | The solution for this is to inject your Cornerstone instance into Cornerstone Tools as follows: 32 | 33 | ````javascript 34 | cornerstoneWebImageLoader.external.$ = $; 35 | cornerstoneWebImageLoader.external.cornerstone = cornerstone; 36 | ```` 37 | 38 | An example commit doing something similar in the OHIF Viewer Meteor application is here: https://github.com/OHIF/Viewers/commit/012bba44806d0fb9bb60af329c4875e7f6b751e0#diff-d9ccd906dfc48b4589d720766fe14715R25 39 | 40 | We apologize for any headaches that the breaking change in 0.8.5 may have caused for those using module systems. 41 | - Note: the dependencies have been updated to require Cornerstone Core 1.0.0 or above 42 | 43 | ## [0.8.6] (deprecated due to breaking change) 44 | 45 | - Added native CustomEvents that are triggered parallel to the jQuery events. This is part of a transition to drop the jQuery dependency entirely. 46 | - *Note:* This version requires Cornerstone Core 0.13.2 or above, where cornerstone.events has the EventTarget interface! 47 | 48 | e.g. CornerstoneImageLoadProgress has a native CustomEvent name 'cornerstoneimageloadprogress' 49 | 50 | ## [0.8.5] (deprecated due to breaking change) 51 | 52 | - Add Jquery and Cornerstone as injection dependencies -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cornerstone Web Image Loader 2 | ============================= 3 | 4 | A cornerstone (legacy) Image Loader for web images (PNG, JPEG) for cornerstone legacy. For cornerstone3D use the new loader [here](https://github.com/cornerstonejs/cornerstone3D-beta/blob/main/packages/core/examples/webLoader/registerWebImageLoader.ts) 5 | 6 | Live Examples 7 | --------------- 8 | 9 | [Click here for a live example of this library in use!](http://rawgit.com/cornerstonejs/cornerstoneWebImageLoader/master/examples/index.html) 10 | 11 | View the [simple image viewer](http://viewer.ohif.org/) built on cornerstone. 12 | 13 | Install 14 | ------- 15 | 16 | Get a packaged source file: 17 | 18 | * [cornerstoneWebImageLoader.js](https://unpkg.com/browse/cornerstone-web-image-loader/dist/) 19 | * [cornerstoneWebImageLoader.min.js](https://unpkg.com/browse/cornerstone-web-image-loader/dist/) 20 | 21 | 22 | Or install via [NPM](https://www.npmjs.com/package/cornerstone-web-image-loader): 23 | 24 | > npm install cornerstone-web-image-loader 25 | 26 | Usage 27 | ------- 28 | 29 | Simply include the cornerstoneWebImageLoader.js in your HTML file after you load cornerstone.js and then set the cornerstone instance as an external module for cornerstoneWebImageLoader: 30 | 31 | ````javascript 32 | cornerstoneWebImageLoader.external.cornerstone = cornerstone; 33 | ```` 34 | 35 | This will let cornerstoneWebImageLoader register itself with cornerstone to load imageId's that have the http or https url schemes. To display an image, pass the url to the image as the imageId parameter to a cornerstone API function loadImage(). 36 | 37 | Key Features 38 | ------------ 39 | 40 | * Provides a bridge between the cornerstone library and standard web images 41 | * Allows XHR to be hooked so custom http headers can be added (e.g. for authentication). View the source of the 42 | [example](http://rawgit.com/cornerstonejs/cornerstoneWebImageLoader/master/examples/index.html) to see how this is done. 43 | 44 | Contributors 45 | ------------ 46 | @onluiz for fixing a bug with images not being properly invalidated 47 | @leonardorame for adding support for CornerstoneImageLoadProgress 48 | 49 | Build System 50 | ============ 51 | 52 | This project uses webpack to build the software. 53 | 54 | Pre-requisites: 55 | --------------- 56 | 57 | NodeJs - [click to visit web site for installation instructions](http://nodejs.org). 58 | 59 | Common Tasks 60 | ------------ 61 | 62 | Update dependencies (after each pull): 63 | > npm install 64 | 65 | Running the build: 66 | > npm start 67 | 68 | Automatically running the build and unit tests after each source change: 69 | > npm run watch 70 | 71 | Why is this a separate library from cornerstone? 72 | ================================================ 73 | 74 | Cornerstone was designed to support loading of any kind of image regardless of its container, 75 | compression algorithm, encoding or transport. This is one of many possible image loaders 76 | that can provide the image pixel data to cornerstone to display 77 | 78 | Copyright 79 | ============ 80 | Copyright 2017 Chris Hafey [chafey@gmail.com](mailto:chafey@gmail.com) 81 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cornerstone-web-image-loader", 3 | "version": "2.1.1", 4 | "description": "Cornerstone ImageLoader for Web Images (PNG, JPG)", 5 | "keywords": [ 6 | "medical", 7 | "imaging", 8 | "JPEG", 9 | "PNG", 10 | "cornerstone" 11 | ], 12 | "author": "Chris Hafey", 13 | "homepage": "https://github.com/cornerstonejs/cornerstoneWebImageLoader", 14 | "license": "MIT", 15 | "main": "./dist/cornerstoneWebImageLoader.min.js", 16 | "module": "./dist/cornerstoneWebImageLoader.min.js", 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/cornerstonejs/cornerstoneWebImageLoader.git" 20 | }, 21 | "scripts": { 22 | "build": "npm run test && npm run version && npm run webpack && npm run doc:generate", 23 | "clean": "npm run clean:dist && npm run clean:coverage", 24 | "clean:dist": "shx rm -rf dist", 25 | "clean:docs": "shx rm -rf documentation", 26 | "clean:coverage": "shx rm -rf coverage", 27 | "doc": "npm run doc:generate && opn documentation/index.html", 28 | "doc:generate": "npm run clean:docs && jsdoc -c .jsdocrc", 29 | "eslint": "eslint -c .eslintrc.js src", 30 | "eslint-quiet": "eslint -c .eslintrc.js --quiet src", 31 | "eslint-fix": "eslint -c .eslintrc.js --fix src", 32 | "start": "npm run webpack", 33 | "start:dev": "webpack-dev-server --config ./config/webpack/webpack-dev", 34 | "test": "npm run test:chrome", 35 | "test:all": "npm run test:chrome && npm run test:firefox", 36 | "test:watch": "karma start config/karma/karma-watch.js", 37 | "test:chrome": "karma start config/karma/karma-chrome.js", 38 | "test:firefox": "karma start config/karma/karma-firefox.js", 39 | "version": "node -p -e \"'export default \\'' + require('./package.json').version + '\\';'\" > src/version.js", 40 | "watch": "npm run clean && shx mkdir dist npm run webpack:watch", 41 | "webpack": "npm run webpack:prod && npm run webpack:dev", 42 | "webpack:dev": "webpack --progress --config ./config/webpack/webpack-dev", 43 | "webpack:prod": "webpack --progress --config ./config/webpack/webpack-prod", 44 | "webpack:watch": "webpack --progress --debug --watch --config ./config/webpack" 45 | }, 46 | "devDependencies": { 47 | "babel-core": "^6.26.0", 48 | "babel-eslint": "^8.0.1", 49 | "babel-loader": "^7.1.2", 50 | "babel-plugin-transform-object-rest-spread": "^6.26.0", 51 | "babel-preset-es2015": "^6.24.1", 52 | "chai": "^4.1.2", 53 | "concat": "^1.0.3", 54 | "cornerstone-core": "^2.0.0", 55 | "coveralls": "^3.0.0", 56 | "docdash": "^0.4.0", 57 | "eslint": "^4.19.1", 58 | "eslint-loader": "^2.0.0", 59 | "eslint-plugin-import": "^2.8.0", 60 | "istanbul-instrumenter-loader": "^3.0.0", 61 | "jsdoc": "^3.5.5", 62 | "karma": "^1.7.1", 63 | "karma-chrome-launcher": "^2.2.0", 64 | "karma-coverage": "^1.1.1", 65 | "karma-firefox-launcher": "^1.0.1", 66 | "karma-mocha": "^1.3.0", 67 | "karma-webpack": "^3.0.0", 68 | "lodash": "4.17.4", 69 | "mocha": "^4.0.1", 70 | "opn-cli": "^3.1.0", 71 | "puppeteer": "^1.2.0", 72 | "shx": "^0.2.2", 73 | "uglify-js": "^3.1.5", 74 | "uglifyjs-webpack-plugin": "^1.2.4", 75 | "webpack": "^4.5.0", 76 | "webpack-cli": "^2.1.4", 77 | "webpack-dev-server": "^3.1.4" 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 37 | 38 |
39 |
40 |
41 | 42 |
43 | 44 |
45 |
46 | 47 |
48 |
49 |
50 |
51 | 52 |
58 |
60 |
61 |
62 |
63 | 64 | 65 | 66 | 67 | 94 | 95 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'env': { 3 | 'browser': true, 4 | 'es6': true, 5 | 'node': true, 6 | 'mocha': true 7 | }, 8 | 'extends': 'eslint:recommended', 9 | 'plugins': ['import'], 10 | "parser": "babel-eslint", 11 | 'parserOptions': { 12 | 'sourceType': 'module' 13 | }, 14 | 'globals': {}, 15 | 'rules': { 16 | 'accessor-pairs': 'warn', 17 | 'array-bracket-spacing': 'warn', 18 | 'array-callback-return': 'warn', 19 | 'arrow-body-style': 'warn', 20 | 'arrow-parens': 'warn', 21 | 'arrow-spacing': 'warn', 22 | //'block-scoped-var': 'warn', 23 | 'block-spacing': 'warn', 24 | 'brace-style': 'warn', 25 | 'callback-return': 'warn', 26 | //'camelcase': 'warn', 27 | //'capitalized-comments': 'warn', 28 | 'class-methods-use-this': 'warn', 29 | 'comma-dangle': 'warn', 30 | 'comma-spacing': [ 31 | 'warn', 32 | { 33 | 'after': true, 34 | 'before': false 35 | } 36 | ], 37 | 'comma-style': 'warn', 38 | 'complexity': 'warn', 39 | 'computed-property-spacing': 'warn', 40 | //'consistent-return': 'warn', 41 | 'consistent-this': 'warn', 42 | 'curly': 'warn', 43 | //'default-case': 'warn', 44 | 'dot-location': 'warn', 45 | 'dot-notation': 'warn', 46 | 'eol-last': 'warn', 47 | 'eqeqeq': 'warn', 48 | 'func-call-spacing': 'warn', 49 | 'func-name-matching': 'warn', 50 | 'func-names': [ 51 | 'warn', 52 | 'never' 53 | ], 54 | //'func-style': 'warn', 55 | 'generator-star-spacing': 'warn', 56 | 'global-require': 'warn', 57 | //'guard-for-in': 'warn', 58 | 'handle-callback-err': 'warn', 59 | 'id-blacklist': 'warn', 60 | 'id-length': 'off', 61 | 'id-match': 'warn', 62 | 'indent': ['warn', 2], 63 | //'init-declarations': 'warn', 64 | 'import/default': 'warn', 65 | 'import/export': 'warn', 66 | 'import/extensions': ['warn', { "js": "always" }], 67 | 'import/first': 'warn', 68 | 'import/named': 'warn', 69 | 'import/namespace': 'warn', 70 | 'import/newline-after-import': 'warn', 71 | 'import/no-unresolved': 'warn', 72 | 'import/no-webpack-loader-syntax': 'warn', 73 | 'jsx-quotes': 'warn', 74 | 'key-spacing': 'warn', 75 | 'keyword-spacing': [ 76 | 'warn', 77 | { 78 | 'after': true, 79 | 'before': true 80 | } 81 | ], 82 | //'line-comment-position': 'warn', 83 | 'linebreak-style': [ 84 | 'warn', 85 | 'unix' 86 | ], 87 | 'lines-around-comment': 'warn', 88 | 'lines-around-directive': 'warn', 89 | 'max-depth': 'warn', 90 | /*'max-len': ['warn', { 91 | 'code': 100, 92 | 'tabWidth': 2, 93 | 'comments': 80, 94 | 'ignoreComments': false, 95 | 'ignoreTrailingComments': true, 96 | 'ignoreUrls': true, 97 | 'ignoreTemplateLiterals': false, 98 | 'ignoreRegExpLiterals': true 99 | }],*/ 100 | //'max-lines': 'warn', 101 | 'max-nested-callbacks': 'warn', 102 | //'max-params': 'warn', 103 | //'max-statements': 'warn', 104 | 'max-statements-per-line': 'warn', 105 | 'multiline-ternary': 'off', 106 | //'new-cap': 'warn', 107 | 'new-parens': 'warn', 108 | 'newline-after-var': 'warn', 109 | 'newline-before-return': 'warn', 110 | //'newline-per-chained-call': 'warn', 111 | 'no-alert': 'warn', 112 | 'no-array-constructor': 'warn', 113 | 'no-bitwise': 'warn', 114 | 'no-caller': 'warn', 115 | 'no-catch-shadow': 'warn', 116 | 'no-confusing-arrow': 'warn', 117 | 'no-console': 'off', 118 | //'no-continue': 'warn', 119 | 'no-div-regex': 'warn', 120 | 'no-duplicate-imports': 'warn', 121 | 'no-else-return': 'warn', 122 | 'no-empty-function': 'off', 123 | 'no-eq-null': 'warn', 124 | 'no-eval': 'warn', 125 | 'no-extend-native': 'warn', 126 | 'no-extra-bind': 'warn', 127 | 'no-extra-label': 'warn', 128 | 'no-extra-parens': 'off', 129 | 'no-floating-decimal': 'warn', 130 | 'no-implicit-coercion': 'warn', 131 | 'no-implicit-globals': 'warn', 132 | 'no-implied-eval': 'warn', 133 | //'no-inline-comments': 'warn', 134 | 'no-invalid-this': 'off', 135 | 'no-iterator': 'warn', 136 | 'no-label-var': 'warn', 137 | 'no-labels': 'warn', 138 | 'no-lone-blocks': 'warn', 139 | 'no-lonely-if': 'warn', 140 | 'no-loop-func': 'warn', 141 | 'no-magic-numbers': 'off', 142 | //'no-mixed-operators': 'warn', 143 | 'no-mixed-requires': 'warn', 144 | 'no-multi-spaces': 'warn', 145 | 'no-multi-str': 'warn', 146 | 'no-multiple-empty-lines': 'warn', 147 | 'no-native-reassign': 'warn', 148 | 'no-negated-condition': 'warn', 149 | 'no-negated-in-lhs': 'warn', 150 | 'no-nested-ternary': 'warn', 151 | //'no-new': 'warn', 152 | 'no-new-func': 'warn', 153 | 'no-new-object': 'warn', 154 | 'no-new-require': 'warn', 155 | 'no-new-wrappers': 'warn', 156 | 'no-octal-escape': 'warn', 157 | //'no-param-reassign': 'warn', 158 | 'no-path-concat': 'warn', 159 | //'no-plusplus': 'warn', 160 | 'no-process-env': 'warn', 161 | 'no-process-exit': 'warn', 162 | 'no-proto': 'warn', 163 | //'no-prototype-builtins': 'warn', 164 | 'no-restricted-globals': 'warn', 165 | 'no-restricted-imports': 'warn', 166 | 'no-restricted-modules': 'warn', 167 | 'no-restricted-properties': 'warn', 168 | 'no-restricted-syntax': 'warn', 169 | 'no-return-assign': 'warn', 170 | 'no-return-await': 'warn', 171 | 'no-script-url': 'warn', 172 | 'no-self-compare': 'warn', 173 | 'no-sequences': 'warn', 174 | //'no-shadow': 'warn', 175 | 'no-shadow-restricted-names': 'warn', 176 | 'no-spaced-func': 'warn', 177 | 'no-sync': 'warn', 178 | 'no-tabs': 'warn', 179 | 'no-template-curly-in-string': 'warn', 180 | 'no-ternary': 'off', 181 | //'no-throw-literal': 'warn', 182 | 'no-trailing-spaces': 'warn', 183 | 'no-undef': 'error', 184 | 'no-undef-init': 'warn', 185 | 'no-undefined': 'off', 186 | 'no-unused-vars': 'warn', 187 | //'no-underscore-dangle': 'warn', 188 | 'no-unmodified-loop-condition': 'warn', 189 | 'no-unneeded-ternary': 'warn', 190 | 'no-unused-expressions': 'warn', 191 | //'no-use-before-define': 'warn', 192 | 'no-useless-call': 'warn', 193 | 'no-useless-computed-key': 'warn', 194 | 'no-useless-concat': 'warn', 195 | 'no-useless-constructor': 'warn', 196 | 'no-useless-escape': 'warn', 197 | 'no-useless-rename': 'warn', 198 | 'no-useless-return': 'off', 199 | 'no-var': 'warn', 200 | 'no-void': 'warn', 201 | //'no-warning-comments': 'warn', 202 | 'no-whitespace-before-property': 'warn', 203 | 'no-with': 'warn', 204 | 'object-curly-spacing': [ 205 | 'warn', 206 | 'always' 207 | ], 208 | 'object-property-newline': 'warn', 209 | 'object-shorthand': 'warn', 210 | 'one-var': 'off', 211 | 'one-var-declaration-per-line': 'warn', 212 | 'operator-assignment': 'warn', 213 | 'operator-linebreak': 'warn', 214 | 'padded-blocks': 'off', 215 | 'prefer-arrow-callback': 'off', 216 | 'prefer-const': 'warn', 217 | 'prefer-numeric-literals': 'warn', 218 | //'prefer-reflect': 'warn', 219 | //'prefer-rest-params': 'warn', 220 | 'prefer-spread': 'warn', 221 | 'prefer-template': 'warn', 222 | 'quote-props': ['warn', 'as-needed'], 223 | 'quotes': [ 224 | 'warn', 225 | 'single' 226 | ], 227 | 'radix': 'warn', 228 | 'require-await': 'warn', 229 | //'require-jsdoc': 'warn', 230 | 'rest-spread-spacing': 'warn', 231 | 'semi': 'warn', 232 | 'semi-spacing': 'warn', 233 | 'sort-imports': 'off', 234 | 'sort-keys': 'off', 235 | 'sort-vars': 'off', 236 | 'space-before-blocks': 'warn', 237 | 'space-before-function-paren': 'warn', 238 | 'space-in-parens': [ 239 | 'warn', 240 | 'never' 241 | ], 242 | 'space-infix-ops': 'warn', 243 | 'space-unary-ops': 'warn', 244 | 'spaced-comment': 'warn', 245 | 'strict': 'warn', 246 | 'symbol-description': 'warn', 247 | 'template-curly-spacing': 'warn', 248 | 'unicode-bom': [ 249 | 'warn', 250 | 'never' 251 | ], 252 | //'valid-jsdoc': 'warn', 253 | 'vars-on-top': 'warn', 254 | 'wrap-iife': ['warn', 'inside'], 255 | 'wrap-regex': 'warn', 256 | 'yield-star-spacing': 'warn', 257 | 'yoda': 'warn' 258 | } 259 | }; 260 | -------------------------------------------------------------------------------- /examples/cornerstoneMath.min.js: -------------------------------------------------------------------------------- 1 | /*! cornerstoneMath - v0.1.3 - 2016-02-04 | (c) 2014 Chris Hafey | https://github.com/chafey/cornerstoneMath */ 2 | var cornerstoneMath=function(a){"use strict";return void 0===a&&(a={}),a.Vector3=function(a,b,c){this.x=a||0,this.y=b||0,this.z=c||0},a.Vector3.prototype={constructor:a.Vector3,set:function(a,b,c){return this.x=a,this.y=b,this.z=c,this},setX:function(a){return this.x=a,this},setY:function(a){return this.y=a,this},setZ:function(a){return this.z=a,this},setComponent:function(a,b){switch(a){case 0:this.x=b;break;case 1:this.y=b;break;case 2:this.z=b;break;default:throw new Error("index is out of range: "+a)}},getComponent:function(a){switch(a){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+a)}},copy:function(a){return this.x=a.x,this.y=a.y,this.z=a.z,this},add:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Vector3's .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(a,b)):(this.x+=a.x,this.y+=a.y,this.z+=a.z,this)},addScalar:function(a){return this.x+=a,this.y+=a,this.z+=a,this},addVectors:function(a,b){return this.x=a.x+b.x,this.y=a.y+b.y,this.z=a.z+b.z,this},sub:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Vector3's .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(a,b)):(this.x-=a.x,this.y-=a.y,this.z-=a.z,this)},subVectors:function(a,b){return this.x=a.x-b.x,this.y=a.y-b.y,this.z=a.z-b.z,this},multiply:function(a,b){return void 0!==b?(console.warn("DEPRECATED: Vector3's .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead."),this.multiplyVectors(a,b)):(this.x*=a.x,this.y*=a.y,this.z*=a.z,this)},multiplyScalar:function(a){return this.x*=a,this.y*=a,this.z*=a,this},multiplyVectors:function(a,b){return this.x=a.x*b.x,this.y=a.y*b.y,this.z=a.z*b.z,this},applyAxisAngle:function(){var b;return function(c,d){return void 0===b&&(b=new a.Quaternion),this.applyQuaternion(b.setFromAxisAngle(c,d)),this}}(),applyMatrix3:function(a){var b=this.x,c=this.y,d=this.z,e=a.elements;return this.x=e[0]*b+e[3]*c+e[6]*d,this.y=e[1]*b+e[4]*c+e[7]*d,this.z=e[2]*b+e[5]*c+e[8]*d,this},applyMatrix4:function(a){var b=this.x,c=this.y,d=this.z,e=a.elements;return this.x=e[0]*b+e[4]*c+e[8]*d+e[12],this.y=e[1]*b+e[5]*c+e[9]*d+e[13],this.z=e[2]*b+e[6]*c+e[10]*d+e[14],this},applyProjection:function(a){var b=this.x,c=this.y,d=this.z,e=a.elements,f=1/(e[3]*b+e[7]*c+e[11]*d+e[15]);return this.x=(e[0]*b+e[4]*c+e[8]*d+e[12])*f,this.y=(e[1]*b+e[5]*c+e[9]*d+e[13])*f,this.z=(e[2]*b+e[6]*c+e[10]*d+e[14])*f,this},applyQuaternion:function(a){var b=this.x,c=this.y,d=this.z,e=a.x,f=a.y,g=a.z,h=a.w,i=h*b+f*d-g*c,j=h*c+g*b-e*d,k=h*d+e*c-f*b,l=-e*b-f*c-g*d;return this.x=i*h+l*-e+j*-g-k*-f,this.y=j*h+l*-f+k*-e-i*-g,this.z=k*h+l*-g+i*-f-j*-e,this},transformDirection:function(a){var b=this.x,c=this.y,d=this.z,e=a.elements;return this.x=e[0]*b+e[4]*c+e[8]*d,this.y=e[1]*b+e[5]*c+e[9]*d,this.z=e[2]*b+e[6]*c+e[10]*d,this.normalize(),this},divide:function(a){return this.x/=a.x,this.y/=a.y,this.z/=a.z,this},divideScalar:function(a){if(0!==a){var b=1/a;this.x*=b,this.y*=b,this.z*=b}else this.x=0,this.y=0,this.z=0;return this},min:function(a){return this.x>a.x&&(this.x=a.x),this.y>a.y&&(this.y=a.y),this.z>a.z&&(this.z=a.z),this},max:function(a){return this.xb.x&&(this.x=b.x),this.yb.y&&(this.y=b.y),this.zb.z&&(this.z=b.z),this},clampScalar:function(){var b,c;return function(d,e){return void 0===b&&(b=new a.Vector3,c=new a.Vector3),b.set(d,d,d),c.set(e,e,e),this.clamp(b,c)}}(),floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this},roundToZero:function(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){var b=this.length();return 0!==b&&a!==b&&this.multiplyScalar(a/b),this},lerp:function(a,b){return this.x+=(a.x-this.x)*b,this.y+=(a.y-this.y)*b,this.z+=(a.z-this.z)*b,this},cross:function(a,b){if(void 0!==b)return console.warn("DEPRECATED: Vector3's .cross() now only accepts one argument. Use .crossVectors( a, b ) instead."),this.crossVectors(a,b);var c=this.x,d=this.y,e=this.z;return this.x=d*a.z-e*a.y,this.y=e*a.x-c*a.z,this.z=c*a.y-d*a.x,this},crossVectors:function(a,b){var c=a.x,d=a.y,e=a.z,f=b.x,g=b.y,h=b.z;return this.x=d*h-e*g,this.y=e*f-c*h,this.z=c*g-d*f,this},projectOnVector:function(){var b,c;return function(d){return void 0===b&&(b=new a.Vector3),b.copy(d).normalize(),c=this.dot(b),this.copy(b).multiplyScalar(c)}}(),projectOnPlane:function(){var b;return function(c){return void 0===b&&(b=new a.Vector3),b.copy(this).projectOnVector(c),this.sub(b)}}(),reflect:function(){var b;return function(c){return void 0===b&&(b=new a.Vector3),this.sub(b.copy(c).multiplyScalar(2*this.dot(c)))}}(),angleTo:function(b){var c=this.dot(b)/(this.length()*b.length());return Math.acos(a.clamp(c,-1,1))},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){var b=this.x-a.x,c=this.y-a.y,d=this.z-a.z;return b*b+c*c+d*d},setEulerFromRotationMatrix:function(a,b){console.error("REMOVED: Vector3's setEulerFromRotationMatrix has been removed in favor of Euler.setFromRotationMatrix(), please update your code.")},setEulerFromQuaternion:function(a,b){console.error("REMOVED: Vector3's setEulerFromQuaternion: has been removed in favor of Euler.setFromQuaternion(), please update your code.")},getPositionFromMatrix:function(a){return console.warn("DEPRECATED: Vector3's .getPositionFromMatrix() has been renamed to .setFromMatrixPosition(). Please update your code."),this.setFromMatrixPosition(a)},getScaleFromMatrix:function(a){return console.warn("DEPRECATED: Vector3's .getScaleFromMatrix() has been renamed to .setFromMatrixScale(). Please update your code."),this.setFromMatrixScale(a)},getColumnFromMatrix:function(a,b){return console.warn("DEPRECATED: Vector3's .getColumnFromMatrix() has been renamed to .setFromMatrixColumn(). Please update your code."),this.setFromMatrixColumn(a,b)},setFromMatrixPosition:function(a){return this.x=a.elements[12],this.y=a.elements[13],this.z=a.elements[14],this},setFromMatrixScale:function(a){var b=this.set(a.elements[0],a.elements[1],a.elements[2]).length(),c=this.set(a.elements[4],a.elements[5],a.elements[6]).length(),d=this.set(a.elements[8],a.elements[9],a.elements[10]).length();return this.x=b,this.y=c,this.z=d,this},setFromMatrixColumn:function(a,b){var c=4*a,d=b.elements;return this.x=d[c],this.y=d[c+1],this.z=d[c+2],this},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},fromArray:function(a){return this.x=a[0],this.y=a[1],this.z=a[2],this},toArray:function(){return[this.x,this.y,this.z]},clone:function(){return new a.Vector3(this.x,this.y,this.z)}},a}(cornerstoneMath),cornerstoneMath=function(a){"use strict";return void 0===a&&(a={}),a.Line3=function(b,c){this.start=void 0!==b?b:new a.Vector3,this.end=void 0!==c?c:new a.Vector3},a.Line3.prototype={constructor:a.Line3,set:function(a,b){return this.start.copy(a),this.end.copy(b),this},copy:function(a){return this.start.copy(a.start),this.end.copy(a.end),this},center:function(b){var c=b||new a.Vector3;return c.addVectors(this.start,this.end).multiplyScalar(.5)},delta:function(b){var c=b||new a.Vector3;return c.subVectors(this.end,this.start)},distanceSq:function(){return this.start.distanceToSquared(this.end)},distance:function(){return this.start.distanceTo(this.end)},at:function(b,c){var d=c||new a.Vector3;return this.delta(d).multiplyScalar(b).add(this.start)},closestPointToPointParameter:function(){var b=new a.Vector3,c=new a.Vector3;return function(d,e){b.subVectors(d,this.start),c.subVectors(this.end,this.start);var f=c.dot(c),g=c.dot(b),h=g/f;return e&&(h=a.Math.clamp(h,0,1)),h}}(),closestPointToPoint:function(b,c,d){var e=this.closestPointToPointParameter(b,c),f=d||new a.Vector3;return this.delta(f).multiplyScalar(e).add(this.start)},applyMatrix4:function(a){return this.start.applyMatrix4(a),this.end.applyMatrix4(a),this},equals:function(a){return a.start.equals(this.start)&&a.end.equals(this.end)},clone:function(){return(new a.Line3).copy(this)},intersectLine:function(a){var b=this.end.clone().sub(this.start),c=a.end.clone().sub(a.start),d=a.start.clone().sub(this.start),e=b.clone().cross(c),f=d.clone().cross(c);if(0!==d.dot(b)){var g=f.dot(e)/e.lengthSq();if(!(g>1||isNaN(g))){var h=this.start.clone().add(b.clone().multiplyScalar(g)),i=h.clone().sub(a.start).lengthSq()+h.clone().sub(a.end).lengthSq();return i<=a.distanceSq()?h:void 0}}}},a}(cornerstoneMath),cornerstoneMath=function(a){"use strict";function b(a){return a*a}function c(a,c){return b(a.x-c.x)+b(a.y-c.y)}function d(a,b){var d=c(a.start,a.end);if(0===d)return c(b,a.start);var e=((b.x-a.start.x)*(a.end.x-a.start.x)+(b.y-a.start.y)*(a.end.y-a.start.y))/d;if(0>e)return c(b,a.start);if(e>1)return c(b,a.end);var f={x:a.start.x+e*(a.end.x-a.start.x),y:a.start.y+e*(a.end.y-a.start.y)};return c(b,f)}function e(a,b){return Math.sqrt(d(a,b))}function f(b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p={},q=b.start.x,r=b.start.y,s=b.end.x,t=b.end.y,u=c.start.x,v=c.start.y,w=c.end.x,x=c.end.y;if(d=t-r,f=q-s,h=s*r-q*t,l=d*u+f*v+h,m=d*w+f*x+h,(0===l||0===m||a.sign(l)!==a.sign(m))&&(e=x-v,g=u-w,i=w*v-u*x,j=e*q+g*r+i,k=e*s+g*t+i,0===j||0===k||a.sign(j)!==a.sign(k))){n=d*g-e*f,o=f*i-g*h;var y=parseFloat(o/n);o=e*h-d*i;var z=parseFloat(o/n);return p.x=y,p.y=z,p}}return void 0===a&&(a={}),a.lineSegment={distanceToPoint:e,intersectLine:f},a}(cornerstoneMath),cornerstoneMath=function(a){"use strict";function b(a,b,c){return b>a?b:a>c?c:a}function c(a){var b=Math.PI/180;return a*b}function d(a){var b=180/Math.PI;return a*b}function e(a){return"number"==typeof a?a?0>a?-1:1:a===a?0:NaN:NaN}return void 0===a&&(a={}),a.clamp=b,a.degToRad=c,a.radToDeg=d,a.sign=e,a}(cornerstoneMath),cornerstoneMath=function(a){"use strict";return void 0===a&&(a={}),a.Matrix4=function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){this.elements=new Float32Array(16);var q=this.elements;q[0]=void 0!==a?a:1,q[4]=b||0,q[8]=c||0,q[12]=d||0,q[1]=e||0,q[5]=void 0!==f?f:1,q[9]=g||0,q[13]=h||0,q[2]=i||0,q[6]=j||0,q[10]=void 0!==k?k:1,q[14]=l||0,q[3]=m||0,q[7]=n||0,q[11]=o||0,q[15]=void 0!==p?p:1},a.Matrix4.prototype.makeRotationFromQuaternion=function(a){var b=this.elements,c=a.x,d=a.y,e=a.z,f=a.w,g=c+c,h=d+d,i=e+e,j=c*g,k=c*h,l=c*i,m=d*h,n=d*i,o=e*i,p=f*g,q=f*h,r=f*i;return b[0]=1-(m+o),b[4]=k-r,b[8]=l+q,b[1]=k+r,b[5]=1-(j+o),b[9]=n-p,b[2]=l-q,b[6]=n+p,b[10]=1-(j+m),b[3]=0,b[7]=0,b[11]=0,b[12]=0,b[13]=0,b[14]=0,b[15]=1,this},a.Matrix4.prototype.multiplyMatrices=function(a,b){var c=a.elements,d=b.elements,e=this.elements,f=c[0],g=c[4],h=c[8],i=c[12],j=c[1],k=c[5],l=c[9],m=c[13],n=c[2],o=c[6],p=c[10],q=c[14],r=c[3],s=c[7],t=c[11],u=c[15],v=d[0],w=d[4],x=d[8],y=d[12],z=d[1],A=d[5],B=d[9],C=d[13],D=d[2],E=d[6],F=d[10],G=d[14],H=d[3],I=d[7],J=d[11],K=d[15];return e[0]=f*v+g*z+h*D+i*H,e[4]=f*w+g*A+h*E+i*I,e[8]=f*x+g*B+h*F+i*J,e[12]=f*y+g*C+h*G+i*K,e[1]=j*v+k*z+l*D+m*H,e[5]=j*w+k*A+l*E+m*I,e[9]=j*x+k*B+l*F+m*J,e[13]=j*y+k*C+l*G+m*K,e[2]=n*v+o*z+p*D+q*H,e[6]=n*w+o*A+p*E+q*I,e[10]=n*x+o*B+p*F+q*J,e[14]=n*y+o*C+p*G+q*K,e[3]=r*v+s*z+t*D+u*H,e[7]=r*w+s*A+t*E+u*I,e[11]=r*x+s*B+t*F+u*J,e[15]=r*y+s*C+t*G+u*K,this},a.Matrix4.prototype.multiply=function(a,b){return void 0!==b?(console.warn("DEPRECATED: Matrix4's .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead."),this.multiplyMatrices(a,b)):this.multiplyMatrices(this,a)},a.Matrix4.prototype.getInverse=function(a,b){var c=this.elements,d=a.elements,e=d[0],f=d[4],g=d[8],h=d[12],i=d[1],j=d[5],k=d[9],l=d[13],m=d[2],n=d[6],o=d[10],p=d[14],q=d[3],r=d[7],s=d[11],t=d[15];c[0]=k*p*r-l*o*r+l*n*s-j*p*s-k*n*t+j*o*t,c[4]=h*o*r-g*p*r-h*n*s+f*p*s+g*n*t-f*o*t,c[8]=g*l*r-h*k*r+h*j*s-f*l*s-g*j*t+f*k*t,c[12]=h*k*n-g*l*n-h*j*o+f*l*o+g*j*p-f*k*p,c[1]=l*o*q-k*p*q-l*m*s+i*p*s+k*m*t-i*o*t,c[5]=g*p*q-h*o*q+h*m*s-e*p*s-g*m*t+e*o*t,c[9]=h*k*q-g*l*q-h*i*s+e*l*s+g*i*t-e*k*t,c[13]=g*l*m-h*k*m+h*i*o-e*l*o-g*i*p+e*k*p,c[2]=j*p*q-l*n*q+l*m*r-i*p*r-j*m*t+i*n*t,c[6]=h*n*q-f*p*q-h*m*r+e*p*r+f*m*t-e*n*t,c[10]=f*l*q-h*j*q+h*i*r-e*l*r-f*i*t+e*j*t,c[14]=h*j*m-f*l*m-h*i*n+e*l*n+f*i*p-e*j*p,c[3]=k*n*q-j*o*q-k*m*r+i*o*r+j*m*s-i*n*s,c[7]=f*o*q-g*n*q+g*m*r-e*o*r-f*m*s+e*n*s,c[11]=g*j*q-f*k*q-g*i*r+e*k*r+f*i*s-e*j*s,c[15]=f*k*m-g*j*m+g*i*n-e*k*n-f*i*o+e*j*o;var u=e*c[0]+i*c[4]+m*c[8]+q*c[12];if(0===u){var v="Matrix4.getInverse(): can't invert matrix, determinant is 0";if(b)throw new Error(v);return console.warn(v),this.identity(),this}return this.multiplyScalar(1/u),this},a.Matrix4.prototype.applyToVector3Array=function(){var b=new a.Vector3;return function(a,c,d){void 0===c&&(c=0),void 0===d&&(d=a.length);for(var e=0,f=c;d>e;e+=3,f+=3)b.x=a[f],b.y=a[f+1],b.z=a[f+2],b.applyMatrix4(this),a[f]=b.x,a[f+1]=b.y,a[f+2]=b.z;return a}},a.Matrix4.prototype.makeTranslation=function(a,b,c){return this.set(1,0,0,a,0,1,0,b,0,0,1,c,0,0,0,1),this},a.Matrix4.prototype.multiplyScalar=function(a){var b=this.elements;return b[0]*=a,b[4]*=a,b[8]*=a,b[12]*=a,b[1]*=a,b[5]*=a,b[9]*=a,b[13]*=a,b[2]*=a,b[6]*=a,b[10]*=a,b[14]*=a,b[3]*=a,b[7]*=a,b[11]*=a,b[15]*=a,this},a.Matrix4.prototype.set=function(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){var q=this.elements;return q[0]=a,q[4]=b,q[8]=c,q[12]=d,q[1]=e,q[5]=f,q[9]=g,q[13]=h,q[2]=i,q[6]=j,q[10]=k,q[14]=l,q[3]=m,q[7]=n,q[11]=o,q[15]=p,this},a.Matrix4.prototype.makeScale=function(a,b,c){return this.set(a,0,0,0,0,b,0,0,0,0,c,0,0,0,0,1),this},a}(cornerstoneMath),cornerstoneMath=function(a){"use strict";return void 0===a&&(a={}),a.Plane=function(b,c){this.normal=void 0!==b?b:new a.Vector3(1,0,0),this.constant=void 0!==c?c:0},a.Plane.prototype={constructor:a.Plane,set:function(a,b){return this.normal.copy(a),this.constant=b,this},setComponents:function(a,b,c,d){return this.normal.set(a,b,c),this.constant=d,this},setFromNormalAndCoplanarPoint:function(a,b){return this.normal.copy(a),this.constant=-b.dot(this.normal),this},setFromCoplanarPoints:function(){var b=new a.Vector3,c=new a.Vector3;return function(a,d,e){var f=b.subVectors(e,d).cross(c.subVectors(a,d)).normalize();return this.setFromNormalAndCoplanarPoint(f,a),this}}(),copy:function(a){return this.normal.copy(a.normal),this.constant=a.constant,this},normalize:function(){var a=1/this.normal.length();return this.normal.multiplyScalar(a),this.constant*=a,this},negate:function(){return this.constant*=-1,this.normal.negate(),this},distanceToPoint:function(a){return this.normal.dot(a)+this.constant},distanceToSphere:function(a){return this.distanceToPoint(a.center)-a.radius},projectPoint:function(a,b){return this.orthoPoint(a,b).sub(a).negate()},orthoPoint:function(b,c){var d=this.distanceToPoint(b),e=c||new a.Vector3;return e.copy(this.normal).multiplyScalar(d)},isIntersectionLine:function(a){var b=this.distanceToPoint(a.start),c=this.distanceToPoint(a.end);return 0>b&&c>0||0>c&&b>0},intersectLine:function(){var b=new a.Vector3;return function(c,d){var e=d||new a.Vector3,f=c.delta(b),g=this.normal.dot(f);if(0===g)return 0===this.distanceToPoint(c.start)?e.copy(c.start):void 0;var h=-(c.start.dot(this.normal)+this.constant)/g;return 0>h||h>1?void 0:e.copy(f).multiplyScalar(h).add(c.start)}}(),intersectPlane:function(b){var c=this.normal.clone().cross(b.normal),d=new a.Vector3,e={origin:d,direction:c};if(this.normal.clone().cross(b.normal).length<1e-10)return e.direction=new a.Vector3,e;var f=this.constant,g=b.constant,h=this.normal.clone().dot(b.normal),i=-(f-g*h)/(1-h*h),j=-(g-f*h)/(1-h*h);return e.origin=this.normal.clone().multiplyScalar(i).add(b.normal.clone().multiplyScalar(j)),e},coplanarPoint:function(b){var c=b||new a.Vector3;return c.copy(this.normal).multiplyScalar(-this.constant)},translate:function(a){return this.constant=this.constant-a.dot(this.normal),this},equals:function(a){return a.normal.equals(this.normal)&&a.constant==this.constant},clone:function(){return(new a.Plane).copy(this)}},a}(cornerstoneMath),cornerstoneMath=function(a){"use strict";function b(a){return{x:a.pageX,y:a.pageY}}function c(a,b){return{x:a.x-b.x,y:a.y-b.y}}function d(a){return{x:a.x,y:a.y}}function e(a,b){return Math.sqrt(f(a,b))}function f(a,b){var d=c(a,b);return d.x*d.x+d.y*d.y}function g(a,b){return a.xb.left+b.width||a.yb.top+b.height?!1:!0}function h(b,c){var d,e=[];b.forEach(function(b,f){var g=a.point.distance(b,c);e.push(g),d=0===f?g:Math.min(g,d)});var f=e.indexOf(d);return b[f]}return void 0===a&&(a={}),a.point={subtract:c,copy:d,pageToPoint:b,distance:e,distanceSquared:f,insideRect:g,findClosestPoint:h},a}(cornerstoneMath),cornerstoneMath=function(a){"use strict";return void 0===a&&(a={}),a.Quaternion=function(a,b,c,d){this.x=a||0,this.y=b||0,this.z=c||0,this.w=void 0!==d?d:1},a.Quaternion.prototype.setFromAxisAngle=function(a,b){var c=b/2,d=Math.sin(c);return this.x=a.x*d,this.y=a.y*d,this.z=a.z*d,this.w=Math.cos(c),this},a.Quaternion.prototype.multiplyQuaternions=function(a,b){var c=a.x,d=a.y,e=a.z,f=a.w,g=b.x,h=b.y,i=b.z,j=b.w;return this.x=c*j+f*g+d*i-e*h,this.y=d*j+f*h+e*g-c*i,this.z=e*j+f*i+c*h-d*g,this.w=f*j-c*g-d*h-e*i,this},a.Quaternion.prototype.setFromRotationMatrix=function(a){var b,c=a.elements,d=c[0],e=c[4],f=c[8],g=c[1],h=c[5],i=c[9],j=c[2],k=c[6],l=c[10],m=d+h+l;return m>0?(b=.5/Math.sqrt(m+1),this.w=.25/b,this.x=(k-i)*b,this.y=(f-j)*b,this.z=(g-e)*b):d>h&&d>l?(b=2*Math.sqrt(1+d-h-l),this.w=(k-i)/b,this.x=.25*b,this.y=(e+g)/b,this.z=(f+j)/b):h>l?(b=2*Math.sqrt(1+h-d-l),this.w=(f-j)/b,this.x=(e+g)/b,this.y=.25*b,this.z=(i+k)/b):(b=2*Math.sqrt(1+l-d-h),this.w=(g-e)/b,this.x=(f+j)/b,this.y=(i+k)/b,this.z=.25*b),this},a}(cornerstoneMath),cornerstoneMath=function(a){"use strict";function b(a){var b={start:{x:a.left,y:a.top},end:{x:a.left+a.width,y:a.top}},c={start:{x:a.left+a.width,y:a.top},end:{x:a.left+a.width,y:a.top+a.height}},d={start:{x:a.left+a.width,y:a.top+a.height},end:{x:a.left,y:a.top+a.height}},e={start:{x:a.left,y:a.top+a.height},end:{x:a.left,y:a.top}},f=[b,c,d,e];return f}function c(c,d){var e=655535,f=b(c);return f.forEach(function(b){var c=a.lineSegment.distanceToPoint(b,d);e>c&&(e=c)}),e}function d(a){var b={topLeft:{x:a.left,y:a.top},bottomRight:{x:a.left+a.width,y:a.top+a.height}};return b}function e(a,b){var c,e,f=d(a),g=d(b);return c=a.width>=0?b.width>=0?!(f.bottomRight.x<=g.topLeft.x||g.bottomRight.x<=f.topLeft.x):!(f.bottomRight.x<=g.bottomRight.x||g.topLeft.x<=f.topLeft.x):b.width>=0?!(f.topLeft.x<=g.topLeft.x||g.bottomRight.x<=f.bottomRight.x):!(f.topLeft.x<=g.bottomRight.x||g.topLeft.x<=f.bottomRight.x),e=a.height>=0?b.height>=0?!(f.bottomRight.y<=g.topLeft.y||g.bottomRight.y<=f.topLeft.y):!(f.bottomRight.y<=g.bottomRight.y||g.topLeft.y<=f.topLeft.y):b.height>=0?!(f.topLeft.y<=g.topLeft.y||g.bottomRight.y<=f.bottomRight.y):!(f.topLeft.y<=g.bottomRight.y||g.top<=f.bottomRight.y),c&&e}function f(a,b){var c={topLeft:{},bottomRight:{}};if(e(a,b)){var f=d(a),g=d(b);return a.width>=0?b.width>=0?(c.topLeft.x=Math.max(f.topLeft.x,g.topLeft.x),c.bottomRight.x=Math.min(f.bottomRight.x,g.bottomRight.x)):(c.topLeft.x=Math.max(f.topLeft.x,g.bottomRight.x),c.bottomRight.x=Math.min(f.bottomRight.x,g.topLeft.x)):b.width>=0?(c.topLeft.x=Math.min(f.topLeft.x,g.bottomRight.x),c.bottomRight.x=Math.max(f.bottomRight.x,g.topLeft.x)):(c.topLeft.x=Math.min(f.topLeft.x,g.topLeft.x),c.bottomRight.x=Math.max(f.bottomRight.x,g.bottomRight.x)),a.height>=0?b.height>=0?(c.topLeft.y=Math.max(f.topLeft.y,g.topLeft.y),c.bottomRight.y=Math.min(f.bottomRight.y,g.bottomRight.y)):(c.topLeft.y=Math.max(f.topLeft.y,g.bottomRight.y),c.bottomRight.y=Math.min(f.bottomRight.y,g.topLeft.y)):b.height>=0?(c.topLeft.y=Math.min(f.topLeft.y,g.bottomRight.y),c.bottomRight.y=Math.max(f.bottomRight.y,g.topLeft.y)):(c.topLeft.y=Math.min(f.topLeft.y,g.topLeft.y),c.bottomRight.y=Math.max(f.bottomRight.y,g.bottomRight.y)),c}}return void 0===a&&(a={}),a.rect={distanceToPoint:c,getIntersectionRect:f},a}(cornerstoneMath); -------------------------------------------------------------------------------- /examples/cornerstone.min.js: -------------------------------------------------------------------------------- 1 | /*! cornerstone-core - 2.0.0 - 2017-12-08 | (c) 2016 Chris Hafey | https://github.com/cornerstonejs/cornerstone */ 2 | !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cornerstone-core",[],t):"object"==typeof exports?exports["cornerstone-core"]=t():e.cornerstone=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=41)}([function(e,t,r){"use strict";function n(e){if(void 0===e)throw new Error("getEnabledElement: parameter element must not be undefined");for(var t=0;t2&&void 0!==arguments[2]?arguments[2]:null,n=void 0;return"function"==typeof window.CustomEvent?n=new CustomEvent(t,{detail:r,cancelable:!0}):(n=document.createEvent("CustomEvent"),n.initCustomEvent(t,!0,!0,r)),e.dispatchEvent(n)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){if(void 0===e)throw new Error("setToPixelCoordinateSystem: parameter enabledElement must not be undefined");if(void 0===t)throw new Error("setToPixelCoordinateSystem: parameter context must not be undefined");var n=(0,a.default)(e,r);t.setTransform(n.m[0],n.m[1],n.m[2],n.m[3],n.m[4],n.m[5])};var n=r(22),a=function(e){return e&&e.__esModule?e:{default:e}}(n)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=(0,n.getEnabledElement)(e);if(void 0===r.image&&!r.layers.length)throw new Error("updateImage: image has not been loaded yet");(0,o.default)(r,t)};var n=r(0),a=r(5),o=function(e){return e&&e.__esModule?e:{default:e}}(a)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e.needsRedraw=!0,t&&(e.invalid=!0)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){if(void 0===e)throw new Error("getDefaultViewport: parameter canvas must not be undefined");if(void 0===t)return{scale:1,translation:{x:0,y:0},voi:{windowWidth:void 0,windowCenter:void 0},invert:!1,pixelReplication:!1,rotation:0,hflip:!1,vflip:!1,modalityLUT:void 0,voiLUT:void 0,colormap:void 0,labelmap:!1};var r=e.height/t.rows,n=e.width/t.columns;return{scale:Math.min(n,r),translation:{x:0,y:0},voi:{windowWidth:t.windowWidth,windowCenter:t.windowCenter},invert:t.invert,pixelReplication:!1,rotation:0,hflip:!1,vflip:!1,modalityLUT:t.modalityLUT,voiLUT:t.voiLUT,colormap:t.colormap,labelmap:Boolean(t.labelmap)}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(28),a=r(29),o=function(e){return e&&e.__esModule?e:{default:e}}(a);t.default={getColormap:n.getColormap,getColormapsList:n.getColormapsList,LookupTable:o.default}},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function a(e,t){return void 0!==e.cachedLut&&e.cachedLut.windowCenter===t.voi.windowCenter&&e.cachedLut.windowWidth===t.voi.windowWidth&&e.cachedLut.invert===t.invert?e.cachedLut.lutArray:((0,f.default)(e,t.voi.windowWidth,t.voi.windowCenter,t.invert),e.cachedLut.windowWidth=t.voi.windowWidth,e.cachedLut.windowCenter=t.voi.windowCenter,e.cachedLut.invert=t.invert,e.cachedLut.lutArray)}function o(e,t,r){e.renderingTools.renderCanvas||(e.renderingTools.renderCanvas=document.createElement("canvas"));var n=e.renderingTools.renderCanvas;if(255===e.viewport.voi.windowWidth&&128===e.viewport.voi.windowCenter&&!1===e.viewport.invert&&t.getCanvas&&t.getCanvas())return t.getCanvas();if(!1===(0,I.default)(e,t)&&!0!==r)return n;n.width===t.width&&n.height===t.height||(0,P.default)(e,t);var o=(0,d.default)(),i=a(t,e.viewport);t.stats=t.stats||{},t.stats.lastLutGenerateTime=(0,d.default)()-o;var l=e.renderingTools.renderCanvasData,u=e.renderingTools.renderCanvasContext;return t.rgba?(0,v.default)(t,i,l.data):(0,m.default)(t,i,l.data),o=(0,d.default)(),u.putImageData(l,0,0),t.stats.lastPutImageDataTime=(0,d.default)()-o,n}function i(e,t){if(void 0===e)throw new Error("renderColorImage: enabledElement parameter must not be undefined");var r=e.image;if(void 0===r)throw new Error("renderColorImage: image must be loaded before it can be drawn");var n=e.canvas.getContext("2d");n.setTransform(1,0,0,1,0,0),n.fillStyle="black",n.fillRect(0,0,e.canvas.width,e.canvas.height),n.imageSmoothingEnabled=!e.viewport.pixelReplication,n.mozImageSmoothingEnabled=n.imageSmoothingEnabled,(0,p.default)(e,n);var a=void 0;a=e.options&&e.options.renderer&&"webgl"===e.options.renderer.toLowerCase()?w.default.renderer.render(e):o(e,r,t),n.drawImage(a,0,0,r.width,r.height,0,0,r.width,r.height),e.renderingTools=(0,E.default)(e)}function l(e,t){if(void 0===e)throw new Error("addColorLayer: layer parameter must not be undefined");var r=e.image;if(void 0===r)throw new Error("addColorLayer: image must be loaded before it can be drawn");r.rgba=!0,e.canvas=o(e,r,t);var n=e.canvas.getContext("2d");n.imageSmoothingEnabled=!e.viewport.pixelReplication,n.mozImageSmoothingEnabled=n.imageSmoothingEnabled,e.renderingTools=(0,E.default)(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.renderColorImage=i,t.addColorLayer=l;var u=r(1),d=n(u),s=r(44),f=n(s),c=r(19),m=n(c),g=r(45),v=n(g),h=r(3),p=n(h),b=r(13),w=n(b),y=r(12),I=n(y),_=r(10),P=n(_),C=r(11),E=n(C)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return(0,a.default)(e)};var n=r(22),a=function(e){return e&&e.__esModule?e:{default:e}}(n)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){var r=e.renderingTools.renderCanvas;r.width=t.width,r.height=t.height;var n=r.getContext("2d");n.fillStyle="white",n.fillRect(0,0,r.width,r.height);var a=n.getImageData(0,0,t.width,t.height);e.renderingTools.renderCanvasContext=n,e.renderingTools.renderCanvasData=a}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=e.image.imageId,r=e.viewport;return e.renderingTools.lastRenderedImageId=t,e.renderingTools.lastRenderedViewport={windowCenter:r.voi.windowCenter,windowWidth:r.voi.windowWidth,invert:r.invert,rotation:r.rotation,hflip:r.hflip,vflip:r.vflip,modalityLUT:r.modalityLUT,voiLUT:r.voiLUT,colormap:r.colormap},e.renderingTools}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){var r=e.renderingTools.lastRenderedImageId,n=e.renderingTools.lastRenderedViewport;return t.imageId!==r||!n||n.windowCenter!==e.viewport.voi.windowCenter||n.windowWidth!==e.viewport.voi.windowWidth||n.invert!==e.viewport.invert||n.rotation!==e.viewport.rotation||n.hflip!==e.viewport.hflip||n.vflip!==e.viewport.vflip||n.modalityLUT!==e.viewport.modalityLUT||n.voiLUT!==e.viewport.voiLUT||n.colormap!==e.viewport.colormap}},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var a=r(46),o=r(34),i=n(o),l=r(33),u=n(l),d={createProgramFromString:i.default,renderer:{render:a.render,initRenderer:a.initRenderer,getRenderCanvas:a.getRenderCanvas,isWebGLAvailable:a.isWebGLAvailable},textureCache:u.default};Object.defineProperty(d,"isWebGLInitialized",{enumerable:!0,configurable:!1,get:function(){return a.isWebGLInitialized}}),t.default=d},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var a=function(){function e(e,t){for(var r=0;r3&&void 0!==arguments[3])||arguments[3];e.renderingTools.renderCanvas||(e.renderingTools.renderCanvas=document.createElement("canvas"));var a=e.renderingTools.renderCanvas;if(!1===(0,y.default)(e,t)&&!0!==r)return a;a.width===t.width&&a.height===t.height||(0,_.default)(e,t);var o=(0,g.default)(),i=(0,b.default)(t,e.viewport,r);t.stats=t.stats||{},t.stats.lastLutGenerateTime=(0,g.default)()-o;var l=e.renderingTools.renderCanvasData,d=e.renderingTools.renderCanvasContext;return n?(0,u.default)(t,i,l.data):(0,s.default)(t,i,l.data),o=(0,g.default)(),d.putImageData(l,0,0),t.stats.lastPutImageDataTime=(0,g.default)()-o,a}function o(e,t){if(void 0===e)throw new Error("drawImage: enabledElement parameter must not be undefined");var r=e.image;if(void 0===r)throw new Error("drawImage: image must be loaded before it can be drawn");var n=e.canvas.getContext("2d");n.setTransform(1,0,0,1,0,0),n.fillStyle="black",n.fillRect(0,0,e.canvas.width,e.canvas.height),n.imageSmoothingEnabled=!e.viewport.pixelReplication,n.mozImageSmoothingEnabled=n.imageSmoothingEnabled,(0,c.default)(e,n);var o=void 0;o=e.options&&e.options.renderer&&"webgl"===e.options.renderer.toLowerCase()?h.default.renderer.render(e):a(e,r,t),n.drawImage(o,0,0,r.width,r.height,0,0,r.width,r.height),e.renderingTools=(0,C.default)(e)}function i(e,t){var r=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(void 0===e)throw new Error("addGrayscaleLayer: layer parameter must not be undefined");var n=e.image;if(void 0===n)throw new Error("addGrayscaleLayer: image must be loaded before it can be drawn");e.canvas=a(e,n,t,r);var o=e.canvas.getContext("2d");o.imageSmoothingEnabled=!e.viewport.pixelReplication,o.mozImageSmoothingEnabled=o.imageSmoothingEnabled,e.renderingTools=(0,C.default)(e)}Object.defineProperty(t,"__esModule",{value:!0}),t.renderGrayscaleImage=o,t.addGrayscaleLayer=i;var l=r(18),u=n(l),d=r(30),s=n(d),f=r(3),c=n(f),m=r(1),g=n(m),v=r(13),h=n(v),p=r(32),b=n(p),w=r(12),y=n(w),I=r(10),_=n(I),P=r(11),C=n(P)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r,n,a,i){var u=e.maxPixelValue,d=e.minPixelValue,s=Math.min(d,0);if(void 0===e.cachedLut){var f=u-s+1;e.cachedLut={},e.cachedLut.lutArray=new Uint8ClampedArray(f)}var c=e.cachedLut.lutArray,m=(0,o.default)(e.slope,e.intercept,a),g=(0,l.default)(t,r,i);if(!0===n)for(var v=d;v<=u;v++)c[v+-s]=255-g(m(v));else for(var h=d;h<=u;h++)c[h+-s]=g(m(h));return c};var a=r(26),o=n(a),i=r(27),l=n(i)},function(e,t,r){"use strict";function n(e){window.setTimeout(e,1e3/60)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return window.requestAnimationFrame(e)||window.webkitRequestAnimationFrame(e)||window.mozRequestAnimationFrame(e)||window.oRequestAnimationFrame(e)||window.msRequestAnimationFrame(e)||n(e)}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){var n=(0,a.default)(),o=e.getPixelData();e.stats.lastGetPixelDataTime=(0,a.default)()-n;var i=o.length,l=e.minPixelValue,u=3,d=0;if(n=(0,a.default)(),o instanceof Int16Array)if(l<0)for(;d=n?r:e.lut[a]}}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){return r?a(r):n(e,t)}},function(e,t,r){"use strict";function n(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t>r,o=e.lut[e.lut.length-1]>>r,i=e.firstValueMapped+e.lut.length-1;return function(t){return t=i?o:e.lut[t-e.firstValueMapped]>>r}}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){return r?o(r):a(e,t)}},function(e,t,r){"use strict";function n(e,t,r){r=null===r?100:r;for(var n=(t-e)/(r-1),a=[];r-- >0;)a.push(e),e+=n;return a[a.length-1]=t,a}function a(e,t){for(var r=0,n=e.length-1;r<=n;){var a=r+Math.floor((n-r)/2),o=e[a];if(o===t)return a;t=0&&e1)throw new Error("HSVToRGB expects hue < 1");var n=[];if(0===t)return n[0]=r,n[1]=r,n[2]=r,n;var a=Math.floor(6*e),o=6*e-a,i=r*(1-t),l=r*(1-t*o),u=r*(1-t*(1-o));switch(a){case 0:case 6:n[0]=r,n[1]=u,n[2]=i;break;case 1:n[0]=l,n[1]=r,n[2]=i;break;case 2:n[0]=i,n[1]=r,n[2]=u;break;case 3:n[0]=i,n[1]=l,n[2]=r;break;case 4:n[0]=u,n[1]=i,n[2]=r;break;case 5:n[0]=r,n[1]=i,n[2]=l}return n}function o(e,t){var r=void 0;return r=et.Range[1]?t.MaxIndex+u+1.5:(e+t.Shift)*t.Scale,Math.floor(r)}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r1)||e){this.Table=[];var t=this.NumberOfColors-1,r=void 0,n=void 0,o=void 0,i=void 0;t?(r=(this.HueRange[1]-this.HueRange[0])/t,n=(this.SaturationRange[1]-this.SaturationRange[0])/t,o=(this.ValueRange[1]-this.ValueRange[0])/t,i=(this.AlphaRange[1]-this.AlphaRange[0])/t):r=n=o=i=0;for(var l=0;l<=t;l++){var u=this.HueRange[0]+l*r,d=this.SaturationRange[0]+l*n,s=this.ValueRange[0]+l*o,f=this.AlphaRange[0]+l*i,c=a(u,d,s),m=[];switch(this.Ramp){case"scurve":m[0]=Math.floor(127.5*(1+Math.cos((1-c[0])*Math.PI))),m[1]=Math.floor(127.5*(1+Math.cos((1-c[1])*Math.PI))),m[2]=Math.floor(127.5*(1+Math.cos((1-c[2])*Math.PI))),m[3]=Math.floor(255*f);break;case"linear":m[0]=Math.floor(255*c[0]+.5),m[1]=Math.floor(255*c[1]+.5),m[2]=Math.floor(255*c[2]+.5),m[3]=Math.floor(255*f+.5);break;case"sqrt":m[0]=Math.floor(255*Math.sqrt(c[0])+.5),m[1]=Math.floor(255*Math.sqrt(c[1])+.5),m[2]=Math.floor(255*Math.sqrt(c[2])+.5),m[3]=Math.floor(255*Math.sqrt(f)+.5);break;default:throw new Error("Invalid Ramp value ("+this.Ramp+")")}this.Table.push(m)}this.buildSpecialColors()}}},{key:"buildSpecialColors",value:function(){var e=this.NumberOfColors,t=e+l,r=e+u,n=e+2;this.UseBelowRangeColor||0===e?this.Table[t]=this.BelowRangeColor:this.Table[t]=this.Table[0],this.UseAboveRangeColor||0===e?this.Table[r]=this.AboveRangeColor:this.Table[r]=this.Table[e-1],this.Table[n]=this.NaNColor}},{key:"mapValue",value:function(e){var t=this.getIndex(e);if(t<0)return this.NaNColor;if(0===t){if(this.UseBelowRangeColor&&ethis.TableRange[1])return this.AboveRangeColor;return this.Table[t]}},{key:"getIndex",value:function(e){var t={};if(t.Range=[],t.MaxIndex=this.NumberOfColors-1,t.Shift=-this.TableRange[0],this.TableRange[1]<=this.TableRange[0]?t.Scale=Number.MAX_VALUE:t.Scale=t.MaxIndex/(this.TableRange[1]-this.TableRange[0]),t.Range[0]=this.TableRange[0],t.Range[1]=this.TableRange[1],isNaN(e))return-1;var r=o(e,t);return r===this.NumberOfColors+l?r=0:r===this.NumberOfColors+u&&(r=this.NumberOfColors-1),r}},{key:"setTableValue",value:function(e,t){if(5===arguments.length&&(t=Array.prototype.slice.call(arguments,1)),e<0)throw new Error("Can't set the table value for negative index ("+e+")");e>=this.NumberOfColors&&new Error("Index "+e+" is greater than the number of colors "+this.NumberOfColors),this.Table[e]=t,0!==e&&e!==this.NumberOfColors-1||this.buildSpecialColors()}}]),e}();t.default=d},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){var n=(0,a.default)(),o=e.getPixelData();e.stats.lastGetPixelDataTime=(0,a.default)()-n;var i=o.length,l=e.minPixelValue,u=0,d=0,s=void 0;if(n=(0,a.default)(),o instanceof Int16Array)if(l<0)for(;dt.timeStamp?-1:e.timeStampp;){var t=h[h.length-1];b-=t.sizeInBytes,delete v[t.imageId],h.pop(),(0,g.default)(c.default,"cornerstonewebgltextureremoved",{imageId:t.imageId})}var r=a();(0,g.default)(c.default,"cornerstonewebgltexturecachefull",r)}}function i(e){if(void 0===e)throw new Error("setMaximumSizeBytes: parameter numBytes must not be undefined");if(void 0===e.toFixed)throw new Error("setMaximumSizeBytes: parameter numBytes must be a number");p=e,o()}function l(e,t){var r=e.imageId;if(void 0===e)throw new Error("putImageTexture: image must not be undefined");if(void 0===r)throw new Error("putImageTexture: imageId must not be undefined");if(void 0===t)throw new Error("putImageTexture: imageTexture must not be undefined");if(!0===Object.prototype.hasOwnProperty.call(v,r))throw new Error("putImageTexture: imageId already in cache");var n={imageId:r,imageTexture:t,timeStamp:new Date,sizeInBytes:t.sizeInBytes};if(v[r]=n,h.push(n),void 0===t.sizeInBytes)throw new Error("putImageTexture: imageTexture.sizeInBytes must not be undefined");if(void 0===t.sizeInBytes.toFixed)throw new Error("putImageTexture: imageTexture.sizeInBytes is not a number");b+=n.sizeInBytes,o()}function u(e){if(void 0===e)throw new Error("getImageTexture: imageId must not be undefined");var t=v[e];if(void 0!==t)return t.timeStamp=new Date,t.imageTexture}function d(e){if(void 0===e)throw new Error("removeImageTexture: imageId must not be undefined");var t=v[e];if(void 0===t)throw new Error("removeImageTexture: imageId must not be undefined");return h.splice(h.indexOf(t),1),b-=t.sizeInBytes,delete v[e],t.imageTexture}function s(){for(;h.length>0;){var e=h.pop();delete v[e.imageId]}b=0}Object.defineProperty(t,"__esModule",{value:!0});var f=r(14),c=n(f),m=r(2),g=n(m),v={},h=[],p=268435456,b=0;t.default={purgeCache:s,getImageTexture:u,putImageTexture:l,removeImageTexture:d,setMaximumSizeBytes:i}},function(e,t,r){"use strict";function n(e,t,r){var n=e.createShader(r);if(e.shaderSource(n,t),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS)&&!e.isContextLost()){var a=e.getShaderInfoLog(n);console.error("Could not compile shader:\n"+a)}return n}function a(e,t,r){var n=e.createProgram();if(e.attachShader(n,t),e.attachShader(n,r),e.linkProgram(n),!e.getProgramParameter(n,e.LINK_STATUS)&&!e.isContextLost()){var a=e.getProgramInfoLog(n);console.error("WebGL program filed to link:\n"+a)}return n}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r){return a(e,n(e,t,e.VERTEX_SHADER),n(e,r,e.FRAGMENT_SHADER))}},function(e,t,r){"use strict";function n(e,t){if(void 0===e)throw new Error("renderWebImage: enabledElement parameter must not be undefined");var r=e.image;if(void 0===r)throw new Error("renderWebImage: image must be loaded before it can be drawn");if(e.viewport.voi.windowWidth===e.image.windowWidth&&e.viewport.voi.windowCenter===e.image.windowCenter&&!1===e.viewport.invert){var n=e.canvas.getContext("2d");n.setTransform(1,0,0,1,0,0),n.fillStyle="black",n.fillRect(0,0,e.canvas.width,e.canvas.height),n.imageSmoothingEnabled=!e.viewport.pixelReplication,n.mozImageSmoothingEnabled=n.imageSmoothingEnabled,(0,o.default)(e,n),n.drawImage(r.getImage(),0,0,r.width,r.height,0,0,r.width,r.height)}else(0,i.renderColorImage)(e,t)}Object.defineProperty(t,"__esModule",{value:!0}),t.renderWebImage=n;var a=r(3),o=function(e){return e&&e.__esModule?e:{default:e}}(a),i=r(8)},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function a(e,t){t.width!==e.clientWidth&&(t.width=e.clientWidth,t.style.width=e.clientWidth+"px"),t.height!==e.clientHeight&&(t.height=e.clientHeight,t.style.height=e.clientHeight+"px")}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){var r=(0,o.getEnabledElement)(e);a(e,r.canvas);var n={element:e};(0,f.default)(e,"cornerstoneelementresized",n),void 0!==r.image&&(!0===t?(0,l.default)(e):(0,d.default)(e))};var o=r(0),i=r(37),l=n(i),u=r(4),d=n(u),s=r(2),f=n(s)},function(e,t,r){"use strict";function n(e){return 0===e.viewport.rotation||180===e.viewport.rotation?{width:e.image.width,height:e.image.height}:{width:e.image.height,height:e.image.width}}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=(0,a.getEnabledElement)(e),r=n(t),o=t.canvas.height/r.height,l=t.canvas.width/r.width;t.viewport.scale=Math.min(l,o),t.viewport.translation.x=0,t.viewport.translation.y=0,(0,i.default)(e)};var a=r(0),o=r(4),i=function(e){return e&&e.__esModule?e:{default:e}}(o)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t,r,a,o){if(void 0===e)throw new Error("getStoredPixels: parameter element must not be undefined");t=Math.round(t),r=Math.round(r);for(var i=(0,n.getEnabledElement)(e),l=[],u=0,d=i.image.getPixelData(),s=0;st.timeStamp?-1:e.timeStampp;){var t=y[y.length-1],r=t.imageId;u(r),(0,h.default)(g.default,"cornerstoneimagecachepromiseremoved",{imageId:r})}var n=d();(0,h.default)(g.default,"cornerstoneimagecachefull",n)}}function i(e,t){if(void 0===e)throw new Error("putImageLoadObject: imageId must not be undefined");if(void 0===t.promise)throw new Error("putImageLoadObject: imageLoadObject.promise must not be undefined");if(!0===w.hasOwnProperty(e))throw new Error("putImageLoadObject: imageId already in cache");if(t.cancelFn&&"function"!=typeof t.cancelFn)throw new Error("putImageLoadObject: imageLoadObject.cancelFn must be a function");var r={loaded:!1,imageId:e,sharedCacheKey:void 0,imageLoadObject:t,timeStamp:Date.now(),sizeInBytes:0};w[e]=r,y.push(r),t.promise.then(function(e){if(-1!==y.indexOf(r)){if(r.loaded=!0,r.image=e,void 0===e.sizeInBytes)throw new Error("putImageLoadObject: image.sizeInBytes must not be undefined");if(void 0===e.sizeInBytes.toFixed)throw new Error("putImageLoadObject: image.sizeInBytes is not a number");r.sizeInBytes=e.sizeInBytes,b+=r.sizeInBytes;var t={action:"addImage",image:r};(0,h.default)(g.default,"cornerstoneimagecachechanged",t),r.sharedCacheKey=e.sharedCacheKey,o()}},function(){var t=w[e];y.splice(y.indexOf(t),1),delete w[e]})}function l(e){if(void 0===e)throw new Error("getImageLoadObject: imageId must not be undefined");var t=w[e];if(void 0!==t)return t.timeStamp=Date.now(),t.imageLoadObject}function u(e){if(void 0===e)throw new Error("removeImageLoadObject: imageId must not be undefined");var t=w[e];if(void 0===t)throw new Error("removeImageLoadObject: imageId was not present in imageCache");y.splice(y.indexOf(t),1),b-=t.sizeInBytes;var r={action:"deleteImage",image:t};(0,h.default)(g.default,"cornerstoneimagecachechanged",r),s(t.imageLoadObject.promise),delete w[e]}function d(){return{maximumSizeInBytes:p,cacheSizeInBytes:b,numberOfImagesCached:y.length}}function s(e){e.then(function(e){e.decache&&e.decache()})}function f(){for(;y.length>0;){u(y[0].imageId)}}function c(e,t){var r=w[e];r&&r.imageLoadObject.promise.then(function(e){var n=t-e.sizeInBytes;e.sizeInBytes=t,r.sizeInBytes=t,b+=n;var a={action:"changeImageSize",image:e};(0,h.default)(g.default,"cornerstoneimagecachechanged",a)})}Object.defineProperty(t,"__esModule",{value:!0}),t.cachedImages=void 0,t.setMaximumSizeBytes=a,t.putImageLoadObject=i,t.getImageLoadObject=l,t.removeImageLoadObject=u,t.getCacheInfo=d,t.purgeCache=f,t.changeImageIdCacheSize=c;var m=r(14),g=n(m),v=r(2),h=n(v),p=1073741824,b=0,w={},y=t.cachedImages=[];t.default={imageCache:w,cachedImages:y,setMaximumSizeBytes:a,putImageLoadObject:i,getImageLoadObject:l,removeImageLoadObject:u,getCacheInfo:d,purgeCache:f,changeImageIdCacheSize:c}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){if(e.color&&!e.falseColor)throw new Error("Color transforms are not implemented yet");var r=e.minPixelValue,n=0,o=0,i=e.width*e.height,l=e.origPixelData||e.getPixelData(),u=new Uint8Array(4*i),d=void 0,s=void 0;if(e.color=!0,e.falseColor=!0,e.origPixelData=l,t instanceof a.default.LookupTable)for(t.build();o=0&&(t="u"+t),e.maxPixelValue>255?t+="16":t+="8",t}function c(e){var t=f(e);return w.shaders.hasOwnProperty(t)?w.shaders[t]:w.shaders.rgb}function m(e){var t={uint8:x.LUMINANCE,int8:x.LUMINANCE_ALPHA,uint16:x.LUMINANCE_ALPHA,int16:x.RGB,rgb:x.RGB},r={int8:1,uint16:2,int16:3,rgb:3},n=f(e),a=t[n],o=x.createTexture();x.bindTexture(x.TEXTURE_2D,o),x.texParameteri(x.TEXTURE_2D,x.TEXTURE_MIN_FILTER,x.NEAREST),x.texParameteri(x.TEXTURE_2D,x.TEXTURE_MAG_FILTER,x.NEAREST),x.texParameteri(x.TEXTURE_2D,x.TEXTURE_WRAP_S,x.CLAMP_TO_EDGE),x.texParameteri(x.TEXTURE_2D,x.TEXTURE_WRAP_T,x.CLAMP_TO_EDGE),x.pixelStorei(x.UNPACK_ALIGNMENT,1);var i=w.dataUtilities[n].storedPixelDataToImageData(e,e.width,e.height);return x.texImage2D(x.TEXTURE_2D,0,a,e.width,e.height,0,a,x.UNSIGNED_BYTE,i),{texture:o,sizeInBytes:e.width*e.height*r[n]}}function g(e){var t=_.default.getImageTexture(e.imageId);return t||(t=m(e),_.default.putImageTexture(e,t)),t.texture}function v(){L=x.createBuffer(),x.bindBuffer(x.ARRAY_BUFFER,L),x.bufferData(x.ARRAY_BUFFER,new Float32Array([1,1,0,1,1,0,0,0]),x.STATIC_DRAW),T=x.createBuffer(),x.bindBuffer(x.ARRAY_BUFFER,T),x.bufferData(x.ARRAY_BUFFER,new Float32Array([1,1,0,1,1,0,0,0]),x.STATIC_DRAW)}function h(e,t,r,n,a){x.clearColor(1,0,0,1),x.viewport(0,0,n,a),x.clear(x.COLOR_BUFFER_BIT|x.DEPTH_BUFFER_BIT),x.useProgram(e.program),x.bindBuffer(x.ARRAY_BUFFER,T),x.vertexAttribPointer(e.attributes.texCoordLocation,2,x.FLOAT,!1,0,0),x.bindBuffer(x.ARRAY_BUFFER,L),x.vertexAttribPointer(e.attributes.positionLocation,2,x.FLOAT,!1,0,0);for(var o in t){var i=x.getUniformLocation(e.program,o);if(i){var u=t[o],d=u.type,s=u.value;"i"===d?x.uniform1i(i,s):"f"===d?x.uniform1f(i,s):"2f"===d&&x.uniform2f(i,s[0],s[1])}}l(x,n,a),x.activeTexture(x.TEXTURE0),x.bindTexture(x.TEXTURE_2D,r),x.drawArrays(x.TRIANGLE_STRIP,0,4)}function p(e){var t=e.image;E.width=t.width,E.height=t.height;var r=e.viewport,n=c(t),a=g(t);return h(n,{u_resolution:{type:"2f",value:[t.width,t.height]},wc:{type:"f",value:r.voi.windowCenter},ww:{type:"f",value:r.voi.windowWidth},slope:{type:"f",value:t.slope},intercept:{type:"f",value:t.intercept},minPixelValue:{type:"f",value:t.minPixelValue},invert:{type:"i",value:r.invert?1:0}},a,t.width,t.height),E}function b(){var e={failIfMajorPerformanceCaveat:!0};try{var t=document.createElement("canvas");return Boolean(window.WebGLRenderingContext)&&(t.getContext("webgl",e)||t.getContext("experimental-webgl",e))}catch(e){return!1}}Object.defineProperty(t,"__esModule",{value:!0}),t.isWebGLInitialized=void 0,t.getRenderCanvas=a,t.initRenderer=i,t.render=p,t.isWebGLAvailable=b;var w=r(47),y=r(53),I=r(33),_=n(I),P=r(34),C=n(P),E=document.createElement("canvas"),x=void 0,T=void 0,L=void 0,O=!1;t.isWebGLInitialized=O},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.dataUtilities=t.shaders=void 0;var n=r(48),a=r(49),o=r(50),i=r(51),l=r(52),u={int16:n.int16Shader,int8:a.int8Shader,rgb:o.rgbShader,uint16:i.uint16Shader,uint8:l.uint8Shader},d={int16:n.int16DataUtilities,int8:a.int8DataUtilities,rgb:o.rgbDataUtilities,uint16:i.uint16DataUtilities,uint8:l.uint8DataUtilities};t.shaders=u,t.dataUtilities=d},function(e,t,r){"use strict";function n(e){for(var t=e.getPixelData(),r=new Uint8Array(e.width*e.height*3),n=0,a=0;a>8,r[n++]=t[a]<0?0:1}return r}Object.defineProperty(t,"__esModule",{value:!0});var a={};t.int16DataUtilities={storedPixelDataToImageData:n};a.frag="precision mediump float;uniform sampler2D u_image;uniform float ww;uniform float wc;uniform float slope;uniform float intercept;uniform int invert;varying vec2 v_texCoord;void main() {vec4 color = texture2D(u_image, v_texCoord);float intensity = color.r*256.0 + color.g*65536.0;if (color.b == 0.0)intensity = -intensity;intensity = intensity * slope + intercept;float center0 = wc - 0.5;float width0 = max(ww, 1.0);intensity = (intensity - center0) / width0 + 0.5;intensity = clamp(intensity, 0.0, 1.0);gl_FragColor = vec4(intensity, intensity, intensity, 1.0);if (invert == 1)gl_FragColor.rgb = 1.0 - gl_FragColor.rgb;}",t.int16Shader=a},function(e,t,r){"use strict";function n(e){for(var t=e.getPixelData(),r=new Uint8Array(e.width*e.height*2),n=0,a=0;a>8}return r}Object.defineProperty(t,"__esModule",{value:!0});var a={};t.uint16DataUtilities={storedPixelDataToImageData:n};a.frag="precision mediump float;uniform sampler2D u_image;uniform float ww;uniform float wc;uniform float slope;uniform float intercept;uniform int invert;varying vec2 v_texCoord;void main() {vec4 color = texture2D(u_image, v_texCoord);float intensity = color.r*256.0 + color.a*65536.0;intensity = intensity * slope + intercept;float center0 = wc - 0.5;float width0 = max(ww, 1.0);intensity = (intensity - center0) / width0 + 0.5;intensity = clamp(intensity, 0.0, 1.0);gl_FragColor = vec4(intensity, intensity, intensity, 1.0);if (invert == 1)gl_FragColor.rgb = 1.0 - gl_FragColor.rgb;}",t.uint16Shader=a},function(e,t,r){"use strict";function n(e){return e.getPixelData()}Object.defineProperty(t,"__esModule",{value:!0});var a={};t.uint8DataUtilities={storedPixelDataToImageData:n};a.frag="precision mediump float;uniform sampler2D u_image;uniform float ww;uniform float wc;uniform float slope;uniform float intercept;uniform int invert;varying vec2 v_texCoord;void main() {vec4 color = texture2D(u_image, v_texCoord);float intensity = color.r*256.0;intensity = intensity * slope + intercept;float center0 = wc - 0.5;float width0 = max(ww, 1.0);intensity = (intensity - center0) / width0 + 0.5;intensity = clamp(intensity, 0.0, 1.0);gl_FragColor = vec4(intensity, intensity, intensity, 1.0);if (invert == 1)gl_FragColor.rgb = 1.0 - gl_FragColor.rgb;}",t.uint8Shader=a},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.vertexShader="attribute vec2 a_position;attribute vec2 a_texCoord;uniform vec2 u_resolution;varying vec2 v_texCoord;void main() {vec2 zeroToOne = a_position / u_resolution;vec2 zeroToTwo = zeroToOne * 2.0;vec2 clipSpace = zeroToTwo - 1.0;gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);v_texCoord = a_texCoord;}"},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){var r=(0,n.getEnabledElement)(e),a=(0,o.default)(r);return a.invert(),a.transformPoint(t.x,t.y)};var n=r(0),a=r(9),o=function(e){return e&&e.__esModule?e:{default:e}}(a)},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){if(void 0===e)throw new Error("disable: element must not be undefined");for(var t=(0,n.getEnabledElements)(),r=0;r1&&void 0!==arguments[1]?arguments[1]:0,r=void 0;for(r=0;ra?r:a;return{minPixelValue:t,maxPixelValue:r}}function a(e){if(e.restore)return e.restore;var t=e.color,r=e.rgba,n=e.cachedLut,a=e.slope,o=e.windowWidth,i=e.windowCenter,l=e.minPixelValue,u=e.maxPixelValue;return function(){if(e.color=t,e.rgba=r,e.cachedLut=n,e.slope=a,e.windowWidth=o,e.windowCenter=i,e.minPixelValue=l,e.maxPixelValue=u,e.origPixelData){var d=e.origPixelData;e.getPixelData=function(){return d}}e.origPixelData=void 0,e.colormapId=void 0,e.falseColor=void 0}}function o(e){return e&&"string"==typeof e&&(e=(0,c.getColormap)(e)),e}function i(e){return!(!e.restore||"function"!=typeof e.restore)&&(e.restore(),!0)}function l(e,t){if(e.color&&!e.falseColor)throw new Error("Color transforms are not implemented yet");t=o(t);var r=t.getId();if(e.colormapId===r)return!1;if(i(e),r){var l=e.minPixelValue||0,u=e.maxPixelValue||255;e.restore=a(e);var d=t.createLookupTable();d.setTableRange(l,u),(0,f.default)(e,d);var s=n(e.getPixelData());e.minPixelValue=s.minPixelValue,e.maxPixelValue=s.maxPixelValue,e.windowWidth=255,e.windowCenter=128,e.colormapId=r}return!0}function u(e,t){return l((0,d.getEnabledElement)(e).image,t)}Object.defineProperty(t,"__esModule",{value:!0}),t.restoreImage=t.convertToFalseColorImage=t.convertImageToFalseColorImage=void 0;var d=r(0),s=r(40),f=function(e){return e&&e.__esModule?e:{default:e}}(s),c=r(28);t.convertImageToFalseColorImage=l,t.convertToFalseColorImage=u,t.restoreImage=i}])}); 3 | //# sourceMappingURL=cornerstone.min.js.map --------------------------------------------------------------------------------