Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(windowing): add forced window/level to JSON config #682

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading