Skip to content

Commit

Permalink
feat(windowing): add forced window/level to JSON config
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Nov 13, 2024
1 parent 048b801 commit adc921f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/composables/useWindowingConfigInitializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ export function useWindowingConfigInitializer(
},
});
}
const forcedWL = store.runtimeConfigWindowLevel;
if (forcedWL) {
store.updateConfig(viewIdVal, imageIdVal, {
preset: {
...forcedWL,
},
});
}
store.resetWindowLevel(viewIdVal, imageIdVal);
});

Expand Down
19 changes: 19 additions & 0 deletions src/io/import/configJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useRulerStore } from '@/src/store/tools/rulers';
import { useDataBrowserStore } from '@/src/store/data-browser';
import { usePolygonStore } from '@/src/store/tools/polygons';
import { useViewStore } from '@/src/store/views';
import { useWindowingStore } from '@/src/store/view-configs/windowing';
import { actionToKey } from '@/src/composables/useKeyboardShortcuts';
import { useSegmentGroupStore } from '@/src/store/segmentGroups';
import { AnnotationToolStore } from '@/src/store/tools/useAnnotationTool';
Expand Down Expand Up @@ -70,12 +71,23 @@ const io = z
})
.optional();

// --------------------------------------------------------------------------
// Window Level

const windowing = z
.object({
level: z.number(),
width: z.number(),
})
.optional();

export const config = z.object({
layout,
dataBrowser,
labels,
shortcuts,
io,
windowing,
});

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

const applyWindowing = (manifest: Config) => {
if (!manifest.windowing) return;

useWindowingStore().runtimeConfigWindowLevel = manifest.windowing;
};

export const applyConfig = (manifest: Config) => {
applyLayout(manifest);
applyLabels(manifest);
applySampleData(manifest);
applyShortcuts(manifest);
applyIo(manifest);
applyWindowing(manifest);
};
10 changes: 9 additions & 1 deletion src/store/view-configs/windowing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ export const defaultWindowLevelConfig = (): WindowLevelConfig => ({
},
});

const useWindowingStore = defineStore('windowing', () => {
type WindowLevel = {
width: number;
level: number;
};

export const useWindowingStore = defineStore('windowing', () => {
const configs = reactive<DoubleKeyRecord<WindowLevelConfig>>({});
const syncAcrossViews = ref(true);
const runtimeConfigWindowLevel = ref<WindowLevel | undefined>();

const setSyncAcrossViews = (yn: boolean) => {
syncAcrossViews.value = yn;
Expand Down Expand Up @@ -69,6 +75,7 @@ const useWindowingStore = defineStore('windowing', () => {
}
};

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

return {
runtimeConfigWindowLevel,
configs,
getConfig,
setSyncAcrossViews,
Expand Down

0 comments on commit adc921f

Please sign in to comment.