Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(camera): Add option to disable camera auto reset #648

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -30,6 +30,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 All @@ -56,6 +62,8 @@ export const useViewCameraStore = defineStore('viewCamera', () => {
configs,
getConfig,
updateConfig,
disableCameraAutoReset,
toggleCameraAutoReset,
removeView,
removeData,
serialize,
Expand Down
Loading