mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2025-12-21 14:50:36 +08:00
small fix for iou3d
Summary: A small numerical fix for IoU for 3D boxes, fixes GH #992 * Adds a check for boxes with zero side areas (invalid boxes) * Fixes numerical issue when two boxes have coplanar sides Reviewed By: nikhilaravi Differential Revision: D33195691 fbshipit-source-id: 8a34b4d1f1e5ec2edb6d54143930da44bdde0906
This commit is contained in:
committed by
Facebook GitHub Bot
parent
069c9fd759
commit
ccfb72cc50
@@ -90,7 +90,8 @@ __global__ void IoUBox3DKernel(
|
||||
for (int b2 = 0; b2 < box2_count; ++b2) {
|
||||
const bool is_coplanar =
|
||||
IsCoplanarFace(box1_intersect[b1], box2_intersect[b2]);
|
||||
if (is_coplanar) {
|
||||
const float area = FaceArea(box1_intersect[b1]);
|
||||
if ((is_coplanar) && (area > kEpsilon)) {
|
||||
tri2_keep[b2].keep = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,8 @@ std::tuple<at::Tensor, at::Tensor> IoUBox3DCpu(
|
||||
for (int b2 = 0; b2 < box2_intersect.size(); ++b2) {
|
||||
const bool is_coplanar =
|
||||
IsCoplanarFace(box1_intersect[b1], box2_intersect[b2]);
|
||||
if (is_coplanar) {
|
||||
const float area = FaceArea(box1_intersect[b1]);
|
||||
if ((is_coplanar) && (area > kEpsilon)) {
|
||||
tri2_keep[b2] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,6 +138,26 @@ FaceNormal(const float3 v0, const float3 v1, const float3 v2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
// The area of the face defined by vertices (v0, v1, v2)
|
||||
// Define e0 to be the edge connecting (v1, v0)
|
||||
// Define e1 to be the edge connecting (v2, v0)
|
||||
// Area is the norm of the cross product of e0, e1 divided by 2.0
|
||||
//
|
||||
// Args
|
||||
// tri: FaceVerts of float3 coordinates of the vertices of the face
|
||||
//
|
||||
// Returns
|
||||
// float: area for the face
|
||||
//
|
||||
__device__ inline float FaceArea(const FaceVerts& tri) {
|
||||
// Get verts for face 1
|
||||
const float3 v0 = tri.v0;
|
||||
const float3 v1 = tri.v1;
|
||||
const float3 v2 = tri.v2;
|
||||
const float3 n = cross(v1 - v0, v2 - v0);
|
||||
return norm(n) / 2.0;
|
||||
}
|
||||
|
||||
// The normal of a box plane defined by the verts in `plane` with
|
||||
// the centroid of the box given by `center`.
|
||||
// Args
|
||||
|
||||
@@ -145,6 +145,26 @@ inline vec3<float> FaceNormal(vec3<float> v0, vec3<float> v1, vec3<float> v2) {
|
||||
return n;
|
||||
}
|
||||
|
||||
// The area of the face defined by vertices (v0, v1, v2)
|
||||
// Define e0 to be the edge connecting (v1, v0)
|
||||
// Define e1 to be the edge connecting (v2, v0)
|
||||
// Area is the norm of the cross product of e0, e1 divided by 2.0
|
||||
//
|
||||
// Args
|
||||
// tri: vec3 coordinates of the vertices of the face
|
||||
//
|
||||
// Returns
|
||||
// float: area for the face
|
||||
//
|
||||
inline float FaceArea(const std::vector<vec3<float>>& tri) {
|
||||
// Get verts for face
|
||||
const vec3<float> v0 = tri[0];
|
||||
const vec3<float> v1 = tri[1];
|
||||
const vec3<float> v2 = tri[2];
|
||||
const vec3<float> n = cross(v1 - v0, v2 - v0);
|
||||
return norm(n) / 2.0;
|
||||
}
|
||||
|
||||
// The normal of a box plane defined by the verts in `plane` with
|
||||
// the centroid of the box given by `center`.
|
||||
// Args
|
||||
|
||||
Reference in New Issue
Block a user