UNPKG

@thewtex/vtk.js-esm

Version:

Visualization Toolkit for the Web

105 lines (79 loc) 3.02 kB
import macro from '../../macro.js'; import vtkAbstractMapper from './AbstractMapper.js'; import { u as uninitializeBounds } from '../../Common/Core/Math/index.js'; // vtkAbstractMapper methods // ---------------------------------------------------------------------------- function vtkAbstractMapper3D(publicAPI, model) { publicAPI.getBounds = function () { return 0; }; publicAPI.getBounds = function (bounds) { publicAPI.getBounds(); for (var i = 0; i < 6; i++) { bounds[i] = model.bounds[i]; } }; publicAPI.getCenter = function () { publicAPI.getBounds(); for (var i = 0; i < 3; i++) { model.center[i] = (model.bounds[2 * i + 1] + model.bounds[2 * i]) / 2.0; } return model.center.slice(); }; publicAPI.getLength = function () { var diff = 0.0; var l = 0.0; publicAPI.getBounds(); for (var i = 0; i < 3; i++) { diff = model.bounds[2 * i + 1] - model.bounds[2 * i]; l += diff * diff; } return Math.sqrt(l); }; publicAPI.getClippingPlaneInDataCoords = function (propMatrix, i, hnormal) { var clipPlanes = model.clippingPlanes; var mat = propMatrix; if (clipPlanes) { var n = clipPlanes.length; if (i >= 0 && i < n) { // Get the plane var plane = clipPlanes[i]; var normal = plane.getNormal(); var origin = plane.getOrigin(); // Compute the plane equation var v1 = normal[0]; var v2 = normal[1]; var v3 = normal[2]; var v4 = -(v1 * origin[0] + v2 * origin[1] + v3 * origin[2]); // Transform normal from world to data coords hnormal[0] = v1 * mat[0] + v2 * mat[4] + v3 * mat[8] + v4 * mat[12]; hnormal[1] = v1 * mat[1] + v2 * mat[5] + v3 * mat[9] + v4 * mat[13]; hnormal[2] = v1 * mat[2] + v2 * mat[6] + v3 * mat[10] + v4 * mat[14]; hnormal[3] = v1 * mat[3] + v2 * mat[7] + v3 * mat[11] + v4 * mat[15]; return; } } macro.vtkErrorMacro("Clipping plane index ".concat(i, " is out of range.")); }; } // ---------------------------------------------------------------------------- // Object factory // ---------------------------------------------------------------------------- var DEFAULT_VALUES = { bounds: [1, -1, 1, -1, 1, -1], center: [0, 0, 0] }; // ---------------------------------------------------------------------------- function extend(publicAPI, model) { var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; Object.assign(model, DEFAULT_VALUES, initialValues); // Inheritance vtkAbstractMapper.extend(publicAPI, model, initialValues); if (!model.bounds) { uninitializeBounds(model.bounds); } if (!model.center) { model.center = [0.0, 0.0, 0.0]; } vtkAbstractMapper3D(publicAPI, model); } // ---------------------------------------------------------------------------- var vtkAbstractMapper3D$1 = { extend: extend }; export default vtkAbstractMapper3D$1; export { extend };