Skip to content

Commit

Permalink
disable 3d viewer toggle if no stereo3d_* attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
bourdaisj committed Jun 28, 2023
1 parent bcf3602 commit 9c220b8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 7 additions & 0 deletions client/dive-common/components/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import context from 'dive-common/store/context';
import { EditAnnotationTypes, VisibleAnnotationTypes } from 'vue-media-annotator/layers';
import { TrackWithContext } from 'vue-media-annotator/BaseFilterControls';
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';
Expand Down Expand Up @@ -95,6 +96,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');
Expand Down Expand Up @@ -698,6 +700,9 @@ export default defineComponent({
await nextTick();
handleResize();
});
watch(attributes, (attrs) => {
hasStereo3dAttributes.value = isStereo3dReady(attrs);
});
onBeforeUnmount(() => {
if (controlsRef.value) observer.unobserve(controlsRef.value.$el);
});
Expand Down Expand Up @@ -882,6 +887,7 @@ export default defineComponent({
datasetId,
showTrack3dViewer,
isStereoConfigMode,
hasStereo3dAttributes,
};
},
});
Expand Down Expand Up @@ -970,6 +976,7 @@ export default defineComponent({
v-model="showTrack3dViewer"
label="Track 3D Viewer"
color="primary"
:disabled="!hasStereo3dAttributes"
hide-details
/>
</template>
Expand Down
33 changes: 32 additions & 1 deletion client/src/components/track_3d_viewer/misc.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 9c220b8

Please sign in to comment.