From d9bd775419e55a5ed44fc45daa432821dfe835b4 Mon Sep 17 00:00:00 2001 From: Jules BOURDAIS Date: Wed, 28 Jun 2023 16:35:25 +0200 Subject: [PATCH] disable 3d viewer toggle if no stereo3d_* attributes --- client/dive-common/components/Viewer.vue | 7 ++++ client/src/components/track_3d_viewer/misc.ts | 33 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/client/dive-common/components/Viewer.vue b/client/dive-common/components/Viewer.vue index 54be9bd09..10631b783 100644 --- a/client/dive-common/components/Viewer.vue +++ b/client/dive-common/components/Viewer.vue @@ -50,6 +50,7 @@ import context from 'dive-common/store/context'; import { MarkChangesPendingFilter, TrackWithContext } from 'vue-media-annotator/BaseFilterControls'; import { EditAnnotationTypes, VisibleAnnotationTypes } from 'vue-media-annotator/layers'; import TrackViewer from 'vue-media-annotator/components/track_3d_viewer/TrackViewer.vue'; +import { isStereo3dReady } from 'vue-media-annotator/components/track_3d_viewer/misc'; import TrackViewerSettingsStore from 'vue-media-annotator/components/track_3d_viewer/TrackViewerSettingsStore'; import TrackViewerSettings from 'vue-media-annotator/components/track_3d_viewer/TrackViewerSettings.vue'; import GroupSidebarVue from './GroupSidebar.vue'; @@ -108,6 +109,7 @@ export default defineComponent({ const showTrack3dViewer = ref(false); const isStereoConfigMode = ref(false); + const hasStereo3dAttributes = ref(false); const baseMulticamDatasetId = ref(null as string | null); const datasetId = toRef(props, 'id'); @@ -793,6 +795,9 @@ export default defineComponent({ await nextTick(); handleResize(); }); + watch(attributes, (attrs) => { + hasStereo3dAttributes.value = isStereo3dReady(attrs); + }); onBeforeUnmount(() => { if (controlsRef.value) observer.unobserve(controlsRef.value.$el); }); @@ -989,6 +994,7 @@ export default defineComponent({ datasetId, showTrack3dViewer, isStereoConfigMode, + hasStereo3dAttributes, }; }, }); @@ -1114,6 +1120,7 @@ export default defineComponent({ v-model="showTrack3dViewer" label="Track 3D Viewer" color="primary" + :disabled="!hasStereo3dAttributes" hide-details /> diff --git a/client/src/components/track_3d_viewer/misc.ts b/client/src/components/track_3d_viewer/misc.ts index d7dcb4ef8..339c416d6 100644 --- a/client/src/components/track_3d_viewer/misc.ts +++ b/client/src/components/track_3d_viewer/misc.ts @@ -1,2 +1,33 @@ -// eslint-disable-next-line import/prefer-default-export +import { Attribute } from 'vue-media-annotator/use/useAttributes'; + +const EXPECTED_ATTRIBUTE_NAMES = [ + 'stereo3d_x', + 'stereo3d_y', + 'stereo3d_z', +]; + export const noOp = () => undefined; + +export function isStereo3dReady(attrs: Attribute[]) { + const attributeNamesToFind = [...EXPECTED_ATTRIBUTE_NAMES]; + + // eslint-disable-next-line no-restricted-syntax + for (const attr of attrs) { + // eslint-disable-next-line no-plusplus + for (let i = 0; i < attributeNamesToFind.length; i++) { + if (attr.name === attributeNamesToFind[i]) { + if (attr.belongs === 'detection' && attr.datatype === 'number') { + attributeNamesToFind.splice(i, 1); + } else { + return false; + } + } + } + + if (attributeNamesToFind.length === 0) { + return true; + } + } + + return false; +}