Explorar o código

add fast boundary helper and unit trait

Alexander Rose %!s(int64=2) %!d(string=hai) anos
pai
achega
0f0185e18c

+ 3 - 1
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
 

+ 7 - 3
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);

+ 9 - 4
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;
         }