Skip to content

Commit ee71c7c

Browse files
gkioxarifacebook-github-bot
authored andcommitted
small numerical fix to point_mesh
Summary: Small fix by adjusting the area `eps` to account for really small faces when computing point to face distances Reviewed By: bottler Differential Revision: D34331336 fbshipit-source-id: 51c4888ea46fefa4e31d5b0bb494a9f9d77813cd
1 parent 3de4122 commit ee71c7c

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

pytorch3d/csrc/utils/geometry_utils.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ __device__ inline bool IsInsideTriangle(
550550
const float3& v1,
551551
const float3& v2) {
552552
bool inside;
553-
if (AreaOfTriangle(v0, v1, v2) < 1e-5) {
553+
if (AreaOfTriangle(v0, v1, v2) < 5e-3) {
554554
inside = 0;
555555
} else {
556556
float3 bary = BarycentricCoords3Forward(p, v0, v1, v2);

pytorch3d/csrc/utils/geometry_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ static bool IsInsideTriangle(
651651
const vec3<T>& v1,
652652
const vec3<T>& v2) {
653653
bool inside;
654-
if (AreaOfTriangle(v0, v1, v2) < 1e-5) {
654+
if (AreaOfTriangle(v0, v1, v2) < 5e-3) {
655655
inside = 0;
656656
} else {
657657
vec3<T> bary = BarycentricCoords3Forward(p, v0, v1, v2);

tests/test_point_mesh_distance.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
from common_testing import TestCaseMixin, get_random_cuda_device
1212
from pytorch3d import _C
1313
from pytorch3d.loss import point_mesh_edge_distance, point_mesh_face_distance
14-
from pytorch3d.structures import Meshes, Pointclouds, packed_to_list
14+
from pytorch3d.structures import (
15+
Meshes,
16+
Pointclouds,
17+
packed_to_list,
18+
)
1519

1620

1721
class TestPointMeshDistance(TestCaseMixin, unittest.TestCase):
@@ -126,7 +130,7 @@ def _is_inside_triangle(point: torch.Tensor, tri: torch.Tensor) -> torch.Tensor:
126130
area = torch.cross(v0, v1).norm() / 2.0
127131

128132
# check if triangle is a line or a point. In that case, return False
129-
if area < 1e-5:
133+
if area < 5e-3:
130134
return False
131135
bary = TestPointMeshDistance._point_to_bary(point, tri)
132136
inside = ((bary >= 0.0) * (bary <= 1.0)).all()

0 commit comments

Comments
 (0)