UNPKG

@thewtex/vtk.js-esm

Version:

Visualization Toolkit for the Web

96 lines (81 loc) 4.35 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import macro from '../../macro.js'; import vtk from '../../vtk.js'; import vtkDataSetAttributes from './DataSetAttributes.js'; import Constants from './DataSet/Constants.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; } // import * as vtkMath from '../../Core/Math'; // // function getBounds(dataset) { // if (dataset.bounds) { // return dataset.bounds; // } // if (dataset.type && dataset[dataset.type]) { // const ds = dataset[dataset.type]; // if (ds.bounds) { // return ds.bounds; // } // if (ds.Points && ds.Points.bounds) { // return ds.Points.bounds; // } // if (ds.Points && ds.Points.values) { // const array = ds.Points.values; // const bbox = [...vtkBoundingBox.INIT_BOUNDS]; // const size = array.length; // const delta = ds.Points.numberOfComponents ? ds.Points.numberOfComponents : 3; // for (let idx = 0; idx < size; idx += delta) { // vtkBoundingBox.addPoint(bbox, array[idx * delta], array[(idx * delta) + 1], array[(idx * delta) + 2]); // } // ds.Points.bounds = bbox; // return ds.Points.bounds; // } // } // return vtkMath.createUninitializedBounds(); // } // ---------------------------------------------------------------------------- // Global methods // ---------------------------------------------------------------------------- var DATASET_FIELDS = ['pointData', 'cellData', 'fieldData']; // ---------------------------------------------------------------------------- // vtkDataSet methods // ---------------------------------------------------------------------------- function vtkDataSet(publicAPI, model) { // Set our className model.classHierarchy.push('vtkDataSet'); // Add dataset attributes DATASET_FIELDS.forEach(function (fieldName) { if (!model[fieldName]) { model[fieldName] = vtkDataSetAttributes.newInstance(); } else { model[fieldName] = vtk(model[fieldName]); } }); var superShallowCopy = publicAPI.shallowCopy; publicAPI.shallowCopy = function (other) { var debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; superShallowCopy(other, debug); DATASET_FIELDS.forEach(function (fieldName) { model[fieldName] = vtkDataSetAttributes.newInstance(); model[fieldName].shallowCopy(other.getReferenceByName(fieldName)); }); }; } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- var DEFAULT_VALUES = {// pointData: null, // cellData: null, // fieldData: 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, DATASET_FIELDS); // Object specific methods vtkDataSet(publicAPI, model); } // ---------------------------------------------------------------------------- var newInstance = macro.newInstance(extend, 'vtkDataSet'); // ---------------------------------------------------------------------------- var vtkDataSet$1 = _objectSpread({ newInstance: newInstance, extend: extend }, Constants); export default vtkDataSet$1; export { extend, newInstance };