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

Help request #2

Closed
taori opened this issue Sep 30, 2021 · 6 comments
Closed

Help request #2

taori opened this issue Sep 30, 2021 · 6 comments

Comments

@taori
Copy link

taori commented Sep 30, 2021

Hello!

Randomly stumbled upon your implementation while researching about naive surface nets. I was wondering whether you would be able to spare some time to answer some questions for implementing your algorithm in C#. I have no experience with rust, so i figured i would just ask. I have seen a lot of algorithms by now, but yours appears to be one of the cleanest ones i have seen

Anyways - great article and thanks a lot for the work you put into this!

@bonsairobo
Copy link
Owner

@taori Yea I'd be happy to help. I've never written a single line of C#, so you will have to interpret what I say :)

@bonsairobo
Copy link
Owner

Yea I guess just post whatever questions you have here and we can do a little virtual Q&A. Probably a good idea to preserve the discussion in this issue.

@taori
Copy link
Author

taori commented Oct 1, 2021

Thanks for doing this! Would be cool to finally have an algorithm to play around with that is comprehensible :)

After starting the c# implementation i ran into my first question:

I understand that this is rusts way of expressing generics - for a standalone function. I assume the meaning of the following lines

sdf: &[T],
shape: &S,

means that &S is just a pointer to a given object - But what is the meaning of &[T] ? Is it a callback to a function to evaluate a flat array of signed values? or is it just a pointer to an array (or something completely different)?

Also the min and max parameters to me seemed to be like the min/max xyz coordinate of where to start/end the mesh extraction, but in the code sample i saw this: [0; 3], [17; 3] - does this essentially mean from (0,0,0) to (17,17,17) or am i misinterpreting the syntax?

Also a brief explanation would be useful to explain what the ndshape functions do. As far as i can tell that is a library of yours? I have a hunch that linearize flattens a multidimensional array which is what shape is, yes?

Sorry if my questions seem silly. Like you have not written a single line of C#, i have never really touched rust yet.

@bonsairobo
Copy link
Owner

&S is a pointer to any type that implements the Shape<u32, 3> trait. That means it describes a 3D array shape. This trait comes from the ndshape crate, which provides some simple math functions for indexing N-dimensional arrays.

&[T] is an immutably borrowed slice of T elements. A slice is effectively a fat pointer (a memory address and a length). So this is the slice of memory that contains the SDF values.

Also the min and max parameters to me seemed to be like the min/max xyz coordinate of where to start/end the mesh extraction, but in the code sample i saw this: [0; 3], [17; 3] - does this essentially mean from (0,0,0) to (17,17,17) or am i misinterpreting the syntax?

You are correct. The shape of the array is 18^3 and that [min, max] range covers the entire array.

Also a brief explanation would be useful to explain what the ndshape functions do. As far as i can tell that is a library of yours? I have a hunch that linearize flattens a multidimensional array which is what shape is, yes?

Yea it's a pretty simple library that provides functions for converting 2D, 3D, and 4D integer vectors into 1D offsets for array indexing. This process is known as "linearization." So it's not actually doing anything to the array, but it lets you address a linear array as if it were laid out for 3D. I mainly do it this way because Rust's N-dimensional array types, e.g. [[[T; 16]; 16]; 16] are actually significantly slower to index than a single-dimensional array. I've benchmarked it.

@taori
Copy link
Author

taori commented Oct 1, 2021

Okay. Let's see how far i can get with this :) Thanks for your current reply!

@bonsairobo
Copy link
Owner

No recent activity, going to close.

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

No branches or pull requests

2 participants