From d331c6789a39d78eac3005e8a3b4faa27fbc7696 Mon Sep 17 00:00:00 2001 From: MaxNumerique Date: Wed, 30 Sep 2026 14:39:08 +0200 Subject: [PATCH] fix(perf): refacto buildColorTable to use nodes for RGB points (from 1,6sec to 300ms) --- app/utils/colormap.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/utils/colormap.ts b/app/utils/colormap.ts index a89a8e7b1..aba07d844 100644 --- a/app/utils/colormap.ts +++ b/app/utils/colormap.ts @@ -40,14 +40,19 @@ const THREE = 3; function buildColorTable(rgbPoints: readonly number[], width: number): Float32Array { const lut = vtkColorTransferFunction(); + // oxlint-disable id-length + const nodes = []; for (let pointIdx = 0; pointIdx < rgbPoints.length; pointIdx += 4) { - lut.addRGBPoint( - rgbPoints[pointIdx] ?? 0, - rgbPoints[pointIdx + 1] ?? 0, - rgbPoints[pointIdx + 2] ?? 0, - rgbPoints[pointIdx + THREE] ?? 0, - ); + nodes.push({ + x: rgbPoints[pointIdx] ?? 0, + r: rgbPoints[pointIdx + 1] ?? 0, + g: rgbPoints[pointIdx + 2] ?? 0, + b: rgbPoints[pointIdx + THREE] ?? 0, + midpoint: 0.5, + sharpness: 0, + }); } + lut.setNodes(nodes); return lut.getUint8Table(rgbPoints[0] ?? 0, rgbPoints.at(-LAST_POINT_OFFSET) ?? 0, width, true); }