Common errors that occur when sorting in C++

The problem here is that using the x of the minimum point of the same point cloud < the x of the maximum point, this result will always be true and there will be no iteration termination condition. Change it to min_pt1.x() < min_pt2.x () is correct

//因为如果使用的min_pt1.x() < max_pt1.x()会导致无论如何都是true,这样就会导致排序出错
sort(steel_saddle_cluster_indices.begin(), steel_saddle_cluster_indices.end(), [steel_saddle](pcl::PointIndices left, pcl::PointIndices right) {
    
    
	Eigen::Vector4f min_pt1, max_pt1;
	Eigen::Vector4f min_pt2, max_pt2;
	pcl::getMinMax3D(*steel_saddle, left, min_pt1, max_pt1);
	pcl::getMinMax3D(*steel_saddle, right, min_pt2, max_pt2);
	bool result= min_pt1.x() < min_pt2.x() ? true : false;
	return result;
	}
);

Guess you like

Origin blog.csdn.net/weixin_42295969/article/details/131081373