diff --git a/pytorch3d/csrc/rasterize_meshes/geometry_utils.cuh b/pytorch3d/csrc/rasterize_meshes/geometry_utils.cuh index f1bac112..12236b28 100644 --- a/pytorch3d/csrc/rasterize_meshes/geometry_utils.cuh +++ b/pytorch3d/csrc/rasterize_meshes/geometry_utils.cuh @@ -218,14 +218,15 @@ BarycentricPerspectiveCorrectionBackward( return thrust::make_tuple(grad_bary, grad_z0, grad_z1, grad_z2); } -// Return minimum distance between line segment (v1 - v0) and point p. +// Calculate minimum squared distance between a line segment (v1 - v0) and a +// point p. // // Args: // p: Coordinates of a point. // v0, v1: Coordinates of the end points of the line segment. // // Returns: -// non-square distance to the boundary of the triangle. +// squared distance to the boundary of the triangle. // __device__ inline float PointLineDistanceForward(const float2& p, const float2& a, const float2& b) { @@ -284,7 +285,7 @@ PointLineDistanceBackward( // v0, v1, v2: Coordinates of the three triangle vertices. // // Returns: -// shortest absolute distance from a point to a triangle. +// shortest squared distance from a point to a triangle. // __device__ inline float PointTriangleDistanceForward( const float2& p, diff --git a/pytorch3d/csrc/rasterize_meshes/geometry_utils.h b/pytorch3d/csrc/rasterize_meshes/geometry_utils.h index e1342e33..396329c5 100644 --- a/pytorch3d/csrc/rasterize_meshes/geometry_utils.h +++ b/pytorch3d/csrc/rasterize_meshes/geometry_utils.h @@ -241,14 +241,15 @@ inline std::tuple, T, T, T> BarycentricPerspectiveCorrectionBackward( return std::make_tuple(grad_bary, grad_z0, grad_z1, grad_z2); } -// Calculate minimum distance between a line segment (v1 - v0) and point p. +// Calculate minimum squared distance between a line segment (v1 - v0) and a +// point p. // // Args: // p: Coordinates of a point. // v0, v1: Coordinates of the end points of the line segment. // // Returns: -// non-square distance of the point to the line. +// squared distance of the point to the line. // // Consider the line extending the segment - this can be parameterized as: // v0 + t (v1 - v0). @@ -322,7 +323,7 @@ inline std::tuple, vec2, vec2> PointLineDistanceBackward( // v0, v1, v2: Coordinates of the three triangle vertices. // // Returns: -// shortest absolute distance from a point to a triangle. +// shortest squared distance from a point to a triangle. // // template diff --git a/pytorch3d/csrc/rasterize_meshes/rasterize_meshes_cpu.cpp b/pytorch3d/csrc/rasterize_meshes/rasterize_meshes_cpu.cpp index 392ad3bf..837fe123 100644 --- a/pytorch3d/csrc/rasterize_meshes/rasterize_meshes_cpu.cpp +++ b/pytorch3d/csrc/rasterize_meshes/rasterize_meshes_cpu.cpp @@ -214,14 +214,15 @@ RasterizeMeshesNaiveCpu( continue; // Point is behind the image plane so ignore. } - // Compute absolute distance of the point to the triangle. - // If the point is inside the triangle then the distance - // is negative. + // Compute squared distance of the point to the triangle. const float dist = PointTriangleDistanceForward(pxy, v0, v1, v2); // Use the bary coordinates to determine if the point is // inside the face. const bool inside = bary.x > 0.0f && bary.y > 0.0f && bary.z > 0.0f; + + // If the point is inside the triangle then signed_dist + // is negative. const float signed_dist = inside ? -dist : dist; // Check if pixel is outside blur region