Skip to content

Commit 6b9dd93

Browse files
authored
Merge pull request #682 from PaulHax/config-wl
feat(windowing): add forced window/level to JSON config
2 parents 048b801 + adc921f commit 6b9dd93

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/composables/useWindowingConfigInitializer.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ export function useWindowingConfigInitializer(
124124
},
125125
});
126126
}
127+
const forcedWL = store.runtimeConfigWindowLevel;
128+
if (forcedWL) {
129+
store.updateConfig(viewIdVal, imageIdVal, {
130+
preset: {
131+
...forcedWL,
132+
},
133+
});
134+
}
127135
store.resetWindowLevel(viewIdVal, imageIdVal);
128136
});
129137

src/io/import/configJson.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { useRulerStore } from '@/src/store/tools/rulers';
99
import { useDataBrowserStore } from '@/src/store/data-browser';
1010
import { usePolygonStore } from '@/src/store/tools/polygons';
1111
import { useViewStore } from '@/src/store/views';
12+
import { useWindowingStore } from '@/src/store/view-configs/windowing';
1213
import { actionToKey } from '@/src/composables/useKeyboardShortcuts';
1314
import { useSegmentGroupStore } from '@/src/store/segmentGroups';
1415
import { AnnotationToolStore } from '@/src/store/tools/useAnnotationTool';
@@ -70,12 +71,23 @@ const io = z
7071
})
7172
.optional();
7273

74+
// --------------------------------------------------------------------------
75+
// Window Level
76+
77+
const windowing = z
78+
.object({
79+
level: z.number(),
80+
width: z.number(),
81+
})
82+
.optional();
83+
7384
export const config = z.object({
7485
layout,
7586
dataBrowser,
7687
labels,
7788
shortcuts,
7889
io,
90+
windowing,
7991
});
8092

8193
export type Config = z.infer<typeof config>;
@@ -140,10 +152,17 @@ const applyIo = (manifest: Config) => {
140152
useLoadDataStore().segmentGroupExtension = manifest.io.segmentGroupExtension;
141153
};
142154

155+
const applyWindowing = (manifest: Config) => {
156+
if (!manifest.windowing) return;
157+
158+
useWindowingStore().runtimeConfigWindowLevel = manifest.windowing;
159+
};
160+
143161
export const applyConfig = (manifest: Config) => {
144162
applyLayout(manifest);
145163
applyLabels(manifest);
146164
applySampleData(manifest);
147165
applyShortcuts(manifest);
148166
applyIo(manifest);
167+
applyWindowing(manifest);
149168
};

src/store/view-configs/windowing.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@ export const defaultWindowLevelConfig = (): WindowLevelConfig => ({
2424
},
2525
});
2626

27-
const useWindowingStore = defineStore('windowing', () => {
27+
type WindowLevel = {
28+
width: number;
29+
level: number;
30+
};
31+
32+
export const useWindowingStore = defineStore('windowing', () => {
2833
const configs = reactive<DoubleKeyRecord<WindowLevelConfig>>({});
2934
const syncAcrossViews = ref(true);
35+
const runtimeConfigWindowLevel = ref<WindowLevel | undefined>();
3036

3137
const setSyncAcrossViews = (yn: boolean) => {
3238
syncAcrossViews.value = yn;
@@ -69,6 +75,7 @@ const useWindowingStore = defineStore('windowing', () => {
6975
}
7076
};
7177

78+
// not really reset, actually translate config object into W/L
7279
const resetWindowLevel = (viewID: string, dataID: string) => {
7380
const config = configs[viewID]?.[dataID];
7481
if (config == null) return;
@@ -105,6 +112,7 @@ const useWindowingStore = defineStore('windowing', () => {
105112
};
106113

107114
return {
115+
runtimeConfigWindowLevel,
108116
configs,
109117
getConfig,
110118
setSyncAcrossViews,

0 commit comments

Comments
 (0)