Bladeren bron

skip identical positions in spheres and lines bounding sphere calculation

Alexander Rose 5 jaren geleden
bovenliggende
commit
99e515604e
3 gewijzigde bestanden met toevoegingen van 11 en 10 verwijderingen
  1. 2 2
      src/mol-geo/geometry/lines/lines.ts
  2. 2 2
      src/mol-geo/geometry/spheres/spheres.ts
  3. 7 6
      src/mol-gl/renderable/util.ts

+ 2 - 2
src/mol-geo/geometry/lines/lines.ts

@@ -177,8 +177,8 @@ export namespace Lines {
 }
 
 function getBoundingSphere(lineStart: Float32Array, lineEnd: Float32Array, lineCount: number, transform: Float32Array, transformCount: number) {
-    const start = calculateBoundingSphere(lineStart, lineCount * 4, transform, transformCount)
-    const end = calculateBoundingSphere(lineEnd, lineCount * 4, transform, transformCount)
+    const start = calculateBoundingSphere(lineStart, lineCount * 4, transform, transformCount, 0, 4)
+    const end = calculateBoundingSphere(lineEnd, lineCount * 4, transform, transformCount, 0, 4)
     return {
         boundingSphere: Sphere3D.expandBySphere(start.boundingSphere, end.boundingSphere),
         invariantBoundingSphere: Sphere3D.expandBySphere(start.invariantBoundingSphere, end.invariantBoundingSphere)

+ 2 - 2
src/mol-geo/geometry/spheres/spheres.ts

@@ -89,7 +89,7 @@ export namespace Spheres {
         const padding = getMaxSize(size)
         const { boundingSphere, invariantBoundingSphere } = calculateBoundingSphere(
             spheres.centerBuffer.ref.value, spheres.sphereCount * 4,
-            transform.aTransform.ref.value, instanceCount, padding
+            transform.aTransform.ref.value, instanceCount, padding, 4
         )
 
         return {
@@ -130,7 +130,7 @@ export namespace Spheres {
         const padding = getMaxSize(values)
         const { boundingSphere, invariantBoundingSphere } = calculateBoundingSphere(
             values.aPosition.ref.value, spheres.sphereCount * 4,
-            values.aTransform.ref.value, values.instanceCount.ref.value, padding
+            values.aTransform.ref.value, values.instanceCount.ref.value, padding, 4
         )
         if (!Sphere3D.equals(boundingSphere, values.boundingSphere.ref.value)) {
             ValueCell.update(values.boundingSphere, boundingSphere)

+ 7 - 6
src/mol-gl/renderable/util.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
@@ -80,14 +80,15 @@ export function printImageData(imageData: ImageData, scale = 1, pixelated = fals
 const v = Vec3.zero()
 const boundaryHelper = new BoundaryHelper()
 
-export function calculateInvariantBoundingSphere(position: Float32Array, positionCount: number): Sphere3D {
+export function calculateInvariantBoundingSphere(position: Float32Array, positionCount: number, stepFactor: number): Sphere3D {
+    const step = stepFactor * 3
     boundaryHelper.reset(0)
-    for (let i = 0, _i = positionCount * 3; i < _i; i += 3) {
+    for (let i = 0, _i = positionCount * 3; i < _i; i += step) {
         Vec3.fromArray(v, position, i)
         boundaryHelper.boundaryStep(v, 0)
     }
     boundaryHelper.finishBoundaryStep()
-    for (let i = 0, _i = positionCount * 3; i < _i; i += 3) {
+    for (let i = 0, _i = positionCount * 3; i < _i; i += step) {
         Vec3.fromArray(v, position, i)
         boundaryHelper.extendStep(v, 0)
     }
@@ -109,8 +110,8 @@ export function calculateTransformBoundingSphere(invariantBoundingSphere: Sphere
     return boundaryHelper.getSphere()
 }
 
-export function calculateBoundingSphere(position: Float32Array, positionCount: number, transform: Float32Array, transformCount: number, padding = 0): { boundingSphere: Sphere3D, invariantBoundingSphere: Sphere3D } {
-    const invariantBoundingSphere = calculateInvariantBoundingSphere(position, positionCount)
+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)