File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments