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

Pass additional data to level set SDF function #427

Merged
merged 7 commits into from
Jul 13, 2023

Conversation

harmanpa
Copy link
Contributor

@harmanpa harmanpa commented May 7, 2023

Please consider this or something similar for the SDF function when calling level set from the C bindings.

This allows a developer to pass some context to the level set function, such as a pointer to an object in the host language, so that parallel calls can be threadsafe.

@google-cla
Copy link

google-cla bot commented May 7, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@pca006132 pca006132 requested a review from geoffder May 7, 2023 16:30
@geoffder
Copy link
Collaborator

geoffder commented May 7, 2023

What is the additional context being used for, could you give an example? Typically an sdf should be a pure computation from a point in space to a distance, so no synchronization should be required.

@codecov
Copy link

codecov bot commented May 7, 2023

Codecov Report

Patch coverage has no change and project coverage change: +90.35 🎉

Comparison is base (8b7bf42) 0.00% compared to head (1a749fa) 90.35%.

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #427       +/-   ##
===========================================
+ Coverage        0   90.35%   +90.35%     
===========================================
  Files           0       35       +35     
  Lines           0     4396     +4396     
===========================================
+ Hits            0     3972     +3972     
- Misses          0      424      +424     

see 35 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@pca006132
Copy link
Collaborator

Perhaps he wants to implement closure as a function + object that contains values of captured variables, so he wants a way of passing that object into the call.

@harmanpa
Copy link
Contributor Author

harmanpa commented May 7, 2023

In our case it is for Java bindings, it would be a struct with the methodid and objectid

@geoffder
Copy link
Collaborator

geoffder commented May 7, 2023

Sorry I'm not really familiar with Java, but if you are able to pass a function pointer that interacts with the provided object pointer, why can't the function whose pointer is being passed do the work (calculating distance)? The function can't have captured variables (even if they are read only)?

@harmanpa
Copy link
Contributor Author

harmanpa commented May 7, 2023

Only if we have a single static function, so it would need a blocking mechanism (in Java or C) to handle the possibility of more than 1 level-set function being called concurrently. Passing an extra pointer is a normal pattern with numerical solvers in C/Fortran, it's not just a Java-specific request.

@pca006132
Copy link
Collaborator

Not familiar with Java as well, but this is a standard way of implementing OOP and functions with captured variables in C.
https://stackoverflow.com/a/351745

@geoffder
Copy link
Collaborator

geoffder commented May 7, 2023

As in calling level_set multiple times concurrently with the same closure? I hadn't really thought of that as a possibility. Anyway, I'm not opposed to it, just trying to understand this gap in my support of patterns in other languages wrt closures. I think that some comments noting intended/potential uses/when you'd need it would help future users to decide whether they are fine with the basic or context added version.

Would level_set_context, with the argument named ctx be clearer?

@harmanpa
Copy link
Contributor Author

harmanpa commented May 7, 2023

As in calling level_set multiple times concurrently with the same closure?

Yes.

Would level_set_context, with the argument named ctx be clearer?

Yes that sounds better.

@elalish
Copy link
Owner

elalish commented May 8, 2023

I don't have a strong opinion on this - I leave it to @pca006132 or @geoffder to approve. Can you sign the CLA? It's pretty generic, but unfortunately required.

@geoffder
Copy link
Collaborator

@harmanpa Are you planning to update this with the renaming and add a comment describing what the intended purpose of the new function is (vs the regular manifold_level_set as discussed above? Also, to pass the CI the changes should be run through an autoformat (whatever the default is with the clangd lsp works for me).

@harmanpa
Copy link
Contributor Author

Yes I do intend to @geoffder , sorry I've been travelling, also weirdly Google rejected my CLA signing so I need to do that again

@elalish
Copy link
Owner

elalish commented Jun 10, 2023

@harmanpa Any luck with the CLA? I happy to help if you're having trouble.

@harmanpa
Copy link
Contributor Author

@elalish CLA is sorted now, thank you :-)

@geoffder I've pushed updated header/implementation, could you take a look please?

There is one conflict reported by github: the #include <cstdint> in manifoldc.h should be inside the #ifdef __cplusplus so I moved it, it seems git sees that as a conflict.

@geoffder
Copy link
Collaborator

geoffder commented Jul 13, 2023

I resolved the conflict, but manifoldc.cpp is failing the clang linter. Otherwise, I think this looks good.

@geoffder geoffder merged commit da3f323 into elalish:master Jul 13, 2023
@geoffder
Copy link
Collaborator

Thanks!

@elalish elalish mentioned this pull request Nov 3, 2023
cartesian-theatrics pushed a commit to SovereignShop/manifold that referenced this pull request Mar 11, 2024
)

Allows a developer to pass some context to the level set function in the C FFI bindings, such as a pointer to an object in the host language, so that parallel calls can be threadsafe.
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.

4 participants