From 7056649c6b16911b1e1a9cf1a54771e19b31cd21 Mon Sep 17 00:00:00 2001 From: Iori Yanokura Date: Thu, 30 May 2024 17:40:26 +0900 Subject: [PATCH] Refactor ear clipping algorithm to improve concave and flat triangle detection - Updated the condition to detect concave vertices: If the z component of the cross product is less than or equal to zero, the triangle is considered concave, indicating that the angle between the vectors is greater than 180 degrees. - Improved the condition to detect flat triangles: If the norm (length) of the cross product is close to zero, the vectors are collinear, making the triangle flat with no area. - Added detailed comments to explain the conditions for concave and flat triangles for better readability and maintainability. --- .../src/pcl/ear_clipping_patched.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jsk_recognition_utils/src/pcl/ear_clipping_patched.cpp b/jsk_recognition_utils/src/pcl/ear_clipping_patched.cpp index c0938a8a14..b73bbcde97 100644 --- a/jsk_recognition_utils/src/pcl/ear_clipping_patched.cpp +++ b/jsk_recognition_utils/src/pcl/ear_clipping_patched.cpp @@ -141,8 +141,17 @@ pcl::EarClippingPatched::isEar (int u, int v, int w, const Vertices& vertices) // 1: Avoid flat triangles and concave vertex Eigen::Vector3f cross = p_vu.cross(p_vw); - if ((cross[2] > 0) || (cross.norm() < eps)) - return (false); + + // Concave vertex condition: + // If the z component of the cross product is less than or equal to zero, + // the triangle is concave, meaning the angle between the vectors is greater than 180 degrees. + if (cross[2] <= 0) { + // Not an ear: concave vertex + return false; + } else if (cross.norm() < eps) { + // Not an ear: flat triangle + return false; + } Eigen::Vector3f p; // 2: Check if any other vertex is inside the triangle.