import '@kitware/vtk.js/favicon';
import '@kitware/vtk.js/Rendering/Profiles/Geometry'; import '@kitware/vtk.js/Rendering/Profiles/Volume';
import '@kitware/vtk.js/IO/Core/DataAccessHelper/HtmlDataAccessHelper'; import '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpDataAccessHelper'; import '@kitware/vtk.js/IO/Core/DataAccessHelper/JSZipDataAccessHelper';
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow'; import vtkHttpDataSetReader from '@kitware/vtk.js/IO/Core/HttpDataSetReader'; import vtkCubeSource from '@kitware/vtk.js/Filters/Sources/CubeSource'; import vtkVolume from '@kitware/vtk.js/Rendering/Core/Volume'; import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor'; import vtkVolumeMapper from '@kitware/vtk.js/Rendering/Core/VolumeMapper'; import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
import controlPanel from './controller.html';
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ background: [0.3, 0.3, 0.3], });
fullScreenRenderer.addController(controlPanel);
const cubeSource = vtkCubeSource.newInstance();
cubeSource.setXLength(100); cubeSource.setYLength(100); cubeSource.setZLength(1);
console.log(cubeSource);
const cubeActor = vtkActor.newInstance(); const cubeMapper = vtkMapper.newInstance();
cubeActor.setMapper(cubeMapper); cubeMapper.setInputConnection(cubeSource.getOutputPort());
const actor = vtkVolume.newInstance(); const mapper = vtkVolumeMapper.newInstance({ sampleDistance: 1.1, });
const renderer = fullScreenRenderer.getRenderer(); const renderWindow = fullScreenRenderer.getRenderWindow();
renderer.addActor(cubeActor);
const reader = vtkHttpDataSetReader.newInstance({ fetchGzip: true, }); reader .setUrl('https://kitware.github.io/vtk-js/data/volume/LIDC2.vti') .then(() => { reader.loadData().then(() => { const imageData = reader.getOutputData(); const dataArray = imageData.getPointData().getScalars();
const rgbTransferFunction = actor.getProperty().getRGBTransferFunction(0); rgbTransferFunction.setRange(...dataArray.getRange());
renderer.addVolume(actor); renderer.resetCamera(); renderWindow.render(); }); });
actor.setMapper(mapper); mapper.setInputConnection(reader.getOutputPort());
mapper.setBlendModeToMaximumIntensity();
renderer.getActiveCamera().setViewUp(0, 1, 0);
let isParallel = false; const button = document.querySelector('.text');
function toggleParallel() { isParallel = !isParallel; const camera = renderer.getActiveCamera(); camera.setParallelProjection(isParallel);
renderer.resetCamera();
button.innerText = `(${isParallel ? 'on' : 'off'})`;
renderWindow.render(); }
global.source = reader; global.mapper = mapper; global.actor = actor; global.renderer = renderer; global.renderWindow = renderWindow; global.toggleParallel = toggleParallel;
|