import macro from 'vtk.js/Sources/macros'; import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData'; import DataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper';
import 'vtk.js/Sources/IO/Core/DataAccessHelper/LiteHttpDataAccessHelper';
function vtkJSONNucleoReader(publicAPI, model) { model.classHierarchy.push('vtkJSONNucleoReader');
if (!model.dataAccessHelper) { model.dataAccessHelper = DataAccessHelper.get('http'); }
function fetchText(url, options) { return model.dataAccessHelper.fetchText(publicAPI, url, options); }
publicAPI.setUrl = (url, options) => { model.url = url;
return publicAPI.loadData(options); };
publicAPI.loadData = (options) => fetchText(model.url, options).then((csv) => { publicAPI.parseAsText(csv); return true; });
publicAPI.parseAsText = (jsonAsTxt) => { const { vertices, indices } = JSON.parse(jsonAsTxt); const nbIndices = indices.length; const nbTriangles = nbIndices / 3; const nbCellsValues = nbTriangles + nbIndices;
model.points = Float32Array.from(vertices); model.polys = nbCellsValues < 65535 ? new Uint16Array(nbCellsValues) : new Uint32Array(nbCellsValues); let srcOffset = 0; let destOffset = 0; while (destOffset < model.polys.length) { model.polys[destOffset++] = 3; model.polys[destOffset++] = indices[srcOffset++]; model.polys[destOffset++] = indices[srcOffset++]; model.polys[destOffset++] = indices[srcOffset++]; }
publicAPI.modified(); };
publicAPI.requestData = (inData, outData) => { const polydata = vtkPolyData.newInstance(); polydata.getPoints().setData(model.points, 3); polydata.getPolys().setData(model.polys); model.output[0] = polydata; }; }
const DEFAULT_VALUES = { };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
macro.obj(publicAPI, model); macro.get(publicAPI, model, ['url']); macro.setGet(publicAPI, model, ['dataAccessHelper']); macro.algo(publicAPI, model, 0, 1);
vtkJSONNucleoReader(publicAPI, model); }
export const newInstance = macro.newInstance(extend, 'vtkJSONNucleoReader');
export default { newInstance, extend };
|