import macro from 'vtk.js/Sources/macros';
import DataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper'; import vtkHttpDataSetReader from 'vtk.js/Sources/IO/Core/HttpDataSetReader';
import 'vtk.js/Sources/IO/Core/DataAccessHelper/LiteHttpDataAccessHelper';
const { vtkErrorMacro } = macro;
function vtkHttpDataSetLODsLoader(publicAPI, model) { model.classHierarchy.push('vtkHttpDataSetLODsLoader');
const internal = { downloadStack: [], };
publicAPI.startDownloads = () => { if (!model.mapper) { vtkErrorMacro('Mapper was not set.'); return; }
if (!model.files || model.files.length === 0) { vtkErrorMacro('No files set.'); return; }
let baseUrl = model.baseUrl; if (baseUrl && !baseUrl.endsWith('/')) { baseUrl += '/'; }
internal.downloadStack = []; model.files.forEach((file) => internal.downloadStack.push(`${baseUrl}${file}`) );
const downloadNextSource = () => { const url = internal.downloadStack.shift(); const nextSource = vtkHttpDataSetReader.newInstance({ dataAccessHelper: DataAccessHelper.get('http'), });
model.currentSource = nextSource;
const options = { compression: 'zip', loadData: true, fullpath: true, }; nextSource.setUrl(url, options).then(() => { model.mapper.setInputConnection(nextSource.getOutputPort());
if (model.sceneItem) { const settings = model.sceneItem.defaultSettings; if (settings.mapper) { if (settings.mapper.colorByArrayName) { nextSource.enableArray( settings.mapper.colorByArrayName, settings.mapper.colorByArrayName ); } } model.sceneItem.source = nextSource; }
if (model.stepFinishedCallback) { model.stepFinishedCallback(); } if (internal.downloadStack.length !== 0) { setTimeout(downloadNextSource, model.waitTimeBetweenDownloads); } }); };
setTimeout(downloadNextSource, model.waitTimeToStart); }; }
const DEFAULT_VALUES = { baseUrl: '', currentSource: null, files: [], mapper: null, sceneItem: null, stepFinishedCallback: null, waitTimeToStart: 4000, waitTimeBetweenDownloads: 0, };
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
macro.obj(publicAPI, model);
macro.setGet(publicAPI, model, [ 'baseUrl', 'files', 'mapper', 'sceneItem', 'stepFinishedCallback', 'waitTimeToStart', 'waitTimeBetweenDownloads', ]);
macro.get(publicAPI, model, ['currentSource']);
vtkHttpDataSetLODsLoader(publicAPI, model); }
export const newInstance = macro.newInstance( extend, 'vtkHttpDataSetLODsLoader' );
export default { newInstance, extend };
|