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

error in poisson surface reconstruction edge case #111

Open
itsvismay opened this issue Dec 28, 2023 · 2 comments
Open

error in poisson surface reconstruction edge case #111

itsvismay opened this issue Dec 28, 2023 · 2 comments

Comments

@itsvismay
Copy link

itsvismay commented Dec 28, 2023

I ran the function
poisson_surface_reconstruction(nerf_pts, nerf_normals, gs=np.array([50,50,50])
and it results in the error
File "<__array_function__ internals>", line 200, in ravel_multi_index ValueError: invalid entry in coordinates array

A possibly fix for it is using "mode: clip" in the np.ravel_multi_index function, or exposing that option to the user.

@sgsellan
Copy link
Owner

sgsellan commented Feb 9, 2024

Hi Vismay, could you please share the points and normal inputs?

@sasha-of-the-pixels
Copy link

sasha-of-the-pixels commented Oct 17, 2024

Hello! I actually ran into the same error when trying to run the SPSR code several weeks ago and ended up tracking down what's probably the cause of the issue.

I believe that the root cause lies in lines 136-145:

envelope_mult = 1.5 # how tightly we want to envelope the data
    if (gs is None):
        assert(h is not None)
        assert(corner is not None)
        gs = np.floor((np.max(envelope_mult*P,axis=0) - corner)/h).astype(int)
        # print(gs)
        # print(gs)
    elif ((h is None) or (corner is None)):
        h = (np.max(envelope_mult*P,axis=0) - np.min(envelope_mult*P,axis=0))/gs
        corner = np.min(envelope_mult*P,axis=0)

The envelope_mult usage seems to expect the minimum of all of the points to be negative and the maximum to be positive. If all points have positive coordinates, for example, then corner is actually going to be larger than the minimum point of the cloud's tight bounding box.

Later down the line, this causes some values in P_cells to be negative (or too large), which raises an index-out-of-bounds error when calling ravel_multi_index.

I'm not sure what the intention is behind how envelope_mult is set, but I implemented an approach where instead of the points themselves being multiplied by envelope_mult, we find the centroid of the point cloud, multiply the vectors from the centroid to each point by envelope_mult, then add those quantities to the centroid. I also had to change floor to ceil when computing gs in order to work on a simple test case where all point locations are negative, but I'm not fully convinced that this fixes all cases.

envelope_mult = 1.5 # how tightly we want to envelope the data
    center = np.mean(P, axis=0)
    if (gs is None):
        assert(h is not None)
        assert(corner is not None)
        gs = np.ceil((np.max(envelope_mult*(P-center)+center,axis=0) - corner)/h).astype(int)
        # print(gs)
        # print(gs)
    elif ((h is None) or (corner is None)):
        h = (np.max(envelope_mult*(P-center),axis=0) - np.min(envelope_mult*(P-center),axis=0))/gs
        corner = np.min(envelope_mult*(P-center)+center,axis=0)
    assert(gs.shape[0] == dim)

This worked on a few very small test point clouds but I have not extensively been able to test the correctness of this solution.

Would it also make sense to just add a padding to the size of the grid instead of using a multiplicative approach?

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

3 participants