Skip to content
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

Multi volume #3133

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
29 changes: 14 additions & 15 deletions Examples/Rendering/ManyRenderWindows/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,24 @@ function createVolumeActor(imageData) {
// Create and setup the mapper
const mapper = vtkVolumeMapper.newInstance();
mapper.setSampleDistance(0.7);
mapper.setVolumetricScatteringBlending(0);
mapper.setLocalAmbientOcclusion(0);
mapper.setLAOKernelSize(10);
mapper.setLAOKernelRadius(5);
mapper.setComputeNormalFromOpacity(true);
mapper.setInputData(imageData);

// Create and setup the actor
const actor = vtkVolume.newInstance();
actor
.getProperty()
.setRGBTransferFunction(0, getRandomColorTransferFunction());
actor.getProperty().setScalarOpacity(0, sharedOpacityFunction);
actor.getProperty().setInterpolationTypeToLinear();
actor.getProperty().setShade(true);
actor.getProperty().setAmbient(0.3);
actor.getProperty().setDiffuse(0.8);
actor.getProperty().setSpecular(1);
actor.getProperty().setSpecularPower(8);
const actorProperty = actor.getProperty();
actorProperty.setComputeNormalFromOpacity(true);
actorProperty.setLAOKernelRadius(5);
actorProperty.setLAOKernelSize(10);
actorProperty.setLocalAmbientOcclusion(0);
actorProperty.setVolumetricScatteringBlending(0);
actorProperty.setRGBTransferFunction(0, getRandomColorTransferFunction());
actorProperty.setScalarOpacity(0, sharedOpacityFunction);
actorProperty.setInterpolationTypeToLinear();
actorProperty.setShade(true);
actorProperty.setAmbient(0.3);
actorProperty.setDiffuse(0.8);
actorProperty.setSpecular(1);
actorProperty.setSpecularPower(8);
actor.setMapper(mapper);

return actor;
Expand Down
27 changes: 13 additions & 14 deletions Examples/Rendering/QuadView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,27 @@ function createVolumeView(renderer, source) {
.reduce((a, b) => a + b, 0)
);
mapper.setSampleDistance(sampleDistance / 2.5);
mapper.setComputeNormalFromOpacity(false);
mapper.setGlobalIlluminationReach(0.0);
mapper.setVolumetricScatteringBlending(0.5);
mapper.setVolumeShadowSamplingDistFactor(5.0);

// Set volume properties
const volProp = vtkVolumeProperty.newInstance();
volProp.setComputeNormalFromOpacity(false);
volProp.setGlobalIlluminationReach(0.0);
volProp.setVolumeShadowSamplingDistFactor(5.0);
volProp.setVolumetricScatteringBlending(0.5);
volProp.setInterpolationTypeToLinear();
volume
.getProperty()
.setScalarOpacityUnitDistance(
0,
vtkBoundingBox.getDiagonalLength(source.getBounds()) /
Math.max(...source.getDimensions())
);
volProp.setScalarOpacityUnitDistance(
0,
vtkBoundingBox.getDiagonalLength(source.getBounds()) /
Math.max(...source.getDimensions())
);
volProp.setGradientOpacityMinimumValue(0, 0);
const dataArray =
source.getPointData().getScalars() || source.getPointData().getArrays()[0];
const dataRange = dataArray.getRange();
volume
.getProperty()
.setGradientOpacityMaximumValue(0, (dataRange[1] - dataRange[0]) * 0.05);
volProp.setGradientOpacityMaximumValue(
0,
(dataRange[1] - dataRange[0]) * 0.05
);
volProp.setShade(true);
volProp.setUseGradientOpacity(0, false);
volProp.setGradientOpacityMinimumOpacity(0, 0.0);
Expand Down
13 changes: 7 additions & 6 deletions Examples/Volume/VolumeMapperBlendModes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ const reader = vtkHttpDataSetReader.newInstance({ fetchGzip: true });
const initialSampleDistance = 1.3;

const actor = vtkVolume.newInstance();
const actorProperty = actor.getProperty();
const mapper = vtkVolumeMapper.newInstance();
mapper.setSampleDistance(initialSampleDistance);

// use half float at the cost of precision to save memory
mapper.setPreferSizeOverAccuracy(true);
actorProperty.setPreferSizeOverAccuracy(true);

actor.setMapper(mapper);

Expand Down Expand Up @@ -125,16 +126,16 @@ function updateSampleDistance(event) {
}

function updateScalarMin(event) {
mapper.setIpScalarRange(
actorProperty.setIpScalarRange(
event.target.valueAsNumber,
mapper.getIpScalarRange()[1]
actorProperty.getIpScalarRange()[1]
);
renderWindow.render();
}

function updateScalarMax(event) {
mapper.setIpScalarRange(
mapper.getIpScalarRange()[0],
actorProperty.setIpScalarRange(
actorProperty.getIpScalarRange()[0],
event.target.valueAsNumber
);
renderWindow.render();
Expand All @@ -146,7 +147,7 @@ function updateBlendMode(event) {
const radonScalars = document.querySelectorAll('.radonScalar');

mapper.setBlendMode(currentBlendMode);
mapper.setIpScalarRange(0.0, 1.0);
actorProperty.setIpScalarRange(0.0, 1.0);

// if average or additive blend mode
for (let i = 0; i < ipScalarEls.length; i += 1) {
Expand Down
101 changes: 49 additions & 52 deletions Examples/Volume/VolumeMapperLightAndShadow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import '@kitware/vtk.js/favicon';

import '@kitware/vtk.js/Rendering/Profiles/Volume';
import '@kitware/vtk.js/Rendering/Profiles/Geometry';
import macro from '@kitware/vtk.js/macros';
import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow';
import vtkPiecewiseFunction from '@kitware/vtk.js/Common/DataModel/PiecewiseFunction';
Expand All @@ -14,6 +13,7 @@ import HttpDataAccessHelper from '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpD
import vtkVolumeController from '@kitware/vtk.js/Interaction/UI/VolumeController';
import vtkBoundingBox from '@kitware/vtk.js/Common/DataModel/BoundingBox';
import vtkFPSMonitor from '@kitware/vtk.js/Interaction/UI/FPSMonitor';
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';

import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import vtkSphereSource from '@kitware/vtk.js/Filters/Sources/SphereSource';
Expand All @@ -31,19 +31,6 @@ const fpsMonitor = vtkFPSMonitor.newInstance();
const progressContainer = document.createElement('div');
myContainer.appendChild(progressContainer);

const progressCallback = (progressEvent) => {
if (progressEvent.lengthComputable) {
const percent = Math.floor(
(100 * progressEvent.loaded) / progressEvent.total
);
progressContainer.innerHTML = `Loading ${percent}%`;
} else {
progressContainer.innerHTML = macro.formatBytesToProperUnit(
progressEvent.loaded
);
}
};

// ----------------------------------------------------------------------------
// Main function to set up and render volume
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -94,10 +81,23 @@ function createVolumeShadowViewer(rootContainer, fileContents) {
const source = vtiReader.getOutputData(0);

const actor = vtkVolume.newInstance();
const actorProperty = actor.getProperty(0);
const mapper = vtkVolumeMapper.newInstance();

actor.setMapper(mapper);
mapper.setInputData(source);
mapper.addInputData(source);

for (let i = 0; i < 3; ++i) {
const otherImageData = vtkImageData.newInstance();
otherImageData.setPointData(source.getPointData());
otherImageData.setDimensions(...source.getDimensions());
otherImageData.setSpacing(...source.getSpacing());
otherImageData.setOrigin(...source.getOrigin());
otherImageData.setDirection(...source.getDirection());
otherImageData.setOrigin(...[120 * (i + 1), 0, 0]);
mapper.addInputData(otherImageData);
actor.setProperty(actorProperty, 1 + i);
}

// Add one positional light
const bounds = actor.getBounds();
Expand All @@ -124,44 +124,42 @@ function createVolumeShadowViewer(rootContainer, fileContents) {
.reduce((a, b) => a + b, 0)
);
mapper.setSampleDistance(sampleDistance / 2.5);
mapper.setComputeNormalFromOpacity(false);
mapper.setGlobalIlluminationReach(0.0);
mapper.setVolumetricScatteringBlending(0.0);
mapper.setVolumeShadowSamplingDistFactor(5.0);

// Add transfer function
const lookupTable = vtkColorTransferFunction.newInstance();
const piecewiseFunction = vtkPiecewiseFunction.newInstance();
actor.getProperty().setRGBTransferFunction(0, lookupTable);
actor.getProperty().setScalarOpacity(0, piecewiseFunction);
actorProperty.setRGBTransferFunction(0, lookupTable);
actorProperty.setScalarOpacity(0, piecewiseFunction);

// Set actor properties
actor.getProperty().setInterpolationTypeToLinear();
actor
.getProperty()
.setScalarOpacityUnitDistance(
0,
vtkBoundingBox.getDiagonalLength(source.getBounds()) /
Math.max(...source.getDimensions())
);
actor.getProperty().setGradientOpacityMinimumValue(0, 0);
actorProperty.setComputeNormalFromOpacity(false);
actorProperty.setGlobalIlluminationReach(0.0);
actorProperty.setVolumetricScatteringBlending(0.0);
actorProperty.setInterpolationTypeToLinear();
actorProperty.setScalarOpacityUnitDistance(
0,
vtkBoundingBox.getDiagonalLength(source.getBounds()) /
Math.max(...source.getDimensions())
);
actorProperty.setGradientOpacityMinimumValue(0, 0);
const dataArray =
source.getPointData().getScalars() || source.getPointData().getArrays()[0];
const dataRange = dataArray.getRange();
actor
.getProperty()
.setGradientOpacityMaximumValue(0, (dataRange[1] - dataRange[0]) * 0.05);
actor.getProperty().setShade(true);
actor.getProperty().setUseGradientOpacity(0, false);
actor.getProperty().setGradientOpacityMinimumOpacity(0, 0.0);
actor.getProperty().setGradientOpacityMaximumOpacity(0, 1.0);
actor.getProperty().setAmbient(0.0);
actor.getProperty().setDiffuse(2.0);
actor.getProperty().setSpecular(0.0);
actor.getProperty().setSpecularPower(0.0);
actor.getProperty().setUseLabelOutline(false);
actor.getProperty().setLabelOutlineThickness(2);
renderer.addActor(actor);
actorProperty.setGradientOpacityMaximumValue(
0,
(dataRange[1] - dataRange[0]) * 0.05
);
actorProperty.setShade(true);
actorProperty.setUseGradientOpacity(0, false);
actorProperty.setGradientOpacityMinimumOpacity(0, 0.0);
actorProperty.setGradientOpacityMaximumOpacity(0, 1.0);
actorProperty.setAmbient(0.0);
actorProperty.setDiffuse(2.0);
actorProperty.setSpecular(0.0);
actorProperty.setSpecularPower(0.0);
actorProperty.setUseLabelOutline(false);
actorProperty.setLabelOutlineThickness(2);

// Control UI for sample distance, transfer function, and shadow on/off
const controllerWidget = vtkVolumeController.newInstance({
Expand Down Expand Up @@ -191,12 +189,12 @@ function createVolumeShadowViewer(rootContainer, fileContents) {
// Add sliders to tune volume shadow effect
function updateVSB(e) {
const vsb = Number(e.target.value);
mapper.setVolumetricScatteringBlending(vsb);
actorProperty.setVolumetricScatteringBlending(vsb);
renderWindow.render();
}
function updateGlobalReach(e) {
const gir = Number(e.target.value);
mapper.setGlobalIlluminationReach(gir);
actorProperty.setGlobalIlluminationReach(gir);
renderWindow.render();
}
function updateSD(e) {
Expand All @@ -206,7 +204,7 @@ function createVolumeShadowViewer(rootContainer, fileContents) {
}
function updateAT(e) {
const at = Number(e.target.value);
mapper.setAnisotropy(at);
actorProperty.setAnisotropy(at);
renderWindow.render();
}
const el = document.querySelector('.volumeBlending');
Expand Down Expand Up @@ -235,7 +233,7 @@ function createVolumeShadowViewer(rootContainer, fileContents) {
const buttonID = document.querySelector('.text2');
function toggleDensityNormal() {
isDensity = !isDensity;
mapper.setComputeNormalFromOpacity(isDensity);
actorProperty.setComputeNormalFromOpacity(isDensity);
buttonID.innerText = `(${isDensity ? 'on' : 'off'})`;
renderWindow.render();
}
Expand All @@ -257,6 +255,9 @@ function createVolumeShadowViewer(rootContainer, fileContents) {
renderer.addActor(actorSphere);
}

// Add the volume actor here to avoid compiling the shader twice
renderer.addActor(actor);

// Camera and first render
renderer.resetCamera();
renderWindow.render();
Expand All @@ -279,11 +280,7 @@ function createVolumeShadowViewer(rootContainer, fileContents) {
// Read volume and render
// ----------------------------------------------------------------------------
HttpDataAccessHelper.fetchBinary(
'https://data.kitware.com/api/v1/item/59de9dc98d777f31ac641dc1/download',
{
progressCallback,
}
`${__BASE_PATH__}/data/volume/head-binary.vti`
).then((binary) => {
myContainer.removeChild(progressContainer);
createVolumeShadowViewer(myContainer, binary);
});
6 changes: 3 additions & 3 deletions Examples/Volume/WebXRChestCTBlendedCVR/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ HttpDataAccessHelper.fetchBinary(fileURL).then((fileContents) => {
actor.getProperty().setAmbient(0.2);
actor.getProperty().setDiffuse(1.3);
actor.getProperty().setSpecular(0.0);
mapper.setGlobalIlluminationReach(0.1);
mapper.setVolumetricScatteringBlending(0.5);
mapper.setVolumeShadowSamplingDistFactor(1.0);
actor.getProperty().setGlobalIlluminationReach(0.1);
actor.getProperty().setVolumetricScatteringBlending(0.5);
actor.getProperty().setVolumeShadowSamplingDistFactor(1.0);
mapper.setAutoAdjustSampleDistances(false);

// Set up rendering
Expand Down
6 changes: 3 additions & 3 deletions Examples/Volume/WebXRHeadFullVolumeCVR/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ HttpDataAccessHelper.fetchBinary(fileURL).then((fileContents) => {
actor.getProperty().setAmbient(0.0);
actor.getProperty().setDiffuse(2.0);
actor.getProperty().setSpecular(0.0);
mapper.setGlobalIlluminationReach(1.0);
mapper.setVolumetricScatteringBlending(1.0);
mapper.setVolumeShadowSamplingDistFactor(1.0);
actor.getProperty().setGlobalIlluminationReach(1.0);
actor.getProperty().setVolumetricScatteringBlending(1.0);
actor.getProperty().setVolumeShadowSamplingDistFactor(1.0);
mapper.setAutoAdjustSampleDistances(false);

// Set up rendering
Expand Down
6 changes: 3 additions & 3 deletions Examples/Volume/WebXRHeadGradientCVR/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ HttpDataAccessHelper.fetchBinary(fileURL).then((fileContents) => {

// CVR
actor.getProperty().setShade(true);
mapper.setGlobalIlluminationReach(0.0);
mapper.setVolumetricScatteringBlending(0.0);
mapper.setVolumeShadowSamplingDistFactor(1.0);
actor.getProperty().setGlobalIlluminationReach(0.0);
actor.getProperty().setVolumetricScatteringBlending(0.0);
actor.getProperty().setVolumeShadowSamplingDistFactor(1.0);
mapper.setAutoAdjustSampleDistances(false);

// Set up rendering
Expand Down
6 changes: 0 additions & 6 deletions Sources/Rendering/Core/Actor/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ export interface vtkActor extends vtkProp3D {
*/
getBackfaceProperty(): vtkProperty;

/**
* Get the bounds for this mapper as [xmin, xmax, ymin, ymax,zmin, zmax].
* @return {Bounds} The bounds for the mapper.
*/
getBounds(): Bounds;

/**
* Check whether the opaque is forced or not.
*/
Expand Down
Loading