Skip to content

Commit 7109ada

Browse files
authored
Merge pull request #3158 from bruyeret/image-reslice-multi-component
Image reslice multi component
2 parents 4bb6513 + 111f193 commit 7109ada

File tree

8 files changed

+449
-290
lines changed

8 files changed

+449
-290
lines changed

Sources/Rendering/Core/ImageResliceMapper/test/testImageResliceMapperShareOpenGLTexture.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ test.onlyIfWebGL('Test ImageResliceMapperShareOpenGLTexture', async (t) => {
8181
const oglrenderer = glwindow.getViewNodeFor(renderer);
8282
const oglamapper = oglrenderer.getViewNodeFor(amapper);
8383
const oglcmapper = oglrenderer.getViewNodeFor(cmapper);
84-
oglcmapper.setOpenGLTexture(oglamapper.getOpenGLTexture());
84+
oglcmapper.setScalarTextures(oglamapper.getScalarTextures());
8585
const oglsmapper = oglrenderer.getViewNodeFor(smapper);
86-
oglsmapper.setOpenGLTexture(oglamapper.getOpenGLTexture());
86+
oglsmapper.setScalarTextures(oglamapper.getScalarTextures());
8787

8888
const promise = reader
8989
.setUrl(`${__BASE_PATH__}/Data/volume/headsq.vti`)

Sources/Rendering/Core/ImageResliceMapper/test/testImageResliceMapperSlabTypes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ test.onlyIfWebGL('Test ImageResliceMapperSlabTypes', async (t) => {
107107
const oglren4 = glwindow.getViewNodeFor(ren4);
108108
const oglamapper = oglren1.getViewNodeFor(amapper);
109109
const oglcmapper = oglren2.getViewNodeFor(cmapper);
110-
oglcmapper.setOpenGLTexture(oglamapper.getOpenGLTexture());
110+
oglcmapper.setScalarTextures(oglamapper.getScalarTextures());
111111
const oglsmapper = oglren3.getViewNodeFor(smapper);
112-
oglsmapper.setOpenGLTexture(oglamapper.getOpenGLTexture());
112+
oglsmapper.setScalarTextures(oglamapper.getScalarTextures());
113113
const oglzmapper = oglren4.getViewNodeFor(zmapper);
114-
oglzmapper.setOpenGLTexture(oglamapper.getOpenGLTexture());
114+
oglzmapper.setScalarTextures(oglamapper.getScalarTextures());
115115

116116
const cam = gc.registerResource(vtkCamera.newInstance());
117117
ren1.setActiveCamera(cam);

Sources/Rendering/OpenGL/ImageCPRMapper/index.js

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import vtkShaderProgram from 'vtk.js/Sources/Rendering/OpenGL/ShaderProgram';
1313
import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode';
1414

1515
import {
16-
getTransferFunctionHash,
16+
getTransferFunctionsHash,
1717
getImageDataHash,
1818
} from 'vtk.js/Sources/Rendering/OpenGL/RenderWindow/resourceSharingHelper';
1919

@@ -243,15 +243,21 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
243243
const numIComps = iComps ? numComp : 1;
244244
const textureHeight = iComps ? 2 * numIComps : 1;
245245

246-
const colorTransferFunc = ppty.getRGBTransferFunction();
247-
const colorTextureHash = getTransferFunctionHash(
248-
colorTransferFunc,
246+
const colorTransferFunctions = [];
247+
for (let component = 0; component < numIComps; ++component) {
248+
colorTransferFunctions.push(ppty.getRGBTransferFunction(component));
249+
}
250+
const colorTextureHash = getTransferFunctionsHash(
251+
colorTransferFunctions,
249252
iComps,
250253
numIComps
251254
);
252255

256+
const firstColorTransferFunc = ppty.getRGBTransferFunction();
253257
const cachedColorEntry =
254-
model._openGLRenderWindow.getGraphicsResourceForObject(colorTransferFunc);
258+
model._openGLRenderWindow.getGraphicsResourceForObject(
259+
firstColorTransferFunc
260+
);
255261
const reBuildColorTexture =
256262
!cachedColorEntry?.oglObject?.getHandle() ||
257263
cachedColorEntry?.hash !== colorTextureHash;
@@ -261,7 +267,7 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
261267
const cTable = new Uint8ClampedArray(cSize);
262268
model.colorTexture = vtkOpenGLTexture.newInstance();
263269
model.colorTexture.setOpenGLRenderWindow(model._openGLRenderWindow);
264-
if (colorTransferFunc) {
270+
if (firstColorTransferFunc) {
265271
const tmpTable = new Float32Array(cWidth * 3);
266272

267273
for (let c = 0; c < numIComps; c++) {
@@ -303,23 +309,23 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
303309
);
304310
}
305311

306-
if (colorTransferFunc) {
312+
if (firstColorTransferFunc) {
307313
model._openGLRenderWindow.setGraphicsResourceForObject(
308-
colorTransferFunc,
314+
firstColorTransferFunc,
309315
model.colorTexture,
310316
colorTextureHash
311317
);
312-
if (colorTransferFunc !== model._colorTransferFunc) {
318+
if (firstColorTransferFunc !== model._colorTransferFunc) {
313319
model._openGLRenderWindow.registerGraphicsResourceUser(
314-
colorTransferFunc,
320+
firstColorTransferFunc,
315321
publicAPI
316322
);
317323
model._openGLRenderWindow.unregisterGraphicsResourceUser(
318324
model._colorTransferFunc,
319325
publicAPI
320326
);
321327
}
322-
model._colorTransferFunc = colorTransferFunc;
328+
model._colorTransferFunc = firstColorTransferFunc;
323329
}
324330
} else {
325331
model.colorTexture = cachedColorEntry.oglObject;
@@ -328,10 +334,18 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
328334
// Build piecewise function buffer. This buffer is used either
329335
// for component weighting or opacity, depending on whether we're
330336
// rendering components independently or not.
331-
const pwFunc = ppty.getPiecewiseFunction();
332-
const pwfTextureHash = getTransferFunctionHash(pwFunc, iComps, numIComps);
337+
const opacityFunctions = [];
338+
for (let component = 0; component < numIComps; ++component) {
339+
opacityFunctions.push(ppty.getPiecewiseFunction(component));
340+
}
341+
const pwfTextureHash = getTransferFunctionsHash(
342+
opacityFunctions,
343+
iComps,
344+
numIComps
345+
);
346+
const firstPwFunc = ppty.getPiecewiseFunction();
333347
const cachedPwfEntry =
334-
model._openGLRenderWindow.getGraphicsResourceForObject(pwFunc);
348+
model._openGLRenderWindow.getGraphicsResourceForObject(firstPwFunc);
335349
const reBuildPwf =
336350
!cachedPwfEntry?.oglObject?.getHandle() ||
337351
cachedPwfEntry?.hash !== pwfTextureHash;
@@ -341,7 +355,7 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
341355
const pwfTable = new Uint8ClampedArray(pwfSize);
342356
model.pwfTexture = vtkOpenGLTexture.newInstance();
343357
model.pwfTexture.setOpenGLRenderWindow(model._openGLRenderWindow);
344-
if (pwFunc) {
358+
if (firstPwFunc) {
345359
const pwfFloatTable = new Float32Array(pwfSize);
346360
const tmpTable = new Float32Array(pwfWidth);
347361

@@ -386,23 +400,23 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
386400
pwfTable
387401
);
388402
}
389-
if (pwFunc) {
403+
if (firstPwFunc) {
390404
model._openGLRenderWindow.setGraphicsResourceForObject(
391-
pwFunc,
405+
firstPwFunc,
392406
model.pwfTexture,
393407
pwfTextureHash
394408
);
395-
if (pwFunc !== model._pwFunc) {
409+
if (firstPwFunc !== model._pwFunc) {
396410
model._openGLRenderWindow.registerGraphicsResourceUser(
397-
pwFunc,
411+
firstPwFunc,
398412
publicAPI
399413
);
400414
model._openGLRenderWindow.unregisterGraphicsResourceUser(
401415
model._pwFunc,
402416
publicAPI
403417
);
404418
}
405-
model._pwFunc = pwFunc;
419+
model._pwFunc = firstPwFunc;
406420
}
407421
} else {
408422
model.pwfTexture = cachedPwfEntry.oglObject;

Sources/Rendering/OpenGL/ImageMapper/index.js

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from 'vtk.js/Sources/Rendering/OpenGL/Texture/Constants';
1515
import { InterpolationType } from 'vtk.js/Sources/Rendering/Core/ImageProperty/Constants';
1616

17-
import { getTransferFunctionHash } from 'vtk.js/Sources/Rendering/OpenGL/RenderWindow/resourceSharingHelper';
17+
import { getTransferFunctionsHash } from 'vtk.js/Sources/Rendering/OpenGL/RenderWindow/resourceSharingHelper';
1818

1919
import vtkPolyDataVS from 'vtk.js/Sources/Rendering/OpenGL/glsl/vtkPolyDataVS.glsl';
2020
import vtkPolyDataFS from 'vtk.js/Sources/Rendering/OpenGL/glsl/vtkPolyDataFS.glsl';
@@ -931,14 +931,21 @@ function vtkOpenGLImageMapper(publicAPI, model) {
931931
const numIComps = iComps ? numComp : 1;
932932
const textureHeight = iComps ? 2 * numIComps : 1;
933933

934-
const colorTransferFunc = actorProperty.getRGBTransferFunction();
935-
const cfunToString = getTransferFunctionHash(
936-
colorTransferFunc,
934+
const colorTransferFunctions = [];
935+
for (let component = 0; component < numIComps; ++component) {
936+
colorTransferFunctions.push(
937+
actorProperty.getRGBTransferFunction(component)
938+
);
939+
}
940+
const cfunToString = getTransferFunctionsHash(
941+
colorTransferFunctions,
937942
iComps,
938943
numIComps
939944
);
940-
const cTex =
941-
model._openGLRenderWindow.getGraphicsResourceForObject(colorTransferFunc);
945+
const firstColorTransferFunc = actorProperty.getRGBTransferFunction();
946+
const cTex = model._openGLRenderWindow.getGraphicsResourceForObject(
947+
firstColorTransferFunc
948+
);
942949

943950
const reBuildC =
944951
!cTex?.oglObject?.getHandle() || cTex?.hash !== cfunToString;
@@ -959,7 +966,7 @@ function vtkOpenGLImageMapper(publicAPI, model) {
959966
model.colorTexture.setMagnificationFilter(Filter.LINEAR);
960967
}
961968

962-
if (colorTransferFunc) {
969+
if (firstColorTransferFunc) {
963970
const tmpTable = new Float32Array(cWidth * 3);
964971

965972
for (let c = 0; c < numIComps; c++) {
@@ -1000,23 +1007,23 @@ function vtkOpenGLImageMapper(publicAPI, model) {
10001007
);
10011008
}
10021009

1003-
if (colorTransferFunc) {
1010+
if (firstColorTransferFunc) {
10041011
model._openGLRenderWindow.setGraphicsResourceForObject(
1005-
colorTransferFunc,
1012+
firstColorTransferFunc,
10061013
model.colorTexture,
10071014
cfunToString
10081015
);
1009-
if (colorTransferFunc !== model._colorTransferFunc) {
1016+
if (firstColorTransferFunc !== model._colorTransferFunc) {
10101017
model._openGLRenderWindow.registerGraphicsResourceUser(
1011-
colorTransferFunc,
1018+
firstColorTransferFunc,
10121019
publicAPI
10131020
);
10141021
model._openGLRenderWindow.unregisterGraphicsResourceUser(
10151022
model._colorTransferFunc,
10161023
publicAPI
10171024
);
10181025
}
1019-
model._colorTransferFunc = colorTransferFunc;
1026+
model._colorTransferFunc = firstColorTransferFunc;
10201027
}
10211028
} else {
10221029
model.colorTexture = cTex.oglObject;
@@ -1025,10 +1032,18 @@ function vtkOpenGLImageMapper(publicAPI, model) {
10251032
// Build piecewise function buffer. This buffer is used either
10261033
// for component weighting or opacity, depending on whether we're
10271034
// rendering components independently or not.
1028-
const pwFunc = actorProperty.getPiecewiseFunction();
1029-
const pwfunToString = getTransferFunctionHash(pwFunc, iComps, numIComps);
1035+
const opacityFunctions = [];
1036+
for (let component = 0; component < numIComps; ++component) {
1037+
opacityFunctions.push(actorProperty.getPiecewiseFunction(component));
1038+
}
1039+
const pwfunToString = getTransferFunctionsHash(
1040+
opacityFunctions,
1041+
iComps,
1042+
numIComps
1043+
);
1044+
const firstPwFunc = actorProperty.getPiecewiseFunction();
10301045
const pwfTex =
1031-
model._openGLRenderWindow.getGraphicsResourceForObject(pwFunc);
1046+
model._openGLRenderWindow.getGraphicsResourceForObject(firstPwFunc);
10321047
// rebuild opacity tfun?
10331048
const reBuildPwf =
10341049
!pwfTex?.oglObject?.getHandle() || pwfTex?.hash !== pwfunToString;
@@ -1049,7 +1064,7 @@ function vtkOpenGLImageMapper(publicAPI, model) {
10491064
model.pwfTexture.setMagnificationFilter(Filter.LINEAR);
10501065
}
10511066

1052-
if (pwFunc) {
1067+
if (firstPwFunc) {
10531068
const pwfFloatTable = new Float32Array(pwfSize);
10541069
const tmpTable = new Float32Array(pwfWidth);
10551070

@@ -1094,23 +1109,23 @@ function vtkOpenGLImageMapper(publicAPI, model) {
10941109
);
10951110
}
10961111

1097-
if (pwFunc) {
1112+
if (firstPwFunc) {
10981113
model._openGLRenderWindow.setGraphicsResourceForObject(
1099-
pwFunc,
1114+
firstPwFunc,
11001115
model.pwfTexture,
11011116
pwfunToString
11021117
);
1103-
if (pwFunc !== model._pwFunc) {
1118+
if (firstPwFunc !== model._pwFunc) {
11041119
model._openGLRenderWindow.registerGraphicsResourceUser(
1105-
pwFunc,
1120+
firstPwFunc,
11061121
publicAPI
11071122
);
11081123
model._openGLRenderWindow.unregisterGraphicsResourceUser(
11091124
model._pwFunc,
11101125
publicAPI
11111126
);
11121127
}
1113-
model._pwFunc = pwFunc;
1128+
model._pwFunc = firstPwFunc;
11141129
}
11151130
} else {
11161131
model.pwfTexture = pwfTex.oglObject;

0 commit comments

Comments
 (0)