Skip to content
Open
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
36 changes: 19 additions & 17 deletions Examples/Volume/VolumeMapperLightAndShadow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import vtkVolume from '@kitware/vtk.js/Rendering/Core/Volume';
import vtkVolumeMapper from '@kitware/vtk.js/Rendering/Core/VolumeMapper';
import vtkLight from '@kitware/vtk.js/Rendering/Core/Light';
import vtkXMLImageDataReader from '@kitware/vtk.js/IO/XML/XMLImageDataReader';
import HttpDataAccessHelper from '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpDataAccessHelper';

Check warning on line 11 in Examples/Volume/VolumeMapperLightAndShadow/index.js

View workflow job for this annotation

GitHub Actions / Check and lint PR

eslint(no-unused-vars)

Identifier 'HttpDataAccessHelper' is imported but never used.

Check warning on line 11 in Examples/Volume/VolumeMapperLightAndShadow/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-24.04 / node 22 / firefox

eslint(no-unused-vars)

Identifier 'HttpDataAccessHelper' is imported but never used.

Check warning on line 11 in Examples/Volume/VolumeMapperLightAndShadow/index.js

View workflow job for this annotation

GitHub Actions / ubuntu-24.04 / node 22 / chromium

eslint(no-unused-vars)

Identifier 'HttpDataAccessHelper' is imported but never used.
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 vtkHttpDataSetReader from '@kitware/vtk.js/IO/Core/HttpDataSetReader';

import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
import vtkSphereSource from '@kitware/vtk.js/Filters/Sources/SphereSource';
Expand All @@ -33,7 +33,7 @@
// ----------------------------------------------------------------------------
// Main function to set up and render volume
// ----------------------------------------------------------------------------
function createVolumeShadowViewer(rootContainer, fileContents) {
function createVolumeShadowViewer(rootContainer, reader, imageData) {
// Container content and style
const background = [0, 0, 0];
const containerStyle = { height: '100%', width: '100%' };
Expand Down Expand Up @@ -76,9 +76,7 @@
fpsMonitor.setRenderWindow(renderWindow);

// Actor and mapper pipeline
const vtiReader = vtkXMLImageDataReader.newInstance();
vtiReader.parseAsArrayBuffer(fileContents);
const source = vtiReader.getOutputData(0);
const source = imageData;

const actor = vtkVolume.newInstance();
const actorProperty = actor.getProperty(0);
Expand Down Expand Up @@ -112,7 +110,7 @@
.reduce((a, b) => a + b, 0)
);
mapper.setSampleDistance(sampleDistance / 2.5);
mapper.setVolumeShadowSamplingDistFactor(5.0);
mapper.setVolumeShadowSamplingDistFactor(3.0);

// Add transfer function
const lookupTable = vtkColorTransferFunction.newInstance();
Expand All @@ -122,8 +120,9 @@

// Set actor properties
actorProperty.setComputeNormalFromOpacity(false);
actorProperty.setGlobalIlluminationReach(0.0);
actorProperty.setVolumetricScatteringBlending(0.0);
actorProperty.setGlobalIlluminationReach(0.5);
actorProperty.setVolumetricScatteringBlending(0.7);
actorProperty.setAnisotropy(0.4);
actorProperty.setInterpolationTypeToLinear();
actorProperty.setScalarOpacityUnitDistance(
0,
Expand Down Expand Up @@ -204,10 +203,10 @@
}
const params = {
DensityNormal: isDensity,
VolumeBlending: 0.0,
GlobalReach: 0.0,
SampleDist: 5.0,
Anisotropy: 0.0,
VolumeBlending: actorProperty.getVolumetricScatteringBlending(),
GlobalReach: actorProperty.getGlobalIlluminationReach(),
SampleDist: mapper.getVolumeShadowSamplingDistFactor(),
Anisotropy: actorProperty.getAnisotropy(),
};
gui
.add(params, 'DensityNormal')
Expand Down Expand Up @@ -256,7 +255,7 @@

// Make some variables global so that you can inspect and
// modify objects in your browser's developer console:
global.source = vtiReader;
global.source = reader;
global.mapper = mapper;
global.actor = actor;
global.renderer = renderer;
Expand All @@ -271,8 +270,11 @@
// ----------------------------------------------------------------------------
// Read volume and render
// ----------------------------------------------------------------------------
HttpDataAccessHelper.fetchBinary(
`${__BASE_PATH__}/data/volume/head-binary.vti`
).then((binary) => {
createVolumeShadowViewer(myContainer, binary);

const reader = vtkHttpDataSetReader.newInstance({ fetchGzip: true });
reader.setUrl(`${__BASE_PATH__}/data/volume/LIDC2.vti`).then(() => {
reader.loadData().then(() => {
const imageData = reader.getOutputData();
createVolumeShadowViewer(myContainer, reader, imageData);
});
});
Loading