checkpoint

This commit is contained in:
Stewart Allen 2023-01-09 16:03:31 -05:00
commit ed90dea0a5
2 changed files with 51 additions and 38 deletions

View file

@ -41,15 +41,18 @@ class Slicer {
const x2 = position[i++]; const x2 = position[i++];
const y2 = position[i++]; const y2 = position[i++];
const z2 = position[i++]; const z2 = position[i++];
if (Math.min(z0, z1, z2) >= min && Math.max(z0, z1, z2) <= max) { const minz = Math.min(z0, z1, z2);
const maxz = Math.max(z0, z1, z2);
if (maxz < min || minz > max) {
continue;
}
pts.push( pts.push(
newPoint(x0, y0, z0), newPoint(x0, y0, z0),
newPoint(x1, y1, z1), newPoint(x1, y1, z1),
newPoint(x2, y2, z2) newPoint(x2, y2, z2)
); );
this.min = Math.min(this.min, z0, z1, z2); this.min = options.min || Math.min(this.min, minz);
this.max = Math.max(this.max, z0, z1, z2); this.max = options.max || Math.max(this.max, maxz);
}
} }
return this; return this;
} }
@ -63,11 +66,14 @@ class Slicer {
const p0 = points[i++]; const p0 = points[i++];
const p1 = points[i++]; const p1 = points[i++];
const p2 = points[i++]; const p2 = points[i++];
if (Math.min(p0.z, p1.z, p2.z) >= min && Math.max(p0.z, p1.z, p2.z) <= max) { const minz = Math.min(p0.z, p1.z, p2.z);
pts.push(p0, p1, p2); const maxz = Math.max(p0.z, p1.z, p2.z);
this.min = Math.min(this.min, p0.z, p1.z, p2.z); if (maxz < min || minz > max) {
this.max = Math.max(this.max, p0.z, p1.z, p2.z); continue;
} }
pts.push(p0, p1, p2);
this.min = options.min || Math.min(this.min, minz);
this.max = options.max || Math.max(this.max, maxz);
} }
return this; return this;
} }
@ -332,6 +338,18 @@ moto.broker.subscribe("worker.started", msg => {
range.min = Math.min(range.min, x); range.min = Math.min(range.min, x);
range.max = Math.max(range.max, 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;
const slices = [];
let slice = { min: range.min, max: range.min + step };
for (let z = range.min; z < range.max; z += resolution) {
if (z > slice.max) {
slices.push(slice);
slice = { min: z, max: z + step };
}
}
slices.push(slice);
console.log({ shards, range, step, slices });
// define sharded ranges // define sharded ranges
if (false && minions.concurrent) { if (false && minions.concurrent) {
dispatch.putCache({ key: widget.id, data: vertices }, { done: data => { dispatch.putCache({ key: widget.id, data: vertices }, { done: data => {
@ -345,8 +363,11 @@ moto.broker.subscribe("worker.started", msg => {
} else { } else {
console.time('nuslice'); console.time('nuslice');
// iterate over shards, merge output // iterate over shards, merge output
const output = new Slicer() const output = [];
.setFromArray(vertices) for (let slice of slices) {
console.log({ slice });
const res = new Slicer()
.setFromArray(vertices, slice)
.slice(resolution) .slice(resolution)
.map(rec => { .map(rec => {
const slice = kiri.newSlice(rec.z); const slice = kiri.newSlice(rec.z);
@ -358,6 +379,9 @@ moto.broker.subscribe("worker.started", msg => {
} }
return slice; return slice;
}); });
output.appendAll(res);
}
output.sort((a,b) => a.z - b.z);
console.log({ output }); console.log({ output });
console.timeEnd('nuslice'); console.timeEnd('nuslice');
return output; return output;

View file

@ -60,7 +60,7 @@ class Topo {
widtopo = widget.topo, widtopo = widget.topo,
topoCache = widtopo && widtopo.resolution === resolution ? widtopo : undefined, topoCache = widtopo && widtopo.resolution === resolution ? widtopo : undefined,
topo = widget.topo = topoCache || { topo = widget.topo = topoCache || {
data: new Float32Array(stepsx * stepsy), data: new Float32Array(new SharedArrayBuffer(stepsx * stepsy * 4)),
stepsx: stepsx, stepsx: stepsx,
stepsy: stepsy, stepsy: stepsy,
bounds: bounds, bounds: bounds,
@ -439,16 +439,13 @@ class Topo {
ondone(newslices); ondone(newslices);
} }
console.log('get vertices and points');
let points = base.verticesToPoints(widget.getGeoVertices({ unroll: true, translate: true }));
console.log('topo slice 2'); console.log('topo slice 2');
const slices2 = await kiri.topo_slice(widget, resolution); const slices2 = await kiri.topo_slice(widget, resolution);
console.log({ topo_slice_done: slices2 }); console.log({ topo_slice_done: slices2 });
processSlices(slices2); processSlices(slices2);
return this; return this;
console.log('old slice setup') let points = base.verticesToPoints(widget.getGeoVertices({ unroll: true, translate: true }));
let slicer = new kiri.cam_slicer(points, { let slicer = new kiri.cam_slicer(points, {
swapX: true, emptyok: true, notopok: true swapX: true, emptyok: true, notopok: true
}); });
@ -457,20 +454,12 @@ class Topo {
if (contourX) stepsTotal += Math.round((maxY-minY) / toolStep); if (contourX) stepsTotal += Math.round((maxY-minY) / toolStep);
if (contourY) stepsTotal += Math.round((maxX-minX) / toolStep); if (contourY) stepsTotal += Math.round((maxX-minX) / toolStep);
console.log('old slice run', stepsTotal)
let slices = topo.slices = topo.slices || slicer.slice(sindex, { each: (data, index, total) => { let slices = topo.slices = topo.slices || slicer.slice(sindex, { each: (data, index, total) => {
onupdate(++stepsTaken, stepsTotal, "topo slice"); onupdate(++stepsTaken, stepsTotal, "topo slice");
}, genso: true }); }, genso: true });
console.log('process slices', stepsTaken)
processSlices(slices.filter(s => s.lines).map(data => data.slice)); processSlices(slices.filter(s => s.lines).map(data => data.slice));
console.log('process done', stepsTaken)
// const t0 = Date.now();
// for (let point of points) point.swapXZ();
// let lines = new kiri.cam_slicer2().setFromPoints(points).slice(resolution);
// console.log({ sindex, lines, time: Date.now() - t0 });
return this; return this;
} }
} }