-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathViewer.vue
More file actions
1240 lines (1187 loc) · 41.1 KB
/
Viewer.vue
File metadata and controls
1240 lines (1187 loc) · 41.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<script lang="ts">
import {
defineComponent, ref, toRef, computed, Ref,
reactive, watch, inject, nextTick, onBeforeUnmount, PropType,
} from 'vue';
import type { Vue } from 'vue/types/vue';
import type Vuetify from 'vuetify/lib';
import { cloneDeep, debounce } from 'lodash';
/* VUE MEDIA ANNOTATOR */
import {
useAttributes,
useImageEnhancements,
useLineChart,
useTimeObserver,
useEventChart,
} from 'vue-media-annotator/use';
import {
Track, Group,
CameraStore,
StyleManager, TrackFilterControls, GroupFilterControls,
} from 'vue-media-annotator/index';
import { provideAnnotator } from 'vue-media-annotator/provides';
import {
ImageAnnotator,
VideoAnnotator,
LargeImageAnnotator,
LayerManager,
useMediaController,
} from 'vue-media-annotator/components';
import type { AnnotationId } from 'vue-media-annotator/BaseAnnotation';
import { getResponseError } from 'vue-media-annotator/utils';
/* DIVE COMMON */
import PolygonBase from 'dive-common/recipes/polygonbase';
import HeadTail from 'dive-common/recipes/headtail';
import EditorMenu from 'dive-common/components/EditorMenu.vue';
import ConfidenceFilter from 'dive-common/components/ConfidenceFilter.vue';
import UserGuideButton from 'dive-common/components/UserGuideButton.vue';
import DeleteControls from 'dive-common/components/DeleteControls.vue';
import ControlsContainer from 'dive-common/components/ControlsContainer.vue';
import Sidebar from 'dive-common/components/Sidebar.vue';
import { useModeManager, useSave } from 'dive-common/use';
import clientSettingsSetup, { clientSettings } from 'dive-common/store/settings';
import { useApi, FrameImage, DatasetType } from 'dive-common/apispec';
import { usePrompt } from 'dive-common/vue-utilities/prompt-service';
import context from 'dive-common/store/context';
import { MarkChangesPendingFilter } from 'vue-media-annotator/BaseFilterControls';
import GroupSidebarVue from './GroupSidebar.vue';
import MultiCamToolsVue from './MultiCamTools.vue';
import MultiCamToolbar from './MultiCamToolbar.vue';
import PrimaryAttributeTrackFilter from './PrimaryAttributeTrackFilter.vue';
export interface ImageDataItem {
url: string;
filename: string;
}
export default defineComponent({
components: {
ControlsContainer,
DeleteControls,
Sidebar,
LayerManager,
VideoAnnotator,
ImageAnnotator,
LargeImageAnnotator,
ConfidenceFilter,
UserGuideButton,
EditorMenu,
MultiCamToolbar,
PrimaryAttributeTrackFilter,
},
// TODO: remove this in vue 3
props: {
id: {
type: String,
required: true,
},
revision: {
type: Number,
default: undefined,
},
readOnlyMode: {
type: Boolean,
default: false,
},
currentSet: {
type: String,
default: '',
},
comparisonSets: {
type: Array as PropType<string[]>,
default: () => [],
},
},
setup(props, { emit }) {
const { prompt } = usePrompt();
const loadError = ref('');
const baseMulticamDatasetId = ref(null as string | null);
const datasetId = toRef(props, 'id');
const multiCamList: Ref<string[]> = ref(['singleCam']);
const defaultCamera = ref('singleCam');
const playbackComponent = ref(undefined as Vue | undefined);
const readonlyState = computed(() => props.readOnlyMode
|| props.revision !== undefined || !!(props.comparisonSets && props.comparisonSets.length));
const sets: Ref<string[]> = ref([]);
const displayComparisons = ref(props.comparisonSets.length
? props.comparisonSets.slice(0, 1) : props.comparisonSets);
const selectedSet = ref('');
const {
aggregateController,
onResize,
clear: mediaControllerClear,
} = useMediaController();
const { time, updateTime, initialize: initTime } = useTimeObserver();
const imageData = ref({ singleCam: [] } as Record<string, FrameImage[]>);
const datasetType: Ref<DatasetType> = ref('image-sequence');
const datasetName = ref('');
const saveInProgress = ref(false);
const videoUrl: Ref<Record<string, string>> = ref({});
const {
loadDetections, loadMetadata, saveMetadata, getTiles, getTileURL,
} = useApi();
const progress = reactive({
// Loaded flag prevents annotator window from populating
// with stale data from props, for example if a persistent store
// like vuex is used to drive them.
loaded: false,
// Tracks loaded
progress: 0,
// Total tracks
total: 0,
});
const controlsRef = ref();
const controlsHeight = ref(0);
const controlsCollapsed = ref(false);
const sideBarCollapsed = ref(false);
const progressValue = computed(() => {
if (progress.total > 0 && (progress.progress !== progress.total)) {
return Math.round((progress.progress / progress.total) * 100);
}
return 0;
});
/**
* Annotation window style source based on value of timeline visualization
*/
const colorBy = computed(() => {
if (controlsRef.value?.currentView === 'Groups') {
return 'group';
}
return 'track';
});
const {
save: saveToServer,
markChangesPending,
discardChanges,
pendingSaveCount,
addCamera: addSaveCamera,
removeCamera: removeSaveCamera,
} = useSave(datasetId, readonlyState);
const {
imageEnhancements,
imageEnhancementOutputs,
isDefaultImage,
setImageEnhancements,
setSVGFilters,
} = useImageEnhancements();
const recipes = [
new PolygonBase(),
new HeadTail(),
];
const vuetify = inject('vuetify') as Vuetify;
const trackStyleManager = new StyleManager({ markChangesPending, vuetify });
const groupStyleManager = new StyleManager({ markChangesPending, vuetify });
const cameraStore = new CameraStore({ markChangesPending });
// This context for removal
const removeGroups = (id: AnnotationId) => {
cameraStore.removeGroups(id);
};
const setTrackType = (
id: AnnotationId,
newType: string,
confidenceVal?: number,
currentType?: string,
) => {
cameraStore.setTrackType(id, newType, confidenceVal, currentType);
};
const removeTypes = (id: AnnotationId, types: string[]) => cameraStore.removeTypes(id, types);
const getTracksMerged = (id: AnnotationId) => cameraStore.getTracksMerged(id);
const groupFilters = new GroupFilterControls({
sorted: cameraStore.sortedGroups,
markChangesPending: (markChangesPending as MarkChangesPendingFilter),
remove: removeGroups,
setType: setTrackType,
removeTypes,
});
// This context for removal
const removeTracks = (id: AnnotationId) => {
cameraStore.removeTracks(id);
};
const trackFilters = new TrackFilterControls({
sorted: cameraStore.sortedTracks,
remove: removeTracks,
markChangesPending: (markChangesPending as MarkChangesPendingFilter),
lookupGroups: cameraStore.lookupGroups,
getTrack: (track: AnnotationId, camera = 'singleCam') => (cameraStore.getTrack(track, camera)),
groupFilterControls: groupFilters,
setType: setTrackType,
removeTypes,
});
clientSettingsSetup(trackFilters.allTypes);
// Provides wrappers for actions to integrate with settings
const {
linkingTrack,
linkingCamera,
multiSelectList,
multiSelectActive,
selectedFeatureHandle,
selectedTrackId,
editingMultiTrack,
editingGroupId,
handler,
editingMode,
editingDetails,
visibleModes,
selectedKey,
selectedCamera,
editingTrack,
} = useModeManager({
recipes,
trackFilterControls: trackFilters,
groupFilterControls: groupFilters,
cameraStore,
aggregateController,
readonlyState,
});
const {
attributesList: attributes,
loadAttributes,
setAttribute,
deleteAttribute,
attributeFilters,
deleteAttributeFilter,
addAttributeFilter,
modifyAttributeFilter,
sortAndFilterAttributes,
setTimelineEnabled,
setTimelineFilter,
attributeTimelineData,
timelineFilter,
timelineEnabled,
} = useAttributes({
markChangesPending,
trackStyleManager,
selectedTrackId,
cameraStore,
});
const allSelectedIds = computed(() => {
const selected = selectedTrackId.value;
if (selected !== null) {
return multiSelectList.value.concat(selected);
}
return multiSelectList.value;
});
const { lineChartData } = useLineChart({
enabledTracks: trackFilters.enabledAnnotations,
typeStyling: trackStyleManager.typeStyling,
allTypes: trackFilters.allTypes,
getTracksMerged,
});
const { eventChartData } = useEventChart({
enabledTracks: trackFilters.enabledAnnotations,
selectedTrackIds: allSelectedIds,
typeStyling: trackStyleManager.typeStyling,
getTracksMerged,
});
const { eventChartData: groupChartData } = useEventChart({
enabledTracks: groupFilters.enabledAnnotations,
typeStyling: groupStyleManager.typeStyling,
selectedTrackIds: computed(() => {
if (editingGroupId.value !== null) {
return [editingGroupId.value];
}
return [];
}),
getTracksMerged,
});
async function trackSplit(trackId: AnnotationId | null, frame: number) {
if (typeof trackId === 'number') {
const track = cameraStore.getTrack(trackId, selectedCamera.value);
const groups = cameraStore.lookupGroups(trackId);
let newtracks: [Track, Track];
try {
newtracks = track.split(frame, cameraStore.getNewTrackId(), cameraStore.getNewTrackId() + 1);
} catch (err) {
await prompt({
title: 'Error while splitting track',
text: err as string,
positiveButton: 'OK',
});
return;
}
const result = await prompt({
title: 'Confirm',
text: 'Do you want to split the selected track?',
confirm: true,
});
if (!result) {
return;
}
const wasEditing = editingTrack.value;
handler.trackSelect(null);
const trackStore = cameraStore.camMap.value.get(selectedCamera.value)?.trackStore;
if (trackStore) {
trackStore.remove(trackId);
trackStore.insert(newtracks[0]);
trackStore.insert(newtracks[1]);
}
if (groups.length) {
// If the track belonged to groups, add the new tracks
// to the same groups the old tracks belonged to.
const groupStore = cameraStore.camMap.value.get(selectedCamera.value)?.groupStore;
if (groupStore) {
groupStore.trackRemove(trackId);
groups.forEach((group) => {
group.removeMembers([trackId]);
group.addMembers({
[newtracks[0].id]: { ranges: [[newtracks[0].begin, newtracks[0].end]] },
[newtracks[1].id]: { ranges: [[newtracks[1].begin, newtracks[1].end]] },
});
});
}
}
handler.trackSelect(newtracks[1].id, wasEditing);
}
}
// Remove a track from within a camera multi-track into it's own track
function unlinkCameraTrack(trackId: AnnotationId, camera: string) {
const track = cameraStore.getTrack(trackId, camera);
handler.trackSelect(null, false);
const newTrack = Track.fromJSON({
id: cameraStore.getNewTrackId(),
meta: track.meta,
begin: track.begin,
end: track.end,
features: track.features,
confidencePairs: track.confidencePairs,
attributes: track.attributes,
});
handler.removeTrack([trackId], true, camera);
const trackStore = cameraStore.camMap.value.get(camera)?.trackStore;
if (trackStore) {
trackStore.insert(newTrack, { imported: false });
}
handler.trackSelect(newTrack.trackId);
}
/**
* Takes a BaseTrack and a merge Track and will attempt to merge the existing track
* into the camera and baseTrack.
* Requires that baseTrack doesn't have a track for the camera already
* Also requires that the mergeTrack isn't a track across multiple cameras.
*/
function linkCameraTrack(baseTrack: AnnotationId, linkTrack: AnnotationId, camera: string) {
cameraStore.camMap.value.forEach((subCamera, key) => {
const { trackStore } = subCamera;
if (trackStore && trackStore.getPossible(linkTrack) && key !== camera) {
throw Error(`Attempting to link Track: ${linkTrack} to camera: ${camera} where there the track exists in another camera: ${key}`);
}
});
const track = cameraStore.getTrack(linkTrack, camera);
const selectedTrack = cameraStore.getAnyTrack(baseTrack);
handler.removeTrack([linkTrack], true, camera);
const newTrack = Track.fromJSON({
id: baseTrack,
meta: track.meta,
begin: track.begin,
end: track.end,
features: track.features,
confidencePairs: selectedTrack.confidencePairs,
attributes: track.attributes,
});
const trackStore = cameraStore.camMap.value.get(camera)?.trackStore;
if (trackStore) {
trackStore.insert(newTrack, { imported: false });
}
handler.trackSelect(newTrack.id);
}
watch(linkingTrack, () => {
if (linkingTrack.value !== null && selectedTrackId.value !== null) {
linkCameraTrack(selectedTrackId.value, linkingTrack.value, linkingCamera.value);
handler.stopLinking();
}
});
async function save(setVal?: string) {
// If editing the track, disable editing mode before save
saveInProgress.value = true;
if (editingTrack.value) {
handler.trackSelect(selectedTrackId.value, false);
}
const saveSet = setVal === 'default' ? undefined : setVal;
// Need to mark all items as updated for any non-default sets
if (saveSet && setVal !== props.currentSet) {
const singleCam = cameraStore.camMap.value.get('singleCam');
if (singleCam) {
singleCam.trackStore.annotationMap.forEach((track) => {
markChangesPending({ action: 'upsert', track });
});
}
}
try {
await saveToServer({
customTypeStyling: trackStyleManager.getTypeStyles(trackFilters.allTypes),
customGroupStyling: groupStyleManager.getTypeStyles(groupFilters.allTypes),
confidenceFilters: trackFilters.confidenceFilters.value,
imageEnhancements: imageEnhancements.value,
// TODO Group confidence filters are not yet supported.
}, saveSet);
} catch (err) {
let text = 'Unable to Save Data';
if (err.response && err.response.status === 403) {
text = 'You do not have permission to Save Data to this Folder.';
}
await prompt({
title: 'Error while Saving Data',
text,
positiveButton: 'OK',
});
saveInProgress.value = false;
throw err;
}
saveInProgress.value = false;
}
function saveThreshold() {
saveMetadata(datasetId.value, {
confidenceFilters: trackFilters.confidenceFilters.value,
});
}
function saveImageEnhancements() {
saveMetadata(datasetId.value, {
imageEnhancements: imageEnhancements.value,
});
}
const debouncedSaveImageEnhancements = debounce(saveImageEnhancements, 1000, { trailing: true });
watch(imageEnhancements, debouncedSaveImageEnhancements, { deep: true });
// Navigation Guards used by parent component
async function warnBrowserExit(event: BeforeUnloadEvent) {
if (pendingSaveCount.value === 0) return;
event.preventDefault();
// eslint-disable-next-line no-param-reassign
event.returnValue = '';
}
async function navigateAwayGuard(): Promise<boolean> {
let result = true;
if (pendingSaveCount.value > 0) {
result = await prompt({
title: 'Save Items',
text: 'There is unsaved data, would you like to continue or cancel and save?',
positiveButton: 'Discard and Leave',
negativeButton: 'Don\'t Leave',
confirm: true,
});
}
return result;
}
async function handleSetChange(set: string) {
const guard = await navigateAwayGuard();
if (guard) {
emit('update:set', set);
}
}
const selectCamera = async (camera: string, editMode = false) => {
if (linkingCamera.value !== '' && linkingCamera.value !== camera) {
await prompt({
title: 'In Linking Mode',
text: ['Currently in Linking Mode, please hit OK and Escape to exit',
'Linking mode or choose another Track in the highlighted Camera to Link'],
positiveButton: 'OK',
});
return;
}
// EditTrack is set false by the LayerMap before executing this
if (selectedTrackId.value !== null) {
// If we had a track selected and it still exists with
// a feature length of 0 we need to remove it
const track = cameraStore.getPossibleTrack(selectedTrackId.value, selectedCamera.value);
if (track && track.features.length === 0) {
handler.trackAbort();
}
}
selectedCamera.value = camera;
/**
* Enters edit mode if no track exists for the camera and forcing edit mode
* or if a track exists and are alrady in edit mode we don't set it again
* Remember trackEdit(number) is a toggle for editing mode
*/
if (selectedTrackId.value !== null && (editMode || editingTrack.value)) {
const track = cameraStore.getPossibleTrack(selectedTrackId.value, selectedCamera.value);
if (track === undefined || !editingTrack.value) {
//Stay in edit mode for the current track
handler.trackEdit(selectedTrackId.value);
}
}
emit('change-camera', camera);
};
// Handles changing camera using the dropdown or mouse clicks
// When using mouse clicks and right button it will remain in edit mode for the selected track
const changeCamera = (camera: string, event?: MouseEvent) => {
if (selectedCamera.value === camera) {
return;
}
if (event) {
event.preventDefault();
}
// Left click should kick out of editing mode automatically
if (event?.button === 0) {
editingTrack.value = false;
}
selectCamera(camera, event?.button === 2);
emit('change-camera', camera);
};
/** Trigger data load */
const loadData = async () => {
try {
// Close and reset sideBar
context.resetActive();
const meta = await loadMetadata(datasetId.value);
const defaultCameraMeta = meta.multiCamMedia?.cameras[meta.multiCamMedia.defaultDisplay];
baseMulticamDatasetId.value = datasetId.value;
if (defaultCameraMeta !== undefined && meta.multiCamMedia) {
/* We're loading a multicamera dataset */
const { cameras } = meta.multiCamMedia;
multiCamList.value = Object.keys(cameras);
defaultCamera.value = meta.multiCamMedia.defaultDisplay;
changeCamera(defaultCamera.value);
baseMulticamDatasetId.value = datasetId.value;
if (!selectedCamera.value) {
throw new Error('Multicamera dataset without default camera specified.');
}
}
/* Otherwise, complete loading of the dataset */
trackStyleManager.populateTypeStyles(meta.customTypeStyling);
groupStyleManager.populateTypeStyles(meta.customGroupStyling);
if (meta.customTypeStyling) {
trackFilters.importTypes(Object.keys(meta.customTypeStyling), false);
}
if (meta.customGroupStyling) {
groupFilters.importTypes(Object.keys(meta.customGroupStyling), false);
}
if (meta.attributes) {
loadAttributes(meta.attributes);
}
trackFilters.setConfidenceFilters(meta.confidenceFilters);
if (meta.imageEnhancements) {
setImageEnhancements(meta.imageEnhancements);
}
datasetName.value = meta.name;
initTime({
frameRate: meta.fps,
originalFps: meta.originalFps || null,
});
for (let i = 0; i < multiCamList.value.length; i += 1) {
const camera = multiCamList.value[i];
let cameraId = baseMulticamDatasetId.value;
if (multiCamList.value.length > 1) {
cameraId = `${baseMulticamDatasetId.value}/${camera}`;
}
// eslint-disable-next-line no-await-in-loop
const subCameraMeta = await loadMetadata(cameraId);
datasetType.value = subCameraMeta.type as DatasetType;
imageData.value[camera] = cloneDeep(subCameraMeta.imageData) as FrameImage[];
if (subCameraMeta.videoUrl) {
videoUrl.value[camera] = subCameraMeta.videoUrl;
}
cameraStore.addCamera(camera);
addSaveCamera(camera);
// eslint-disable-next-line no-await-in-loop
const {
tracks,
groups,
sets: foundSets,
// eslint-disable-next-line no-await-in-loop
} = await loadDetections(cameraId, props.revision, props.currentSet);
sets.value = foundSets.filter((item) => item);
if (props.currentSet !== '' || sets.value.length > 0) {
sets.value.push('default');
}
selectedSet.value = props.currentSet ? props.currentSet : 'default';
progress.total = tracks.length + groups.length;
const trackStore = cameraStore.camMap.value.get(camera)?.trackStore;
const groupStore = cameraStore.camMap.value.get(camera)?.groupStore;
if (trackStore && groupStore) {
// We can start sorting if our total tracks are less than 20000
// If greater we do one sort at the end instead to speed loading.
if (tracks.length < 20000) {
trackStore.setEnableSorting();
}
let baseSet: string | undefined;
if (props.comparisonSets.length) {
baseSet = selectedSet.value;
}
for (let j = 0; j < tracks.length; j += 1) {
if (j % 4000 === 0) {
/* Every N tracks, yeild some cycles for other scheduled tasks */
progress.progress = j;
// eslint-disable-next-line no-await-in-loop
await new Promise((resolve) => window.setTimeout(resolve, 500));
}
trackStore.insert(Track.fromJSON(tracks[j], baseSet), { imported: true });
}
for (let j = 0; j < groups.length; j += 1) {
if (j % 4000 === 0) {
/* Every N tracks, yeild some cycles for other scheduled tasks */
progress.progress = tracks.length + j;
// eslint-disable-next-line no-await-in-loop
await new Promise((resolve) => window.setTimeout(resolve, 500));
}
groupStore.insert(Group.fromJSON(groups[j]), { imported: true });
}
}
// Check if we load more data for comparions
if (props.comparisonSets.length) {
// Only compare one at a time
const firstSet = props.comparisonSets.slice(0, 1);
for (let setIndex = 0; setIndex < firstSet.length; setIndex += 1) {
const loadingSet = firstSet[setIndex] === 'default' ? undefined : firstSet[setIndex];
const {
tracks: setTracks,
groups: setGroups,
// eslint-disable-next-line no-await-in-loop
} = await loadDetections(cameraId, props.revision, loadingSet);
progress.total = setTracks.length + setGroups.length;
if (trackStore && groupStore) {
// We can start sorting if our total tracks are less than 20000
// If greater we do one sort at the end instead to speed loading.
if (tracks.length < 20000) {
trackStore.setEnableSorting();
}
for (let j = 0; j < setTracks.length; j += 1) {
if (j % 4000 === 0) {
/* Every N tracks, yeild some cycles for other scheduled tasks */
progress.progress = j;
// eslint-disable-next-line no-await-in-loop
await new Promise((resolve) => window.setTimeout(resolve, 500));
}
// We need to increment the trackIds for the new comparison sets
setTracks[j].id = trackStore.getNewId();
trackStore.insert(
Track.fromJSON(
setTracks[j],
firstSet[setIndex],
),
{ imported: true },
);
}
}
}
}
}
cameraStore.camMap.value.forEach((cam, key) => {
const { trackStore } = cam;
// Enable Sorting after loading is complete if it isn't enabled already
if (trackStore) {
trackStore.setEnableSorting();
}
if (!multiCamList.value.includes(key)) {
cameraStore.removeCamera(key);
removeSaveCamera(key);
}
});
// Needs to be done after the cameraMap is created
if (meta.attributeTrackFilters) {
trackFilters.loadTrackAttributesFilter(Object.values(meta.attributeTrackFilters));
}
progress.loaded = true;
// If multiCam add Tools and remove group Tools
if (cameraStore.camMap.value.size > 1) {
context.unregister({
description: 'Group Manager',
component: GroupSidebarVue,
});
context.register({
component: MultiCamToolsVue,
description: 'Multi Camera Tools',
});
} else {
context.unregister({
component: MultiCamToolsVue,
description: 'Multi Camera Tools',
});
context.register({
description: 'Group Manager',
component: GroupSidebarVue,
});
}
} catch (err) {
progress.loaded = false;
console.error(err);
const errorEl = document.createElement('div');
errorEl.innerHTML = getResponseError(err);
loadError.value = errorEl.innerText
.concat(". If you don't know how to resolve this, please contact the server administrator.");
throw err;
}
};
loadData();
const reloadAnnotations = async () => {
progress.loaded = false;
discardChanges();
cameraStore.clearAll();
mediaControllerClear();
await loadData();
displayComparisons.value = props.comparisonSets.length
? props.comparisonSets.slice(0, 1) : props.comparisonSets;
};
watch(datasetId, reloadAnnotations);
watch(readonlyState, () => handler.trackSelect(null, false));
function handleResize() {
if (controlsRef.value) {
controlsHeight.value = controlsRef.value.$el.clientHeight;
onResize();
}
}
const observer = new ResizeObserver(handleResize);
/* On a reload this will watch the controls element and add on observer
* so that once done loading the or if the controlsRef is collapsed it will resize all cameras
*/
watch(controlsRef, (previous) => {
if (previous) observer.unobserve(previous.$el);
if (controlsRef.value) observer.observe(controlsRef.value.$el);
});
watch([controlsCollapsed, sideBarCollapsed], async () => {
await nextTick();
handleResize();
});
onBeforeUnmount(() => {
if (controlsRef.value) observer.unobserve(controlsRef.value.$el);
});
const globalHandler = {
...handler,
save,
trackSplit,
setAttribute,
deleteAttribute,
reloadAnnotations,
setSVGFilters,
selectCamera,
linkCameraTrack,
unlinkCameraTrack,
setChange: handleSetChange,
};
const useAttributeFilters = {
attributeFilters,
addAttributeFilter,
deleteAttributeFilter,
modifyAttributeFilter,
sortAndFilterAttributes,
setTimelineEnabled,
setTimelineFilter,
attributeTimelineData,
timelineFilter,
timelineEnabled,
};
provideAnnotator(
{
annotatorPreferences: toRef(clientSettings, 'annotatorPreferences'),
attributes,
cameraStore,
datasetId,
editingMode,
groupFilters,
groupStyleManager,
multiSelectList,
pendingSaveCount,
progress,
revisionId: toRef(props, 'revision'),
annotationSet: toRef(props, 'currentSet'),
annotationSets: sets,
comparisonSets: toRef(props, 'comparisonSets'),
selectedCamera,
selectedKey,
selectedTrackId,
editingMultiTrack,
editingGroupId,
time,
trackFilters,
trackStyleManager,
visibleModes,
readOnlyMode: readonlyState,
imageEnhancements,
},
globalHandler,
useAttributeFilters,
);
const disableAnnotationFilters = computed(() => (
trackFilters.disableAnnotationFilters.value
));
return {
/* props */
aggregateController,
confidenceFilters: trackFilters.confidenceFilters,
cameraStore,
controlsRef,
controlsHeight,
controlsCollapsed,
sideBarCollapsed,
colorBy,
clientSettings,
datasetName,
datasetType,
editingTrack,
editingMode,
editingDetails,
eventChartData,
groupChartData,
imageData,
lineChartData,
loadError,
multiSelectActive,
pendingSaveCount,
progress,
progressValue,
saveInProgress,
playbackComponent,
recipes,
selectedFeatureHandle,
selectedTrackId,
editingGroupId,
selectedKey,
trackFilters,
videoUrl,
visibleModes,
frameRate: time.frameRate,
originalFps: time.originalFps,
context,
readonlyState,
imageEnhancementOutputs,
isDefaultImage,
disableAnnotationFilters,
/* large image methods */
getTiles,
getTileURL,
/* methods */
handler: globalHandler,
save,
saveThreshold,
updateTime,
// multicam
multiCamList,
defaultCamera,
selectedCamera,
changeCamera,
// For Navigation Guarding
navigateAwayGuard,
warnBrowserExit,
reloadAnnotations,
// Annotation Sets,
sets,
selectedSet,
displayComparisons,
annotationSetColor: trackStyleManager.typeStyling.value.annotationSetColor,
};
},
});
</script>
<template>
<v-main class="viewer">
<v-app-bar app>
<slot name="title" />
<span
class="title pl-3 flex-row"
style="white-space:nowrap;overflow:hidden;text-overflow: ellipsis;"
>
{{ datasetName }}
<v-tooltip
v-if="currentSet || sets.length > 0 || comparisonSets.length"
bottom
>
<template #activator="{ on }">
<v-chip
outlined
:color="annotationSetColor(currentSet || 'default')"
small
v-on="on"
@click="context.toggle('AnnotationSets')"
> {{ currentSet || 'default' }}</v-chip>
</template>
<span>Custom Annotation Set. Click to open the Annotation Set Settings</span>
</v-tooltip>
<span
v-if="displayComparisons && displayComparisons.length"
style="font-size:small"
class="px-2"
> Comparing: </span>
<v-tooltip
v-if="displayComparisons && displayComparisons.length"
bottom
>
<template #activator="{ on: onIcon }">
<v-chip
class="pl-2"
small
outlined
:color="annotationSetColor(displayComparisons[0] || 'default')"
v-on="onIcon"
> {{ displayComparisons[0] }}</v-chip>
</template>
Click on the {{ currentSet || 'default' }} chip to open the Comparison Menu
</v-tooltip>
<div
v-if="readonlyState"
class="mx-auto my-0 pa-0"
style="line-height:0.2em;"
>
<v-tooltip
bottom
>
<template #activator="{ on }">
<v-chip
class="warning pr-1"
style="white-space:nowrap;display:inline"
small
v-on="on"
>
Read Only Mode
<v-icon
class="pl-1"
small
>mdi-information-outline</v-icon>
</v-chip>
</template>
<span>Read Only Mode: Editing, Deleting and Importing actions are disabled</span>
</v-tooltip>
</div>
</span>
<v-spacer />
<template #extension>
<v-tooltip
bottom
>
<template #activator="{ on }">
<v-icon
v-on="on"
@click="sideBarCollapsed = !sideBarCollapsed"
>
{{ sideBarCollapsed ? 'mdi-chevron-right-box' : 'mdi-chevron-left-box' }}
</v-icon>
</template>
<span>Collapse Side Panel</span>
</v-tooltip>
<EditorMenu
v-bind="{
editingMode,
visibleModes,
editingTrack,
recipes,
multiSelectActive,
editingDetails,