|
1 | 1 | import test from 'tape-catch';
|
2 | 2 |
|
3 | 3 | import vtkCalculator from 'vtk.js/Sources/Filters/General/Calculator';
|
| 4 | +import vtkImageGridSource from 'vtk.js/Sources/Filters/Sources/ImageGridSource'; |
4 | 5 | import vtkPlaneSource from 'vtk.js/Sources/Filters/Sources/PlaneSource';
|
5 | 6 | import { AttributeTypes } from 'vtk.js/Sources/Common/DataModel/DataSetAttributes/Constants';
|
6 | 7 | import { FieldDataTypes } from 'vtk.js/Sources/Common/DataModel/DataSet/Constants';
|
@@ -93,3 +94,42 @@ test('Test vtkCalculator execution', (t) => {
|
93 | 94 |
|
94 | 95 | t.end();
|
95 | 96 | });
|
| 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