转自PCL中国,原文链接:http://www.pclcn.org/bbs/forum.php?mod=viewthread&tid=223&extra=page%3D1
C:\Program Files\VTK5.10\include\vtk-5.10; C:\Program Files\PCL 1.6.0\3rdParty\Boost\include; C:\Program Files\PCL 1.6.0\include\pcl-1.6; C:\Program Files\PCL 1.6.0\3rdParty\Eigen\include; C:\Program Files\PCL 1.6.0\3rdParty\Flann\include; D:\Program\VS2010\Project\PCLDialog\PCLDialog;
C:\Program Files\PCL 1.6.0\3rdParty\Qhull\lib; C:\Program Files\VTK5.10\lib; C:\Program Files\PCL 1.6.0\3rdParty\Boost\lib; C:\Program Files\PCL 1.6.0\lib; C:\Program Files\PCL 1.6.0\3rdParty\Flann\lib; C:\Program Files\OpenNI\Lib; C:\Program Files\PCL 1.6.0\3rdParty\Eigen\bin;
#include "pcl\point_cloud.h" #include "pcl\point_types.h" #include "pclvisualization_mfc\include\pcl_mfc_visualizer.h" #include "vtkRenderer.h" #include <pcl/io/pcd_io.h>
private: //视图窗口 pcl::mfc_visualization::PCLVisualizer *viewer; //vtkRenderer *pvtkRenderer; POINT ptBorder; //数据点 sensor_msgs::PointCloud2::Ptr binary_blob; //数据点句柄 pcl::mfc_visualization::PointCloudGeometryHandlerXYZ<sensor_msgs::PointCloud2>::Ptr xyz_Handler; pcl::mfc_visualization::PointCloudColorHandlerRGBField<sensor_msgs::PointCloud2>::Ptr color_Handler; //传感器位置方向矩阵 Eigen::Vector4f sensor_origin; Eigen::Quaternion<float> sensor_orientation;
CPCLDialogDlg::CPCLDialogDlg(CWnd* pParent /*=NULL*/): CDialogEx(CPCLDialogDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); /////////////////////////////////////////////////////////////////////////////////////////////////// //begin tyz //初始化 this->viewer = NULL; sensor_origin = Eigen::Vector4f::Zero(); sensor_orientation = Eigen::Quaternionf::Identity (); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////// //利用PictControl控件加载PCD窗口 CWnd *viewer_pcWnd; viewer_pcWnd = this->GetDlgItem(IDC_PCDVIWER); this->viewer = new pcl::mfc_visualization::PCLVisualizer(viewer_pcWnd); CRect cRectPCL; this->viewer->GetClientRect(&cRectPCL); CRect cRectClient; GetClientRect(&cRectClient); this->ptBorder.x = cRectClient.Width() - cRectPCL.Width(); this->ptBorder.y = cRectClient.Height() - cRectPCL.Height(); ////////////////////////////////////////////////////////////////////////////////////////////////////////////
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); } } }
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.GetFileName(); //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(); } } <em>复制代码</em>
附加注释:
转载请注明出处(http://www.pclcn.org/bbs/forum.php?mod=viewthread&tid=227&extra=)this->viewer=NULL;
CWnd *viewer_pcWnd; viewer_pcWnd = this->GetDlgItem(IDC_PCDVIWER); this->viewer = new pcl::mfc_visualization::PCLVisualizer(viewer_pcWnd);<em>复制代码</em>