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 vtkCylinderSource from '@kitware/vtk.js/Filters/Sources/CylinderSource'; import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper';
import controlPanel from './controlPanel.html';
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ background: [0, 0, 0], }); const renderer = fullScreenRenderer.getRenderer(); const renderWindow = fullScreenRenderer.getRenderWindow();
function createCylinderPipeline() { const cylinderSource = vtkCylinderSource.newInstance(); const actor = vtkActor.newInstance(); const mapper = vtkMapper.newInstance();
actor.setMapper(mapper); mapper.setInputConnection(cylinderSource.getOutputPort());
renderer.addActor(actor); return { cylinderSource, mapper, actor }; }
const pipelines = [createCylinderPipeline(), createCylinderPipeline()];
pipelines[0].actor.getProperty().setRepresentation(1); pipelines[0].actor.getProperty().setColor(1, 0, 0);
renderer.resetCamera(); renderWindow.render();
fullScreenRenderer.addController(controlPanel);
['height', 'radius', 'resolution'].forEach((propertyName) => { document.querySelector(`.${propertyName}`).addEventListener('input', (e) => { const value = Number(e.target.value); pipelines[0].cylinderSource.set({ [propertyName]: value }); pipelines[1].cylinderSource.set({ [propertyName]: value }); renderWindow.render(); }); });
document.querySelector('.capping').addEventListener('change', (e) => { const capping = !!e.target.checked; pipelines[0].cylinderSource.set({ capping }); pipelines[1].cylinderSource.set({ capping }); renderWindow.render(); });
const centerElems = document.querySelectorAll('.center');
function updateTransformedCylinder() { const center = [0, 0, 0]; for (let i = 0; i < 3; i++) { center[Number(centerElems[i].dataset.index)] = Number(centerElems[i].value); } console.log('updateTransformedCylinder', center); pipelines[1].cylinderSource.set({ center }); renderWindow.render(); }
for (let i = 0; i < 3; i++) { centerElems[i].addEventListener('input', updateTransformedCylinder); }
global.pipelines = pipelines; global.renderer = renderer; global.renderWindow = renderWindow;
|