import '@kitware/vtk.js/favicon';
import '@kitware/vtk.js/Rendering/Profiles/Geometry';
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor'; import vtkCalculator from '@kitware/vtk.js/Filters/General/Calculator'; import vtkConeSource from '@kitware/vtk.js/Filters/Sources/ConeSource'; import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow'; import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper'; import { AttributeTypes } from '@kitware/vtk.js/Common/DataModel/DataSetAttributes/Constants'; import { FieldDataTypes } from '@kitware/vtk.js/Common/DataModel/DataSet/Constants';
import vtkFPSMonitor from '@kitware/vtk.js/Interaction/UI/FPSMonitor';
import controlPanel from './controller.html';
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ background: [0, 0, 0], }); const renderer = fullScreenRenderer.getRenderer(); const renderWindow = fullScreenRenderer.getRenderWindow();
const fpsMonitor = vtkFPSMonitor.newInstance(); const fpsElm = fpsMonitor.getFpsMonitorContainer(); fpsElm.style.position = 'absolute'; fpsElm.style.left = '10px'; fpsElm.style.bottom = '10px'; fpsElm.style.background = 'rgba(255,255,255,0.5)'; fpsElm.style.borderRadius = '5px';
fpsMonitor.setContainer(document.querySelector('body')); fpsMonitor.setRenderWindow(renderWindow);
fullScreenRenderer.setResizeCallback(fpsMonitor.update);
const coneSource = vtkConeSource.newInstance({ center: [0, 500000, 0], height: 1.0, });
const filter = vtkCalculator.newInstance();
filter.setInputConnection(coneSource.getOutputPort());
filter.setFormula({ getArrays: (inputDataSets) => ({ input: [], output: [ { location: FieldDataTypes.CELL, name: 'Random', dataType: 'Float32Array', attribute: AttributeTypes.SCALARS, }, ], }), evaluate: (arraysIn, arraysOut) => { const [scalars] = arraysOut.map((d) => d.getData()); for (let i = 0; i < scalars.length; i++) { scalars[i] = Math.random(); } }, });
const mapper = vtkMapper.newInstance(); mapper.setInputConnection(filter.getOutputPort());
const actor = vtkActor.newInstance(); actor.setMapper(mapper); actor.setPosition(500000.0, 0.0, 0.0);
renderer.addActor(actor); renderer.resetCamera(); renderWindow.render(); fpsMonitor.update();
fullScreenRenderer.addController(controlPanel); const representationSelector = document.querySelector('.representations'); const resolutionChange = document.querySelector('.resolution');
representationSelector.addEventListener('change', (e) => { const newRepValue = Number(e.target.value); actor.getProperty().setRepresentation(newRepValue); renderWindow.render(); fpsMonitor.update(); });
resolutionChange.addEventListener('input', (e) => { const resolution = Number(e.target.value); coneSource.setResolution(resolution); renderWindow.render(); fpsMonitor.update(); });
global.source = coneSource; global.mapper = mapper; global.actor = actor; global.renderer = renderer; global.renderWindow = renderWindow;
|