Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heightfield() output fails vnf_validate() #1345

Closed
RAMilewski opened this issue Jan 14, 2024 · 6 comments · Fixed by #1429
Closed

Heightfield() output fails vnf_validate() #1345

RAMilewski opened this issue Jan 14, 2024 · 6 comments · Fixed by #1429

Comments

@RAMilewski
Copy link
Contributor

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
Copy link
Contributor Author

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

@RAMilewski
Copy link
Contributor Author

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

@RAMilewski
Copy link
Contributor Author

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

@revarbat
Copy link
Collaborator

revarbat commented Mar 14, 2024

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
Copy link
Collaborator

revarbat commented Mar 14, 2024

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
Copy link
Collaborator

revarbat commented Mar 14, 2024

Something like:

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

@adrianVmariano adrianVmariano linked a pull request May 20, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants