Quellcode durchsuchen

wip, bounding sphere of spheres calculation improvements

Alexander Rose vor 5 Jahren
Ursprung
Commit
0a84e1bb7b

+ 2 - 2
src/mol-gl/renderable/util.ts

@@ -101,12 +101,12 @@ export function calculateTransformBoundingSphere(invariantBoundingSphere: Sphere
     eposHelper98.reset()
     for (let i = 0, _i = transformCount; i < _i; ++i) {
         Vec3.transformMat4Offset(v, center, transform, 0, 0, i * 16)
-        eposHelper98.includeStep(v)
+        eposHelper98.includeSphereStep(v, radius)
     }
     eposHelper98.finishedIncludeStep()
     for (let i = 0, _i = transformCount; i < _i; ++i) {
         Vec3.transformMat4Offset(v, center, transform, 0, 0, i * 16)
-        eposHelper98.paddedRadiusStep(v, radius)
+        eposHelper98.radiusSphereStep(v, radius)
     }
     return eposHelper98.getSphere()
 }

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

@@ -24,13 +24,13 @@ function calculateBoundingSphere(renderables: Renderable<RenderableValues & Base
     for (let i = 0, il = renderables.length; i < il; ++i) {
         const boundingSphere = renderables[i].values.boundingSphere.ref.value
         if (!boundingSphere.radius) continue;
-        eposHelper98.includeStep(boundingSphere.center);
+        eposHelper98.includeSphereStep(boundingSphere.center, boundingSphere.radius);
     }
     eposHelper98.finishedIncludeStep();
     for (let i = 0, il = renderables.length; i < il; ++i) {
         const boundingSphere = renderables[i].values.boundingSphere.ref.value
         if (!boundingSphere.radius) continue;
-        eposHelper98.paddedRadiusStep(boundingSphere.center, boundingSphere.radius);
+        eposHelper98.radiusSphereStep(boundingSphere.center, boundingSphere.radius);
     }
 
     return eposHelper98.getSphere(boundingSphere);

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

@@ -37,9 +37,8 @@ class CentroidHelper {
         if (d > this.radiusSq) this.radiusSq = d;
     }
 
-    paddedRadiusStep(p: Vec3, padding: number) {
-        // TODO take existing radius into account
-        const _d = Vec3.distance(p, this.center) + padding;
+    radiusSphereStep(center: Vec3, radius: number) {
+        const _d = Vec3.distance(center, this.center) + radius;
         const d = _d * _d;
         if (d > this.radiusSq) this.radiusSq = d;
     }

+ 22 - 3
src/mol-math/geometry/epos-helper.ts

@@ -16,7 +16,7 @@ export class EposHelper {
     private minDist: number[] = []
     private maxDist: number[] = []
     private extrema: Vec3[] = []
-    private centroidHelper = new CentroidHelper()
+    centroidHelper = new CentroidHelper()
 
     private computeExtrema(i: number, p: Vec3) {
         const d = Vec3.dot(this.dir[i], p)
@@ -31,12 +31,31 @@ export class EposHelper {
         }
     }
 
+    private computeSphereExtrema(i: number, center: Vec3, radius: number) {
+        const d = Vec3.dot(this.dir[i], center)
+
+        if (d - radius < this.minDist[i]) {
+            this.minDist[i] = d - radius
+            Vec3.scaleAndSub(this.extrema[i * 2], center, this.dir[i], radius)
+        }
+        if (d + radius > this.maxDist[i]) {
+            this.maxDist[i] = d + radius
+            Vec3.scaleAndAdd(this.extrema[i * 2 + 1], center, this.dir[i], radius)
+        }
+    }
+
     includeStep(p: Vec3) {
         for (let i = 0, il = this.dir.length; i < il; ++i) {
             this.computeExtrema(i, p)
         }
     }
 
+    includeSphereStep(center: Vec3, radius: number) {
+        for (let i = 0, il = this.dir.length; i < il; ++i) {
+            this.computeSphereExtrema(i, center, radius)
+        }
+    }
+
     finishedIncludeStep() {
         for (let i = 0; i < this.extrema.length; i++) {
             this.centroidHelper.includeStep(this.extrema[i]);
@@ -48,8 +67,8 @@ export class EposHelper {
         this.centroidHelper.radiusStep(p);
     }
 
-    paddedRadiusStep(p: Vec3, padding: number) {
-        this.centroidHelper.paddedRadiusStep(p, padding);
+    radiusSphereStep(center: Vec3, radius: number) {
+        this.centroidHelper.radiusSphereStep(center, radius);
     }
 
     getSphere(sphere?: Sphere3D) {