Skip to content
Snippets Groups Projects
Commit 99e51560 authored by Alexander Rose's avatar Alexander Rose
Browse files

skip identical positions in spheres and lines bounding sphere calculation

parent 84dfa60f
No related branches found
No related tags found
No related merge requests found
...@@ -177,8 +177,8 @@ export namespace Lines { ...@@ -177,8 +177,8 @@ export namespace Lines {
} }
function getBoundingSphere(lineStart: Float32Array, lineEnd: Float32Array, lineCount: number, transform: Float32Array, transformCount: number) { function getBoundingSphere(lineStart: Float32Array, lineEnd: Float32Array, lineCount: number, transform: Float32Array, transformCount: number) {
const start = calculateBoundingSphere(lineStart, lineCount * 4, transform, transformCount) const start = calculateBoundingSphere(lineStart, lineCount * 4, transform, transformCount, 0, 4)
const end = calculateBoundingSphere(lineEnd, lineCount * 4, transform, transformCount) const end = calculateBoundingSphere(lineEnd, lineCount * 4, transform, transformCount, 0, 4)
return { return {
boundingSphere: Sphere3D.expandBySphere(start.boundingSphere, end.boundingSphere), boundingSphere: Sphere3D.expandBySphere(start.boundingSphere, end.boundingSphere),
invariantBoundingSphere: Sphere3D.expandBySphere(start.invariantBoundingSphere, end.invariantBoundingSphere) invariantBoundingSphere: Sphere3D.expandBySphere(start.invariantBoundingSphere, end.invariantBoundingSphere)
......
...@@ -89,7 +89,7 @@ export namespace Spheres { ...@@ -89,7 +89,7 @@ export namespace Spheres {
const padding = getMaxSize(size) const padding = getMaxSize(size)
const { boundingSphere, invariantBoundingSphere } = calculateBoundingSphere( const { boundingSphere, invariantBoundingSphere } = calculateBoundingSphere(
spheres.centerBuffer.ref.value, spheres.sphereCount * 4, spheres.centerBuffer.ref.value, spheres.sphereCount * 4,
transform.aTransform.ref.value, instanceCount, padding transform.aTransform.ref.value, instanceCount, padding, 4
) )
return { return {
...@@ -130,7 +130,7 @@ export namespace Spheres { ...@@ -130,7 +130,7 @@ export namespace Spheres {
const padding = getMaxSize(values) const padding = getMaxSize(values)
const { boundingSphere, invariantBoundingSphere } = calculateBoundingSphere( const { boundingSphere, invariantBoundingSphere } = calculateBoundingSphere(
values.aPosition.ref.value, spheres.sphereCount * 4, 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)) { if (!Sphere3D.equals(boundingSphere, values.boundingSphere.ref.value)) {
ValueCell.update(values.boundingSphere, boundingSphere) ValueCell.update(values.boundingSphere, boundingSphere)
......
/** /**
* 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> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
...@@ -80,14 +80,15 @@ export function printImageData(imageData: ImageData, scale = 1, pixelated = fals ...@@ -80,14 +80,15 @@ export function printImageData(imageData: ImageData, scale = 1, pixelated = fals
const v = Vec3.zero() const v = Vec3.zero()
const boundaryHelper = new BoundaryHelper() 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) 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) Vec3.fromArray(v, position, i)
boundaryHelper.boundaryStep(v, 0) boundaryHelper.boundaryStep(v, 0)
} }
boundaryHelper.finishBoundaryStep() 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) Vec3.fromArray(v, position, i)
boundaryHelper.extendStep(v, 0) boundaryHelper.extendStep(v, 0)
} }
...@@ -109,8 +110,8 @@ export function calculateTransformBoundingSphere(invariantBoundingSphere: Sphere ...@@ -109,8 +110,8 @@ export function calculateTransformBoundingSphere(invariantBoundingSphere: Sphere
return boundaryHelper.getSphere() return boundaryHelper.getSphere()
} }
export function calculateBoundingSphere(position: Float32Array, positionCount: number, transform: Float32Array, transformCount: number, padding = 0): { boundingSphere: Sphere3D, invariantBoundingSphere: Sphere3D } { export function calculateBoundingSphere(position: Float32Array, positionCount: number, transform: Float32Array, transformCount: number, padding = 0, stepFactor = 1): { boundingSphere: Sphere3D, invariantBoundingSphere: Sphere3D } {
const invariantBoundingSphere = calculateInvariantBoundingSphere(position, positionCount) const invariantBoundingSphere = calculateInvariantBoundingSphere(position, positionCount, stepFactor)
const boundingSphere = calculateTransformBoundingSphere(invariantBoundingSphere, transform, transformCount) const boundingSphere = calculateTransformBoundingSphere(invariantBoundingSphere, transform, transformCount)
Sphere3D.expand(boundingSphere, boundingSphere, padding) Sphere3D.expand(boundingSphere, boundingSphere, padding)
Sphere3D.expand(invariantBoundingSphere, invariantBoundingSphere, padding) Sphere3D.expand(invariantBoundingSphere, invariantBoundingSphere, padding)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment