forked from cornerstonejs/cornerstoneTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wwwc.js
executable file
·88 lines (70 loc) · 3.39 KB
/
wwwc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { external } from '../externalModules.js';
import simpleMouseButtonTool from './simpleMouseButtonTool.js';
import touchDragTool from './touchDragTool.js';
import isMouseButtonEnabled from '../util/isMouseButtonEnabled.js';
function mouseUpCallback (e, eventData) {
external.$(eventData.element).off('CornerstoneToolsMouseDrag', mouseDragCallback);
external.$(eventData.element).off('CornerstoneToolsMouseUp', mouseUpCallback);
external.$(eventData.element).off('CornerstoneToolsMouseClick', mouseUpCallback);
}
function mouseDownCallback (e, eventData) {
if (isMouseButtonEnabled(eventData.which, e.data.mouseButtonMask)) {
external.$(eventData.element).on('CornerstoneToolsMouseDrag', mouseDragCallback);
external.$(eventData.element).on('CornerstoneToolsMouseUp', mouseUpCallback);
external.$(eventData.element).on('CornerstoneToolsMouseClick', mouseUpCallback);
return false; // False = causes jquery to preventDefault() and stopPropagation() this event
}
}
function defaultStrategy (eventData) {
// Here we normalize the ww/wc adjustments so the same number of on screen pixels
// Adjusts the same percentage of the dynamic range of the image. This is needed to
// Provide consistency for the ww/wc tool regardless of the dynamic range (e.g. an 8 bit
// Image will feel the same as a 16 bit image would)
const maxVOI = eventData.image.maxPixelValue * eventData.image.slope + eventData.image.intercept;
const minVOI = eventData.image.minPixelValue * eventData.image.slope + eventData.image.intercept;
const imageDynamicRange = maxVOI - minVOI;
const multiplier = imageDynamicRange / 1024;
const deltaX = eventData.deltaPoints.page.x * multiplier;
const deltaY = eventData.deltaPoints.page.y * multiplier;
eventData.viewport.voi.windowWidth += (deltaX);
eventData.viewport.voi.windowCenter += (deltaY);
}
function mouseDragCallback (e, eventData) {
wwwc.strategy(eventData);
external.cornerstone.setViewport(eventData.element, eventData.viewport);
return false; // False = cases jquery to preventDefault() and stopPropagation() this event
}
function touchDragCallback (e, eventData) {
e.stopImmediatePropagation(); // Prevent CornerstoneToolsTouchStartActive from killing any press events
const dragData = eventData;
const maxVOI = dragData.image.maxPixelValue * dragData.image.slope + dragData.image.intercept;
const minVOI = dragData.image.minPixelValue * dragData.image.slope + dragData.image.intercept;
const imageDynamicRange = maxVOI - minVOI;
const multiplier = imageDynamicRange / 1024;
const deltaX = dragData.deltaPoints.page.x * multiplier;
const deltaY = dragData.deltaPoints.page.y * multiplier;
const config = wwwc.getConfiguration();
if (config.orientation) {
if (config.orientation === 0) {
dragData.viewport.voi.windowWidth += (deltaX);
dragData.viewport.voi.windowCenter += (deltaY);
} else {
dragData.viewport.voi.windowWidth += (deltaY);
dragData.viewport.voi.windowCenter += (deltaX);
}
} else {
dragData.viewport.voi.windowWidth += (deltaX);
dragData.viewport.voi.windowCenter += (deltaY);
}
external.cornerstone.setViewport(dragData.element, dragData.viewport);
}
const wwwc = simpleMouseButtonTool(mouseDownCallback);
wwwc.strategies = {
default: defaultStrategy
};
wwwc.strategy = defaultStrategy;
const wwwcTouchDrag = touchDragTool(touchDragCallback);
export {
wwwc,
wwwcTouchDrag
};