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

Marching cubes algorithm on own x,y,z data #5176

Closed
rajeshm71 opened this issue Jan 6, 2021 · 3 comments
Closed

Marching cubes algorithm on own x,y,z data #5176

rajeshm71 opened this issue Jan 6, 2021 · 3 comments

Comments

@rajeshm71
Copy link

Hello all,
I am using marching cubes lewinar algorithm for surfaces reconstruction in 3d . I have data in the format of x,y,z coordinates. How to convert it into 3d volumetric data.

suppose i have
x=np.array([1,2,3])
y=np.array([4,5,6])
z=np.array([7,8,9])

Note: I have taken 3 points just for exapmle purpose

marchine cubes algorithm requires data in 3d numpy array. plz help

@jni
Copy link
Member

jni commented Jan 7, 2021

@rajeshm71 can you tell us more specifically what you are aiming to do? The point of marching_cubes_lewiner is to go from volumetric data to triangles. If you already have triangles, there is no point doing the round trip via volumetric data. If you only have points and are looking to get a surface via triangulation, then you probably want to use scipy.spatial.Delaunay rather than marching cubes.

I'm going to close this issue because it is not a bug or feature request, but please feel free to continue the discussion below!

@jni jni closed this as completed Jan 7, 2021
@rajeshm71
Copy link
Author

Hi @jni Thanks for your reply. I have point cloud data as x,y,z coordinates in .ply format file. I am looking to get a surface by triangulation .I have tried with scipy.spatial.Delaunay but not getting proper results. so i was looking to reconstruct surface using marching cube algorithm. Is there any way by which i can convert pointcloud data to volumetric data and use marching cube algorithm for surface reconstruction in it.

@jni
Copy link
Member

jni commented Jan 10, 2021

Yeah, Delaunay is actually not exactly what you need here, but I thought it might be good enough.

I think that raster + marching cubes will probably also not give you good results. I found a guide that seems to do what you want, without scikit-image (which is not designed for point clouds). Here's an attempt for the point-cloud -> volume -> mesh pipeline:

# input: z_coords, y_coords, x_coords
zint, yint, xint = [
    np.floor(coords).astype(int)
    for coords in [z_coords, y_coords, x_coords]
]
shape = tuple([np.max(intcoords) + 1
               for intcoords in [zint, yint, xint]])
image = np.zeros(shape)
image[zint, yint, xint] += 1

You can then apply marching cubes to that image. But, to reiterate, I suggest you instead follow the guide in this blog post:

https://towardsdatascience.com/5-step-guide-to-generate-3d-meshes-from-point-clouds-with-python-36bad397d8ba

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