import '@kitware/vtk.js/favicon';
import '@kitware/vtk.js/Rendering/Profiles/Geometry';
import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow'; import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor'; import vtkCamera from '@kitware/vtk.js/Rendering/Core/Camera'; import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper'; import vtkHttpDataSetReader from '@kitware/vtk.js/IO/Core/HttpDataSetReader'; import vtkWindowedSincPolyDataFilter from '@kitware/vtk.js/Filters/General/WindowedSincPolyDataFilter';
import controlPanel from './controller.html';
import '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpDataAccessHelper';
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ background: [0, 0, 0], }); const renderer = fullScreenRenderer.getRenderer(); const renderWindow = fullScreenRenderer.getRenderWindow();
const actor = vtkActor.newInstance(); renderer.addActor(actor);
const mapper = vtkMapper.newInstance({ interpolateScalarBeforeMapping: true }); actor.setMapper(mapper);
const cam = vtkCamera.newInstance(); renderer.setActiveCamera(cam); cam.setFocalPoint(0, 0, 0); cam.setPosition(0, 0, 10); cam.setClippingRange(0.1, 50.0);
const reader = vtkHttpDataSetReader.newInstance({ fetchGzip: true }); reader.setUrl(`${__BASE_PATH__}/data/cow.vtp`).then(() => { reader.loadData().then(() => { renderer.resetCamera(); renderWindow.render(); }); });
const smoothFilter = vtkWindowedSincPolyDataFilter.newInstance({ nonManifoldSmoothing: 0, numberOfIterations: 10, }); smoothFilter.setInputConnection(reader.getOutputPort()); mapper.setInputConnection(smoothFilter.getOutputPort());
fullScreenRenderer.addController(controlPanel);
[ 'numberOfIterations', 'passBand', 'featureAngle', 'edgeAngle', 'nonManifoldSmoothing', 'featureEdgeSmoothing', 'boundarySmoothing', ].forEach((propertyName) => { document.querySelector(`.${propertyName}`).addEventListener('input', (e) => { let value; if (Number.isNaN(e.target.valueAsNumber)) { value = e.target.checked ? 1 : 0; } else { value = e.target.valueAsNumber; } if (propertyName === 'passBand') { value = 10.0 ** (-4.0 * value); } smoothFilter.set({ [propertyName]: value }); renderWindow.render(); console.log({ [propertyName]: value }); }); });
renderer.resetCamera(); renderWindow.render();
global.source = reader; global.filter = smoothFilter; global.mapper = mapper; global.actor = actor;
|