fix(Hotkeys): add firstImage and lastImage commands referenced by 'home' and 'end' hotkeys (#3127)
* -fix 'home' and 'end' hotkeys ->implement firstImage lastImage commands * -extra comments * -add check for compatible viewport in firstImage command
This commit is contained in:
parent
b51c59016c
commit
f7c886878d
@ -1,6 +1,7 @@
|
|||||||
import {
|
import {
|
||||||
getEnabledElement,
|
getEnabledElement,
|
||||||
StackViewport,
|
StackViewport,
|
||||||
|
VolumeViewport,
|
||||||
utilities as csUtils,
|
utilities as csUtils,
|
||||||
} from '@cornerstonejs/core';
|
} from '@cornerstonejs/core';
|
||||||
import {
|
import {
|
||||||
@ -313,6 +314,51 @@ const commandsModule = ({ servicesManager }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
firstImage: () => {
|
||||||
|
// Get current active viewport (return if none active)
|
||||||
|
const enabledElement = _getActiveViewportEnabledElement();
|
||||||
|
if (!enabledElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { viewport } = enabledElement;
|
||||||
|
|
||||||
|
// Check viewport is supported
|
||||||
|
if (
|
||||||
|
viewport! instanceof StackViewport &&
|
||||||
|
viewport! instanceof VolumeViewport
|
||||||
|
) {
|
||||||
|
throw new Error('Unsupported viewport type');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set slice to first slice
|
||||||
|
const options = { imageIndex: 0 };
|
||||||
|
cstUtils.jumpToSlice(viewport.element, options);
|
||||||
|
},
|
||||||
|
lastImage: () => {
|
||||||
|
// Get current active viewport (return if none active)
|
||||||
|
const enabledElement = _getActiveViewportEnabledElement();
|
||||||
|
if (!enabledElement) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { viewport } = enabledElement;
|
||||||
|
|
||||||
|
// Get number of slices
|
||||||
|
// -> Copied from cornerstone3D jumpToSlice\_getImageSliceData()
|
||||||
|
let numberOfSlices = 0;
|
||||||
|
|
||||||
|
if (viewport instanceof StackViewport) {
|
||||||
|
numberOfSlices = viewport.getImageIds().length;
|
||||||
|
} else if (viewport instanceof VolumeViewport) {
|
||||||
|
numberOfSlices = csUtils.getImageSliceDataForVolumeViewport(viewport)
|
||||||
|
.numberOfSlices;
|
||||||
|
} else {
|
||||||
|
throw new Error('Unsupported viewport type');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set slice to last slice
|
||||||
|
const options = { imageIndex: numberOfSlices - 1 };
|
||||||
|
cstUtils.jumpToSlice(viewport.element, options);
|
||||||
|
},
|
||||||
scroll: ({ direction }) => {
|
scroll: ({ direction }) => {
|
||||||
const enabledElement = _getActiveViewportEnabledElement();
|
const enabledElement = _getActiveViewportEnabledElement();
|
||||||
|
|
||||||
@ -475,6 +521,16 @@ const commandsModule = ({ servicesManager }) => {
|
|||||||
storeContexts: [],
|
storeContexts: [],
|
||||||
options: { direction: -1 },
|
options: { direction: -1 },
|
||||||
},
|
},
|
||||||
|
firstImage: {
|
||||||
|
commandFn: actions.firstImage,
|
||||||
|
storeContexts: [],
|
||||||
|
options: {},
|
||||||
|
},
|
||||||
|
lastImage: {
|
||||||
|
commandFn: actions.lastImage,
|
||||||
|
storeContexts: [],
|
||||||
|
options: {},
|
||||||
|
},
|
||||||
showDownloadViewportModal: {
|
showDownloadViewportModal: {
|
||||||
commandFn: actions.showDownloadViewportModal,
|
commandFn: actions.showDownloadViewportModal,
|
||||||
storeContexts: [],
|
storeContexts: [],
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user