@@ -64,8 +64,43 @@ export const useLayerColoringStore = defineStore('layerColoring', () => {
6464
6565 const configs = reactive < DoubleKeyRecord < LayersConfig > > ( { } ) ;
6666
67- const getConfig = ( viewID : Maybe < string > , dataID : Maybe < string > ) =>
68- getDoubleKeyRecord ( configs , viewID , dataID ) ?? defaultLayersConfig ( ) ;
67+ const computeDefaultConfig = ( dataID : string ) : LayersConfig => {
68+ const defaults = defaultLayersConfig ( ) ;
69+ const preset = getPreset ( dataID ) ;
70+
71+ const image = imageCacheStore . getVtkImageData ( dataID ) ;
72+ if ( ! image ) return defaults ;
73+
74+ const imageDataRange = image . getPointData ( ) . getScalars ( ) . getRange ( ) ;
75+
76+ const ctRange = getColorFunctionRangeFromPreset ( preset ) ;
77+ const ctFunc : Partial < ColorTransferFunction > = {
78+ preset,
79+ mappingRange : ctRange || imageDataRange ,
80+ } ;
81+
82+ const opacityFunction = {
83+ ...getOpacityFunctionFromPreset ( preset ) ,
84+ mappingRange : imageDataRange ,
85+ } ;
86+
87+ return {
88+ ...defaults ,
89+ transferFunction : { ...defaults . transferFunction , ...ctFunc } ,
90+ opacityFunction,
91+ } ;
92+ } ;
93+
94+ const getConfig = ( viewID : Maybe < string > , dataID : Maybe < string > ) => {
95+ if ( ! viewID || ! dataID ) return defaultLayersConfig ( ) ;
96+ const config = getDoubleKeyRecord ( configs , viewID , dataID ) ;
97+ if ( config ) return config ;
98+
99+ // If no config exists, compute and store the default with proper preset
100+ const defaultConfig = computeDefaultConfig ( dataID ) ;
101+ patchDoubleKeyRecord ( configs , viewID , dataID , defaultConfig ) ;
102+ return defaultConfig ;
103+ } ;
69104
70105 const updateConfig = (
71106 viewID : string ,
@@ -116,8 +151,10 @@ export const useLayerColoringStore = defineStore('layerColoring', () => {
116151 } ;
117152 updateColorTransferFunction ( viewID , layerID , ctFunc ) ;
118153
119- const opFunc = getOpacityFunctionFromPreset ( preset ) ;
120- opFunc . mappingRange = imageDataRange ;
154+ const opFunc = {
155+ ...getOpacityFunctionFromPreset ( preset ) ,
156+ mappingRange : imageDataRange ,
157+ } ;
121158 updateOpacityFunction ( viewID , layerID , opFunc ) ;
122159 } ;
123160
0 commit comments