import '@kitware/vtk.js/favicon';
import '@kitware/vtk.js/Rendering/Profiles/Geometry';
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor'; import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow'; import vtkImageMarchingCubes from '@kitware/vtk.js/Filters/General/ImageMarchingCubes'; import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper'; import vtkSampleFunction from '@kitware/vtk.js/Imaging/Hybrid/SampleFunction'; import vtkSphere from '@kitware/vtk.js/Common/DataModel/Sphere';
import controlPanel from './controller.html';
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance(); const renderer = fullScreenRenderer.getRenderer(); const renderWindow = fullScreenRenderer.getRenderWindow();
const actor = vtkActor.newInstance(); renderer.addActor(actor);
const mapper = vtkMapper.newInstance(); actor.setMapper(mapper);
const sphere = vtkSphere.newInstance({ center: [0.0, 0.0, 0.0], radius: 0.5 }); const sample = vtkSampleFunction.newInstance({ implicitFunction: sphere, sampleDimensions: [50, 50, 50], modelBounds: [-0.5, 0.5, -0.5, 0.5, -0.5, 0.5], }); const mCubes = vtkImageMarchingCubes.newInstance({ contourValue: 0.0 });
mCubes.setInputConnection(sample.getOutputPort()); mapper.setInputConnection(mCubes.getOutputPort());
fullScreenRenderer.addController(controlPanel);
document.querySelector('.isoValue').addEventListener('input', (e) => { const value = Number(e.target.value); mCubes.setContourValue(value); renderWindow.render(); });
document.querySelector('.volumeResolution').addEventListener('input', (e) => { const value = Number(e.target.value); sample.setSampleDimensions(value, value, value); renderWindow.render(); });
document.querySelector('.sphereRadius').addEventListener('input', (e) => { const value = Number(e.target.value); sphere.setRadius(value); renderWindow.render(); });
document.querySelector('.computeNormals').addEventListener('change', (e) => { mCubes.setComputeNormals(!!e.target.checked); renderWindow.render(); });
document.querySelector('.mergePoints').addEventListener('change', (e) => { mCubes.setMergePoints(!!e.target.checked); renderWindow.render(); });
renderer.resetCamera(); renderWindow.render();
global.source = sample; global.filter = mCubes; global.mapper = mapper; global.actor = actor;
|