从另一个标记点​​云生成点云

时间:2017-08-21 11:06:29

标签: point-cloud-library point-clouds

我有一个标记点​​云数据(云),它的要点包括" x"," y"," z"和"标签"标签的信息可以是1,2或3。

Input is a dichotomous 9x10 matrix

    X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
1 NA  1  1  1  1  1  1  1  0   1
2  1  1  1  1  1  1  1  0  1   0
3  1  1  1  1  1  1  0  1  0   0
4  1  1  1  1  1  1  0  1  0   0
5  1  1  1  1  1  1  0  1  0   0
6  1  1  1  1  1  0  1  0  0   0
7  1  1  1  1  0  1  0  0  0   0
8  1  0  1  0  1  0  0  0  0   0
9  0  1  0  1  0  0  0  0  0   0



 x<-c( 2.0794415,1.3862944,0.8472979, 0.8472979, 0.8472979,0.4054651,0.0000000, -0.8472979, -1.3862944)
    y<-c(-1.4404130, -1.5739444, -1.5739444, -1.5739444, -0.7472659, -0.1876501, 1.1986443 , 0.7286407,2.5849387,2.5849387 )
    result<-matrix(nrow = length(x), ncol = length(y))
    calculation<-function(x,y)
    {
      result<-outer(x,y,function(x,y){ z<-exp(x-y);z/(1+z)})
      result[!is.finite(result)]<-NA
      variance_result<-result*(1-result)
      row_var<- (-1)*rowSums(variance_result,na.rm=T)
      col_var<- (-1)*colSums(variance_result,na.rm=T)
      residual<-input-result
      row_residual<-rowSums(residual,na.rm=T)#(not to be multiplied by -1) 
      col_residual<-(-1)*colSums(residual,na.rm=T)
      new_x<-x-(row_residual/row_var)
      new_x[!is.finite(new_x)]<-NA
      new_x<as.array(new_x)
      new_y<-y-(col_residual/col_var)
      new_y[!is.finite(new_y)]<-NA
      avg_new_y<-mean(new_y, na.rm = T)
      new_y<-new_y-avg_new_y
      new_y<-as.array(new_y)
      sq_sum_residual<-round(sum(row_residual^2),5)
      if(sq_sum_residual>=.01)
      {calculation(new_x,new_y)}
      else(return(residual))
    }
    calculation(x,y)

现在,我想根据他们的标签将此点云划分为3个单独的点云。 例如,我想生成一个点云,它只包含标签为1 pcl::PointCloud<pcl::PointXYZL>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZL>); 的那些点的x,y,z信息。 我这样做了:

(cloud1)

但我收到int ll=0; pcl::PointCloud<pcl::PointXYZL>::Ptr cloud1 (new pcl::PointCloud<pcl::PointXYZL>); for (int ii = 0; ii < cloud->points.size (); ++ii){ if(cloud->points[ii].label==1) { cloud1->points[ll].x=cloud->points[ii].x; cloud1->points[ll].y=cloud->points[ii].y; cloud1->points[ll].z=cloud->points[ii].z; ll++; } } for (int ii = 0; ii < cloud->points.size (); ++ii){ { cloud1->points[ll].x=cloud->points[ii].x; cloud1->points[ll].y=cloud->points[ii].y; cloud1->points[ll].z=cloud->points[ii].z; ll++; } } 错误。我想知道问题出在哪里?

3 个答案:

答案 0 :(得分:1)

尝试在提供数据之前设置输出云大小:

{{1}}

答案 1 :(得分:1)

您正在索引到尚未拥有大小的cloud1存储向量。你不能这样做,因为ll超出界限,这就是它出现分段错误的原因。您需要使用push_back附加一个新点。

if (cloud->points[ii].label == 1)
{
  cloud1->push_back(cloud->points[ii]);
}

答案 2 :(得分:1)

什么acraig5075说。但是,如果原始云没有带有一个或多个标签的任何点,并且可能导致程序在运行时崩溃,则可能会出现空云。

pcl::PointCloud<pcl::PointXYZL>::Ptr cloud1 (new pcl::PointCloud<pcl::PointXYZL>);
pcl::PointCloud<pcl::PointXYZL>::Ptr cloud2 (new pcl::PointCloud<pcl::PointXYZL>);
pcl::PointCloud<pcl::PointXYZL>::Ptr cloud3 (new pcl::PointCloud<pcl::PointXYZL>);

for( int ii = 0; ii < cloud->size(); ii++){
    if(cloud->points[ii].label==1){
        cloud1->push_back(cloud->points[ii]);
    }
    if(cloud->points[ii].label==2){
        cloud2->push_back(cloud->points[ii]);
    }
    if(cloud->points[ii].label==3){
        cloud3->push_back(cloud->points[ii]);
    }
}
if(cloud1->size() > 0) ...