本帖最后由 tyzaizl 于 2015-7-23 22:27 编辑
如何实现基于MFC对话框的PCL显示(2)
田玉珍(CIOMP)
2.3.9 添加消息WM_SIZE响应函数OnSize,保证PCLVisualizer窗口viewer随对话框变化。 - void CPCLDialogDlg::OnSize(UINT nType, int cx, int cy)
- {
- CDialogEx::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- if (::IsWindow(this->GetSafeHwnd()))
- {
- if (this->viewer)
- {
- cx -= ptBorder.x;
- cy -= ptBorder.y;
- this->GetDlgItem(IDC_PCLVIWER)->SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
- this->viewer->SetWindowPos(NULL, 0, 0, cx, cy, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
- }
- }
- }
复制代码2.3.10 新建button控件,caption:Open PCD,ID:IDC_OPENPCD,为控件添加响应函OnBnClickedOpenpcd() - void CPCLDialogDlg::OnBnClickedOpenpcd()
- {
- this->viewer->removeAllPointClouds ();
- // TODO: Add your control notification handler code here
- static TCHAR BASED_CODE szFilter[] = _T("PCD (*.pcd )|*.pcd||");
- CFileDialog cFileDialog(true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT| OFN_NOCHANGEDIR ,szFilter);
- if (cFileDialog.DoModal() == IDOK)
- {
- /////////////////////////////////////////////////////////////////////////////
- //文档名称
- std::string filename;
- filename = cFileDialog.GetPathName();
- //reset data
- this->binary_blob.reset();
- binary_blob = sensor_msgs::PointCloud2::Ptr (new sensor_msgs::PointCloud2);
- // read new data
- //*.pcd文件
- pcl::PCDReader pcd_reader;
- if (pcd_reader.read ((char*)_bstr_t(filename.c_str()), *binary_blob) != 0) //* load the file
- {
- MessageBox (_T("Couldn't read PCData file!"));
- return;
- }
- }
- if (binary_blob == NULL)
- {
- MessageBox("Please load PCD file firstly!");
- return;
- }
- else
- {
- //其他句柄
- if (pcl::getFieldIndex(*binary_blob, "rgb") > 0)
- {
- color_Handler = pcl::mfc_visualization::PointCloudColorHandlerRGBField<sensor_msgs::PointCloud2>::Ptr
- (new pcl::mfc_visualization::PointCloudColorHandlerRGBField<sensor_msgs::PointCloud2> (binary_blob));
- this->viewer->addPointCloud(binary_blob, color_Handler, sensor_origin, sensor_orientation);
- }
- else
- {
- xyz_Handler = pcl::mfc_visualization::PointCloudGeometryHandlerXYZ<sensor_msgs::PointCloud2>::Ptr
- (new pcl::mfc_visualization::PointCloudGeometryHandlerXYZ<sensor_msgs::PointCloud2> (binary_blob));
- this->viewer->addPointCloud(binary_blob, xyz_Handler, sensor_origin, sensor_orientation);
- }
- this->viewer->resetCamera();
- }
- }
复制代码2.3.11 最终效果,图4所示
2.3.12实现多项功能的程序效果,如图5所示
由于级别不够所以附件大小限制,这里只给出图4和图5,图1~3不重要,所以不给出了。压缩文件是修改好的源代码(如有需要请回复留下邮箱,我可以发给大家),按说明操作即可。
修改源代码的使用请看如何实现基于MFC对话框的PCL显示(4)——关于修改源代码的使用。 |