import '@kitware/vtk.js/favicon';
import '@kitware/vtk.js/Rendering/Profiles/Geometry'; import '@kitware/vtk.js/Rendering/Profiles/Molecule';
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor'; import vtkCalculator from '@kitware/vtk.js/Filters/General/Calculator'; import vtkFullScreenRenderWindow from '@kitware/vtk.js/Rendering/Misc/FullScreenRenderWindow'; import vtkPlaneSource from '@kitware/vtk.js/Filters/Sources/PlaneSource'; import vtkStickMapper from '@kitware/vtk.js/Rendering/Core/StickMapper';
import { AttributeTypes } from '@kitware/vtk.js/Common/DataModel/DataSetAttributes/Constants'; import { FieldDataTypes } from '@kitware/vtk.js/Common/DataModel/DataSet/Constants';
import controlPanel from './controlPanel.html';
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ background: [0, 0, 0], }); const renderer = fullScreenRenderer.getRenderer(); const renderWindow = fullScreenRenderer.getRenderWindow();
const planeSource = vtkPlaneSource.newInstance(); const simpleFilter = vtkCalculator.newInstance(); const mapper = vtkStickMapper.newInstance(); const actor = vtkActor.newInstance();
simpleFilter.setFormula({ getArrays: (inputDataSets) => ({ input: [{ location: FieldDataTypes.COORDINATE }], output: [ { location: FieldDataTypes.POINT, name: 'orientation', dataType: 'Float32Array', numberOfComponents: 3, }, { location: FieldDataTypes.POINT, name: 'temperature', dataType: 'Float32Array', attribute: AttributeTypes.SCALARS, numberOfComponents: 1, }, { location: FieldDataTypes.POINT, name: 'pressure', dataType: 'Float32Array', numberOfComponents: 2, }, ], }), evaluate: (arraysIn, arraysOut) => { const [coords] = arraysIn.map((d) => d.getData()); const [orient, temp, press] = arraysOut.map((d) => d.getData());
for (let i = 0, sz = coords.length / 3; i < sz; ++i) { orient[i * 3] = (coords[3 * i] - 0.5) * (coords[3 * i] - 0.5) + (coords[3 * i + 1] - 0.5) * (coords[3 * i + 1] - 0.5); orient[i * 3 + 1] = (coords[3 * i] - 0.5) * (coords[3 * i] - 0.5) + (coords[3 * i + 1] - 0.5) * (coords[3 * i + 1] - 0.5); orient[i * 3 + 2] = 1.0;
temp[i] = coords[3 * i + 1];
press[i * 2] = (coords[3 * i] * coords[3 * i] + coords[3 * i + 1] * coords[3 * i + 1]) * 0.05 + 0.05; press[i * 2 + 1] = (coords[3 * i] * coords[3 * i] + coords[3 * i + 1] * coords[3 * i + 1]) * 0.01 + 0.01; } arraysOut.forEach((x) => x.modified()); }, });
simpleFilter.setInputConnection(planeSource.getOutputPort());
mapper.setInputConnection(simpleFilter.getOutputPort());
mapper.setOrientationArray('orientation'); mapper.setScaleArray('pressure');
actor.setMapper(mapper);
renderer.addActor(actor); renderer.resetCamera(); renderWindow.render();
fullScreenRenderer.addController(controlPanel); ['xResolution', 'yResolution'].forEach((propertyName) => { document.querySelector(`.${propertyName}`).addEventListener('input', (e) => { const value = Number(e.target.value); planeSource.set({ [propertyName]: value }); renderWindow.render(); }); });
global.planeSource = planeSource; global.mapper = mapper; global.actor = actor; global.renderer = renderer; global.renderWindow = renderWindow;
|