1. 程式人生 > >把pcl的VTK顯示融合到MFC(程式碼找原作者)

把pcl的VTK顯示融合到MFC(程式碼找原作者)

    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>