remove minion-based cam slicing
This commit is contained in:
parent
db13a61d3b
commit
883bf90091
5 changed files with 5 additions and 85 deletions
|
|
@ -16,7 +16,7 @@ gapp.overlay(base, {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* converts a geometry point array into a kiri point array
|
* converts a geometry point array into a kiri point array
|
||||||
* with auto-decimation
|
* with optional decimation
|
||||||
*/
|
*/
|
||||||
function verticesToPoints(array, options) {
|
function verticesToPoints(array, options) {
|
||||||
let parr = new Array(array.length / 3),
|
let parr = new Array(array.length / 3),
|
||||||
|
|
@ -49,7 +49,7 @@ function verticesToPoints(array, options) {
|
||||||
// maxpass = max number of decimations
|
// maxpass = max number of decimations
|
||||||
threshold = threshold > 0 ? threshold : config.decimate_threshold;
|
threshold = threshold > 0 ? threshold : config.decimate_threshold;
|
||||||
precision = precision >= 0 ? precision : config.precision_decimate;
|
precision = precision >= 0 ? precision : config.precision_decimate;
|
||||||
maxpass = maxpass >= 0 ? maxpass : 10;
|
maxpass = maxpass >= 0 ? maxpass : 0;
|
||||||
|
|
||||||
// decimate until all point spacing > precision
|
// decimate until all point spacing > precision
|
||||||
if (maxpass && precision > 0.0)
|
if (maxpass && precision > 0.0)
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ class Slicer {
|
||||||
let zSum = this.zSum;
|
let zSum = this.zSum;
|
||||||
let zMax = this.bounds.max.z;
|
let zMax = this.bounds.max.z;
|
||||||
let points = this.points;
|
let points = this.points;
|
||||||
let bucketCount = this.threaded ? 0 : Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1);
|
let bucketCount = Math.max(1, Math.ceil(zMax / (zSum / points.length)) - 1);
|
||||||
let zScale = this.zScale = 1 / (zMax / bucketCount);
|
let zScale = this.zScale = 1 / (zMax / bucketCount);
|
||||||
let buckets = this.buckets = {};
|
let buckets = this.buckets = {};
|
||||||
|
|
||||||
|
|
@ -166,14 +166,6 @@ class Slicer {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
async sliceAsync(zarr, options) {
|
|
||||||
if (!this.threaded) {
|
|
||||||
return this.slice(zarr, options);
|
|
||||||
}
|
|
||||||
return await kiri.minions.camSliceZ(zarr, this, options);
|
|
||||||
// return this.slice(zarr, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
// slice through points at given Z and return polygons
|
// slice through points at given Z and return polygons
|
||||||
slice(z, options, index, total, mark) {
|
slice(z, options, index, total, mark) {
|
||||||
const opt = this.setOptions(options);
|
const opt = this.setOptions(options);
|
||||||
|
|
|
||||||
|
|
@ -446,7 +446,7 @@ 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);
|
||||||
|
|
||||||
let slices = topo.slices = topo.slices || await slicer.sliceAsync(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 });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,25 +138,8 @@ const funcs = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
camSliceZ: (data, seq) => {
|
|
||||||
const { zarr, set } = data;
|
|
||||||
const slicer = new kiri.cam_slicer();
|
|
||||||
set.points = cache.camPoints;
|
|
||||||
set.options.each = (data, index, total) => {
|
|
||||||
// log({ data, index, total });
|
|
||||||
datas.push({
|
|
||||||
z: data.z,
|
|
||||||
lines: kiri.codec.encodePointArray(data.lines.map(line => [ line.p1, line.p2 ]).flat())
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Object.assign(slicer, set);
|
|
||||||
const datas = [];
|
|
||||||
slicer.slice(zarr);
|
|
||||||
reply({ seq, data: datas });
|
|
||||||
},
|
|
||||||
|
|
||||||
camSetPoints: data => {
|
camSetPoints: data => {
|
||||||
const points = new Float32Array(data.data.slice());
|
const points = new Float32Array(data.data);
|
||||||
let i = 0, p = 0, realp = new Array(points.length / 3);
|
let i = 0, p = 0, realp = new Array(points.length / 3);
|
||||||
while (i < points.length) {
|
while (i < points.length) {
|
||||||
realp[p++] = base.newPoint(points[i++], points[i++], points[i++]).round(3);
|
realp[p++] = base.newPoint(points[i++], points[i++], points[i++]).round(3);
|
||||||
|
|
|
||||||
|
|
@ -204,61 +204,6 @@ kiri.minions = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
camSliceZ(zarr, slicer, options) {
|
|
||||||
let { points, bounds, zFlat, zLine, zList, zSum, ox } = slicer;
|
|
||||||
let shared = new SharedArrayBuffer(points.length * 3 * 4)
|
|
||||||
let i = 0, floatP = new Float32Array(shared);
|
|
||||||
options = Object.assign(options, slicer.options);
|
|
||||||
options.each();
|
|
||||||
delete options.each;
|
|
||||||
for (let p of points) {
|
|
||||||
floatP[i++] = p.x;
|
|
||||||
floatP[i++] = p.y;
|
|
||||||
floatP[i++] = p.z;
|
|
||||||
}
|
|
||||||
minwork.broadcast('camSetPoints', shared);
|
|
||||||
let ps = [];
|
|
||||||
let step = zarr.length / concurrent;
|
|
||||||
while (zarr.length) {
|
|
||||||
let arr = zarr.slice(0, step);
|
|
||||||
zarr = zarr.slice(step);
|
|
||||||
ps.push(minwork.queueAsync({
|
|
||||||
cmd: "camSliceZ",
|
|
||||||
zarr: arr,
|
|
||||||
set: {
|
|
||||||
bounds,
|
|
||||||
buckets: {},
|
|
||||||
options,
|
|
||||||
zFlat,
|
|
||||||
zLine,
|
|
||||||
zList,
|
|
||||||
zSum,
|
|
||||||
ox
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
return Promise.all(ps).then(data => {
|
|
||||||
minwork.broadcast('camClearPoints');
|
|
||||||
let result = data
|
|
||||||
.map(data => data.data)
|
|
||||||
.flat()
|
|
||||||
.map(rec => {
|
|
||||||
const slice = kiri.newSlice(rec.z);
|
|
||||||
const points = kiri.codec.decodePointArray(rec.lines);
|
|
||||||
slice.lines = [];
|
|
||||||
points.forEachPair((p1, p2) => {
|
|
||||||
slice.lines.push(base.newLine(p1, p2));
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
z: rec.z,
|
|
||||||
lines: slice.lines,
|
|
||||||
slice
|
|
||||||
};
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
queue(work, ondone, direct) {
|
queue(work, ondone, direct) {
|
||||||
minionq.push({work, ondone, direct});
|
minionq.push({work, ondone, direct});
|
||||||
minwork.kick();
|
minwork.kick();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue