Qt可以跟VTK和PCL等其他库联合使用,十分强大,下面的代码展示了如何使用Qt联合PCL库来加载和保存PCL/PLY格式的点云:
通过按钮加载点云:
void QMainWindow::on_pb_load_clicked() { QString filename = QFileDialog::getOpenFileName (this, tr ("Open point cloud"), "", tr ("Point cloud data (*.pcd *.ply)")); PCL_INFO("File chosen: %s\n", filename.toStdString ().c_str ()); PointCloudT::Ptr cloud_tmp (new PointCloudT); if (filename.isEmpty ()) return; int return_status; if (filename.endsWith (".pcd", Qt::CaseInsensitive)) return_status = pcl::io::loadPCDFile (filename.toStdString (), *cloud_tmp); else return_status = pcl::io::loadPLYFile (filename.toStdString (), *cloud_tmp); if (return_status != 0) { PCL_ERROR("Error reading point cloud %s\n", filename.toStdString ().c_str ()); return; } }
保存点云:
void QMainWindow::on_pb_save_clicked() { QString filename = QFileDialog::getSaveFileName(this, tr ("Open point cloud"), "", tr ("Point cloud data (*.pcd *.ply)")); PCL_INFO("File chosen: %s\n", filename.toStdString ().c_str ()); if (filename.isEmpty ()) return; int return_status; if (filename.endsWith (".pcd", Qt::CaseInsensitive)) return_status = pcl::io::savePCDFileBinary (filename.toStdString (), *cloud_); else if (filename.endsWith (".ply", Qt::CaseInsensitive)) return_status = pcl::io::savePLYFileBinary (filename.toStdString (), *cloud_); else { filename.append(".ply"); return_status = pcl::io::savePLYFileBinary (filename.toStdString (), *cloud_); } if (return_status != 0) { PCL_ERROR("Error writing point cloud %s\n", filename.toStdString ().c_str ()); return; } }
本文转自博客园Grandyang的博客,原文链接:加载和保存点云Qt Load and Save PCL/PLY ,如需转载请自行联系原博主。