瀏覽代碼

fix BoundaryHelper edge cases & naming tweaks

Alexander Rose 5 年之前
父節點
當前提交
c1a8627702

+ 23 - 20
src/mol-gl/renderable/util.ts

@@ -66,7 +66,10 @@ export function printImageData(imageData: ImageData, scale = 1, pixelated = fals
         img.src = objectURL
         img.style.width = imageData.width * scale + 'px'
         img.style.height = imageData.height * scale + 'px';
-        if (pixelated) (img.style as any).imageRendering = 'pixelated' // supported only in Chrome
+        if (pixelated) {
+            // not supported in Firefox and IE
+            img.style.imageRendering = 'pixelated'
+        }
         img.style.position = 'absolute'
         img.style.top = '0px'
         img.style.left = '0px'
@@ -78,37 +81,37 @@ export function printImageData(imageData: ImageData, scale = 1, pixelated = fals
 //
 
 const v = Vec3.zero()
-const eposHelperCoarse = new BoundaryHelper('14')
-const eposHelperFine = new BoundaryHelper('98')
+const boundaryHelperCoarse = new BoundaryHelper('14')
+const boundaryHelperFine = new BoundaryHelper('98')
 const hierarchyHelperCoarse = new HierarchyHelper('14')
 const hierarchyHelperFine = new HierarchyHelper('98')
 
 function getHelper(count: number) {
     return count > 500_000 ? {
-        eposHelper: eposHelperCoarse,
+        boundaryHelper: boundaryHelperCoarse,
         hierarchyHelper: hierarchyHelperCoarse
     } : {
-        eposHelper: eposHelperFine,
+        boundaryHelper: boundaryHelperFine,
         hierarchyHelper: hierarchyHelperFine
     }
 }
 
 export function calculateInvariantBoundingSphere(position: Float32Array, positionCount: number, stepFactor: number): Sphere3D {
     const step = stepFactor * 3
-    const { eposHelper, hierarchyHelper } = getHelper(positionCount)
+    const { boundaryHelper, hierarchyHelper } = getHelper(positionCount)
 
-    eposHelper.reset()
+    boundaryHelper.reset()
     for (let i = 0, _i = positionCount * 3; i < _i; i += step) {
         Vec3.fromArray(v, position, i)
-        eposHelper.includeStep(v)
+        boundaryHelper.includeStep(v)
     }
-    eposHelper.finishedIncludeStep()
+    boundaryHelper.finishedIncludeStep()
     for (let i = 0, _i = positionCount * 3; i < _i; i += step) {
         Vec3.fromArray(v, position, i)
-        eposHelper.radiusStep(v)
+        boundaryHelper.radiusStep(v)
     }
 
-    const hierarchyInput = eposHelper.getHierarchyInput()
+    const hierarchyInput = boundaryHelper.getHierarchyInput()
     if (hierarchyInput) {
         hierarchyHelper.reset(hierarchyInput.sphere, hierarchyInput.normal)
         for (let i = 0, _i = positionCount * 3; i < _i; i += step) {
@@ -122,13 +125,13 @@ export function calculateInvariantBoundingSphere(position: Float32Array, positio
         }
         return hierarchyHelper.getSphere()
     } else {
-        return eposHelper.getSphere()
+        return boundaryHelper.getSphere()
     }
 }
 
 export function calculateTransformBoundingSphere(invariantBoundingSphere: Sphere3D, transform: Float32Array, transformCount: number): Sphere3D {
-    const { eposHelper } = getHelper(transformCount)
-    eposHelper.reset()
+    const { boundaryHelper } = getHelper(transformCount)
+    boundaryHelper.reset()
 
     const transformedSpheres: Sphere3D[] = []
     for (const b of Sphere3D.getList(invariantBoundingSphere)) {
@@ -139,14 +142,14 @@ export function calculateTransformBoundingSphere(invariantBoundingSphere: Sphere
     }
 
     for (const b of transformedSpheres) {
-        eposHelper.includeSphereStep(b.center, b.radius)
+        boundaryHelper.includeSphereStep(b.center, b.radius)
     }
-    eposHelper.finishedIncludeStep()
+    boundaryHelper.finishedIncludeStep()
     for (const b of transformedSpheres) {
-        eposHelper.radiusSphereStep(b.center, b.radius)
+        boundaryHelper.radiusSphereStep(b.center, b.radius)
     }
 
-    const sphere = eposHelper.getSphere()
+    const sphere = boundaryHelper.getSphere()
     if (transformedSpheres.length > 1) {
         (sphere as Sphere3D.Hierarchy).hierarchy = transformedSpheres
     }
@@ -156,7 +159,7 @@ export function calculateTransformBoundingSphere(invariantBoundingSphere: Sphere
 export function calculateBoundingSphere(position: Float32Array, positionCount: number, transform: Float32Array, transformCount: number, padding = 0, stepFactor = 1): { boundingSphere: Sphere3D, invariantBoundingSphere: Sphere3D } {
     const invariantBoundingSphere = calculateInvariantBoundingSphere(position, positionCount, stepFactor)
     const boundingSphere = calculateTransformBoundingSphere(invariantBoundingSphere, transform, transformCount)
-    Sphere3D.expand(boundingSphere, boundingSphere, padding)
-    Sphere3D.expand(invariantBoundingSphere, invariantBoundingSphere, padding)
+    // Sphere3D.expand(boundingSphere, boundingSphere, padding)
+    // Sphere3D.expand(invariantBoundingSphere, invariantBoundingSphere, padding)
     return { boundingSphere, invariantBoundingSphere }
 }

+ 6 - 6
src/mol-gl/scene.ts

@@ -16,30 +16,30 @@ import { now } from '../mol-util/now';
 import { arraySetRemove } from '../mol-util/array';
 import { BoundaryHelper } from '../mol-math/geometry/boundary-helper';
 
-const eposHelper = new BoundaryHelper('98')
+const boundaryHelper = new BoundaryHelper('98')
 
 function calculateBoundingSphere(renderables: Renderable<RenderableValues & BaseValues>[], boundingSphere: Sphere3D): Sphere3D {
-    eposHelper.reset();
+    boundaryHelper.reset();
 
     for (let i = 0, il = renderables.length; i < il; ++i) {
         const boundingSphere = renderables[i].values.boundingSphere.ref.value
         if (!boundingSphere.radius) continue;
 
         for (const b of Sphere3D.getList(boundingSphere)) {
-            eposHelper.includeSphereStep(b.center, b.radius);
+            boundaryHelper.includeSphereStep(b.center, b.radius);
         }
     }
-    eposHelper.finishedIncludeStep();
+    boundaryHelper.finishedIncludeStep();
     for (let i = 0, il = renderables.length; i < il; ++i) {
         const boundingSphere = renderables[i].values.boundingSphere.ref.value
         if (!boundingSphere.radius) continue;
 
         for (const b of Sphere3D.getList(boundingSphere)) {
-            eposHelper.radiusSphereStep(b.center, b.radius);
+            boundaryHelper.radiusSphereStep(b.center, b.radius);
         }
     }
 
-    return eposHelper.getSphere(boundingSphere);
+    return boundaryHelper.getSphere(boundingSphere);
 }
 
 function renderableSort(a: Renderable<RenderableValues & BaseValues>, b: Renderable<RenderableValues & BaseValues>) {

+ 5 - 1
src/mol-math/geometry/boundary-helper.ts

@@ -11,6 +11,8 @@ import { Box3D } from './primitives/box3d';
 
 // implementing http://www.ep.liu.se/ecp/034/009/ecp083409.pdf
 
+const MinThresholdDist = 0.1
+
 export class BoundaryHelper {
     private dir: Vec3[]
 
@@ -73,6 +75,8 @@ export class BoundaryHelper {
     }
 
     getHierarchyInput() {
+        if (this.centroidHelper.getCount() < 2) return false
+
         const sphere = this.centroidHelper.getSphere();
         const normal = Vec3()
         const t = sphere.radius * this.hierarchyThresholdFactor
@@ -89,7 +93,7 @@ export class BoundaryHelper {
             if (halfDist < t) belowThreshold = true
         }
 
-        return belowThreshold ? { sphere, normal } : false
+        return (belowThreshold && maxDist > MinThresholdDist) ? { sphere, normal } : false
     }
 
     getSphere(sphere?: Sphere3D) {

+ 4 - 2
src/mol-math/geometry/centroid-helper.ts

@@ -50,9 +50,11 @@ class CentroidHelper {
         return sphere
     }
 
-    constructor() {
-
+    getCount() {
+        return this.count;
     }
+
+    constructor() { }
 }
 
 namespace CentroidHelper {