【无标题】

void minimizationExtraction(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, pcl::PointCloud<pcl::PointXYZ>::Ptr cloudFirst, pcl::PointCloud<pcl::Normal>::Ptr normals,supervoxel& sv,int MinNum) {
	std::vector<int> pointIndex;//cloud中近邻4点的索引
	std::vector<float> pointSquareDis;//cloud中近邻4点de对应点距离
	std::vector<std::vector<int>> neighbor_index; neighbor_index.clear();
	double ppooww = pow(cloud->size(), 0.3333333);//pow里面的数都是取整,1/3直接=0
	double lloogg = log2(ppooww);
	int resolution = ceil(lloogg);
	pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree(resolution);
	octree.setInputCloud(cloud);
	octree.addPointsFromInputCloud();
	//pcl::PointCloud<pcl::PointXYZ>::Ptr cloudP_neighbor(new pcl::PointCloud<pcl::PointXYZ>);
	//pcl::PointCloud<pcl::PointXYZ>::Ptr cloudQ_neighbor(new pcl::PointCloud<pcl::PointXYZ>);

	for (int i = 0; i < cloud->size(); i++) {//i为cloud中点索引
		int size = sv.nonrepresent[i].size();
		if (cloud->points[i].x != NULL) {//令每一个参加后续计算的点都是 represent point,假设这个supervoxel为P,represent是rp
			octree.nearestKSearch(cloud->points[i], 6, pointIndex, pointSquareDis);//rp的周边supervoxel代表点 rq们
			for (int j = 0; j < sv.nonrepresent[i].size(); j++) {//j表示遍历P的non-represent点
				int svNi = sv.nonrepresent[i][j];
				double Dp = Dissimilarity(cloud->points[i], cloudFirst->points[svNi], normals->points[i], normals->points[svNi]);
				for (int k = 1; k < pointIndex.size(); k++) {//用周围的几个Q与P比较关于j点的D
					int K = pointIndex[k];//Q represent点索引
					double Dq= Dissimilarity(cloud->points[K], cloudFirst->points[svNi], normals->points[K], normals->points[svNi]);
					if (Dq < Dp) {//P的非代表点距离Q更近,那么就把点给Q,这样Q的non-represent+1,P的non-represent-1
						if (sv.nonrepresent[i].size() > MinNum) {//同时P的supervoxel中点个数满足这样的条件
							sv.nonrepresent[K].push_back(svNi);
							if ((svNi == sv.nonrepresent[i][j])&(size== sv.nonrepresent[i].size())) {
								sv.nonrepresent[i].erase(sv.nonrepresent[i].begin() + j);//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
								continue;//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%需要判断一下这里是否会跳出当前循环并指定下一个j
							}
						}

					}
				}
				//cloudP_neighbor->push_back(cloudFirst->points[svNi]);//superVoxel P的non-represent 点云
			}


		}
	}
	pcl::PointCloud<pcl::PointXYZRGB>::Ptr represent(new pcl::PointCloud<pcl::PointXYZRGB>);
	represent->resize(cloudFirst->size());
	for (int i = 0; i < cloud->size(); i++) {
		if (cloud->points[i].x != NULL) {
			represent->points[i].x = cloud->points[i].x;
			represent->points[i].y = cloud->points[i].y;
			represent->points[i].z = cloud->points[i].z;
			represent->points[i].r = rand() % 256;//为represent点赋颜色
			represent->points[i].g = rand() % 256;
			represent->points[i].b = rand() % 256;
			for (int j = 0; j < sv.nonrepresent[i].size(); j++) {
				int K = sv.nonrepresent[i][j];
				represent->points[K].x = cloudFirst->points[K].x;
				represent->points[K].y = cloudFirst->points[K].y;
				represent->points[K].z = cloudFirst->points[K].z;
				represent->points[K].r = represent->points[i].r;//为represent的non-represent点赋颜色
				represent->points[K].g = represent->points[i].g;
				represent->points[K].b = represent->points[i].b;
			}
		}
	}
	rgbVis(represent);
}
void main() {
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud18000(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud600(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
	readtxt("blade0.txt", cloud18000);
	for (int i = 1; i < 1200; i++) {
		cloud600->push_back(cloud18000->points[i]);
	}
	pcl::copyPointCloud(*cloud600, *cloud);
	supervoxel supervoxel;
	minimizationFusion(cloud, normals,70, supervoxel);
	minimizationExtraction(cloud, cloud600, normals, supervoxel, 2);

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值