import '@kitware/vtk.js/favicon';
import '@kitware/vtk.js/Rendering/Profiles/Geometry';
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor'; import vtkCamera from '@kitware/vtk.js/Rendering/Core/Camera'; import vtkCellArray from '@kitware/vtk.js/Common/Core/CellArray'; import vtkContourTriangulator from '@kitware/vtk.js/Filters/General/ContourTriangulator'; import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow'; import vtkMapper from '@kitware/vtk.js/Rendering/Core/Mapper'; import vtkPoints from '@kitware/vtk.js/Common/Core/Points'; import vtkPolyData from '@kitware/vtk.js/Common/DataModel/PolyData';
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 source = vtkPolyData.newInstance();
const nbPoints = 16; const points = vtkPoints.newInstance({ size: nbPoints * 3, }); source.setPoints(points); const lines = vtkCellArray.newInstance(); source.setLines(lines);
for (let i = 0; i < nbPoints; i++) { const phi = (i * (2 * Math.PI)) / nbPoints; points.setPoint(i, Math.cos(phi), Math.sin(phi), 0);
if (i === nbPoints - 1) { lines.insertNextCell([i, 0]); } else { lines.insertNextCell([i, i + 1]); } }
const filter = vtkContourTriangulator.newInstance(); filter.setInputData(source);
mapper.setInputConnection(filter.getOutputPort());
renderer.resetCamera(); renderWindow.render();
global.source = source; global.filter = filter; global.filterData = filter.getOutputData(); global.mapper = mapper; global.actor = actor;
|