Created
March 1, 2024 23:23
-
-
Save Ahanio/9bbe195467b6ca089122610c4af97bcf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sample_pts(x, delta): | |
""" Given points X sample points that are shifted by delta in axis aligned directions """ | |
points = torch.stack( | |
[ | |
x + torch.as_tensor([delta, 0.0, 0.0]).to(x), | |
x + torch.as_tensor([-delta, 0.0, 0.0]).to(x), | |
x + torch.as_tensor([0.0, delta, 0.0]).to(x), | |
x + torch.as_tensor([0.0, -delta, 0.0]).to(x), | |
x + torch.as_tensor([0.0, 0.0, delta]).to(x), | |
x + torch.as_tensor([0.0, 0.0, -delta]).to(x), | |
x | |
], | |
dim=0, | |
) | |
return points | |
def get_grad_and_lapl(sampled_points_sdf, delta): | |
""" Given SDF values for points sampled by sample_pts(...) function compute Laplacian """ | |
gradients = torch.stack( | |
[ | |
0.5 * (points_sdf[0] - points_sdf[1]) / delta, | |
0.5 * (points_sdf[2] - points_sdf[3]) / delta, | |
0.5 * (points_sdf[4] - points_sdf[5]) / delta, | |
], | |
dim=-1, | |
) | |
hessian = torch.stack( | |
[ | |
(points_sdf[0] + points_sdf[1] - 2 * points_sdf[-1]) / delta**2, | |
(points_sdf[2] + points_sdf[3] - 2 * points_sdf[-1]) / delta**2, | |
(points_sdf[4] + points_sdf[5] - 2 * points_sdf[-1]) / delta**2, | |
], | |
dim=-1, | |
) | |
lapl = hessian.sum(dim=-1)**2 | |
return gradients, lapl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment