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

Adding thresholding option to matrix_to_marching_cubes() #2320

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

bhacha
Copy link
Contributor

@bhacha bhacha commented Nov 5, 2024

I found that it was a bit of an annoying pre-processing step to convert my numpy arrays to Boolean arrays before using the ops.matrix_to_marching_cubes function. I think adding an optional arg for setting a threshold could be a quality of life improvement.

In this implementation 'threshold' is None by default but if a float or int is passed, that value is used to binarize the input matrix. It converts every Element > Threshold to True and then works the same way as the existing version of the function.

@mikedh mikedh changed the base branch from main to test/iteration November 8, 2024 18:52
@mikedh mikedh merged commit 3dbde01 into mikedh:test/iteration Nov 8, 2024
3 of 9 checks passed
@mikedh
Copy link
Owner

mikedh commented Nov 8, 2024

Awesome thanks for the PR!!

One numpy "gotcha" is that numpy integers and floats aren't always instances of Python integers and floats. I changed the check to threshold is None, or you can also do isinstance(item, (int, np.integer, float, np.floating)). This should be released in #2319

In [3]: a = np.zeros(10, dtype=np.int32)[0]

In [4]: isinstance(a, int)
Out[4]: False

In [5]: isinstance(a, (int, np.integer))
Out[5]: True

In [7]: isinstance(10, (int, np.integer, float, np.floating))
Out [7]: True

@mikedh mikedh mentioned this pull request Nov 8, 2024
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 this pull request may close these issues.

2 participants