Skip to content

Commit bbfd897

Browse files
bruyeretfinetjul
authored andcommitted
fix: Change texture coordinates cache behavior
1 parent 86deb6b commit bbfd897

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

Sources/Rendering/Core/Mapper/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ function getZigZagTextureCoordinatesFromTexelPosition(
125125
textureCoordinate[2] = (textureCoordinate[2] + 0.5) / dimensions[2];
126126
}
127127

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();
129132
/**
130133
* The minimum of the range is mapped to the center of the first texel excluding min texel (texel at index distance 1)
131134
* 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(
155158
const arg = arguments[argIndex];
156159
argStrings[argIndex] = arg.getMTime?.() ?? arg;
157160
}
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;
162166
}
163167

164168
// The range used for computing coordinates have to change
@@ -279,7 +283,10 @@ function getOrCreateColorTextureCoordinates(
279283
}
280284
}
281285

282-
colorTextureCoordinatesCache.set(cacheString, output);
286+
colorTextureCoordinatesCache.set(input, {
287+
stringHash,
288+
textureCoordinates: output,
289+
});
283290
return output;
284291
}
285292

@@ -480,7 +487,7 @@ function vtkMapper(publicAPI, model) {
480487
const maxColorsInRangeForCells = maxTextureWidthForCells ** 3 - 3; // 3D but keep a color for min, max and NaN
481488
const maxTextureWidthForPoints = 4096;
482489
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)
484491
const minColorsInRange = 2;
485492
// Maximum number of colors, limited by the maximum possible texture size
486493
const maxColorsInRange = cellFlag

0 commit comments

Comments
 (0)