UNPKG

@kitware/vtk.js

Version:

Visualization Toolkit for the Web

76 lines (60 loc) 3.72 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import macro from '../../macros.js'; import { d as dot } from '../Core/Math/index.js'; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } // Global methods // ---------------------------------------------------------------------------- function evaluate(radius, center, axis, x) { var x2C = new Float32Array(3); x2C[0] = x[0] - center[0]; x2C[1] = x[1] - center[1]; x2C[2] = x[2] - center[2]; var proj = dot(axis, x2C); var retVal = dot(x2C, x2C) - proj * proj - radius * radius; return retVal; } // ---------------------------------------------------------------------------- // Static API // ---------------------------------------------------------------------------- var STATIC = { evaluate: evaluate }; // ---------------------------------------------------------------------------- // vtkCylinder methods // ---------------------------------------------------------------------------- function vtkCylinder(publicAPI, model) { // Set our className model.classHierarchy.push('vtkCylinder'); publicAPI.evaluateFunction = function (xyz) { var x2C = [xyz[0] - model.center[0], xyz[1] - model.center[1], xyz[2] - model.center[2]]; var proj = dot(model.axis, x2C); var retVal = dot(x2C, x2C) - proj * proj - model.radius * model.radius; return retVal; }; publicAPI.evaluateGradient = function (xyz) { var t = model.axis[0] * (xyz[0] - model.center[0]) + model.axis[1] * (xyz[1] - model.center[1]) + model.axis[2] * (xyz[2] - model.center[2]); var cp = [model.center[0] + t * model.axis[0], model.center[1] + t * model.axis[1], model.center[2] + t * model.axis[2]]; var retVal = [2.0 * (xyz[0] - cp[0]), 2.0 * (xyz[1] - cp[1]), 2.0 * (xyz[2] - cp[2])]; return retVal; }; } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- var DEFAULT_VALUES = { radius: 0.5, center: [0.0, 0.0, 0.0], axis: [0.0, 1.0, 0.0] }; // ---------------------------------------------------------------------------- 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, ['radius']); macro.setGetArray(publicAPI, model, ['center', 'axis'], 3); vtkCylinder(publicAPI, model); } // ---------------------------------------------------------------------------- var newInstance = macro.newInstance(extend, 'vtkCylinder'); // ---------------------------------------------------------------------------- var vtkCylinder$1 = _objectSpread({ newInstance: newInstance, extend: extend }, STATIC); export { STATIC, vtkCylinder$1 as default, extend, newInstance };