-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathcamera.ts
More file actions
106 lines (91 loc) · 2.84 KB
/
camera.ts
File metadata and controls
106 lines (91 loc) · 2.84 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
import { defineStore } from 'pinia';
import {
DoubleKeyRecord,
deleteSecondKey,
getDoubleKeyRecord,
patchDoubleKeyRecord,
} from '@/src/utils/doubleKeyRecord';
import { reactive } from 'vue';
import { Maybe } from '@/src/types';
import { useCurrentImage } from '@/src/composables/useCurrentImage';
import { createViewConfigSerializer } from './common';
import { ViewConfig } from '../../io/state-file/schema';
import { CameraConfig } from './types';
import { useImageStore } from '../datasets-images';
export const useViewCameraStore = defineStore('viewCamera', () => {
const imageStore = useImageStore();
const configs = reactive<DoubleKeyRecord<CameraConfig>>({});
const getConfig = (viewID: Maybe<string>, dataID: Maybe<string>) =>
getDoubleKeyRecord(configs, viewID, dataID);
const updateConfig = (
viewID: string,
dataID: string,
patch: Partial<CameraConfig>
) => {
const config = {
...getConfig(viewID, dataID),
...patch,
};
patchDoubleKeyRecord(configs, viewID, dataID, config);
};
const removeView = (viewID: string) => {
delete configs[viewID];
};
const removeData = (dataID: string, viewID?: string) => {
if (viewID) {
delete configs[viewID]?.[dataID];
} else {
deleteSecondKey(configs, dataID);
}
};
const toggleSyncCameras = () => {
// Synchronize all cameras when toggled
Object.keys(configs).forEach((viewID) => {
imageStore.idList.forEach((imageID) => {
const { syncState } = {
...getConfig(viewID, imageID)
};
updateConfig(viewID, imageID, { syncState: !syncState });
});
});
}
const isSync = () => {
const allSync = Object.keys(configs).every((sc) => Object.keys(configs[sc]).every((c) => configs[sc][c].syncState));
return allSync;
}
const updateSyncConfigs = () => {
Object.keys(configs).forEach((viewID) => {
const { currentImageID } = useCurrentImage();
const config = getConfig(viewID, currentImageID.value);
imageStore.idList.forEach((imageID) => {
const { syncState } = {
...getConfig(viewID, imageID)
};
if (syncState) {
updateConfig(viewID, imageID, { position: config?.position, focalPoint: config?.focalPoint, parallelScale: config?.parallelScale });
}
});
});
}
const serialize = createViewConfigSerializer(configs, 'camera');
const deserialize = (viewID: string, config: Record<string, ViewConfig>) => {
Object.entries(config).forEach(([dataID, viewConfig]) => {
if (viewConfig.camera) {
updateConfig(viewID, dataID, viewConfig.camera);
}
});
};
return {
configs,
getConfig,
updateConfig,
removeView,
removeData,
toggleSyncCameras,
updateSyncConfigs,
isSync,
serialize,
deserialize,
};
});
export default useViewCameraStore;