@@ -125,7 +125,10 @@ function getZigZagTextureCoordinatesFromTexelPosition(
125
125
textureCoordinate [ 2 ] = ( textureCoordinate [ 2 ] + 0.5 ) / dimensions [ 2 ] ;
126
126
}
127
127
128
- const colorTextureCoordinatesCache = new Map ( ) ;
128
+ // Associate an input vtkDataArray to an object { stringHash, textureCoordinates }
129
+ // A single dataArray only caches one array of texture coordinates, so this cache is useless when
130
+ // the input data array is used with two different lookup tables (which is very unlikely)
131
+ const colorTextureCoordinatesCache = new WeakMap ( ) ;
129
132
/**
130
133
* The minimum of the range is mapped to the center of the first texel excluding min texel (texel at index distance 1)
131
134
* The maximum of the range is mapped to the center of the last texel excluding max and NaN texels (texel at index distance numberOfColorsInRange)
@@ -155,10 +158,11 @@ function getOrCreateColorTextureCoordinates(
155
158
const arg = arguments [ argIndex ] ;
156
159
argStrings [ argIndex ] = arg . getMTime ?. ( ) ?? arg ;
157
160
}
158
- const cacheString = argStrings . join ( '/' ) ;
159
- const cachedResult = colorTextureCoordinatesCache . get ( cacheString ) ;
160
- if ( cachedResult ) {
161
- return cachedResult ;
161
+ const stringHash = argStrings . join ( '/' ) ;
162
+
163
+ const cachedResult = colorTextureCoordinatesCache . get ( input ) ;
164
+ if ( cachedResult && cachedResult . stringHash === stringHash ) {
165
+ return cachedResult . textureCoordinates ;
162
166
}
163
167
164
168
// The range used for computing coordinates have to change
@@ -279,7 +283,10 @@ function getOrCreateColorTextureCoordinates(
279
283
}
280
284
}
281
285
282
- colorTextureCoordinatesCache . set ( cacheString , output ) ;
286
+ colorTextureCoordinatesCache . set ( input , {
287
+ stringHash,
288
+ textureCoordinates : output ,
289
+ } ) ;
283
290
return output ;
284
291
}
285
292
@@ -480,7 +487,7 @@ function vtkMapper(publicAPI, model) {
480
487
const maxColorsInRangeForCells = maxTextureWidthForCells ** 3 - 3 ; // 3D but keep a color for min, max and NaN
481
488
const maxTextureWidthForPoints = 4096 ;
482
489
const maxColorsInRangeForPoints = maxTextureWidthForPoints - 2 ; // 1D but keep a color for min and max (NaN is in a different row)
483
- // Minimum number of colors excluding minColor, maxColor and NaNColor
490
+ // Minimum number of colors in range ( excluding special colors like minColor, maxColor and NaNColor)
484
491
const minColorsInRange = 2 ;
485
492
// Maximum number of colors, limited by the maximum possible texture size
486
493
const maxColorsInRange = cellFlag
0 commit comments