Skip to content

Commit 315045a

Browse files
bourdaisjfinetjul
authored andcommitted
test(calculator): add a test to make sure vtkCalculator does not crash with a vtkImageData input
1 parent 46b13cc commit 315045a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Sources/Filters/General/Calculator/test/testCalculator.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import test from 'tape-catch';
22

33
import vtkCalculator from 'vtk.js/Sources/Filters/General/Calculator';
4+
import vtkImageGridSource from 'vtk.js/Sources/Filters/Sources/ImageGridSource';
45
import vtkPlaneSource from 'vtk.js/Sources/Filters/Sources/PlaneSource';
56
import { AttributeTypes } from 'vtk.js/Sources/Common/DataModel/DataSetAttributes/Constants';
67
import { FieldDataTypes } from 'vtk.js/Sources/Common/DataModel/DataSet/Constants';
@@ -93,3 +94,42 @@ test('Test vtkCalculator execution', (t) => {
9394

9495
t.end();
9596
});
97+
98+
test('make sure vtkCalculator does not crash with a vtkImageData input', (t) => {
99+
const source = vtkImageGridSource.newInstance();
100+
const filter = vtkCalculator.newInstance();
101+
102+
filter.setInputConnection(source.getOutputPort());
103+
filter.setFormulaSimple(FieldDataTypes.POINT, ['scalars'], 'mask', (value) =>
104+
value > 10 ? 1 : 0
105+
);
106+
107+
source.update();
108+
filter.update();
109+
110+
const input = source.getOutputData();
111+
const output = filter.getOutputData();
112+
113+
t.ok(output, 'Output dataset exists');
114+
t.equal(
115+
output.isA('vtkImageData'),
116+
true,
117+
'The output dataset should be a vtkImagedata'
118+
);
119+
t.equal(
120+
input.getNumberOfPoints(),
121+
output.getNumberOfPoints(),
122+
`The number of points did not change between input ${input.getNumberOfPoints()} and output ${output.getNumberOfPoints()}`
123+
);
124+
t.ok(
125+
output.getPointData().getScalars(),
126+
'Output point-scalars array exists.'
127+
);
128+
t.equal(
129+
output.getPointData().getScalars().getName(),
130+
'mask',
131+
'Output point-scalars is "mask".'
132+
);
133+
134+
t.end();
135+
});

0 commit comments

Comments
 (0)