checkpoint extract contour as async function
This commit is contained in:
parent
d6b53d425e
commit
f751f75c74
1 changed files with 132 additions and 101 deletions
|
|
@ -112,7 +112,7 @@ class Topo {
|
||||||
newslices.push(debug);
|
newslices.push(debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
const probe = new Probe({
|
const probe = this.probe = new Probe({
|
||||||
profile: toolOffset,
|
profile: toolOffset,
|
||||||
data,
|
data,
|
||||||
stepsX,
|
stepsX,
|
||||||
|
|
@ -128,7 +128,180 @@ class Topo {
|
||||||
this.toolAtXY = toolAtXY;
|
this.toolAtXY = toolAtXY;
|
||||||
this.zAtXY = zAtXY;
|
this.zAtXY = zAtXY;
|
||||||
|
|
||||||
function contouring() {
|
const trace = this.trace = new Trace({
|
||||||
|
probe,
|
||||||
|
curvesOnly,
|
||||||
|
maxangle,
|
||||||
|
flatness
|
||||||
|
});
|
||||||
|
|
||||||
|
if (topo.raster) {
|
||||||
|
const box = topo.box = new THREE.Box2();
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
resolution,
|
||||||
|
curvesOnly,
|
||||||
|
flatness,
|
||||||
|
stepsY,
|
||||||
|
minY,
|
||||||
|
maxY,
|
||||||
|
zMin,
|
||||||
|
data,
|
||||||
|
box
|
||||||
|
};
|
||||||
|
|
||||||
|
onupdate(0, 1, "raster");
|
||||||
|
await this.raster(widget, params);
|
||||||
|
topo.raster = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.contour({
|
||||||
|
box: topo.box,
|
||||||
|
minX,
|
||||||
|
maxX,
|
||||||
|
minY,
|
||||||
|
maxY,
|
||||||
|
stepsX,
|
||||||
|
stepsY,
|
||||||
|
boundsX,
|
||||||
|
boundsY,
|
||||||
|
partOff,
|
||||||
|
gridDelta,
|
||||||
|
resolution,
|
||||||
|
toolStep,
|
||||||
|
contourX,
|
||||||
|
contourY,
|
||||||
|
clipTo,
|
||||||
|
clipTab,
|
||||||
|
tabHeight,
|
||||||
|
onupdate,
|
||||||
|
newslices,
|
||||||
|
color
|
||||||
|
});
|
||||||
|
|
||||||
|
ondone(newslices);
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
async raster(widget, params) {
|
||||||
|
const { resolution } = params;
|
||||||
|
const { box } = params;
|
||||||
|
|
||||||
|
console.log({ topo_raster: widget, resolution });
|
||||||
|
|
||||||
|
// const worker = kiri.worker;
|
||||||
|
// const minions = kiri.minions;
|
||||||
|
const { worker, minions } = kiri;
|
||||||
|
const vertices = widget.getGeoVertices().toShared();
|
||||||
|
const range = { min: Infinity, max: -Infinity };
|
||||||
|
|
||||||
|
// swap XZ in shared array
|
||||||
|
for (let i=0,l=vertices.length; i<l; i += 3) {
|
||||||
|
const x = vertices[i];
|
||||||
|
const z = vertices[i + 2];
|
||||||
|
vertices[i] = z;
|
||||||
|
vertices[i + 2] = x;
|
||||||
|
range.min = Math.min(range.min, x);
|
||||||
|
range.max = Math.max(range.max, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
const shards = Math.ceil(Math.min(25, vertices.length / 27000));
|
||||||
|
const step = (range.max - range.min) / shards;
|
||||||
|
|
||||||
|
let slices = [];
|
||||||
|
let index = 0;
|
||||||
|
let slice = { min: range.min, max: range.min + step, index };
|
||||||
|
for (let z = range.min; z < range.max; z += resolution) {
|
||||||
|
if (z > slice.max) {
|
||||||
|
slices.push(slice);
|
||||||
|
slice = { min: z, max: z + step, index };
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
slices.push(slice);
|
||||||
|
console.log({ shards, range, step, slices });
|
||||||
|
|
||||||
|
// define sharded ranges
|
||||||
|
if (minions.running > 1) {
|
||||||
|
|
||||||
|
console.time('topo raster minion');
|
||||||
|
worker.putCache({ key: widget.id, data: vertices }, { done: data => {
|
||||||
|
// console.log({ put_cache_done: data });
|
||||||
|
}});
|
||||||
|
|
||||||
|
let promises = slices.map((slice, index) => {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
minions.queue({
|
||||||
|
cmd: "topo_raster",
|
||||||
|
id: widget.id,
|
||||||
|
params,
|
||||||
|
slice
|
||||||
|
}, data => {
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// merge boxes for all rasters for contouring clipping
|
||||||
|
(await Promise.all(promises))
|
||||||
|
.map(rec => rec.box)
|
||||||
|
.map(box => new THREE.Box2(
|
||||||
|
new THREE.Vector2(box.min.x, box.min.y),
|
||||||
|
new THREE.Vector2(box.max.x, box.max.y)
|
||||||
|
))
|
||||||
|
.map(box2 => {
|
||||||
|
box.union(box2);
|
||||||
|
return box2;
|
||||||
|
});
|
||||||
|
|
||||||
|
worker.clearCache({}, { done: data => {
|
||||||
|
// console.log({ clear_cache_done: data });
|
||||||
|
}});
|
||||||
|
console.timeEnd('topo raster minion');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
console.time('topo raster');
|
||||||
|
// iterate over shards, merge output
|
||||||
|
// const output = [];
|
||||||
|
for (let slice of slices) {
|
||||||
|
new kiri.topo_slicer(slice.index)
|
||||||
|
.setFromArray(vertices, slice)
|
||||||
|
.slice(resolution)
|
||||||
|
.map(rec => {
|
||||||
|
|
||||||
|
const slice = kiri.newSlice(rec.z);
|
||||||
|
slice.index = rec.index;
|
||||||
|
slice.lines = rec.lines;
|
||||||
|
for (let line of rec.lines) {
|
||||||
|
const { p1, p2 } = line;
|
||||||
|
if (!p1.swapped) { p1.swapXZ(); p1.swapped = true }
|
||||||
|
if (!p2.swapped) { p2.swapXZ(); p2.swapped = true }
|
||||||
|
}
|
||||||
|
|
||||||
|
raster_slice({
|
||||||
|
...params,
|
||||||
|
box,
|
||||||
|
lines: rec.lines,
|
||||||
|
gridx: rec.index
|
||||||
|
});
|
||||||
|
|
||||||
|
return slice;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
console.timeEnd('topo raster');
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async contour(params) {
|
||||||
|
const trace = this.trace;
|
||||||
|
|
||||||
|
const { minX, maxX, minY, maxY, boundsX, boundsY, stepsX, stepsY } = params;
|
||||||
|
const { gridDelta, resolution, partOff, toolStep, contourX, contourY } = params;
|
||||||
|
const { clipTo, clipTab, tabHeight, onupdate, newslices, color } = params;
|
||||||
|
|
||||||
let gridx = 0,
|
let gridx = 0,
|
||||||
gridy,
|
gridy,
|
||||||
gridi, // index
|
gridi, // index
|
||||||
|
|
@ -145,17 +318,10 @@ class Topo {
|
||||||
stepsTotal += ((maxY - minY + partOff * 2) / toolStep) | 0;
|
stepsTotal += ((maxY - minY + partOff * 2) / toolStep) | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const box = topo.box.clone().expandByVector(new THREE.Vector3(
|
const box = params.box.clone().expandByVector(new THREE.Vector3(
|
||||||
partOff, partOff, 0
|
partOff, partOff, 0
|
||||||
));
|
));
|
||||||
|
|
||||||
const trace = new Trace({
|
|
||||||
probe,
|
|
||||||
curvesOnly,
|
|
||||||
maxangle,
|
|
||||||
flatness
|
|
||||||
});
|
|
||||||
|
|
||||||
if (contourY) {
|
if (contourY) {
|
||||||
// emit slice per X
|
// emit slice per X
|
||||||
for (x = minX - partOff; x <= maxX + partOff; x += toolStep) {
|
for (x = minX - partOff; x <= maxX + partOff; x += toolStep) {
|
||||||
|
|
@ -221,141 +387,6 @@ class Topo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (topo.raster) {
|
|
||||||
const box = topo.box = new THREE.Box2();
|
|
||||||
|
|
||||||
const params = {
|
|
||||||
resolution,
|
|
||||||
curvesOnly,
|
|
||||||
flatness,
|
|
||||||
stepsY,
|
|
||||||
minY,
|
|
||||||
maxY,
|
|
||||||
zMin,
|
|
||||||
data,
|
|
||||||
box
|
|
||||||
};
|
|
||||||
|
|
||||||
onupdate(0, 1, "raster");
|
|
||||||
await this.topo_raster(widget, params);
|
|
||||||
topo.raster = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
contouring();
|
|
||||||
ondone(newslices);
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
async topo_raster(widget, params) {
|
|
||||||
const { resolution } = params;
|
|
||||||
|
|
||||||
console.log({ topo_raster: widget, resolution });
|
|
||||||
|
|
||||||
const dispatch = kiri.worker;
|
|
||||||
const minions = kiri.minions;
|
|
||||||
const vertices = widget.getGeoVertices().toShared();
|
|
||||||
const range = { min: Infinity, max: -Infinity };
|
|
||||||
const { box } = params;
|
|
||||||
|
|
||||||
// swap XZ in shared array
|
|
||||||
for (let i=0,l=vertices.length; i<l; i += 3) {
|
|
||||||
const x = vertices[i];
|
|
||||||
const z = vertices[i + 2];
|
|
||||||
vertices[i] = z;
|
|
||||||
vertices[i + 2] = x;
|
|
||||||
range.min = Math.min(range.min, x);
|
|
||||||
range.max = Math.max(range.max, x);
|
|
||||||
}
|
|
||||||
|
|
||||||
const shards = Math.ceil(Math.min(25, vertices.length / 27000));
|
|
||||||
const step = (range.max - range.min) / shards;
|
|
||||||
|
|
||||||
let slices = [];
|
|
||||||
let index = 0;
|
|
||||||
let slice = { min: range.min, max: range.min + step, index };
|
|
||||||
for (let z = range.min; z < range.max; z += resolution) {
|
|
||||||
if (z > slice.max) {
|
|
||||||
slices.push(slice);
|
|
||||||
slice = { min: z, max: z + step, index };
|
|
||||||
}
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
slices.push(slice);
|
|
||||||
console.log({ shards, range, step, slices });
|
|
||||||
|
|
||||||
// define sharded ranges
|
|
||||||
if (minions.running > 1) {
|
|
||||||
|
|
||||||
console.time('topo raster minion');
|
|
||||||
dispatch.putCache({ key: widget.id, data: vertices }, { done: data => {
|
|
||||||
// console.log({ put_cache_done: data });
|
|
||||||
}});
|
|
||||||
|
|
||||||
let promises = slices.map((slice, index) => {
|
|
||||||
return new Promise(resolve => {
|
|
||||||
minions.queue({
|
|
||||||
cmd: "topo_raster",
|
|
||||||
id: widget.id,
|
|
||||||
params,
|
|
||||||
slice
|
|
||||||
}, data => {
|
|
||||||
resolve(data);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// merge boxes for all rasters for contouring clipping
|
|
||||||
(await Promise.all(promises))
|
|
||||||
.map(rec => rec.box)
|
|
||||||
.map(box => new THREE.Box2(
|
|
||||||
new THREE.Vector2(box.min.x, box.min.y),
|
|
||||||
new THREE.Vector2(box.max.x, box.max.y)
|
|
||||||
))
|
|
||||||
.map(box2 => {
|
|
||||||
box.union(box2);
|
|
||||||
return box2;
|
|
||||||
});
|
|
||||||
|
|
||||||
dispatch.clearCache({}, { done: data => {
|
|
||||||
// console.log({ clear_cache_done: data });
|
|
||||||
}});
|
|
||||||
console.timeEnd('topo raster minion');
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
console.time('topo raster');
|
|
||||||
// iterate over shards, merge output
|
|
||||||
// const output = [];
|
|
||||||
for (let slice of slices) {
|
|
||||||
new kiri.topo_slicer(slice.index)
|
|
||||||
.setFromArray(vertices, slice)
|
|
||||||
.slice(resolution)
|
|
||||||
.map(rec => {
|
|
||||||
|
|
||||||
const slice = kiri.newSlice(rec.z);
|
|
||||||
slice.index = rec.index;
|
|
||||||
slice.lines = rec.lines;
|
|
||||||
for (let line of rec.lines) {
|
|
||||||
const { p1, p2 } = line;
|
|
||||||
if (!p1.swapped) { p1.swapXZ(); p1.swapped = true }
|
|
||||||
if (!p2.swapped) { p2.swapXZ(); p2.swapped = true }
|
|
||||||
}
|
|
||||||
|
|
||||||
raster_slice({
|
|
||||||
...params,
|
|
||||||
box,
|
|
||||||
lines: rec.lines,
|
|
||||||
gridx: rec.index
|
|
||||||
});
|
|
||||||
|
|
||||||
return slice;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
console.timeEnd('topo raster');
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Probe {
|
class Probe {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue