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);
}
【无标题】
于 2022-04-04 18:32:03 首次发布