Skip to content

Commit

Permalink
Merge pull request Kitware#679 from lchauvin/keyboard-change-slice
Browse files Browse the repository at this point in the history
feat(Slice): Use keyboard to change slices of the active view
  • Loading branch information
floryst authored Jan 20, 2025
2 parents a76e8fb + a38efeb commit 17ea21e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/vtk/VtkSliceViewSlicingManipulator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import vtkMouseRangeManipulator, {
} from '@kitware/vtk.js/Interaction/Manipulators/MouseRangeManipulator';
import vtkInteractorStyleManipulator from '@kitware/vtk.js/Interaction/Style/InteractorStyleManipulator';
import { syncRef } from '@vueuse/core';
import { inject, toRefs, computed } from 'vue';
import { inject, toRefs, unref, watch, computed } from 'vue';
import { useViewStore } from '@/src/store/views';
interface Props {
viewId: string;
Expand Down Expand Up @@ -58,6 +59,13 @@ const scroll = useMouseRangeManipulatorListener(
sliceConfig.slice.value
);
watch(scroll, () => {
const viewStore = useViewStore();
if (unref(viewId) !== viewStore.activeViewID) {
viewStore.setActiveViewID(unref(viewId));
}
});
syncRef(scroll, sliceConfig.slice, { immediate: true });
</script>

Expand Down
14 changes: 14 additions & 0 deletions src/composables/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { Tools } from '../store/tools/types';
import { useRectangleStore } from '../store/tools/rectangles';
import { useRulerStore } from '../store/tools/rulers';
import { usePolygonStore } from '../store/tools/polygons';
import { useViewStore } from '../store/views';
import { Action } from '../constants';
import { useKeyboardShortcutsStore } from '../store/keyboard-shortcuts';
import { useCurrentImage } from './useCurrentImage';
import { useSliceConfig } from './useSliceConfig';

const applyLabelOffset = (offset: number) => () => {
const toolToStore = {
Expand Down Expand Up @@ -36,6 +39,14 @@ const showKeyboardShortcuts = () => {
keyboardStore.settingsOpen = !keyboardStore.settingsOpen;
};

const changeSlice = (offset: number) => () => {
const { currentImageID } = useCurrentImage();
const { activeViewID } = useViewStore();

const { slice: currentSlice } = useSliceConfig(activeViewID, currentImageID);
currentSlice.value += offset;
};

export const ACTION_TO_FUNC = {
windowLevel: setTool(Tools.WindowLevel),
pan: setTool(Tools.Pan),
Expand All @@ -48,6 +59,9 @@ export const ACTION_TO_FUNC = {
polygon: setTool(Tools.Polygon),
select: setTool(Tools.Select),

nextSlice: changeSlice(1),
previousSlice: changeSlice(-1),

decrementLabel: applyLabelOffset(-1),
incrementLabel: applyLabelOffset(1),

Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ export const ACTION_TO_KEY = {
mergeNewPolygon: 'Shift',
select: 's',

nextSlice: 'arrowdown',
previousSlice: 'arrowup',

decrementLabel: 'q',
incrementLabel: 'w',

Expand Down
7 changes: 7 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ export const ACTIONS = {
readable: 'Activate Select tool',
},

nextSlice: {
readable: 'Next Slice',
},
previousSlice: {
readable: 'Previous Slice',
},

decrementLabel: {
readable: 'Activate previous Label',
},
Expand Down

0 comments on commit 17ea21e

Please sign in to comment.