@@ -13,6 +13,11 @@ import { createViewConfigSerializer } from './common';
1313import { ViewConfig } from '../../io/state-file/schema' ;
1414import { WindowLevelConfig } from './types' ;
1515
16+ type WindowLevel = {
17+ width : number ;
18+ level : number ;
19+ } ;
20+
1621export const defaultWindowLevelConfig = ( ) =>
1722 ( {
1823 width : 1 ,
@@ -22,15 +27,10 @@ export const defaultWindowLevelConfig = () =>
2227 userTriggered : false ,
2328 } as const ) ;
2429
25- type WindowLevel = {
26- width : number ;
27- level : number ;
28- } ;
29-
3030export const useWindowingStore = defineStore ( 'windowing' , ( ) => {
3131 const configs = reactive < DoubleKeyRecord < WindowLevelConfig > > ( { } ) ;
32- const syncAcrossViews = ref ( true ) ;
3332 const runtimeConfigWindowLevel = ref < WindowLevel | undefined > ( ) ;
33+ const syncAcrossViews = ref ( true ) ;
3434 const imageStatsStore = useImageStatsStore ( ) ;
3535
3636 const setSyncAcrossViews = ( yn : boolean ) => {
@@ -45,33 +45,22 @@ export const useWindowingStore = defineStore('windowing', () => {
4545 return defaultWindowLevelConfig ( ) ;
4646 }
4747
48- let widthLevel = {
49- width : internalConfig . width ,
50- level : internalConfig . level ,
51- } ;
52- if ( internalConfig . useAuto ) {
53- const autoKey = internalConfig . auto ;
54- const statsRef = imageStatsStore . getAutoRangeValues ( dataID ) ;
55- const autoValues = statsRef . value ;
56-
57- if ( autoValues && autoValues [ autoKey ] ) {
58- const [ min , max ] = autoValues [ autoKey ] ;
59- widthLevel = {
60- width : max - min ,
61- level : ( max + min ) / 2 ,
62- } ;
63- } else {
64- widthLevel = {
65- width : internalConfig . width ,
66- level : internalConfig . level ,
67- } ;
68- }
48+ if ( ! internalConfig . useAuto ) {
49+ return { ...internalConfig } as const ;
6950 }
7051
71- return {
72- ...internalConfig ,
73- ...widthLevel ,
74- } as const ;
52+ const autoKey = internalConfig . auto ;
53+ const statsRef = imageStatsStore . getAutoRangeValues ( dataID ) ;
54+ const autoValues = statsRef . value ;
55+ if ( autoValues && autoValues [ autoKey ] ) {
56+ const [ min , max ] = autoValues [ autoKey ] ;
57+ return {
58+ ...internalConfig ,
59+ width : max - min ,
60+ level : ( max + min ) / 2 ,
61+ } as const ;
62+ }
63+ return { ...internalConfig } as const ;
7564 } ) ;
7665 } ;
7766
@@ -106,19 +95,19 @@ export const useWindowingStore = defineStore('windowing', () => {
10695 effectiveUseAuto = patch . useAuto ;
10796 } else if ( patch . auto !== undefined ) {
10897 effectiveUseAuto = true ;
109- } else if ( patch . width !== undefined || patch . level !== undefined ) {
110- if ( patch . useAuto === undefined ) {
111- effectiveUseAuto = false ;
112- }
98+ }
99+ if (
100+ ( patch . width !== undefined || patch . level !== undefined ) &&
101+ patch . useAuto === undefined
102+ ) {
103+ effectiveUseAuto = false ;
113104 if ( ! effectiveUseAuto ) {
114105 // patch may be only width or level so ensure we have both in the end
115106 const config = getConfig ( viewID , dataID ) . value ;
116- if ( config ) {
117- widthLevelPatchOnSwitchingFromAuto = {
118- width : config . width ,
119- level : config . level ,
120- } ;
121- }
107+ widthLevelPatchOnSwitchingFromAuto = {
108+ width : config . width ,
109+ level : config . level ,
110+ } ;
122111 }
123112 }
124113
0 commit comments