BOSL2 icon indicating copy to clipboard operation
BOSL2 copied to clipboard

Heightfield() output fails vnf_validate()

Open RAMilewski opened this issue 1 year ago • 6 comments
trafficstars

20x20

Running the 20x20 pixel png above through img2scad.py generates this file:

20x20S.txt (I changed the extension from .scad to .txt because GitHub refuses to load .scad files here.)

include <BOSL2/std.scad>
include <tex/20x20S.scad>

vnf =   heightfield(custom, size = [20,20], bottom = 0, maxz = 1);
vnf_validate(vnf);

...results in: Screenshot 2024-01-13 at 4 59 46 PM ...and the following console messages: validate_messages.txt

It also appears that the rendering attempt is not symmetrical while the input png is.

RAMilewski avatar Jan 14 '24 01:01 RAMilewski

This probably argues for deprecating heightfield() and replacing it with the textured cuboid top described in the comments in #1346

RAMilewski avatar Jan 17 '24 23:01 RAMilewski

It does pass however if you set bottom < 0. ...even by as little as -1e-12.

RAMilewski avatar Mar 04 '24 23:03 RAMilewski

After some testing it appears that the resulting heighfield is invalid if any data point exactly matches the bottom argument.

include <BOSL2/std.scad>
bottom =9;
maxz = 10;
data = [
    [ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,  ],
    [ 8, 12, 12, 12, 12, 12, 12, 12, 12, 8, ],
    [ 8, 12, 8, 8, 8, 8, 8, 8, 12, 8,  ],
    [ 8, 12, 8, 8, 8, 8, 8, 8, 12, 8,  ],
    [ 8, 12, 8, 8, 8, 9, 8, 8, 12, 8,  ],
    [ 8, 12, 8, 8, 8, 8, 8, 8, 12, 8,  ],
    [ 8, 12, 8, 8, 8, 8, 8, 8, 12, 8,  ],
    [ 8, 12, 8, 8, 8, 8, 8, 8, 12, 8,  ],
    [ 8, 12, 12, 12, 12, 12, 12, 12, 12, 8,  ],
    [ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,  ],
   
];

vnf = heightfield(data, size = [10,10], bottom = bottom, maxz = maxz);
vnf_validate(vnf);
Screenshot 2024-03-08 at 12 06 40 PM

RAMilewski avatar Mar 08 '24 20:03 RAMilewski

First, giving a size=0.1 argument to vnf_validate() will make much smaller purple balls in that rendering.

Second, if you view that in Thrown Together mode, you'll see that way more than the one point at z==9 is bad. You have the bottom set higher than the lowest datums, which makes a bad polyhedron. This admittedly should assert an error. But basically this is an issue of Garbage-In, Garbage Out.

Screenshot 2024-03-13 at 5 59 56 PM

revarbat avatar Mar 14 '24 01:03 revarbat

Mind you, if I were to rewrite this now, I'd have the bottom always at 0, and have two arguments that would define the minimum and maximum expected input values, and two more to define the high and low heights those would map to.

revarbat avatar Mar 14 '24 01:03 revarbat

Something like:

heightfield(data/fn, minval=0, maxval=255, minz=1, maxz=10, size=[100,100]);

revarbat avatar Mar 14 '24 01:03 revarbat