Skip to content

Image reslice multi component #3158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ test.onlyIfWebGL('Test ImageResliceMapperShareOpenGLTexture', async (t) => {
const oglrenderer = glwindow.getViewNodeFor(renderer);
const oglamapper = oglrenderer.getViewNodeFor(amapper);
const oglcmapper = oglrenderer.getViewNodeFor(cmapper);
oglcmapper.setOpenGLTexture(oglamapper.getOpenGLTexture());
oglcmapper.setScalarTextures(oglamapper.getScalarTextures());
const oglsmapper = oglrenderer.getViewNodeFor(smapper);
oglsmapper.setOpenGLTexture(oglamapper.getOpenGLTexture());
oglsmapper.setScalarTextures(oglamapper.getScalarTextures());

const promise = reader
.setUrl(`${__BASE_PATH__}/Data/volume/headsq.vti`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ test.onlyIfWebGL('Test ImageResliceMapperSlabTypes', async (t) => {
const oglren4 = glwindow.getViewNodeFor(ren4);
const oglamapper = oglren1.getViewNodeFor(amapper);
const oglcmapper = oglren2.getViewNodeFor(cmapper);
oglcmapper.setOpenGLTexture(oglamapper.getOpenGLTexture());
oglcmapper.setScalarTextures(oglamapper.getScalarTextures());
const oglsmapper = oglren3.getViewNodeFor(smapper);
oglsmapper.setOpenGLTexture(oglamapper.getOpenGLTexture());
oglsmapper.setScalarTextures(oglamapper.getScalarTextures());
const oglzmapper = oglren4.getViewNodeFor(zmapper);
oglzmapper.setOpenGLTexture(oglamapper.getOpenGLTexture());
oglzmapper.setScalarTextures(oglamapper.getScalarTextures());

const cam = gc.registerResource(vtkCamera.newInstance());
ren1.setActiveCamera(cam);
Expand Down
54 changes: 34 additions & 20 deletions Sources/Rendering/OpenGL/ImageCPRMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import vtkShaderProgram from 'vtk.js/Sources/Rendering/OpenGL/ShaderProgram';
import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode';

import {
getTransferFunctionHash,
getTransferFunctionsHash,
getImageDataHash,
} from 'vtk.js/Sources/Rendering/OpenGL/RenderWindow/resourceSharingHelper';

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

const colorTransferFunc = ppty.getRGBTransferFunction();
const colorTextureHash = getTransferFunctionHash(
colorTransferFunc,
const colorTransferFunctions = [];
for (let component = 0; component < numIComps; ++component) {
colorTransferFunctions.push(ppty.getRGBTransferFunction(component));
}
const colorTextureHash = getTransferFunctionsHash(
colorTransferFunctions,
iComps,
numIComps
);

const firstColorTransferFunc = ppty.getRGBTransferFunction();
const cachedColorEntry =
model._openGLRenderWindow.getGraphicsResourceForObject(colorTransferFunc);
model._openGLRenderWindow.getGraphicsResourceForObject(
firstColorTransferFunc
);
const reBuildColorTexture =
!cachedColorEntry?.oglObject?.getHandle() ||
cachedColorEntry?.hash !== colorTextureHash;
Expand All @@ -261,7 +267,7 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
const cTable = new Uint8ClampedArray(cSize);
model.colorTexture = vtkOpenGLTexture.newInstance();
model.colorTexture.setOpenGLRenderWindow(model._openGLRenderWindow);
if (colorTransferFunc) {
if (firstColorTransferFunc) {
const tmpTable = new Float32Array(cWidth * 3);

for (let c = 0; c < numIComps; c++) {
Expand Down Expand Up @@ -303,23 +309,23 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
);
}

if (colorTransferFunc) {
if (firstColorTransferFunc) {
model._openGLRenderWindow.setGraphicsResourceForObject(
colorTransferFunc,
firstColorTransferFunc,
model.colorTexture,
colorTextureHash
);
if (colorTransferFunc !== model._colorTransferFunc) {
if (firstColorTransferFunc !== model._colorTransferFunc) {
model._openGLRenderWindow.registerGraphicsResourceUser(
colorTransferFunc,
firstColorTransferFunc,
publicAPI
);
model._openGLRenderWindow.unregisterGraphicsResourceUser(
model._colorTransferFunc,
publicAPI
);
}
model._colorTransferFunc = colorTransferFunc;
model._colorTransferFunc = firstColorTransferFunc;
}
} else {
model.colorTexture = cachedColorEntry.oglObject;
Expand All @@ -328,10 +334,18 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
// Build piecewise function buffer. This buffer is used either
// for component weighting or opacity, depending on whether we're
// rendering components independently or not.
const pwFunc = ppty.getPiecewiseFunction();
const pwfTextureHash = getTransferFunctionHash(pwFunc, iComps, numIComps);
const opacityFunctions = [];
for (let component = 0; component < numIComps; ++component) {
opacityFunctions.push(ppty.getPiecewiseFunction(component));
}
const pwfTextureHash = getTransferFunctionsHash(
opacityFunctions,
iComps,
numIComps
);
const firstPwFunc = ppty.getPiecewiseFunction();
const cachedPwfEntry =
model._openGLRenderWindow.getGraphicsResourceForObject(pwFunc);
model._openGLRenderWindow.getGraphicsResourceForObject(firstPwFunc);
const reBuildPwf =
!cachedPwfEntry?.oglObject?.getHandle() ||
cachedPwfEntry?.hash !== pwfTextureHash;
Expand All @@ -341,7 +355,7 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
const pwfTable = new Uint8ClampedArray(pwfSize);
model.pwfTexture = vtkOpenGLTexture.newInstance();
model.pwfTexture.setOpenGLRenderWindow(model._openGLRenderWindow);
if (pwFunc) {
if (firstPwFunc) {
const pwfFloatTable = new Float32Array(pwfSize);
const tmpTable = new Float32Array(pwfWidth);

Expand Down Expand Up @@ -386,23 +400,23 @@ function vtkOpenGLImageCPRMapper(publicAPI, model) {
pwfTable
);
}
if (pwFunc) {
if (firstPwFunc) {
model._openGLRenderWindow.setGraphicsResourceForObject(
pwFunc,
firstPwFunc,
model.pwfTexture,
pwfTextureHash
);
if (pwFunc !== model._pwFunc) {
if (firstPwFunc !== model._pwFunc) {
model._openGLRenderWindow.registerGraphicsResourceUser(
pwFunc,
firstPwFunc,
publicAPI
);
model._openGLRenderWindow.unregisterGraphicsResourceUser(
model._pwFunc,
publicAPI
);
}
model._pwFunc = pwFunc;
model._pwFunc = firstPwFunc;
}
} else {
model.pwfTexture = cachedPwfEntry.oglObject;
Expand Down
57 changes: 36 additions & 21 deletions Sources/Rendering/OpenGL/ImageMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from 'vtk.js/Sources/Rendering/OpenGL/Texture/Constants';
import { InterpolationType } from 'vtk.js/Sources/Rendering/Core/ImageProperty/Constants';

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

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

const colorTransferFunc = actorProperty.getRGBTransferFunction();
const cfunToString = getTransferFunctionHash(
colorTransferFunc,
const colorTransferFunctions = [];
for (let component = 0; component < numIComps; ++component) {
colorTransferFunctions.push(
actorProperty.getRGBTransferFunction(component)
);
}
const cfunToString = getTransferFunctionsHash(
colorTransferFunctions,
iComps,
numIComps
);
const cTex =
model._openGLRenderWindow.getGraphicsResourceForObject(colorTransferFunc);
const firstColorTransferFunc = actorProperty.getRGBTransferFunction();
const cTex = model._openGLRenderWindow.getGraphicsResourceForObject(
firstColorTransferFunc
);

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

if (colorTransferFunc) {
if (firstColorTransferFunc) {
const tmpTable = new Float32Array(cWidth * 3);

for (let c = 0; c < numIComps; c++) {
Expand Down Expand Up @@ -1000,23 +1007,23 @@ function vtkOpenGLImageMapper(publicAPI, model) {
);
}

if (colorTransferFunc) {
if (firstColorTransferFunc) {
model._openGLRenderWindow.setGraphicsResourceForObject(
colorTransferFunc,
firstColorTransferFunc,
model.colorTexture,
cfunToString
);
if (colorTransferFunc !== model._colorTransferFunc) {
if (firstColorTransferFunc !== model._colorTransferFunc) {
model._openGLRenderWindow.registerGraphicsResourceUser(
colorTransferFunc,
firstColorTransferFunc,
publicAPI
);
model._openGLRenderWindow.unregisterGraphicsResourceUser(
model._colorTransferFunc,
publicAPI
);
}
model._colorTransferFunc = colorTransferFunc;
model._colorTransferFunc = firstColorTransferFunc;
}
} else {
model.colorTexture = cTex.oglObject;
Expand All @@ -1025,10 +1032,18 @@ function vtkOpenGLImageMapper(publicAPI, model) {
// Build piecewise function buffer. This buffer is used either
// for component weighting or opacity, depending on whether we're
// rendering components independently or not.
const pwFunc = actorProperty.getPiecewiseFunction();
const pwfunToString = getTransferFunctionHash(pwFunc, iComps, numIComps);
const opacityFunctions = [];
for (let component = 0; component < numIComps; ++component) {
opacityFunctions.push(actorProperty.getPiecewiseFunction(component));
}
const pwfunToString = getTransferFunctionsHash(
opacityFunctions,
iComps,
numIComps
);
const firstPwFunc = actorProperty.getPiecewiseFunction();
const pwfTex =
model._openGLRenderWindow.getGraphicsResourceForObject(pwFunc);
model._openGLRenderWindow.getGraphicsResourceForObject(firstPwFunc);
// rebuild opacity tfun?
const reBuildPwf =
!pwfTex?.oglObject?.getHandle() || pwfTex?.hash !== pwfunToString;
Expand All @@ -1049,7 +1064,7 @@ function vtkOpenGLImageMapper(publicAPI, model) {
model.pwfTexture.setMagnificationFilter(Filter.LINEAR);
}

if (pwFunc) {
if (firstPwFunc) {
const pwfFloatTable = new Float32Array(pwfSize);
const tmpTable = new Float32Array(pwfWidth);

Expand Down Expand Up @@ -1094,23 +1109,23 @@ function vtkOpenGLImageMapper(publicAPI, model) {
);
}

if (pwFunc) {
if (firstPwFunc) {
model._openGLRenderWindow.setGraphicsResourceForObject(
pwFunc,
firstPwFunc,
model.pwfTexture,
pwfunToString
);
if (pwFunc !== model._pwFunc) {
if (firstPwFunc !== model._pwFunc) {
model._openGLRenderWindow.registerGraphicsResourceUser(
pwFunc,
firstPwFunc,
publicAPI
);
model._openGLRenderWindow.unregisterGraphicsResourceUser(
model._pwFunc,
publicAPI
);
}
model._pwFunc = pwFunc;
model._pwFunc = firstPwFunc;
}
} else {
model.pwfTexture = pwfTex.oglObject;
Expand Down
Loading
Loading