1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 14:18:13 +01:00

flat isolines/isobands

This commit is contained in:
Justin Lin 2020-03-24 07:27:29 +08:00
parent 3921f5c7fc
commit 5c37382c26
5 changed files with 35 additions and 47 deletions

View File

@ -118,10 +118,8 @@ module image_slicer(levels, level_step, contour_width) {
module contours(points, z, contour_width) {
union() {
for(row = marching_squares(points, [0, z])) {
for(iso_band = row) {
polygon([for(p = iso_band) [p[0], p[1]]]);
}
for(iso_band = marching_squares(points, [0, z])) {
polygon([for(p = iso_band) [p[0], p[1]]]);
}
}
}

View File

@ -110,20 +110,18 @@ function _isolines_of(cell_pts, sigma) =
function _marching_squares_isolines(points, sigma) =
let(labeled_pts = _isolines_pn_label(points, sigma))
[
for(y = [0:len(labeled_pts) - 2])
[
for(x = [0:len(labeled_pts[0]) - 2])
let(
p0 = labeled_pts[y][x],
p1 = labeled_pts[y + 1][x],
p2 = labeled_pts[y + 1][x + 1],
p3 = labeled_pts[y][x + 1],
cell_pts = [p0, p1, p2, p3],
isolines_lt = _isolines_of(cell_pts, sigma)
)
if(isolines_lt != [])
each isolines_lt
]
for(y = [0:len(labeled_pts) - 2])
for(x = [0:len(labeled_pts[0]) - 2])
let(
p0 = labeled_pts[y][x],
p1 = labeled_pts[y + 1][x],
p2 = labeled_pts[y + 1][x + 1],
p3 = labeled_pts[y][x + 1],
cell_pts = [p0, p1, p2, p3],
isolines_lt = _isolines_of(cell_pts, sigma)
)
if(isolines_lt != [])
each isolines_lt
];
/*
@ -940,7 +938,7 @@ function _case2010_isobands(cell_pts, lower, upper) =
function _isobands_of(cell_pts, lower, upper) =
let(cv = _isobands_corner_value(cell_pts))
// no contour
cv == "0000" ? [] :
cv == "0000" || cv == "2222" ? [] :
// single square
cv == "1111" ? [[for(i = 3; i >= 0; i = i - 1) [cell_pts[i][0], cell_pts[i][1]]]] :
// single triangle
@ -1026,27 +1024,23 @@ function _isobands_of(cell_pts, lower, upper) =
cv == "1202" ? _case1202_isobands(cell_pts, lower, upper) :
cv == "1020" ? _case1020_isobands(cell_pts, lower, upper) :
cv == "0212" ? _case0212_isobands(cell_pts, lower, upper) :
cv == "2010" ? _case2010_isobands(cell_pts, lower, upper) :
// no contour
[]; // 2222
_case2010_isobands(cell_pts, lower, upper);
function _marching_squares_isobands(points, lower, upper) =
let(labeled_pts = _isobands_tri_label(points, lower, upper))
[
for(y = [0:len(labeled_pts) - 2])
[
for(x = [0:len(labeled_pts[0]) - 2])
let(
p0 = labeled_pts[y][x],
p1 = labeled_pts[y + 1][x],
p2 = labeled_pts[y + 1][x + 1],
p3 = labeled_pts[y][x + 1],
cell_pts = [p0, p1, p2, p3],
isobands_lt = _isobands_of(cell_pts, lower, upper)
)
if(isobands_lt != [])
each isobands_lt
]
for(x = [0:len(labeled_pts[0]) - 2])
let(
p0 = labeled_pts[y][x],
p1 = labeled_pts[y + 1][x],
p2 = labeled_pts[y + 1][x + 1],
p3 = labeled_pts[y][x + 1],
cell_pts = [p0, p1, p2, p3],
isobands_lt = _isobands_of(cell_pts, lower, upper)
)
if(isobands_lt != [])
each isobands_lt
];
/*

View File

@ -11,14 +11,11 @@ points = [
];
for(row = marching_squares(points, 0.1)) {
for(isoline = row) {
hull_polyline2d(isoline, width = .1);
}
for(isoline = marching_squares(points, 0.1)) {
hull_polyline2d(isoline, width = .1);
}
translate([12, 0]) for(row = marching_squares(points, [-.2, .2])) {
for(isoband = row) {
polygon([for(p = isoband) [p[0], p[1]]]);
}
translate([12, 0])
for(isoband = marching_squares(points, [-.2, .2])) {
polygon([for(p = isoband) [p[0], p[1]]]);
}

View File

@ -111,9 +111,7 @@ points = [
];
for(z = [0:40:255]) {
for(row = marching_squares(points, z)) {
for(isoline = row) {
hull_polyline2d(isoline, width = .25);
}
for(isoline = marching_squares(points, z)) {
hull_polyline2d(isoline, width = .25);
}
}

View File

@ -27,6 +27,7 @@ Preview
- `util/dedup`
- `util/bsearch`
- `util/sort` supports `by = "vt"`
- `shape_circle`
Bugfixes:
- `helix_extrude`: wrong orientation when CLK