From 0f0185e18cfb937a2d3dc89c9116b0f17fc3304d Mon Sep 17 00:00:00 2001 From: Alexander Rose <alexander.rose@weirdbyte.de> Date: Sun, 5 Feb 2023 13:34:33 -0800 Subject: [PATCH] add fast boundary helper and unit trait --- CHANGELOG.md | 4 +++- src/mol-math/geometry/boundary.ts | 10 +++++++--- src/mol-model/structure/structure/unit.ts | 13 +++++++++---- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa13409da..dd69f369d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,10 +11,12 @@ Note that since we don't clearly distinguish between a public and private interf - The average position of the residues of the first chain should be in the first quadrant if there is more than one chain - Add `HeadlessPluginContext` and `HeadlessScreenshotHelper` to be used in Node.js - Add example `image-renderer` -- Fix wrong offset when rendering text with orthographic projection +- Fix wrong offset when rendering text with orthographic projectio +n - Update camera/handle helper when `devicePixelRatio` changes - Add various options to customize the axes camera-helper - Fix issue with texture-mesh color smoothing when changing themes +- Add fast boundary helper and corresponding unit trait ## [v3.30.0] - 2023-01-29 diff --git a/src/mol-math/geometry/boundary.ts b/src/mol-math/geometry/boundary.ts index 52e1cb198..888e5b36d 100644 --- a/src/mol-math/geometry/boundary.ts +++ b/src/mol-math/geometry/boundary.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2018-2023 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> * @author Alexander Rose <alexander.rose@weirdbyte.de> @@ -22,6 +22,11 @@ function getBoundaryHelper(count: number) { return count > 10_000 ? boundaryHelperCoarse : boundaryHelperFine; } +export function getFastBoundary(data: PositionData): Boundary { + const box = Box3D.computeBounding(data); + return { box, sphere: Sphere3D.fromBox3D(Sphere3D(), box) }; +} + const p = Vec3(); export function getBoundary(data: PositionData): Boundary { @@ -29,8 +34,7 @@ export function getBoundary(data: PositionData): Boundary { const n = OrderedSet.size(indices); if (n > 250_000) { - const box = Box3D.computeBounding(data); - return { box, sphere: Sphere3D.fromBox3D(Sphere3D(), box) }; + return getFastBoundary(data); } const boundaryHelper = getBoundaryHelper(n); diff --git a/src/mol-model/structure/structure/unit.ts b/src/mol-model/structure/structure/unit.ts index 6f6d1a814..65d407684 100644 --- a/src/mol-model/structure/structure/unit.ts +++ b/src/mol-model/structure/structure/unit.ts @@ -20,7 +20,7 @@ import { getAtomicPolymerElements, getCoarsePolymerElements, getAtomicGapElement import { mmCIF_Schema } from '../../../mol-io/reader/cif/schema/mmcif'; import { PrincipalAxes } from '../../../mol-math/linear-algebra/matrix/principal-axes'; import { getPrincipalAxes } from './util/principal-axes'; -import { Boundary, getBoundary } from '../../../mol-math/geometry/boundary'; +import { Boundary, getBoundary, getFastBoundary } from '../../../mol-math/geometry/boundary'; import { Mat4, Vec3 } from '../../../mol-math/linear-algebra'; import { IndexPairBonds } from '../../../mol-model-formats/structure/property/bonds/index-pair'; import { ElementSetIntraBondCache } from './unit/bonds/element-set-intra-bond-cache'; @@ -128,7 +128,8 @@ namespace Unit { export enum Trait { None = 0x0, MultiChain = 0x1, - Partitioned = 0x2 + Partitioned = 0x2, + FastBoundary = 0x4, } export namespace Traits { export const is: (t: Traits, f: Trait) => boolean = BitFlags.has; @@ -255,7 +256,9 @@ namespace Unit { get boundary() { if (this.props.boundary) return this.props.boundary; const { x, y, z } = this.model.atomicConformation; - this.props.boundary = getBoundary({ x, y, z, indices: this.elements }); + this.props.boundary = Traits.is(this.traits, Trait.FastBoundary) + ? getFastBoundary({ x, y, z, indices: this.elements }) + : getBoundary({ x, y, z, indices: this.elements }); return this.props.boundary; } @@ -417,7 +420,9 @@ namespace Unit { if (this.props.boundary) return this.props.boundary; // TODO: support sphere radius? const { x, y, z } = this.getCoarseConformation(); - this.props.boundary = getBoundary({ x, y, z, indices: this.elements }); + this.props.boundary = Traits.is(this.traits, Trait.FastBoundary) + ? getFastBoundary({ x, y, z, indices: this.elements }) + : getBoundary({ x, y, z, indices: this.elements }); return this.props.boundary; } -- GitLab