Hi, dear vtk.js experts:
I try to learn how to use vtkCalculator, this is example html code using setFormularSimple
for testing:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="renderer"></div>
<script src="https://unpkg.com/vtk.js"></script>
<script>
// using vtk namespace
const vtkActor = vtk.Rendering.Core.vtkActor;
const vtkCalculator = vtk.Filters.General.vtkCalculator;
const vtkMapper = vtk.Rendering.Core.vtkMapper;
const vtkFullScreenRenderWindow = vtk.Rendering.Misc.vtkFullScreenRenderWindow;
const vtkPlaneSource = vtk.Filters.Sources.vtkPlaneSource;
const AttributeTypes = vtk.Common.DataModel.vtkDataSetAttributes.AttributeTypes;
const FieldDataTypes = vtk.Common.DataModel.vtkDataSet.FieldAssociations;
// ----------------------------------------------------------------------------
// Standard rendering code setup
// ----------------------------------------------------------------------------
const fullScreenRenderer = vtkFullScreenRenderWindow.newInstance({
background: [0, 0, 0],
});
const renderer = fullScreenRenderer.getRenderer();
const renderWindow = fullScreenRenderer.getRenderWindow();
// ----------------------------------------------------------------------------
// Example code
// ----------------------------------------------------------------------------
const simpleFilter = vtkCalculator.newInstance();
simpleFilter.setFormulaSimple(
FieldDataTypes.POINT, // Generate an output array defined over points.
[], // We don't request any point-data arrays because point coordinates are made available by default.
'z', // Name the output array "z"
(x) => (x[0] - 0.5) * (x[0] - 0.5) + (x[1] - 0.5) * (x[1] - 0.5) + 0.125
); // Our formula for z
const planeSource = vtkPlaneSource.newInstance({
xResolution: 25,
yResolution: 25,
});
const planeMapper = vtkMapper.newInstance({
interpolateScalarsBeforeMapping: true,
useLookupTableScalarRange: true,
});
console.log("planeSource",planeSource.getOutputData().toJSON())
simpleFilter.setInputConnection(planeSource.getOutputPort());
console.log("simpleFilter",simpleFilter.getOutputData())
const planeActor = vtkActor.newInstance();
//planeMapper.setInputConnection(planeSource.getOutputPort());
planeMapper.setInputConnection(simpleFilter.getOutputPort());
planeActor.setMapper(planeMapper);
planeActor.getProperty().setEdgeVisibility(true);
renderer.addActor(planeActor);
renderer.resetCamera();
renderWindow.render();
</script>
</body>
</html>
However, I got this error message:
vtk.js:2 Output array size could not be determined for {"name":"z","attribute":0,"numberOfComponents":1}.
Could you provide some suggestions about how to use the simpleFilter properly? Thanks a lot for the help!