-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathuseSliceConfig.ts
More file actions
37 lines (33 loc) · 1.12 KB
/
useSliceConfig.ts
File metadata and controls
37 lines (33 loc) · 1.12 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
import useViewSliceStore, {
defaultSliceConfig,
} from '@/src/store/view-configs/slicing';
import { Maybe } from '@/src/types';
import type { Vector2 } from '@kitware/vtk.js/types';
import { unref, MaybeRef, computed } from 'vue';
export function useSliceConfig(
viewID: MaybeRef<string>,
imageID: MaybeRef<Maybe<string>>
) {
const store = useViewSliceStore();
const configDefaults = defaultSliceConfig();
const config = computed(() => store.getConfig(unref(viewID), unref(imageID)));
const slice = computed({
get: () => config.value?.slice ?? configDefaults.slice,
set: (val) => {
const imageIdVal = unref(imageID);
if (!imageIdVal || val == null) return;
store.updateConfig(unref(viewID), imageIdVal, { slice: val });
// Update other synchronized views if any
if (config.value?.syncState) {
store.updateSyncConfigs();
}
},
});
const range = computed((): Vector2 => {
const { min, max } = config.value ?? {};
if (min == null || max == null)
return [configDefaults.min, configDefaults.max];
return [min, max];
});
return { config, slice, range };
}