First, build the MFC framework
1. Environmental description
This tutorial is for vs2022, pcl1.12.1 version, other versions should be modified appropriately, for reference only.
2. Method steps
(1) Create a new project, select "Dialog Based", and click "Next"
Second, configure the pcl environment
Regarding the configuration environment, there are many tutorials on the Internet, and my "pcl column" also has detailed instructions. Do it slowly by yourself, don't worry, and you can proceed to the next step after the final configuration is completed.
pcl1.12.1 reinstall the boost library
3. Add picture control and button to display gradient point cloud
The picture above is a pcl frame written by me, the first "open point cloud" button is such an effect
Unfinished, to be continued...I don't have time today, sorry,
First paste the code inside the button1 button
void CMFCPCLSHFDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
CString strFile = _T("");
CFileDialog dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Describe Files (*.pcd)|*.pcd|All Files (*.*)|*.*||"), NULL);
if (dlgFile.DoModal())
{
strFile = dlgFile.GetPathName();
//Cstring 转string
CString theCStr;
std::string STDStr(CW2A(strFile.GetString()));
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile<pcl::PointXYZ>(STDStr, *cloud) == -1)//*打开点云文件
{
AfxMessageBox(_T("读入点云数据失败"));
}
m_viewer->removeAllPointClouds();//将前一次点云移除
// 设置单一颜色
//pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> color_h(pcd_src, 0, 255, 0);//点云为绿色
//按照z方向深度进行渲染(带渐变色)
pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> color_h(cloud, "z");
m_viewer->addPointCloud<pcl::PointXYZ >(cloud, color_h, "sample cloud");
m_viewer->addText("show cloud", 0, 20);
}
}