import macro from 'vtk.js/Sources/macros'; import vtk from 'vtk.js/Sources/vtk';
let readPolyDataArrayBuffer = null; let resultPreprocessor = (result) => result;
function setReadPolyDataArrayBufferFromITK(fn) { readPolyDataArrayBuffer = fn;
readPolyDataArrayBuffer = (...args) => fn(null, ...args);
resultPreprocessor = ({ webWorker, polyData }) => { webWorker.terminate(); return polyData; }; }
function vtkITKPolyDataReader(publicAPI, model) { model.classHierarchy.push('vtkITKPolyDataReader');
publicAPI.parseAsArrayBuffer = (arrayBuffer) => { if (!arrayBuffer || arrayBuffer === model.rawDataBuffer) { return Promise.resolve(); }
model.rawDataBuffer = arrayBuffer;
return readPolyDataArrayBuffer(arrayBuffer, model.fileName) .then(resultPreprocessor) .then((polyData) => { model.output[0] = vtk(polyData);
publicAPI.modified(); }); };
publicAPI.requestData = (inData, outData) => { publicAPI.parseAsArrayBuffer(model.rawDataBuffer, model.fileName); }; }
const DEFAULT_VALUES = { fileName: '', arrayName: null, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
macro.obj(publicAPI, model); macro.algo(publicAPI, model, 0, 1); macro.setGet(publicAPI, model, ['fileName', 'arrayName']);
vtkITKPolyDataReader(publicAPI, model);
if (!readPolyDataArrayBuffer) { console.error(` // Dependency needs to be added inside your project import readPolyDataArrayBuffer from 'itk/readPolyDataArrayBuffer'; vtkITKPolyDataReader.setReadPolyDataArrayBufferFromITK(readPolyDataArrayBuffer); `); } }
export const newInstance = macro.newInstance(extend, 'vtkITKPolyDataReader');
export default { newInstance, extend, setReadPolyDataArrayBufferFromITK };
|