UNPKG

molstar

Version:

A comprehensive macromolecular library.

64 lines (63 loc) 3.55 kB
/** * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __assign, __awaiter, __generator } from "tslib"; import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { Lines } from '../../../mol-geo/geometry/lines/lines'; import { computeUnitGaussianDensity, GaussianDensityParams } from './util/gaussian'; import { computeMarchingCubesLines } from '../../../mol-geo/util/marching-cubes/algorithm'; import { UnitsLinesParams, UnitsLinesVisual } from '../units-visual'; import { ElementIterator, getElementLoci, eachElement } from './util/element'; import { Sphere3D } from '../../../mol-math/geometry'; function createGaussianWireframe(ctx, unit, structure, theme, props, lines) { return __awaiter(this, void 0, void 0, function () { var smoothness, _a, transform, field, idField, maxRadius, params, wireframe, sphere; return __generator(this, function (_b) { switch (_b.label) { case 0: smoothness = props.smoothness; return [4 /*yield*/, computeUnitGaussianDensity(structure, unit, theme.size, props).runInContext(ctx.runtime)]; case 1: _a = _b.sent(), transform = _a.transform, field = _a.field, idField = _a.idField, maxRadius = _a.maxRadius; params = { isoLevel: Math.exp(-smoothness), scalarField: field, idField: idField }; return [4 /*yield*/, computeMarchingCubesLines(params, lines).runAsChild(ctx.runtime)]; case 2: wireframe = _b.sent(); Lines.transform(wireframe, transform); sphere = Sphere3D.expand(Sphere3D(), unit.boundary.sphere, maxRadius); wireframe.setBoundingSphere(sphere); return [2 /*return*/, wireframe]; } }); }); } export var GaussianWireframeParams = __assign(__assign(__assign({}, UnitsLinesParams), GaussianDensityParams), { sizeFactor: PD.Numeric(3, { min: 0, max: 10, step: 0.1 }), lineSizeAttenuation: PD.Boolean(false), ignoreHydrogens: PD.Boolean(false), includeParent: PD.Boolean(false, { isHidden: true }) }); export function GaussianWireframeVisual(materialId) { return UnitsLinesVisual({ defaultProps: PD.getDefaultValues(GaussianWireframeParams), createGeometry: createGaussianWireframe, createLocationIterator: ElementIterator.fromGroup, getLoci: getElementLoci, eachLocation: eachElement, setUpdateState: function (state, newProps, currentProps) { if (newProps.resolution !== currentProps.resolution) state.createGeometry = true; if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true; if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true; if (newProps.ignoreHydrogens !== currentProps.ignoreHydrogens) state.createGeometry = true; if (newProps.traceOnly !== currentProps.traceOnly) state.createGeometry = true; if (newProps.includeParent !== currentProps.includeParent) state.createGeometry = true; } }, materialId); }