LineSource

Live example

Source

import 'vtk.js/Sources/favicon';
import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow';
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import vtkLineSource from 'vtk.js/Sources/Filters/Sources/LineSource';
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
import { Representation } from 'vtk.js/Sources/Rendering/Core/Property/Constants';
import controlPanel from './controlPanel.html';
// ----------------------------------------------------------------------------
// Standard rendering code setup
// ----------------------------------------------------------------------------
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({ background: [0, 0, 0] });
const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();
// ----------------------------------------------------------------------------
// Example code
// ----------------------------------------------------------------------------
const lineSource = vtkLineSource.newInstance();
const actor = vtkActor.newInstance();
const mapper = vtkMapper.newInstance();
actor.getProperty().setPointSize(10);
actor.getProperty().setRepresentation(Representation.POINTS);
actor.setMapper(mapper);
mapper.setInputConnection(lineSource.getOutputPort());
renderer.addActor(actor);
renderer.resetCamera();
renderWindow.render();
// -----------------------------------------------------------
// UI control handling
// -----------------------------------------------------------
fullScreenRenderer.addController(controlPanel);
['resolution'].forEach((propertyName) => {
document.querySelector(`.${propertyName}`).addEventListener('input', (e) => {
const value = Number(e.target.value);
lineSource.set({ [propertyName]: value });
renderWindow.render();
});
});
const mapping = 'xyz';
const points = [[0, 0, 0], [0, 0, 0]];
['x1', 'y1', 'z1', 'x2', 'y2', 'z2'].forEach((propertyName) => {
document.querySelector(`.${propertyName}`).addEventListener('input', (e) => {
const value = Number(e.target.value);
const pointIdx = Number(propertyName[1]);
points[pointIdx - 1][mapping.indexOf(propertyName[0])] = value;
lineSource.set({ [`point${pointIdx}`]: points[pointIdx - 1] });
renderWindow.render();
});
});
// -----------------------------------------------------------
// Make some variables global so that you can inspect and
// modify objects in your browser's developer console:
// -----------------------------------------------------------
global.lineSource = lineSource;
global.mapper = mapper;
global.actor = actor;
global.renderer = renderer;
global.renderWindow = renderWindow;