import macro from 'vtk.js/Sources/macros'; import vtkImageData from 'vtk.js/Sources/Common/DataModel/ImageData'; import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
const { vtkErrorMacro } = macro;
function vtkImageSliceFilter(publicAPI, model) { model.classHierarchy.push('vtkImageSliceFilter');
publicAPI.requestData = (inData, outData) => { const input = inData[0];
if (!input) { vtkErrorMacro('Invalid or missing input'); return; }
const scalars = input.getPointData().getScalars();
if (!scalars) { vtkErrorMacro('No scalars from input'); return; }
const datasetDefinition = input.get('extent', 'spacing', 'origin'); datasetDefinition.extent[4] = model.sliceIndex; datasetDefinition.extent[5] = datasetDefinition.extent[4];
const numberOfComponents = scalars.getNumberOfComponents(); const sliceSize = (datasetDefinition.extent[1] - datasetDefinition.extent[0] + 1) * (datasetDefinition.extent[3] - datasetDefinition.extent[2] + 1) * numberOfComponents; const offset = sliceSize * model.sliceIndex; const sliceRawArray = scalars.getData().slice(offset, offset + sliceSize); const sliceArray = vtkDataArray.newInstance({ name: scalars.getName(), numberOfComponents, values: sliceRawArray, });
const output = vtkImageData.newInstance(datasetDefinition); output.getPointData().setScalars(sliceArray);
outData[0] = output; }; }
const DEFAULT_VALUES = { sliceIndex: 0, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
macro.obj(publicAPI, model);
macro.algo(publicAPI, model, 1, 1);
macro.setGet(publicAPI, model, ['sliceIndex', 'orientation']);
vtkImageSliceFilter(publicAPI, model); }
export const newInstance = macro.newInstance(extend, 'vtkImageSliceFilter');
export default { newInstance, extend };
|