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

Report a bug in signed_distance_to_mesh function. #97

Open
Maikouuu opened this issue Sep 7, 2024 · 0 comments
Open

Report a bug in signed_distance_to_mesh function. #97

Maikouuu opened this issue Sep 7, 2024 · 0 comments

Comments

@Maikouuu
Copy link

Maikouuu commented Sep 7, 2024

Hi,

Thanks for your excellent implementation.

I am calling signed_distance_to_mesh() to compute the signed distances of a triangle mesh with a uniform sampled volume. However, I find something quite strange when I apply a marching cube to the signed distance: the extracted mesh suffers a significant distortion from the original. The images below show that the signed distances of the left hood may be incorrect.

Original:
截屏2024-09-08 03 28 59

Extracted:
截屏2024-09-08 03 30 18

The car.obj file and code block are attached to reproduce it.

car.obj.zip

import numpy as np
import trimesh
import point_cloud_utils as pcu
from skimage.measure import marching_cubes

# init query point
octree_depth = 7
boundary = 1.0
bbox_min = np.array([-boundary, -boundary, -boundary])
bbox_max = np.array([boundary, boundary, boundary])
bbox_size = bbox_max - bbox_min
length = bbox_max - bbox_min
num_cells = np.exp2(octree_depth)
x = np.linspace(bbox_min[0], bbox_max[0], int(num_cells) + 2, dtype=np.float32)
y = np.linspace(bbox_min[1], bbox_max[1], int(num_cells) + 2, dtype=np.float32)
z = np.linspace(bbox_min[2], bbox_max[2], int(num_cells) + 2, dtype=np.float32)
[xs, ys, zs] = np.meshgrid(x, y, z, indexing="ij")
xyz = np.stack((xs, ys, zs), axis=-1)
query_points = xyz.reshape(-1, 3)
grid_size = [int(num_cells) + 2, int(num_cells) + 2, int(num_cells) + 2]

# load mesh
mesh = trimesh.load('car.obj')
v = mesh.vertices
f = mesh.faces

# compute sdf
sdf = mesh2sdf.core.compute(v, f, size=int(np.exp2(octree_depth)))
sdf.resize(grid_size[0], grid_size[1], grid_size[2])

# extract mesh
vertices, faces, normals, _ = marching_cubes(query_sdf, level=0)
watertight_mesh = trimesh.Trimesh(vertices, faces, normals=normals)
watertight_mesh.export('watertight_mesh.obj')
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

1 participant