利用PCL库画简单的三维立体图形

您所在的位置:网站首页 简单的立体绘画 利用PCL库画简单的三维立体图形

利用PCL库画简单的三维立体图形

2024-06-04 16:29| 来源: 网络整理| 查看: 265

利用PCL库画简单的三维立体图形需要知道各种图形的参数方程,然后给每个参数赋值便可以。

圆柱面的参数方程为:x = R*cos(θ); y = R*sin(θ); z = z;其中 θ范围是[-2*PI, 2*PI), z的范围是(-∞,+∞)

球面的参数方程是:x = R*sin(θ)*cos(ψ); y = R*sin(θ)*sin(ψ); z = R*cos(θ);其中θ∈[0, PI), ψ∈[0, 2*PI)

下面给出代码:

[cpp]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片 #include     #include    #include    #include    #include     #include    // #include       boost::shared_ptr simpleVis(pcl::PointCloud::ConstPtr cloud)   {       boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));       viewer->setBackgroundColor(0.0, 0.0, 0.0);       viewer->addPointCloud(cloud, "sample cloud");       viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1.0, "sample cloud");       viewer->addCoordinateSystem(1.0);       viewer->initCameraParameters();          return viewer;   }      //构造圆柱体点云   void ConsCylinderCloud(pcl::PointCloud::Ptr basic_cloud_ptr)   {       for(float z = -1.0; z width = (int)basic_cloud_ptr->points.size();       basic_cloud_ptr->height = 1;   }      //构造球体点云   void ConsSphereCloud(pcl::PointCloud::Ptr basic_cloud_ptr)   {       float radius = 0.2;          for (float angle1 = 0.0; angle1 width = (int)basic_cloud_ptr->points.size();       basic_cloud_ptr->height = 1;   }      int main(int _Argc, char *argv[])   {       pcl::PointCloud::Ptr basic_cloud_ptr(new pcl::PointCloud);       pcl::PointCloud::Ptr point_cloud_ptr(new pcl::PointCloud);      #define SPHERE   #if defined CYLINDER       ConsCylinderCloud(basic_cloud_ptr);   #elif defined SPHERE       ConsSphereCloud(basic_cloud_ptr);   #endif       boost::shared_ptr viewer = simpleVis(basic_cloud_ptr);       while ( !viewer->wasStopped())       {           viewer->spinOnce(100);           boost::this_thread::sleep(boost::posix_time::microseconds(100000));       }       return 0;   }  

这个是画出的球面。

如果要画出圆柱面,则将代码中的#define SPHERE改为#define CYLINDER,然后编译运行即可显示以xoy平面对称的圆柱面。

以上显示方式是在程序中写死的,也可以将点云保存为文件, 程序中的main函数中稍微修改下,将viewer的代码替换为 [cpp]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片 ConsSphereCloud(basic_cloud_ptr);       pcl::io::savePCDFileASCII("sphere.pcd", *basic_cloud_ptr);   然后在控制台下切换到C:\Program Files (x86)\PCL 1.6.0\bin目录中,再执行 [cpp]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片 C:\Users\pc>pcd_viewer_release D:\pcl_test\visualizer\cmake-bin\sphere.pcd   The viewer window provides interactive commands; for help, press 'h' or 'H' from within the window.   > Loading D:\pcl_test\visualizer\cmake-bin\sphere.pcd [done, 140 ms : 2701 points]   Available dimensions: x y z   显示的图像如下所示:  


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3