forked from cornerstonejs/cornerstone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/module name cornerstone core (cornerstonejs#149)
* Module name: cornerstone-core * add jquery names for commonjs, commonjs2 and amd * Undo removing dist/ files (Mishandling) * import $ from 'jquery'; * Same method than in cornerstoneTools to import jQuery: Use an intermediate file src/jquery.js, in which we can remove the import line to load the sources directly).
- Loading branch information
Showing
13 changed files
with
806 additions
and
780 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,39 @@ | ||
import { getEnabledElements } from './enabledElements.js'; | ||
|
||
/** | ||
* Disable an HTML element for further use in Cornerstone | ||
* | ||
* @param {HTMLElement} element An HTML Element enabled for Cornerstone | ||
* @returns {void} | ||
*/ | ||
export default function (element) { | ||
if (element === undefined) { | ||
throw new Error('disable: element must not be undefined'); | ||
} | ||
|
||
// Search for this element in this list of enabled elements | ||
const enabledElements = getEnabledElements(); | ||
|
||
for (let i = 0; i < enabledElements.length; i++) { | ||
if (enabledElements[i].element === element) { | ||
// We found it! | ||
|
||
// Fire an event so dependencies can cleanup | ||
const eventData = { | ||
element | ||
}; | ||
|
||
$(element).trigger('CornerstoneElementDisabled', eventData); | ||
|
||
// Remove the child DOM elements that we created (e.g.canvas) | ||
enabledElements[i].element.removeChild(enabledElements[i].canvas); | ||
enabledElements[i].canvas = undefined; | ||
|
||
// Remove this element from the list of enabled elements | ||
enabledElements.splice(i, 1); | ||
|
||
break; | ||
} | ||
} | ||
} | ||
import $ from './jquery.js'; | ||
import { getEnabledElements } from './enabledElements.js'; | ||
|
||
/** | ||
* Disable an HTML element for further use in Cornerstone | ||
* | ||
* @param {HTMLElement} element An HTML Element enabled for Cornerstone | ||
* @returns {void} | ||
*/ | ||
export default function (element) { | ||
if (element === undefined) { | ||
throw new Error('disable: element must not be undefined'); | ||
} | ||
|
||
// Search for this element in this list of enabled elements | ||
const enabledElements = getEnabledElements(); | ||
|
||
for (let i = 0; i < enabledElements.length; i++) { | ||
if (enabledElements[i].element === element) { | ||
// We found it! | ||
|
||
// Fire an event so dependencies can cleanup | ||
const eventData = { | ||
element | ||
}; | ||
|
||
$(element).trigger('CornerstoneElementDisabled', eventData); | ||
|
||
// Remove the child DOM elements that we created (e.g.canvas) | ||
enabledElements[i].element.removeChild(enabledElements[i].canvas); | ||
enabledElements[i].canvas = undefined; | ||
|
||
// Remove this element from the list of enabled elements | ||
enabledElements.splice(i, 1); | ||
|
||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,90 @@ | ||
/** | ||
* This module is responsible for enabling an element to display images with cornerstone | ||
*/ | ||
|
||
import { addEnabledElement } from './enabledElements.js'; | ||
import resize from './resize.js'; | ||
import drawImageSync from './internal/drawImageSync.js'; | ||
import requestAnimationFrame from './internal/requestAnimationFrame.js'; | ||
import webGL from './webgl/index.js'; | ||
|
||
function hasImageOrLayers (enabledElement) { | ||
return enabledElement.image !== undefined || enabledElement.layers.length; | ||
} | ||
|
||
|
||
/** | ||
* Enable an HTML Element for use in Cornerstone | ||
* | ||
* @param {HTMLElement} element An HTML Element enabled for Cornerstone | ||
* @param {Object} options Options for the enabledElement | ||
* | ||
* @return {void} | ||
*/ | ||
export default function (element, options) { | ||
if (element === undefined) { | ||
throw new Error('enable: parameter element cannot be undefined'); | ||
} | ||
|
||
// If this enabled element has the option set for WebGL, we should | ||
// Check if this device actually supports it | ||
if (options && options.renderer && options.renderer.toLowerCase() === 'webgl') { | ||
if (webGL.renderer.isWebGLAvailable()) { | ||
// If WebGL is available on the device, initialize the renderer | ||
// And return the renderCanvas from the WebGL rendering path | ||
webGL.renderer.initRenderer(); | ||
options.renderer = 'webgl'; | ||
} else { | ||
// If WebGL is not available on this device, we will fall back | ||
// To using the Canvas renderer | ||
console.error('WebGL not available, falling back to Canvas renderer'); | ||
delete options.renderer; | ||
} | ||
} | ||
|
||
const canvas = document.createElement('canvas'); | ||
|
||
element.appendChild(canvas); | ||
|
||
const enabledElement = { | ||
element, | ||
canvas, | ||
image: undefined, // Will be set once image is loaded | ||
invalid: false, // True if image needs to be drawn, false if not | ||
needsRedraw: true, | ||
options, | ||
layers: [], | ||
data: {}, | ||
renderingTools: {} | ||
}; | ||
|
||
addEnabledElement(enabledElement); | ||
|
||
resize(element, true); | ||
|
||
/** | ||
* Draw the image immediately | ||
* | ||
* @param {DOMHighResTimeStamp} timestamp The current time for when requestAnimationFrame starts to fire callbacks | ||
* @returns {void} | ||
*/ | ||
function draw (timestamp) { | ||
if (enabledElement.canvas === undefined) { | ||
return; | ||
} | ||
|
||
$(enabledElement.element).trigger('CornerstonePreRender', { | ||
enabledElement, | ||
timestamp | ||
}); | ||
|
||
if (enabledElement.needsRedraw && hasImageOrLayers(enabledElement)) { | ||
drawImageSync(enabledElement, enabledElement.invalid); | ||
} | ||
|
||
requestAnimationFrame(draw); | ||
} | ||
|
||
draw(); | ||
} | ||
/** | ||
* This module is responsible for enabling an element to display images with cornerstone | ||
*/ | ||
|
||
import $ from './jquery.js'; | ||
import { addEnabledElement } from './enabledElements.js'; | ||
import resize from './resize.js'; | ||
import drawImageSync from './internal/drawImageSync.js'; | ||
import requestAnimationFrame from './internal/requestAnimationFrame.js'; | ||
import webGL from './webgl/index.js'; | ||
|
||
function hasImageOrLayers (enabledElement) { | ||
return enabledElement.image !== undefined || enabledElement.layers.length; | ||
} | ||
|
||
|
||
/** | ||
* Enable an HTML Element for use in Cornerstone | ||
* | ||
* @param {HTMLElement} element An HTML Element enabled for Cornerstone | ||
* @param {Object} options Options for the enabledElement | ||
* | ||
* @return {void} | ||
*/ | ||
export default function (element, options) { | ||
if (element === undefined) { | ||
throw new Error('enable: parameter element cannot be undefined'); | ||
} | ||
|
||
// If this enabled element has the option set for WebGL, we should | ||
// Check if this device actually supports it | ||
if (options && options.renderer && options.renderer.toLowerCase() === 'webgl') { | ||
if (webGL.renderer.isWebGLAvailable()) { | ||
// If WebGL is available on the device, initialize the renderer | ||
// And return the renderCanvas from the WebGL rendering path | ||
webGL.renderer.initRenderer(); | ||
options.renderer = 'webgl'; | ||
} else { | ||
// If WebGL is not available on this device, we will fall back | ||
// To using the Canvas renderer | ||
console.error('WebGL not available, falling back to Canvas renderer'); | ||
delete options.renderer; | ||
} | ||
} | ||
|
||
const canvas = document.createElement('canvas'); | ||
|
||
element.appendChild(canvas); | ||
|
||
const enabledElement = { | ||
element, | ||
canvas, | ||
image: undefined, // Will be set once image is loaded | ||
invalid: false, // True if image needs to be drawn, false if not | ||
needsRedraw: true, | ||
options, | ||
layers: [], | ||
data: {}, | ||
renderingTools: {} | ||
}; | ||
|
||
addEnabledElement(enabledElement); | ||
|
||
resize(element, true); | ||
|
||
/** | ||
* Draw the image immediately | ||
* | ||
* @param {DOMHighResTimeStamp} timestamp The current time for when requestAnimationFrame starts to fire callbacks | ||
* @returns {void} | ||
*/ | ||
function draw (timestamp) { | ||
if (enabledElement.canvas === undefined) { | ||
return; | ||
} | ||
|
||
$(enabledElement.element).trigger('CornerstonePreRender', { | ||
enabledElement, | ||
timestamp | ||
}); | ||
|
||
if (enabledElement.needsRedraw && hasImageOrLayers(enabledElement)) { | ||
drawImageSync(enabledElement, enabledElement.invalid); | ||
} | ||
|
||
requestAnimationFrame(draw); | ||
} | ||
|
||
draw(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.