@@ -4,6 +4,7 @@ import type { Manifest, StateFile } from '@/src/io/state-file/schema';
44import type { Maybe } from '@/src/types' ;
55import { useImageStatsStore } from '@/src/store/image-stats' ;
66import { computed , ref } from 'vue' ;
7+ import { watchImmediate } from '@vueuse/core' ;
78import { vec3 } from 'gl-matrix' ;
89import { defineStore } from 'pinia' ;
910import { PaintMode } from '@/src/core/tools/paint' ;
@@ -212,6 +213,26 @@ export const usePaintToolStore = defineStore('paint', () => {
212213 doPaintStroke . call ( this , axisIndex ) ;
213214 }
214215
216+ const currentImageStats = computed ( ( ) => {
217+ if ( ! currentImageID . value ) return null ;
218+ return imageStatsStore . stats [ currentImageID . value ] ;
219+ } ) ;
220+
221+ function resetThresholdRange ( imageID : Maybe < string > ) {
222+ if ( imageID ) {
223+ const stats = imageStatsStore . stats [ imageID ] ;
224+ if ( stats ) {
225+ thresholdRange . value = [ stats . scalarMin , stats . scalarMax ] ;
226+ } else {
227+ thresholdRange . value = [ ...DEFAULT_THRESHOLD_RANGE ] ;
228+ }
229+ }
230+ }
231+
232+ watchImmediate ( [ currentImageID , currentImageStats ] , ( [ id ] ) => {
233+ resetThresholdRange ( id ) ;
234+ } ) ;
235+
215236 // --- setup and teardown --- //
216237
217238 function activateTool ( this : _This ) {
@@ -222,13 +243,6 @@ export const usePaintToolStore = defineStore('paint', () => {
222243 ensureActiveSegmentGroupForImage ( imageID ) ;
223244 this . $paint . setBrushSize ( this . brushSize ) ;
224245
225- const stats = imageStatsStore . stats [ imageID ] ;
226- if ( stats ) {
227- thresholdRange . value = [ stats . scalarMin , stats . scalarMax ] ;
228- } else {
229- thresholdRange . value = [ ...DEFAULT_THRESHOLD_RANGE ] ;
230- }
231-
232246 isActive . value = true ;
233247 return true ;
234248 }
0 commit comments