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 vtkCircleSource from '@kitware/vtk.js/Filters/Sources/CircleSource'; 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 createCirclePipeline() { const cylinderSource = vtkCircleSource.newInstance(); const actor = vtkActor.newInstance(); const mapper = vtkMapper.newInstance();
cylinderSource.setLines(true); cylinderSource.setFace(true);
actor.setMapper(mapper); mapper.setInputConnection(cylinderSource.getOutputPort());
renderer.addActor(actor); return { cylinderSource, mapper, actor }; }
const pipelines = [createCirclePipeline()]; pipelines[0].actor.getProperty().setColor(1, 0, 0);
renderer.resetCamera(); renderWindow.render();
fullScreenRenderer.addController(controlPanel);
['radius', 'resolution'].forEach((propertyName) => { document.querySelector(`.${propertyName}`).addEventListener('input', (e) => { const value = Number(e.target.value); pipelines[0].cylinderSource.set({ [propertyName]: value }); renderWindow.render(); }); });
['lines', 'face'].forEach((propertyName) => { document.querySelector(`.${propertyName}`).addEventListener('input', (e) => { pipelines[0].cylinderSource.set({ [propertyName]: e.target.checked }); renderWindow.render(); }); });
const centerElems = document.querySelectorAll('.center');
function updateTransformedCircle() { const center = [0, 0, 0]; for (let i = 0; i < 3; i++) { center[Number(centerElems[i].dataset.index)] = Number(centerElems[i].value); } pipelines[0].cylinderSource.set({ center }); renderWindow.render(); }
for (let i = 0; i < 3; i++) { centerElems[i].addEventListener('input', updateTransformedCircle); }
global.pipelines = pipelines; global.renderer = renderer; global.renderWindow = renderWindow;
|