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

gaussian density, avoid large async function

parent 735e497a
No related branches found
No related tags found
No related merge requests found
...@@ -24,10 +24,6 @@ export async function GaussianDensityCPU(ctx: RuntimeContext, position: Position ...@@ -24,10 +24,6 @@ export async function GaussianDensityCPU(ctx: RuntimeContext, position: Position
const r = radius(OrderedSet.getAt(indices, i)) + radiusOffset const r = radius(OrderedSet.getAt(indices, i)) + radiusOffset
if (maxRadius < r) maxRadius = r if (maxRadius < r) maxRadius = r
radii[i] = r radii[i] = r
if (i % 100000 === 0 && ctx.shouldUpdate) {
await ctx.update({ message: 'calculating max radius', current: i, max: n })
}
} }
const pad = maxRadius * 2 + resolution const pad = maxRadius * 2 + resolution
...@@ -54,10 +50,10 @@ export async function GaussianDensityCPU(ctx: RuntimeContext, position: Position ...@@ -54,10 +50,10 @@ export async function GaussianDensityCPU(ctx: RuntimeContext, position: Position
const densData = space.create() const densData = space.create()
const alpha = smoothness const alpha = smoothness
const updateChunk = Math.ceil(1000000 / (Math.pow(maxRadius * 2, 3) * resolution)) const updateChunk = Math.ceil(100000 / ((Math.pow(Math.pow(maxRadius, 3), 3) * scaleFactor)))
console.time('gaussian density cpu') function accumulateRange(begI: number, endI: number) {
for (let i = 0; i < n; ++i) { for (let i = begI; i < endI; ++i) {
const j = OrderedSet.getAt(indices, i) const j = OrderedSet.getAt(indices, i)
const vx = x[j], vy = y[j], vz = z[j] const vx = x[j], vy = y[j], vz = z[j]
...@@ -110,12 +106,22 @@ export async function GaussianDensityCPU(ctx: RuntimeContext, position: Position ...@@ -110,12 +106,22 @@ export async function GaussianDensityCPU(ctx: RuntimeContext, position: Position
} }
} }
} }
}
}
async function accumulate() {
for (let i = 0; i < n; i += updateChunk) {
accumulateRange(i, Math.min(i + updateChunk, n))
if (i % updateChunk === 0 && ctx.shouldUpdate) { if (ctx.shouldUpdate) {
await ctx.update({ message: 'filling density grid', current: i, max: n }) await ctx.update({ message: 'filling density grid', current: i, max: n })
} }
} }
console.timeEnd('gaussian density cpu') }
// console.time('gaussian density cpu')
await accumulate()
// console.timeEnd('gaussian density cpu')
const transform = Mat4.identity() const transform = Mat4.identity()
Mat4.fromScaling(transform, Vec3.create(resolution, resolution, resolution)) Mat4.fromScaling(transform, Vec3.create(resolution, resolution, resolution))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment