主要问题:
1. 回调函数作为类的成员函数
*2. registerPointPickingCallback函数的参数,传this指针的值(this)作为一个实例对象。
//类成员函数 Smoothing::showAll()
//显示点云vector中的所有点云。
//调用宿主函数registerPointPickingCallback来监视点的拾取。
//并指定回调函数为Smoothing::pp_callback
void Smoothing::showAll() {
viewer->removeAllPointClouds();
//ui.CheckComboBox->setCurrentIndex(0);
for(int pc=0;pc<turnPc.size();pc++){
pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> fildColor(turnPc[pc], "z");
viewer->addPointCloud(turnPc[pc], fildColor, "cloud " +to_string(pc));
PointXYZ current_point= PointXYZ();
viewer->registerPointPickingCallback(&Smoothing::pp_callback, *this, ¤t_point);
//std::cout << current_point.x << " " << current_point.y << " " << current_point.z << std::endl;
}
viewer->resetCamera();
ui.qvtkWidget->update();
}
//类成员函数Smoothing::pp_callback()作为回调函数
void Smoothing::pp_callback(const pcl::visualization::PointPickingEvent& event, void *args)
{
if (event.getPointIndex() == -1)
return;
PointXYZ *current_point = (PointXYZ*)(args);
event.getPoint(current_point->x, current_point->y, current_point->z);
//std::cout << current_point->x << " " << current_point->y << " " << current_point->z << std::endl;
string x = "X: " + to_string(current_point->x);
string y = "Y: " + to_string(current_point->y);
string z = "Z: " + to_string(current_point->z);
//ui中的三个标签
ui.label_24->setText(QString::fromStdString(x));
ui.label_25->setText(QString::fromStdString(y));
ui.label_26->setText(QString::fromStdString(z));
return ;
}