Skip to content

Commit 34eb9bb

Browse files
bruyeretfinetjul
authored andcommitted
feat(volumeMapper): add a first interaction render quality setting
The setting "initialInteractionScale" set the quality of the rendering when interacting
1 parent 188c7fb commit 34eb9bb

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

Sources/Rendering/Core/VolumeMapper/index.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ export interface vtkVolumeMapper extends vtkAbstractMapper {
6868
*/
6969
getAutoAdjustSampleDistances(): boolean;
7070

71+
/**
72+
* Get at what scale the quality is reduced when interacting for the first time with the volume
73+
* It should should be set before any call to render for this volume
74+
* The higher the scale is, the lower the quality of rendering is during interaction
75+
* @default 4
76+
*/
77+
getInitialInteractionScale(): number;
78+
7179
/**
7280
*
7381
*/
@@ -188,6 +196,12 @@ export interface vtkVolumeMapper extends vtkAbstractMapper {
188196
*/
189197
setAutoAdjustSampleDistances(autoAdjustSampleDistances: boolean): boolean;
190198

199+
/**
200+
*
201+
* @param initialInteractionScale
202+
*/
203+
setInitialInteractionScale(initialInteractionScale: number): boolean;
204+
191205
/**
192206
* Set the normal computation to be dependent on the transfer function.
193207
* By default, the mapper relies on the scalar gradient for computing normals at sample locations

Sources/Rendering/Core/VolumeMapper/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ const DEFAULT_VALUES = {
147147
imageSampleDistance: 1.0,
148148
maximumSamplesPerRay: 1000,
149149
autoAdjustSampleDistances: true,
150+
initialInteractionScale: 100.0,
150151
blendMode: BlendMode.COMPOSITE_BLEND,
151152
ipScalarRange: [-1000000.0, 1000000.0],
152153
filterMode: FilterMode.OFF, // ignored by WebGL so no behavior change
@@ -175,6 +176,7 @@ export function extend(publicAPI, model, initialValues = {}) {
175176
'imageSampleDistance',
176177
'maximumSamplesPerRay',
177178
'autoAdjustSampleDistances',
179+
'initialInteractionScale',
178180
'blendMode',
179181
'filterMode',
180182
'preferSizeOverAccuracy',

Sources/Rendering/OpenGL/VolumeMapper/index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,9 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
11361136
publicAPI.renderPieceStart = (ren, actor) => {
11371137
const rwi = ren.getVTKWindow().getInteractor();
11381138

1139+
if (!model._lastScale) {
1140+
model._lastScale = model.renderable.getInitialInteractionScale();
1141+
}
11391142
model._useSmallViewport = false;
11401143
if (rwi.isAnimating() && model._lastScale > 1.5) {
11411144
model._useSmallViewport = true;
@@ -1166,19 +1169,15 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
11661169
model.renderable.getImageSampleDistance() *
11671170
model.renderable.getImageSampleDistance();
11681171
}
1169-
const size = model._openGLRenderWindow.getFramebufferSize();
1170-
model._smallViewportWidth = Math.ceil(
1171-
size[0] / Math.sqrt(model._lastScale)
1172-
);
1173-
model._smallViewportHeight = Math.ceil(
1174-
size[1] / Math.sqrt(model._lastScale)
1175-
);
11761172
});
11771173
}
11781174

11791175
// use/create/resize framebuffer if needed
11801176
if (model._useSmallViewport) {
11811177
const size = model._openGLRenderWindow.getFramebufferSize();
1178+
const scaleFactor = 1 / Math.sqrt(model._lastScale);
1179+
model._smallViewportWidth = Math.ceil(scaleFactor * size[0]);
1180+
model._smallViewportHeight = Math.ceil(scaleFactor * size[1]);
11821181

11831182
// adjust viewportSize to always be at most the dest fo size
11841183
if (model._smallViewportHeight > size[1]) {
@@ -1662,8 +1661,6 @@ export function extend(publicAPI, model, initialValues = {}) {
16621661
model.projectionToView = mat4.identity(new Float64Array(16));
16631662
model.projectionToWorld = mat4.identity(new Float64Array(16));
16641663

1665-
model._lastScale = 1.0;
1666-
16671664
// Build VTK API
16681665
macro.setGet(publicAPI, model, ['context']);
16691666

Sources/Rendering/WebGPU/VolumePass/index.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,14 @@ function vtkWebGPUVolumePass(publicAPI, model) {
262262
}, publicAPI.delete);
263263

264264
publicAPI.computeTiming = (viewNode) => {
265-
model._useSmallViewport = false;
266265
const rwi = viewNode.getRenderable().getInteractor();
267266

267+
if (model._lastScale == null) {
268+
const firstMapper = model.volumes[0].getRenderable().getMapper();
269+
model._lastScale = firstMapper.getInitialInteractionScale() || 1.0;
270+
}
271+
model._useSmallViewport = false;
268272
if (rwi.isAnimating() && model._lastScale > 1.5) {
269-
if (!model._smallViewportHeight) {
270-
model._smallViewportWidth = Math.ceil(
271-
viewNode.getCanvas().width / Math.sqrt(model._lastScale)
272-
);
273-
model._smallViewportHeight = Math.ceil(
274-
viewNode.getCanvas().height / Math.sqrt(model._lastScale)
275-
);
276-
}
277273
model._useSmallViewport = true;
278274
}
279275

@@ -305,13 +301,6 @@ function vtkWebGPUVolumePass(publicAPI, model) {
305301
}
306302
if (model._lastScale < 1.5) {
307303
model._lastScale = 1.5;
308-
} else {
309-
model._smallViewportWidth = Math.ceil(
310-
viewNode.getCanvas().width / Math.sqrt(model._lastScale)
311-
);
312-
model._smallViewportHeight = Math.ceil(
313-
viewNode.getCanvas().height / Math.sqrt(model._lastScale)
314-
);
315304
}
316305
});
317306
}
@@ -326,6 +315,10 @@ function vtkWebGPUVolumePass(publicAPI, model) {
326315
let width = model._colorTextureView.getTexture().getWidth();
327316
let height = model._colorTextureView.getTexture().getHeight();
328317
if (model._useSmallViewport) {
318+
const canvas = viewNode.getCanvas();
319+
const scaleFactor = 1 / Math.sqrt(model._lastScale);
320+
model._smallViewportWidth = Math.ceil(scaleFactor * canvas.width);
321+
model._smallViewportHeight = Math.ceil(scaleFactor * canvas.height);
329322
width = model._smallViewportWidth;
330323
height = model._smallViewportHeight;
331324
}
@@ -723,7 +716,6 @@ export function extend(publicAPI, model, initialValues = {}) {
723716
// Build VTK API
724717
vtkRenderPass.extend(publicAPI, model, initialValues);
725718

726-
model._lastScale = 2.0;
727719
model._mapper = vtkWebGPUSimpleMapper.newInstance();
728720
model._mapper.setFragmentShaderTemplate(DepthBoundsFS);
729721
model._mapper

0 commit comments

Comments
 (0)