UNPKG

@thewtex/vtk.js-esm

Version:

Visualization Toolkit for the Web

202 lines (162 loc) 8.69 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import macro from '../../macro.js'; import Constants from './AbstractImageInterpolator/Constants.js'; import { vtkInterpolationInfo } from './AbstractImageInterpolator/InterpolationInfo.js'; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } var ImageBorderMode = Constants.ImageBorderMode; // ---------------------------------------------------------------------------- // Global methods // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- // vtkAbstractImageInterpolator methods // ---------------------------------------------------------------------------- function vtkAbstractImageInterpolator(publicAPI, model) { // Set our className model.classHierarchy.push('vtkAbstractImageInterpolator'); publicAPI.initialize = function (data) { publicAPI.releaseData(); model.scalars = data.getPointData().getScalars(); model.spacing = data.getSpacing(); model.origin = data.getOrigin(); model.extent = data.getExtent(); publicAPI.update(); }; publicAPI.releaseData = function () { model.scalars = null; }; publicAPI.update = function () { if (!model.scalars) { model.interpolationInfo.pointer = null; model.interpolationInfo.numberOfComponents = 1; return; } model.interpolationInfo.extent = model.extent.slice(); var supportSize = publicAPI.computeSupportSize(null); var kernelSize = Math.max(Math.max(supportSize[0], supportSize[1]), supportSize[2]); var minBound = Number.MIN_SAFE_INTEGER + kernelSize / 2; var maxBound = Number.MAX_SAFE_INTEGER - kernelSize / 2; for (var i = 0; i < 3; ++i) { var newTol = Math.max(0.5 * (model.extent[2 * i] === model.extent[2 * i + 1]), model.tolerance); model.structuredBounds[2 * i] = Math.max(model.extent[2 * i] - newTol, minBound); model.structuredBounds[2 * i + 1] = Math.min(model.extent[2 * i + 1] + newTol, maxBound); } var xdim = model.extent[1] - model.extent[0] + 1; var ydim = model.extent[3] - model.extent[2] + 1; var ncomp = model.scalars.getNumberOfComponents(); model.interpolationInfo.increments[0] = ncomp; model.interpolationInfo.increments[1] = model.interpolationInfo.increments[0] * xdim; model.interpolationInfo.increments[2] = model.interpolationInfo.increments[1] * ydim; var component = model.componentOffset; component = component > 0 ? component : 0; component = component < ncomp ? component : ncomp - 1; var dataSize = 1; // scalars.getDataTypeSize() var inPtr = model.scalars.getData(); model.interpolationInfo.pointer = inPtr.subarray(component * dataSize); model.interpolationInfo.scalarType = model.scalars.dataType; model.interpolationInfo.dataTypeSize = 1; // model.scalars.getElementComponentSize(); model.interpolationInfo.numberOfComponents = publicAPI.computeNumberOfComponents(ncomp); model.interpolationInfo.borderMode = model.borderMode; publicAPI.internalUpdate(); // TODO get functions }; publicAPI.internalUpdate = function () {}; publicAPI.interpolateXYZ = function (x, y, z, component) { var value = model.outValue; var point = [x, y, z]; var p = [(point[0] - model.origin[0]) / model.spacing[0], (point[1] - model.origin[1]) / model.spacing[1], (point[2] - model.origin[2]) / model.spacing[2]]; if (publicAPI.checkBoundsIJK(p)) { var iinfo = _objectSpread({}, model.interpolationInfo); var ncomp = iinfo.increments[0] - model.componentOffset; var dataTypeSize = 1; // iinfo.dataTypeSize; // vtkAbstractArray::getDataTypeSize(iinfo.scalarType) var c = component > 0 ? component : 0; c = c < ncomp ? c : ncomp - 1; iinfo.pointer = model.interpolationInfo.pointer.subarray(dataTypeSize * c); iinfo.numberOfComponents = 1; var v = [value]; publicAPI.interpolatePoint(iinfo, p, v); value = v[0]; } return value; }; publicAPI.interpolate = function (point, value) { var p = [(point[0] - model.origin[0]) / model.spacing[0], (point[1] - model.origin[1]) / model.spacing[1], (point[2] - model.origin[2]) / model.spacing[2]]; if (publicAPI.checkBoundsIJK(p)) { publicAPI.interpolatePoint(model.interpolationInfo, p, value); return true; } for (var i = 0; i < model.interpolationInfo.numberOfComponents; ++i) { value[i] = model.outValue; } return false; }; publicAPI.computeNumberOfComponents = function (inputCount) { var component = Math.min(Math.max(model.componentOffset, 0), inputCount - 1); var count = model.componentCount < inputCount - component ? model.componentCount : inputCount - component; return count > 0 ? count : inputCount - component; }; publicAPI.getNumberOfComponents = function () { return model.interpolationInfo.numberOfComponents; }; publicAPI.interpolateIJK = function (point, value) { publicAPI.interpolatePoint(model.interpolationInfo, point, value); }; publicAPI.checkBoundsIJK = function (point) { return !(point[0] < model.structuredBounds[0] || point[0] > model.structuredBounds[1] || point[1] < model.structuredBounds[2] || point[1] > model.structuredBounds[3] || point[2] < model.structuredBounds[4] || point[2] > model.structuredBounds[5]); }; publicAPI.computeSupportSize = null; // (matrix) => {}; publicAPI.isSeparable = null; publicAPI.precomputeWeightsForExtent = function (matrix, inExtent, checkExtent) {}; publicAPI.FreePrecomputedWeights = function (weights) { /* for (let k = 0; k < 3; ++k) { const step = weights.kernelSize[k]; // TODO: check if ok weights.positions[k] += step * weights.weightExtent[2 * k]; if (weights.weights[k]) { // TODO: check if ok weights.weights[k] += step * weights.weightExtent[2 * k]; } } if (weights.workspace) { for (let i = 1; i < weights.kernelSize[1]; ++i) { // TODO ... } } */ }; publicAPI.interpolatePoint = function (interpolationInfo, point, value) {}; publicAPI.interpolateRow = function (weights, xIdx, yIdx, zIdx, value, n) {}; } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- var DEFAULT_VALUES = { outValue: 0, tolerance: Number.EPSILON, componentOffset: 0, componentCount: -1, borderMode: ImageBorderMode.CLAMP, slidingWindow: false, scalars: null, interpolationInfo: _objectSpread({}, vtkInterpolationInfo), interpolationFunc: null, rowInterpolationFunc: null, structuredBounds: [0, -1, 0, -1, 0, -1], spacing: null, origin: null, extent: null }; // ---------------------------------------------------------------------------- function extend(publicAPI, model) { var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; Object.assign(model, DEFAULT_VALUES, initialValues); // Object methods macro.obj(publicAPI, model); macro.setGet(publicAPI, model, ['outValue', 'tolerance', 'componentOffset', 'componentCount', 'borderMode', 'slidingWindow']); macro.get(publicAPI, model, ['origin', 'spacing']); // Object specific methods vtkAbstractImageInterpolator(publicAPI, model); } // ---------------------------------------------------------------------------- var newInstance = macro.newInstance(extend, 'vtkAbstractImageInterpolator'); // ---------------------------------------------------------------------------- var vtkAbstractImageInterpolator$1 = _objectSpread({ newInstance: newInstance, extend: extend }, Constants); export default vtkAbstractImageInterpolator$1; export { extend, newInstance };