clean up raster code. tee up contour tracing in minions
This commit is contained in:
parent
94cf3c452d
commit
9afba1b567
2 changed files with 148 additions and 99 deletions
|
|
@ -1281,7 +1281,7 @@ CAM.init = function(kiri, api) {
|
||||||
axis: UC.newSelect(LANG.cd_axis, {}, "regaxis"),
|
axis: UC.newSelect(LANG.cd_axis, {}, "regaxis"),
|
||||||
sep: UC.newBlank({class:"pop-sep"}),
|
sep: UC.newBlank({class:"pop-sep"}),
|
||||||
spindle: UC.newInput(LANG.cc_spnd_s, {title:LANG.cc_spnd_l, convert:UC.toInt, show:hasSpindle}),
|
spindle: UC.newInput(LANG.cc_spnd_s, {title:LANG.cc_spnd_l, convert:UC.toInt, show:hasSpindle}),
|
||||||
step: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.01,1.0)}),
|
step: UC.newInput(LANG.cc_sovr_s, {title:LANG.cc_sovr_l, convert:UC.toFloat, bound:UC.bound(0.01,2.0)}),
|
||||||
rate: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true}),
|
rate: UC.newInput(LANG.cc_feed_s, {title:LANG.cc_feed_l, convert:UC.toInt, units:true}),
|
||||||
angle: UC.newInput(LANG.cf_angl_s, {title:LANG.cf_angl_l, convert:UC.toFloat, bound:UC.bound(45,90)}),
|
angle: UC.newInput(LANG.cf_angl_s, {title:LANG.cf_angl_l, convert:UC.toFloat, bound:UC.bound(45,90)}),
|
||||||
sep: UC.newBlank({class:"pop-sep"}),
|
sep: UC.newBlank({class:"pop-sep"}),
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ class Topo {
|
||||||
maxangle = contour.angle,
|
maxangle = contour.angle,
|
||||||
curvesOnly = contour.curves,
|
curvesOnly = contour.curves,
|
||||||
bridge = contour.bridging || 0,
|
bridge = contour.bridging || 0,
|
||||||
R2A = 180 / Math.PI,
|
// R2A = 180 / Math.PI,
|
||||||
stepsX = Math.ceil(boundsX / resolution),
|
stepsX = Math.ceil(boundsX / resolution),
|
||||||
stepsY = Math.ceil(boundsY / resolution),
|
stepsY = Math.ceil(boundsY / resolution),
|
||||||
widtopo = widget.topo,
|
widtopo = widget.topo,
|
||||||
|
|
@ -116,10 +116,7 @@ class Topo {
|
||||||
sliceout,
|
sliceout,
|
||||||
latent,
|
latent,
|
||||||
lastP,
|
lastP,
|
||||||
slice, lx, ly,
|
slice;
|
||||||
startTime = time(),
|
|
||||||
stepsTaken = 0,
|
|
||||||
stepsTotal = 0;
|
|
||||||
|
|
||||||
// return the touching z given topo x,y and a tool profile
|
// return the touching z given topo x,y and a tool profile
|
||||||
function toolAtZ(x,y) {
|
function toolAtZ(x,y) {
|
||||||
|
|
@ -165,8 +162,8 @@ class Topo {
|
||||||
return topo.data[ix * stepsY + iy] || zMin;
|
return topo.data[ix * stepsY + iy] || zMin;
|
||||||
};
|
};
|
||||||
|
|
||||||
function push_point(x,y,z) {
|
function push_point(x, y, z) {
|
||||||
const newP = newPoint(x,y,z);
|
const newP = newPoint(x, y, z);
|
||||||
// todo: merge co-linear, not just co-planar
|
// todo: merge co-linear, not just co-planar
|
||||||
if (lastP && Math.abs(lastP.z - z) < flatness) {
|
if (lastP && Math.abs(lastP.z - z) < flatness) {
|
||||||
if (curvesOnly) {
|
if (curvesOnly) {
|
||||||
|
|
@ -217,21 +214,28 @@ class Topo {
|
||||||
gridy,
|
gridy,
|
||||||
gridi, // index
|
gridi, // index
|
||||||
gridv, // value
|
gridv, // value
|
||||||
i, il, j, jl, x, y, tv, ltv;
|
i, il, j, x, y, tv,
|
||||||
|
stepsTaken = 0,
|
||||||
|
stepsTotal = 0;
|
||||||
|
|
||||||
const box = topo.box.expandByVector(new THREE.Vector3(
|
if (contourX) {
|
||||||
|
stepsTotal += ((maxX - minX + partOff * 2) / toolStep) | 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contourY) {
|
||||||
|
stepsTotal += ((maxY - minY + partOff * 2) / toolStep) | 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const box = topo.box.clone().expandByVector(new THREE.Vector3(
|
||||||
partOff, partOff, 0
|
partOff, partOff, 0
|
||||||
));
|
));
|
||||||
|
|
||||||
const checkr = newPoint(0,0);
|
const inClip = function(clips, checkZ, point) {
|
||||||
const inClip = function(polys, checkZ) {
|
for (let i=0; i<clips.length; i++) {
|
||||||
checkr.x = x;
|
let poly = clips[i];
|
||||||
checkr.y = y;
|
|
||||||
for (let i=0; i<polys.length; i++) {
|
|
||||||
let poly = polys[i];
|
|
||||||
let zok = checkZ ? checkZ <= poly.z : true;
|
let zok = checkZ ? checkZ <= poly.z : true;
|
||||||
tabZ = poly.z;
|
tabZ = poly.z;
|
||||||
if (zok && checkr.isInPolygon(poly)) {
|
if (zok && point.isInPolygon(poly)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -239,111 +243,156 @@ class Topo {
|
||||||
};
|
};
|
||||||
let tabZ;
|
let tabZ;
|
||||||
|
|
||||||
|
function traceY(params) {
|
||||||
|
let { from, to, step, box, x, gridx, gridy } = params;
|
||||||
|
let { clipTab, tabHeight, clipTo } = params;
|
||||||
|
const checkr = newPoint(0,0);
|
||||||
|
newtrace = newPolygon().setOpen();
|
||||||
|
sliceout = [];
|
||||||
|
for (let y = from; y < to; y += step) {
|
||||||
|
if (y < box.min.y || y > box.max.y) {
|
||||||
|
gridy++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// find tool z at grid point
|
||||||
|
let tv = toolAtZ(gridx, gridy);
|
||||||
|
checkr.x = x;
|
||||||
|
checkr.y = y;
|
||||||
|
// when tabs are on and this point is inside the
|
||||||
|
// tab polygon, ensure z is at least tabHeight
|
||||||
|
if (clipTab && tv < tabHeight && inClip(clipTab, tv, checkr)) {
|
||||||
|
tv = tabZ;
|
||||||
|
}
|
||||||
|
// if the value is on the floor and inside the clip
|
||||||
|
// poly (usually shadow), end the segment
|
||||||
|
if (clipTo && !inClip(clipTo, undefined, checkr)) {
|
||||||
|
end_poly();
|
||||||
|
gridy++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
push_point(x, y, tv);
|
||||||
|
gridy++;
|
||||||
|
}
|
||||||
|
end_poly();
|
||||||
|
}
|
||||||
|
|
||||||
|
function traceX(params) {
|
||||||
|
let { from, to, step, box, y, gridx, gridy } = params;
|
||||||
|
let { clipTab, tabHeight, clipTo } = params;
|
||||||
|
const checkr = newPoint(0,0);
|
||||||
|
newtrace = newPolygon().setOpen();
|
||||||
|
sliceout = [];
|
||||||
|
for (let x = from; x < to; x += step) {
|
||||||
|
if (x < box.min.x || y > box.max.x) {
|
||||||
|
gridx++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// find tool z at grid point
|
||||||
|
let tv = toolAtZ(gridx, gridy);
|
||||||
|
checkr.x = x;
|
||||||
|
checkr.y = y;
|
||||||
|
// when tabs are on and this point is inside the
|
||||||
|
// tab polygon, ensure z is at least tabHeight
|
||||||
|
if (clipTab && tv < tabHeight && inClip(clipTab, tv, checkr)) {
|
||||||
|
tv = tabZ;
|
||||||
|
}
|
||||||
|
// if the value is on the floor and inside the clip
|
||||||
|
// poly (usually shadow), end the segment
|
||||||
|
if (clipTo && !inClip(clipTo, undefined, checkr)) {
|
||||||
|
end_poly();
|
||||||
|
gridx++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
push_point(x, y, tv);
|
||||||
|
gridx++;
|
||||||
|
}
|
||||||
|
end_poly();
|
||||||
|
}
|
||||||
|
|
||||||
if (contourY) {
|
if (contourY) {
|
||||||
startTime = time();
|
|
||||||
// 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) {
|
||||||
if (x < box.min.x || x > box.max.x) continue;
|
if (x < box.min.x || x > box.max.x) continue;
|
||||||
gridx = Math.round(((x - minX) / boundsX) * stepsX);
|
gridx = Math.round(((x - minX) / boundsX) * stepsX);
|
||||||
ly = gridy = -gridDelta;
|
gridy = -gridDelta;
|
||||||
slice = newSlice(gridx);
|
|
||||||
newtrace = newPolygon().setOpen();
|
traceY({
|
||||||
sliceout = [];
|
from: minY - partOff,
|
||||||
for (y = minY - partOff; y < maxY + partOff; y += resolution) {
|
to: maxY + partOff,
|
||||||
if (y < box.min.y || y > box.max.y) {
|
step: resolution,
|
||||||
gridy++;
|
box,
|
||||||
continue;
|
x,
|
||||||
}
|
gridx,
|
||||||
// find tool z at grid point
|
gridy,
|
||||||
tv = toolAtZ(gridx, gridy);
|
clipTo,
|
||||||
// when tabs are on and this point is inside the
|
clipTab,
|
||||||
// tab polygon, ensure z is at least tabHeight
|
tabHeight
|
||||||
if (tabsOn && tv < tabHeight && inClip(clipTab, tv)) {
|
});
|
||||||
tv = tabZ;//tabHeight;
|
|
||||||
}
|
|
||||||
// if the value is on the floor and inside the clip
|
|
||||||
// poly (usually shadow), end the segment
|
|
||||||
if (clipTo && !inClip(clipTo)) {
|
|
||||||
end_poly();
|
|
||||||
gridy++;
|
|
||||||
ly = -gridDelta;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
push_point(x,y,tv);
|
|
||||||
ly = y;
|
|
||||||
ltv = tv;
|
|
||||||
gridy++;
|
|
||||||
}
|
|
||||||
end_poly();
|
|
||||||
if (sliceout.length > 0) {
|
if (sliceout.length > 0) {
|
||||||
newslices.push(slice);
|
slice = newSlice(gridx);
|
||||||
slice.camLines = sliceout;
|
slice.camLines = sliceout;
|
||||||
slice.output()
|
slice.output()
|
||||||
.setLayer("contour y", {face: color, line: color})
|
.setLayer("contour y", {face: color, line: color})
|
||||||
.addPolys(sliceout);
|
.addPolys(sliceout);
|
||||||
|
newslices.push(slice);
|
||||||
}
|
}
|
||||||
onupdate(++stepsTaken, stepsTotal, "contour y");
|
onupdate(++stepsTaken, stepsTotal, "contour y");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contourX) {
|
if (contourX) {
|
||||||
startTime = time();
|
|
||||||
// emit slice per Y
|
// emit slice per Y
|
||||||
for (y = minY - partOff; y <= maxY + partOff; y += toolStep) {
|
for (y = minY - partOff; y <= maxY + partOff; y += toolStep) {
|
||||||
if (y < box.min.y || y > box.max.y) continue;
|
if (y < box.min.y || y > box.max.y) continue;
|
||||||
gridy = Math.round(((y - minY) / boundsY) * stepsY);
|
gridy = Math.round(((y - minY) / boundsY) * stepsY);
|
||||||
lx = gridx = -gridDelta;
|
gridx = -gridDelta;
|
||||||
slice = newSlice(gridy);
|
|
||||||
newtrace = newPolygon().setOpen();
|
traceX({
|
||||||
sliceout = [];
|
from: minX - partOff,
|
||||||
for (x = minX - partOff; x <= maxX + partOff; x += resolution) {
|
to: maxX + partOff,
|
||||||
if (x < box.min.x || x > box.max.x) {
|
step: resolution,
|
||||||
gridx++;
|
box,
|
||||||
continue;
|
y,
|
||||||
}
|
gridx,
|
||||||
tv = toolAtZ(gridx, gridy);
|
gridy,
|
||||||
if (tabsOn && tv < tabHeight && inClip(clipTab, tv)) {
|
clipTo,
|
||||||
tv = tabZ;
|
clipTab,
|
||||||
}
|
tabHeight
|
||||||
if (clipTo && !inClip(clipTo)) {
|
});
|
||||||
end_poly();
|
|
||||||
gridx++;
|
|
||||||
lx = -gridDelta;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
push_point(x,y,tv);
|
|
||||||
lx = x;
|
|
||||||
ltv = tv;
|
|
||||||
gridx++;
|
|
||||||
}
|
|
||||||
end_poly();
|
|
||||||
if (sliceout.length > 0) {
|
if (sliceout.length > 0) {
|
||||||
newslices.push(slice);
|
slice = newSlice(gridy);
|
||||||
slice.camLines = sliceout;
|
slice.camLines = sliceout;
|
||||||
slice.output()
|
slice.output()
|
||||||
.setLayer("contour x", {face: color, line: color})
|
.setLayer("contour x", {face: color, line: color})
|
||||||
.addPolys(sliceout);
|
.addPolys(sliceout);
|
||||||
|
newslices.push(slice);
|
||||||
}
|
}
|
||||||
onupdate(++stepsTaken, stepsTotal, "contour x");
|
onupdate(++stepsTaken, stepsTotal, "contour x");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const box = topo.box = new THREE.Box2();
|
if (topo.raster) {
|
||||||
|
const box = topo.box = new THREE.Box2();
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
resolution,
|
resolution,
|
||||||
curvesOnly,
|
curvesOnly,
|
||||||
flatness,
|
flatness,
|
||||||
stepsY,
|
stepsY,
|
||||||
minY,
|
minY,
|
||||||
maxY,
|
maxY,
|
||||||
zMin,
|
zMin,
|
||||||
data,
|
data,
|
||||||
box
|
box
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.topo_slice(widget, params);
|
onupdate(0, 1, "raster");
|
||||||
|
await this.topo_raster(widget, params);
|
||||||
|
topo.raster = false;
|
||||||
|
}
|
||||||
|
|
||||||
contouring();
|
contouring();
|
||||||
ondone(newslices);
|
ondone(newslices);
|
||||||
|
|
@ -351,10 +400,10 @@ class Topo {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
async topo_slice(widget, params) {
|
async topo_raster(widget, params) {
|
||||||
const { resolution } = params;
|
const { resolution } = params;
|
||||||
|
|
||||||
console.log({ topo_slice: widget, resolution });
|
console.log({ topo_raster: widget, resolution });
|
||||||
|
|
||||||
const dispatch = kiri.worker;
|
const dispatch = kiri.worker;
|
||||||
const minions = kiri.minions;
|
const minions = kiri.minions;
|
||||||
|
|
@ -391,7 +440,7 @@ class Topo {
|
||||||
// define sharded ranges
|
// define sharded ranges
|
||||||
if (minions.running > 1) {
|
if (minions.running > 1) {
|
||||||
|
|
||||||
console.time('new topo slice minion');
|
console.time('topo raster minion');
|
||||||
dispatch.putCache({ key: widget.id, data: vertices }, { done: data => {
|
dispatch.putCache({ key: widget.id, data: vertices }, { done: data => {
|
||||||
// console.log({ put_cache_done: data });
|
// console.log({ put_cache_done: data });
|
||||||
}});
|
}});
|
||||||
|
|
@ -399,7 +448,7 @@ class Topo {
|
||||||
let promises = slices.map((slice, index) => {
|
let promises = slices.map((slice, index) => {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
minions.queue({
|
minions.queue({
|
||||||
cmd: "topo_slice",
|
cmd: "topo_raster",
|
||||||
id: widget.id,
|
id: widget.id,
|
||||||
params,
|
params,
|
||||||
slice
|
slice
|
||||||
|
|
@ -424,11 +473,11 @@ class Topo {
|
||||||
dispatch.clearCache({}, { done: data => {
|
dispatch.clearCache({}, { done: data => {
|
||||||
// console.log({ clear_cache_done: data });
|
// console.log({ clear_cache_done: data });
|
||||||
}});
|
}});
|
||||||
console.timeEnd('new topo slice minion');
|
console.timeEnd('topo raster minion');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
console.time('new topo slice');
|
console.time('topo raster');
|
||||||
// iterate over shards, merge output
|
// iterate over shards, merge output
|
||||||
// const output = [];
|
// const output = [];
|
||||||
for (let slice of slices) {
|
for (let slice of slices) {
|
||||||
|
|
@ -456,7 +505,7 @@ class Topo {
|
||||||
return slice;
|
return slice;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.timeEnd('new topo slice');
|
console.timeEnd('topo raster');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -470,7 +519,7 @@ function raster_slice(inputs) {
|
||||||
let gridy,
|
let gridy,
|
||||||
gridi, // index
|
gridi, // index
|
||||||
gridv, // value
|
gridv, // value
|
||||||
i, il, j, jl, x, y, tv, ltv;
|
i, il, j, x, y, tv;
|
||||||
|
|
||||||
// filter lines pairs to only surface "up-facing", "uncovered" lines
|
// filter lines pairs to only surface "up-facing", "uncovered" lines
|
||||||
let points = [];
|
let points = [];
|
||||||
|
|
@ -561,7 +610,7 @@ moto.broker.subscribe("minion.started", msg => {
|
||||||
// console.log({ cam_slicer2_minion: msg });
|
// console.log({ cam_slicer2_minion: msg });
|
||||||
const { funcs, cache, reply, log } = msg;
|
const { funcs, cache, reply, log } = msg;
|
||||||
|
|
||||||
funcs.topo_slice = (data, seq) => {
|
funcs.topo_raster = (data, seq) => {
|
||||||
const { id, slice, params } = data;
|
const { id, slice, params } = data;
|
||||||
const { resolution } = params;
|
const { resolution } = params;
|
||||||
const vertices = cache[id];
|
const vertices = cache[id];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue