This is my custom signed distance(SDF) computation of points to manifold mesh with PyTorch API on GPU. The code and framework is modified from Kaolin.
python setup.py installIf encounter circular import, try:
pip install -e .or manually modify csdf/__init__.py.
The code provide two function:
compute_sdf(pointclouds, face_vertices)- input
- unbatched points with shape (num, 3)
- unbatched face_vertices with shape (num , 3, 3)
- returns
- squared distance
- normal defined by gradient
- distance signs (inside -1 and outside 1)
- closest face indexes
- distance type (plane, vertices or edges)
- input
index_vertices_by_faces(vertices_features, faces): return face_verts reqired bycompute_sdf(pointclouds, face_vertices).
- Sign is defined by
sign(dis.dot(face_normal)), check your mesh has perfect normal information. - Returned normal is defined by
(p - closest_point).normalized()or equally$\frac{\partial d}{\partial p}$ , not face normal. - The code only run on cuda.
- Scripts in
testscannnot run independently (requires kaolin api or mesh datasets).