@thewtex/vtk.js-esm
Version:
Visualization Toolkit for the Web
169 lines (143 loc) • 7.29 kB
JavaScript
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import macro from '../../macro.js';
import vtkMatrixBuilder from '../../Common/Core/MatrixBuilder.js';
import vtkPolyData from '../../Common/DataModel/PolyData.js';
import Constants from './Arrow2DSource/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; }
var ShapeType = Constants.ShapeType; // ----------------------------------------------------------------------------
// vtkArrow2DSource methods
// ----------------------------------------------------------------------------
function vtkStarSource(publicAPI, model) {
var dataset = vtkPolyData.newInstance();
var points = macro.newTypedArray(model.pointType, 10 * 3);
var edges = new Uint32Array(11);
edges[0] = 10;
for (var i = 0; i < 10; i++) {
var radius = i % 2 === 1 ? model.height : model.height * 0.4;
points[3 * i + 0] = radius * Math.cos((2 * i - 1) * Math.PI / 10);
points[3 * i + 1] = radius * Math.sin((2 * i - 1) * Math.PI / 10);
points[3 * i + 2] = 0;
edges[1 + i] = i;
}
dataset.getPoints().setData(points, 3);
dataset.getPolys().setData(edges, 1);
return dataset;
}
function vtk6PointsArrow(publicAPI, model) {
var dataset = vtkPolyData.newInstance();
var points = macro.newTypedArray(model.pointType, 6 * 3);
var thickOp = model.height * 0.5 * model.thickness;
var offsetOp = model.height * 0.5 - thickOp;
var baseOffsetOp = (model.height * 0.9 + thickOp - offsetOp - (model.height * 0.5 - thickOp - offsetOp)) * (1 - model.base);
points[0] = model.width / 2 * -1 - thickOp;
points[1] = model.height / 4 - offsetOp - baseOffsetOp;
points[2] = 0.0;
points[3] = 0.0;
points[4] = model.height * 0.9 + thickOp - offsetOp - baseOffsetOp;
points[5] = 0.0;
points[6] = model.width / 2 + thickOp;
points[7] = model.height / 4 - offsetOp - baseOffsetOp;
points[8] = 0.0;
points[9] = model.width / 3;
points[10] = model.height * 0.1 - thickOp - offsetOp - baseOffsetOp;
points[11] = 0.0;
points[12] = 0.0;
points[13] = model.height * 0.5 - thickOp - offsetOp - baseOffsetOp;
points[14] = 0.0;
points[15] = model.width / 3 * -1;
points[16] = model.height * 0.1 - thickOp - offsetOp - baseOffsetOp;
points[17] = 0.0; // prettier-ignore
var cells = Uint8Array.from([3, 0, 1, 5, 3, 1, 4, 5, 3, 1, 4, 3, 3, 1, 2, 3]);
dataset.getPoints().setData(points, 3);
dataset.getPolys().setData(cells, 1);
return dataset;
}
function vtk4PointsArrow(publicAPI, model) {
var dataset = vtkPolyData.newInstance();
var points = macro.newTypedArray(model.pointType, 4 * 3);
var thickOp = model.height / 3 * model.thickness;
var offsetOp = model.height / 3 - thickOp;
var baseOffsetOp = (model.height - offsetOp - (model.height / 3 - thickOp - offsetOp)) * (1 - model.base);
points[0] = model.width / 2 * -1;
points[1] = 0.0 - offsetOp - baseOffsetOp;
points[2] = 0.0;
points[3] = 0.0;
points[4] = model.height - offsetOp - baseOffsetOp;
points[5] = 0.0;
points[6] = model.width / 2;
points[7] = 0.0 - offsetOp - baseOffsetOp;
points[8] = 0.0;
points[9] = 0.0;
points[10] = model.height / 3 - thickOp - offsetOp - baseOffsetOp;
points[11] = 0.0;
var cells = Uint8Array.from([3, 0, 1, 3, 3, 1, 2, 3]);
dataset.getPoints().setData(points, 3);
dataset.getPolys().setData(cells, 1);
return dataset;
}
function vtkTriangleSource(publicAPI, model) {
var dataset = vtkPolyData.newInstance();
var points = macro.newTypedArray(model.pointType, 3 * 3);
var baseOffsetOp = model.height * (1 - model.base);
points[0] = model.width / 2 * -1;
points[1] = 0.0 - baseOffsetOp;
points[2] = 0.0;
points[3] = 0.0;
points[4] = model.height - baseOffsetOp;
points[5] = 0.0;
points[6] = model.width / 2;
points[7] = 0.0 - baseOffsetOp;
points[8] = 0.0;
var cells = Uint8Array.from([3, 0, 1, 2]);
dataset.getPoints().setData(points, 3);
dataset.getPolys().setData(cells, 1);
return dataset;
}
function vtkArrow2DSource(publicAPI, model) {
var _shapeToSource;
var shapeToSource = (_shapeToSource = {}, _defineProperty(_shapeToSource, ShapeType.TRIANGLE, vtkTriangleSource), _defineProperty(_shapeToSource, ShapeType.STAR, vtkStarSource), _defineProperty(_shapeToSource, ShapeType.ARROW_4, vtk4PointsArrow), _defineProperty(_shapeToSource, ShapeType.ARROW_6, vtk6PointsArrow), _shapeToSource);
publicAPI.requestData = function (inData, outData) {
var _vtkMatrixBuilder$bui;
outData[0] = shapeToSource[model.shape](publicAPI, model);
(_vtkMatrixBuilder$bui = vtkMatrixBuilder.buildFromRadian()).translate.apply(_vtkMatrixBuilder$bui, _toConsumableArray(model.center)).rotateFromDirections([1, 0, 0], model.direction).apply(outData[0].getPoints().getData());
};
} // ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
/**
* height modifies the size of the source along x axis
* width modifies the size of the source along y axis
* thickness modifies the shape of the source, which becomes wider on
* y axis
* base modifies the position which lowers the source on x axis for 0 and moves
* the source up on x axis for 1
*/
function defaultValues(initialValues) {
return _objectSpread({
base: 0,
center: [0, 0, 0],
height: 1.0,
direction: [1, 0, 0],
pointType: 'Float32Array',
thickness: 0,
width: 1.0
}, initialValues);
} // ----------------------------------------------------------------------------
function extend(publicAPI, model) {
var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
Object.assign(model, defaultValues(initialValues)); // Build VTK API
macro.obj(publicAPI, model);
macro.setGet(publicAPI, model, ['height', 'width', 'thickness', 'base']);
macro.setGetArray(publicAPI, model, ['center', 'direction'], 3);
macro.algo(publicAPI, model, 0, 1);
vtkArrow2DSource(publicAPI, model);
} // ----------------------------------------------------------------------------
var newInstance = macro.newInstance(extend, 'vtkArrow2DSource'); // ----------------------------------------------------------------------------
var vtkArrow2DSource$1 = {
newInstance: newInstance,
extend: extend
};
export default vtkArrow2DSource$1;
export { extend, newInstance };