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 Apr 17, 2024
1 parent c93df3e commit d9bd775
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 @@ -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';
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -989,6 +994,7 @@ export default defineComponent({
datasetId,
showTrack3dViewer,
isStereoConfigMode,
hasStereo3dAttributes,
};
},
});
Expand Down Expand Up @@ -1114,6 +1120,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 d9bd775

Please sign in to comment.