mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-12 09:44:16 +02:00
refactor
This commit is contained in:
@@ -116,23 +116,34 @@ module image_slicer(levels, level_step, contour_width) {
|
|||||||
|
|
||||||
max_h = (floor(255 / level_step) + 1) * level_step;
|
max_h = (floor(255 / level_step) + 1) * level_step;
|
||||||
|
|
||||||
|
module contour_lines(points, z, contour_width) {
|
||||||
|
for(row = marching_squares(points, z)) {
|
||||||
|
for(line = row) {
|
||||||
|
hull_polyline2d(line, width = contour_width);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Even though we can calculate isobands using [the algorithm](https://en.wikipedia.org/wiki/Marching_squares#Isoband),
|
||||||
|
it's easier to fill pixels when the z value of the point is lower than the z parameter.
|
||||||
|
*/
|
||||||
|
module simple_isobands(points, z) {
|
||||||
|
for(row = points) {
|
||||||
|
for(p = row) {
|
||||||
|
if(p[2] < z) {
|
||||||
|
translate([p[0], p[1]])
|
||||||
|
square(1, center = true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(z = [level_step:level_step:255]) {
|
for(z = [level_step:level_step:255]) {
|
||||||
render()
|
|
||||||
linear_extrude((max_h - z) / level_step)
|
linear_extrude((max_h - z) / level_step)
|
||||||
union() {
|
union() {
|
||||||
for(row = marching_squares(points, z)) {
|
contour_lines(points, z, contour_width);
|
||||||
for(line = row) {
|
simple_isobands(points, z);
|
||||||
hull_polyline2d(line, width = contour_width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(row = points) {
|
|
||||||
for(p = row) {
|
|
||||||
if(p[2] < z) {
|
|
||||||
translate([p[0], p[1]])
|
|
||||||
square(1, center = true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user