Skip to content

Commit

Permalink
feat(camera): Add option to disable camera auto reset
Browse files Browse the repository at this point in the history
  • Loading branch information
lchauvin authored and Laurent Chauvin committed Sep 11, 2024
1 parent f78981a commit deaa77c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
13 changes: 13 additions & 0 deletions src/components/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
hide-details
></v-switch>

<v-switch
:label="`Camera Auto Reset (${disableCameraAutoReset ? 'On' : 'Off'})`"
v-model="disableCameraAutoReset"
color="secondary"
density="compact"
hide-details
></v-switch>

<v-switch
v-if="errorReportingConfigured"
:label="`Error Reporting (${reportingEnabled ? 'On' : 'Off'})`"
Expand Down Expand Up @@ -39,6 +47,7 @@

<script lang="ts">
import { defineComponent, ref, watch } from 'vue';
import { storeToRefs } from 'pinia';
import { useTheme } from 'vuetify';
import { useLocalStorage } from '@vueuse/core';
Expand All @@ -50,6 +59,7 @@ import {
useErrorReporting,
errorReportingConfigured,
} from '../utils/errorReporting';
import { useViewCameraStore } from '@/src/store/view-configs/camera';
export default defineComponent({
setup() {
Expand All @@ -68,6 +78,8 @@ export default defineComponent({
errorReportingStore.disableReporting = !enabled;
});
const { disableCameraAutoReset } = storeToRefs(useViewCameraStore());
const keyboardStore = useKeyboardShortcutsStore();
const openKeyboardShortcuts = () => {
keyboardStore.settingsOpen = true;
Expand All @@ -78,6 +90,7 @@ export default defineComponent({
reportingEnabled,
errorReportingConfigured,
openKeyboardShortcuts,
disableCameraAutoReset,
};
},
components: {
Expand Down
4 changes: 4 additions & 0 deletions src/components/SliceViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class="vtk-view"
ref="vtkView"
data-testid="vtk-view vtk-two-view"
:disable-auto-reset-camera="disableCameraAutoReset"
:view-id="id"
:image-id="currentImageID"
:view-direction="viewDirection"
Expand Down Expand Up @@ -172,6 +173,7 @@ import SliceSlider from '@/src/components/SliceSlider.vue';
import SliceViewerOverlay from '@/src/components/SliceViewerOverlay.vue';
import { useToolSelectionStore } from '@/src/store/tools/toolSelection';
import { useAnnotationToolStore, useToolStore } from '@/src/store/tools';
import { useViewCameraStore } from '@/src/store/view-configs/camera';
import { doesToolFrameMatchViewAxis } from '@/src/composables/annotationTool';
import { useWebGLWatchdog } from '@/src/composables/useWebGLWatchdog';
import { useSliceConfig } from '@/src/composables/useSliceConfig';
Expand All @@ -192,6 +194,8 @@ const vtkView = ref<VtkViewApi>();
const props = defineProps<Props>();
const { disableCameraAutoReset } = storeToRefs(useViewCameraStore());
const { id: viewId, type: viewType, viewDirection, viewUp } = toRefs(props);
const viewAxis = computed(() => getLPSAxisFromDir(viewDirection.value));
Expand Down
13 changes: 7 additions & 6 deletions src/components/vtk/VtkSliceView.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { ref, toRefs, provide, markRaw, effectScope, onUnmounted } from 'vue';
import { storeToRefs } from 'pinia';
import vtkInteractorStyleManipulator from '@kitware/vtk.js/Interaction/Style/InteractorStyleManipulator';
import { useVtkView } from '@/src/core/vtk/useVtkView';
import { useImage } from '@/src/composables/useCurrentImage';
Expand All @@ -12,6 +13,7 @@ import { useAutoFitState } from '@/src/composables/useAutoFitState';
import { Maybe } from '@/src/types';
import { VtkViewApi } from '@/src/types/vtk-types';
import { VtkViewContext } from '@/src/components/vtk/context';
import { useViewCameraStore } from '@/src/store/view-configs/camera';
interface Props {
viewId: string;
Expand All @@ -21,19 +23,18 @@ interface Props {
disableAutoResetCamera?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
disableAutoResetCamera: false,
});
const props = defineProps<Props>();
const {
viewId: viewID,
imageId: imageID,
viewDirection,
viewUp,
disableAutoResetCamera,
} = toRefs(props);
const vtkContainerRef = ref<HTMLElement>();
const { disableCameraAutoReset } = storeToRefs(useViewCameraStore());
const { metadata: imageMetadata } = useImage(imageID);
// use a detached scope so that actors can be removed from
Expand Down Expand Up @@ -72,7 +73,7 @@ function autoFitImage() {
}
useResizeObserver(vtkContainerRef, () => {
if (disableAutoResetCamera.value) return;
if (disableCameraAutoReset.value) return;
autoFitImage();
});
Expand All @@ -89,7 +90,7 @@ function resetCamera() {
});
}
watchImmediate([disableAutoResetCamera, viewID, imageID], ([noAutoReset]) => {
watchImmediate([disableCameraAutoReset, viewID, imageID], ([noAutoReset]) => {
if (noAutoReset) return;
resetCamera();
});
Expand Down
12 changes: 6 additions & 6 deletions src/components/vtk/VtkVolumeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import {
effectScope,
onUnmounted,
} from 'vue';
import { storeToRefs } from 'pinia';
import vtkInteractorStyleManipulator from '@kitware/vtk.js/Interaction/Style/InteractorStyleManipulator';
import vtkMouseCameraTrackballPanManipulator from '@kitware/vtk.js/Interaction/Manipulators/MouseCameraTrackballPanManipulator';
import vtkMouseCameraTrackballZoomManipulator from '@kitware/vtk.js/Interaction/Manipulators/MouseCameraTrackballZoomManipulator';
import { useVtkView } from '@/src/core/vtk/useVtkView';
import { useImage } from '@/src/composables/useCurrentImage';
import { useViewCameraStore } from '@/src/store/view-configs/camera';
import { useVtkInteractorStyle } from '@/src/core/vtk/useVtkInteractorStyle';
import { useVtkInteractionManipulator } from '@/src/core/vtk/useVtkInteractionManipulator';
import { LPSAxisDir } from '@/src/types/lps';
Expand All @@ -30,22 +32,20 @@ interface Props {
imageId: Maybe<string>;
viewDirection: LPSAxisDir;
viewUp: LPSAxisDir;
disableAutoResetCamera?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
disableAutoResetCamera: false,
});
const props = defineProps<Props>();
const {
viewId: viewID,
imageId: imageID,
viewDirection,
viewUp,
disableAutoResetCamera,
} = toRefs(props);
const vtkContainerRef = ref<HTMLElement>();
const { disableCameraAutoReset } = storeToRefs(useViewCameraStore());
const { metadata: imageMetadata } = useImage(imageID);
// use a detached scope so that actors can be removed from
Expand Down Expand Up @@ -95,7 +95,7 @@ function resetCamera() {
);
}
watchImmediate([disableAutoResetCamera, viewID, imageID], ([noAutoReset]) => {
watchImmediate([disableCameraAutoReset, viewID, imageID], ([noAutoReset]) => {
if (noAutoReset) return;
resetCamera();
});
Expand Down
10 changes: 9 additions & 1 deletion src/store/view-configs/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getDoubleKeyRecord,
patchDoubleKeyRecord,
} from '@/src/utils/doubleKeyRecord';
import { reactive } from 'vue';
import { reactive, ref } from 'vue';
import { Maybe } from '@/src/types';
import { createViewConfigSerializer } from './common';
import { ViewConfig } from '../../io/state-file/schema';
Expand All @@ -29,6 +29,12 @@ export const useViewCameraStore = defineStore('viewCamera', () => {

patchDoubleKeyRecord(configs, viewID, dataID, config);
};

const disableCameraAutoReset = ref(false);

const toggleCameraAutoReset = () => {
disableCameraAutoReset.value = !disableCameraAutoReset.value;
}

const removeView = (viewID: string) => {
delete configs[viewID];
Expand Down Expand Up @@ -56,6 +62,8 @@ export const useViewCameraStore = defineStore('viewCamera', () => {
configs,
getConfig,
updateConfig,
disableCameraAutoReset,
toggleCameraAutoReset,
removeView,
removeData,
serialize,
Expand Down

0 comments on commit deaa77c

Please sign in to comment.