Skip to content

Commit 370e71c

Browse files
bruyeretfinetjul
authored andcommitted
feat(volumeMapper): add an interaction sample distance factor
Its purpose is to increase the sample distance when interacting to increase the framerate without sacrifying XY sample distance / viewport resolution
1 parent 34eb9bb commit 370e71c

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,17 @@ export interface vtkVolumeMapper extends vtkAbstractMapper {
7272
* Get at what scale the quality is reduced when interacting for the first time with the volume
7373
* It should should be set before any call to render for this volume
7474
* The higher the scale is, the lower the quality of rendering is during interaction
75-
* @default 4
75+
* @default 16
7676
*/
7777
getInitialInteractionScale(): number;
7878

79+
/**
80+
* Get by how much the sample distance should be increased when interacting
81+
* This feature is only implemented in the OpenGL volume mapper
82+
* @default 4
83+
*/
84+
getInteractionSampleDistanceFactor(): number;
85+
7986
/**
8087
*
8188
*/
@@ -202,6 +209,12 @@ export interface vtkVolumeMapper extends vtkAbstractMapper {
202209
*/
203210
setInitialInteractionScale(initialInteractionScale: number): boolean;
204211

212+
/**
213+
*
214+
* @param interactionSampleDistanceFactor
215+
*/
216+
setInteractionSampleDistanceFactor(interactionSampleDistanceFactor: number): boolean;
217+
205218
/**
206219
* Set the normal computation to be dependent on the transfer function.
207220
* By default, the mapper relies on the scalar gradient for computing normals at sample locations

Sources/Rendering/Core/VolumeMapper/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ const DEFAULT_VALUES = {
147147
imageSampleDistance: 1.0,
148148
maximumSamplesPerRay: 1000,
149149
autoAdjustSampleDistances: true,
150-
initialInteractionScale: 100.0,
150+
initialInteractionScale: 1.0,
151+
interactionSampleDistanceFactor: 1.0,
151152
blendMode: BlendMode.COMPOSITE_BLEND,
152153
ipScalarRange: [-1000000.0, 1000000.0],
153154
filterMode: FilterMode.OFF, // ignored by WebGL so no behavior change
@@ -177,6 +178,7 @@ export function extend(publicAPI, model, initialValues = {}) {
177178
'maximumSamplesPerRay',
178179
'autoAdjustSampleDistances',
179180
'initialInteractionScale',
181+
'interactionSampleDistanceFactor',
180182
'blendMode',
181183
'filterMode',
182184
'preferSizeOverAccuracy',

Sources/Rendering/OpenGL/VolumeMapper/index.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
179179
);
180180

181181
const maxSamples =
182-
vec3.length(vsize) / model.renderable.getSampleDistance();
182+
vec3.length(vsize) / publicAPI.getCurrentSampleDistance(ren);
183183

184184
FSSource = vtkShaderProgram.substitute(
185185
FSSource,
@@ -468,7 +468,7 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
468468
);
469469

470470
const maxSamples =
471-
vec3.length(vsize) / model.renderable.getSampleDistance();
471+
vec3.length(vsize) / publicAPI.getCurrentSampleDistance(ren);
472472

473473
const state = {
474474
interpolationType: actor.getProperty().getInterpolationType(),
@@ -593,7 +593,10 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
593593
}
594594

595595
program.setUniformi('texture1', model.scalarTexture.getTextureUnit());
596-
program.setUniformf('sampleDistance', model.renderable.getSampleDistance());
596+
program.setUniformf(
597+
'sampleDistance',
598+
publicAPI.getCurrentSampleDistance(ren)
599+
);
597600

598601
const volInfo = model.scalarTexture.getVolumeInfo();
599602
const ipScalarRange = model.renderable.getIpScalarRange();
@@ -739,7 +742,7 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
739742
);
740743

741744
const maxSamples =
742-
vec3.length(vsize) / model.renderable.getSampleDistance();
745+
vec3.length(vsize) / publicAPI.getCurrentSampleDistance(ren);
743746
if (maxSamples > model.renderable.getMaximumSamplesPerRay()) {
744747
vtkWarningMacro(`The number of steps required ${Math.ceil(
745748
maxSamples
@@ -1133,6 +1136,16 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
11331136
return [lowerLeftU, lowerLeftV];
11341137
};
11351138

1139+
publicAPI.getCurrentSampleDistance = (ren) => {
1140+
const rwi = ren.getVTKWindow().getInteractor();
1141+
const baseSampleDistance = model.renderable.getSampleDistance();
1142+
if (rwi.isAnimating()) {
1143+
const factor = model.renderable.getInteractionSampleDistanceFactor();
1144+
return baseSampleDistance * factor;
1145+
}
1146+
return baseSampleDistance;
1147+
};
1148+
11361149
publicAPI.renderPieceStart = (ren, actor) => {
11371150
const rwi = ren.getVTKWindow().getInteractor();
11381151

@@ -1437,7 +1450,7 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
14371450
for (let c = 0; c < numIComps; ++c) {
14381451
const ofun = vprop.getScalarOpacity(c);
14391452
const opacityFactor =
1440-
model.renderable.getSampleDistance() /
1453+
publicAPI.getCurrentSampleDistance(ren) /
14411454
vprop.getScalarOpacityUnitDistance(c);
14421455

14431456
const oRange = ofun.getRange();

0 commit comments

Comments
 (0)