Skip to content

Commit

Permalink
Merge pull request #682 from PaulHax/config-wl
Browse files Browse the repository at this point in the history
feat(windowing): add forced window/level to JSON config
  • Loading branch information
PaulHax authored Nov 14, 2024
2 parents 048b801 + adc921f commit 0345957
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 0345957

Please sign in to comment.