fix layer fingerprinting for some geometries. gyroid test options
This commit is contained in:
parent
4d697e1cd2
commit
fe8de60f58
3 changed files with 90 additions and 34 deletions
|
|
@ -834,6 +834,7 @@ var gs_base_polygons = exports;
|
||||||
}).forEach(p => {
|
}).forEach(p => {
|
||||||
finger.push(p.area());
|
finger.push(p.area());
|
||||||
finger.push(p.perimeter());
|
finger.push(p.perimeter());
|
||||||
|
finger.push(p.bounds);
|
||||||
});
|
});
|
||||||
return finger;
|
return finger;
|
||||||
}
|
}
|
||||||
|
|
@ -848,13 +849,19 @@ var gs_base_polygons = exports;
|
||||||
if (a.length !== b.length) {
|
if (a.length !== b.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (let i=0; i<a.length; i += 2) {
|
for (let i=0; i<a.length; i += 3) {
|
||||||
if (Math.abs(a[i] - b[i]) > 0.001) {
|
if (Math.abs(a[i] - b[i]) > 0.001) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Math.abs(a[i+1] - b[i+1]) > 0.0001) {
|
if (Math.abs(a[i+1] - b[i+1]) > 0.0001) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (Math.abs(a[i+2].centerx() - b[i+2].centerx()) > 0.0001) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Math.abs(a[i+2].centery() - b[i+2].centery()) > 0.0001) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
notes.md
1
notes.md
|
|
@ -30,6 +30,7 @@
|
||||||
* `F` option to support interior bridges when 0% infill
|
* `F` option to support interior bridges when 0% infill
|
||||||
* `P` disable infill fingerprinting for gyroids
|
* `P` disable infill fingerprinting for gyroids
|
||||||
* `P` refactor thin fill to use outline and inside poly normal dist to self
|
* `P` refactor thin fill to use outline and inside poly normal dist to self
|
||||||
|
* `P` segment large polygons for extremely large parts / infill
|
||||||
|
|
||||||
# SLA
|
# SLA
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,17 @@
|
||||||
min-width: 3px;
|
min-width: 3px;
|
||||||
min-height: 3px;
|
min-height: 3px;
|
||||||
}
|
}
|
||||||
#stats {
|
#stats,#opts {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
#stats {
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
#stats > input {
|
#stats > input {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
width: 5em;
|
width: 5em;
|
||||||
|
background-color: #eee;
|
||||||
}
|
}
|
||||||
svg {
|
svg {
|
||||||
border: 1px solid #888;
|
border: 1px solid #888;
|
||||||
|
|
@ -97,33 +101,32 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
class Grid {
|
class Grid {
|
||||||
constructor(x,y,div) {
|
constructor(size,div) {
|
||||||
this.x = (x/div)|0;
|
this.size = (size/div)|0;
|
||||||
this.y = (y/div)|0;
|
|
||||||
this.div = div;
|
this.div = div;
|
||||||
this.grid = new Array(this.x * this.y);
|
this.grid = new Array(div * div);
|
||||||
}
|
}
|
||||||
|
|
||||||
get(x,y) {
|
get(x,y) {
|
||||||
x = (x/this.div)|0;
|
x = (x/this.size)|0;
|
||||||
y = (y/this.div)|0;
|
y = (y/this.size)|0;
|
||||||
let pos = x + y * this.x;
|
let pos = x + y * this.size;
|
||||||
let rec = this.grid[pos];
|
let rec = this.grid[pos];
|
||||||
if (rec) return rec;
|
if (rec) return rec;
|
||||||
return this.grid[pos] = [];
|
return this.grid[pos] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
_get(x,y) {
|
_get(x,y) {
|
||||||
if (x < 0 || y < 0 || x > this.x || y > this.y) return undefined;
|
if (x < 0 || y < 0 || x > this.size || y > this.size) return undefined;
|
||||||
return this.grid[x + y * this.x];
|
return this.grid[x + y * this.size];
|
||||||
}
|
}
|
||||||
|
|
||||||
peers(x,y) {
|
peers(x,y) {
|
||||||
let grid = this.grid;
|
let grid = this.grid;
|
||||||
let r = this.x;
|
let r = this.x;
|
||||||
// console.log('peers',x,y)
|
// console.log('peers',x,y)
|
||||||
x = (x/this.div)|0;
|
x = (x/this.size)|0;
|
||||||
y = (y/this.div)|0;
|
y = (y/this.size)|0;
|
||||||
let peers = [], p;
|
let peers = [], p;
|
||||||
p = this._get(x,y); if (p) peers.push(p);
|
p = this._get(x,y); if (p) peers.push(p);
|
||||||
p = this._get(x-1,y); if (p) peers.push(p);
|
p = this._get(x-1,y); if (p) peers.push(p);
|
||||||
|
|
@ -145,17 +148,48 @@
|
||||||
let zcache = {};
|
let zcache = {};
|
||||||
let timer = new Timer();
|
let timer = new Timer();
|
||||||
let maxdist = rez * 0.01;
|
let maxdist = rez * 0.01;
|
||||||
let fast = false;
|
let fast = true;
|
||||||
|
let tip = 0.2;
|
||||||
|
|
||||||
function $(id) {
|
function $(id) {
|
||||||
return document.getElementById(id);
|
return document.getElementById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
let opt = document.location.search.substring(1).split('&').map(v => {
|
||||||
|
return v.split('=').map(v => decodeURIComponent(v));
|
||||||
|
}).reduce( (m,v) => {
|
||||||
|
m[v[0]] = v[1];
|
||||||
|
return m;
|
||||||
|
}, {});
|
||||||
|
function reload() {
|
||||||
|
opt.speed = $('fast').checked ? 'fast' : 'slow';
|
||||||
|
opt.caps = $('caps').checked ? 1 : 0;
|
||||||
|
opt.raw = $('raw').checked ? 1 : 0;
|
||||||
|
let search = [];
|
||||||
|
Object.entries(opt).forEach((k,v) => {
|
||||||
|
search.push(encodeURIComponent(k[0]) + '=' + encodeURIComponent(k[1]));
|
||||||
|
});
|
||||||
|
document.location.search = search.join('&');
|
||||||
|
};
|
||||||
|
$('offset').onkeypress = (ev) => {
|
||||||
|
if (ev.key === 'Enter') {
|
||||||
|
opt.offset = $('offset').value;
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$('offset').focus();
|
||||||
|
if (opt.offset) tip = $('offset').value = (parseFloat(opt.offset) || 0);
|
||||||
|
if (opt.raw) $('raw').checked = opt.raw === 1;
|
||||||
|
if (opt.caps) $('caps').checked = opt.caps === 1;
|
||||||
|
$('fast').checked = fast = opt.speed !== 'slow';
|
||||||
|
$('fast').onchange = reload;
|
||||||
|
$('raw').onchange = update;
|
||||||
|
$('caps').onchange = update;
|
||||||
$('zval').max = rez;
|
$('zval').max = rez;
|
||||||
let mark = Date.now();
|
let mark = Date.now();
|
||||||
for (let z=0; z<PI2; z += inc) {
|
for (let z=0, zi=0; z<PI2; z += inc) {
|
||||||
generate(z);
|
generate(z, zi++);
|
||||||
}
|
}
|
||||||
console.log(Date.now() - mark, timer.toString());
|
console.log(Date.now() - mark, timer.toString());
|
||||||
render(0);
|
render(0);
|
||||||
|
|
@ -166,7 +200,7 @@
|
||||||
render((z / rez) * PI2);
|
render((z / rez) * PI2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function generate(z) {
|
function generate(z,zi) {
|
||||||
let zkey = z.toFixed(8);
|
let zkey = z.toFixed(8);
|
||||||
let cached = zcache[zkey];
|
let cached = zcache[zkey];
|
||||||
|
|
||||||
|
|
@ -181,15 +215,21 @@
|
||||||
let points = 0;
|
let points = 0;
|
||||||
let points_lr = 0;
|
let points_lr = 0;
|
||||||
let points_td = 0;
|
let points_td = 0;
|
||||||
let tip = 0.2;
|
|
||||||
let xv = 0;
|
let xv = 0;
|
||||||
|
let sin = new Float32Array(size);
|
||||||
|
let cos = new Float32Array(size);
|
||||||
|
for (let i=0, iv=0; i<size; i++) {
|
||||||
|
sin[i] = Math.sin(iv);
|
||||||
|
cos[i] = Math.cos(iv);
|
||||||
|
iv += inc;
|
||||||
|
}
|
||||||
for (let x=0; x<size; x++) {
|
for (let x=0; x<size; x++) {
|
||||||
let yv = 0;
|
let yv = 0;
|
||||||
for (let y=0; y<size; y++) {
|
for (let y=0; y<size; y++) {
|
||||||
vals.put(x,y,
|
vals.put(x,y,
|
||||||
Math.sin(xv) * Math.cos(yv) +
|
sin[x] * cos[y] +
|
||||||
Math.sin(yv) * Math.cos(z) +
|
sin[y] * cos[zi] +
|
||||||
Math.sin(z) * Math.cos(xv)
|
sin[zi] * cos[x]
|
||||||
);
|
);
|
||||||
yv += inc;
|
yv += inc;
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +246,6 @@
|
||||||
(v0 <= tip && v1 >= tip) || (v0 >= tip && v1 <= tip) ||
|
(v0 <= tip && v1 >= tip) || (v0 >= tip && v1 <= tip) ||
|
||||||
(v0 <= -tip && v1 >= -tip) || (v0 >= -tip && v1 <= -tip)
|
(v0 <= -tip && v1 >= -tip) || (v0 >= -tip && v1 <= -tip)
|
||||||
) {
|
) {
|
||||||
// if ((v0 <= 0 && v1 >= 0) || (v0 >= 0 && v1 <= 0)) {
|
|
||||||
edge.put(x,y,1);
|
edge.put(x,y,1);
|
||||||
points++;
|
points++;
|
||||||
points_lr++;
|
points_lr++;
|
||||||
|
|
@ -224,7 +263,6 @@
|
||||||
(v0 <= tip && v1 >= tip) || (v0 >= tip && v1 <= tip) ||
|
(v0 <= tip && v1 >= tip) || (v0 >= tip && v1 <= tip) ||
|
||||||
(v0 <= -tip && v1 >= -tip) || (v0 >= -tip && v1 <= -tip)
|
(v0 <= -tip && v1 >= -tip) || (v0 >= -tip && v1 <= -tip)
|
||||||
) {
|
) {
|
||||||
// if ((v0 <= 0 && v1 >= 0) || (v0 >= 0 && v1 <= 0)) {
|
|
||||||
if (edge.get(x,y)) {
|
if (edge.get(x,y)) {
|
||||||
edge.put(x,y,3);
|
edge.put(x,y,3);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -243,7 +281,7 @@
|
||||||
// create sparse representation
|
// create sparse representation
|
||||||
let sparse = [];
|
let sparse = [];
|
||||||
let center = rez / 2;
|
let center = rez / 2;
|
||||||
let grid = new Grid(size,size,10);
|
let grid = new Grid(size,10);
|
||||||
for (let x=0; x<size; x++) {
|
for (let x=0; x<size; x++) {
|
||||||
for (let y=0; y<size; y++) {
|
for (let y=0; y<size; y++) {
|
||||||
let val = edge.get(x,y);
|
let val = edge.get(x,y);
|
||||||
|
|
@ -295,7 +333,7 @@
|
||||||
let cl_dst = Infinity; // candidate distance
|
let cl_dst = Infinity; // candidate distance
|
||||||
// look for next closest point to end of chain\
|
// look for next closest point to end of chain\
|
||||||
if (fast) {
|
if (fast) {
|
||||||
let peers = grid.peers(target.x,target.y);
|
let peers = grid.peers(target.x, target.y);
|
||||||
if (peers.length === 0) break;
|
if (peers.length === 0) break;
|
||||||
for (let ps=0, psl=peers.length; ps<psl; ps++) {
|
for (let ps=0, psl=peers.length; ps<psl; ps++) {
|
||||||
let peera = peers[ps];
|
let peera = peers[ps];
|
||||||
|
|
@ -394,13 +432,16 @@
|
||||||
$('polys').value = polys.length;
|
$('polys').value = polys.length;
|
||||||
|
|
||||||
// raw threshold points
|
// raw threshold points
|
||||||
html.push('<g>');
|
if ($('raw').checked) {
|
||||||
raw.forEach(point => {
|
html.push('<g>');
|
||||||
let x = point.x;
|
raw.forEach(point => {
|
||||||
let y = point.y;
|
let x = point.x;
|
||||||
let color = ['black','#f00a','#0f0a','#00fa'][point.val];
|
let y = point.y;
|
||||||
html.push(`<rect dist="${point.dist}" x="${x*wh}" y="${y*wh}" width="${wh}" height="${wh}" style="fill:${color};stroke-width:0"/>`);
|
let color = ['black','#f00a','#0f0a','#00fa'][point.val];
|
||||||
})
|
html.push(`<rect dist="${point.dist}" x="${x*wh}" y="${y*wh}" width="${wh}" height="${wh}" style="fill:${color};stroke-width:0"/>`);
|
||||||
|
})
|
||||||
|
html.push('</g>');
|
||||||
|
}
|
||||||
// polys.forEach(poly => {
|
// polys.forEach(poly => {
|
||||||
// poly.forEach(point => {
|
// poly.forEach(point => {
|
||||||
// let x = point.x;
|
// let x = point.x;
|
||||||
|
|
@ -409,7 +450,6 @@
|
||||||
// html.push(`<rect dist="${point.dist}" x="${x*wh}" y="${y*wh}" width="${wh}" height="${wh}" style="fill:${color};stroke-width:0"/>`);
|
// html.push(`<rect dist="${point.dist}" x="${x*wh}" y="${y*wh}" width="${wh}" height="${wh}" style="fill:${color};stroke-width:0"/>`);
|
||||||
// });
|
// });
|
||||||
// });
|
// });
|
||||||
html.push('</g>');
|
|
||||||
|
|
||||||
// points joined into poly lines
|
// points joined into poly lines
|
||||||
html.push('<g>');
|
html.push('<g>');
|
||||||
|
|
@ -419,7 +459,9 @@
|
||||||
.join(',')).join(' ');
|
.join(',')).join(' ');
|
||||||
let x = poly[0].x - 1;
|
let x = poly[0].x - 1;
|
||||||
let y = poly[0].y - 1;
|
let y = poly[0].y - 1;
|
||||||
html.push(`<rect x="${x*wh}" y="${y*wh}" width="${wh*3}" height="${wh*3}" style="fill:#f0f5;stroke-width:0"/>`);
|
if ($('caps').checked) {
|
||||||
|
html.push(`<rect x="${x*wh}" y="${y*wh}" width="${wh*3}" height="${wh*3}" style="fill:#f0f5;stroke-width:0"/>`);
|
||||||
|
}
|
||||||
html.push(`<polyline points="${points}"/ fill="none" stroke="black" />`);
|
html.push(`<polyline points="${points}"/ fill="none" stroke="black" />`);
|
||||||
});
|
});
|
||||||
html.push('</g>');
|
html.push('</g>');
|
||||||
|
|
@ -434,6 +476,12 @@
|
||||||
<div id="test">
|
<div id="test">
|
||||||
<div id="gyroid"></div>
|
<div id="gyroid"></div>
|
||||||
<input id="zval" type="range" min="0" max="200" value="0" oninput="update()"/>
|
<input id="zval" type="range" min="0" max="200" value="0" oninput="update()"/>
|
||||||
|
<div id="opts">
|
||||||
|
<input id="offset" size="5" value="0.2">offset
|
||||||
|
<input id="raw" type="checkbox" checked>raw
|
||||||
|
<input id="caps" type="checkbox" checked>caps
|
||||||
|
<input id="fast" type="checkbox" checked>fast
|
||||||
|
</div>
|
||||||
<div id="stats">
|
<div id="stats">
|
||||||
<input id="points"></input>
|
<input id="points"></input>
|
||||||
<input id="direction"></input>
|
<input id="direction"></input>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue