Skip to content

Commit 6b38623

Browse files
feat: add fallback to obb when knn on normals gives insufficiently different axes
1 parent b00e145 commit 6b38623

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/diffCheck/geometry/DFPointCloud.cc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,32 @@ namespace diffCheck::geometry
256256

257257
for(size_t i = 0; i < nComponents; ++i)
258258
{
259-
principalAxes.push_back(sortedClustersBySize[i].second);
259+
if(principalAxes.size() == 0)
260+
{
261+
principalAxes.push_back(sortedClustersBySize[i].second);
262+
}
263+
else
264+
{
265+
bool isAlreadyPresent = false;
266+
for (const auto& axis : principalAxes)
267+
{
268+
double dotProduct = std::abs(axis.dot(sortedClustersBySize[i].second));
269+
if (std::abs(dotProduct) > 0.7) // Threshold to consider as similar direction
270+
{
271+
isAlreadyPresent = true;
272+
break;
273+
}
274+
}
275+
if (!isAlreadyPresent)
276+
{
277+
principalAxes.push_back(sortedClustersBySize[i].second);
278+
}
279+
}
280+
}
281+
if (principalAxes.size() < 2) // Fallback to OBB if k-means fails to provide enough distinct axes
282+
{
283+
open3d::geometry::OrientedBoundingBox obb = this->Cvt2O3DPointCloud()->GetOrientedBoundingBox();
284+
principalAxes = {obb.R_.col(0), obb.R_.col(1), obb.R_.col(2)};
260285
}
261286
return principalAxes;
262287
}

0 commit comments

Comments
 (0)