您当前的位置: 首页 >  phymat.nico

PCL学习:基于B样条曲线的曲面重建

phymat.nico 发布时间:2020-03-27 13:04:32 ,浏览量:4

测试示例:

 vs2015+release+x64

    #include
    #include
    #include
     
    #include
    #include
    #include
    #include
    #include
     
    using namespace pcl::console;
    typedef pcl::PointXYZ Point;
     
    void
    PointCloud2Vector3d (pcl::PointCloud::Ptr cloud, pcl::on_nurbs::vector_vec3d &data);
     
    void
    visualizeCurve (ON_NurbsCurve &curve,
                    ON_NurbsSurface &surface,
                    pcl::visualization::PCLVisualizer &viewer);
     
    int
    main (int argc, char *argv[])
    {
      std::string pcd_file, file_3dm;
     
      if (argc < 2)
      {
        printf ("\nUsage: pcl_example_nurbs_fitting_surface pcd-in-file -o 3 -rn 4 -in 10 -mr 128 -td 1\n\n");
        exit (0);
      }
      pcd_file = argv[1];
      //file_3dm = argv[2];
     
      pcl::visualization::PCLVisualizer viewer ("B样条曲面拟合点云数据");
      viewer.setBackgroundColor(0,0,0);
      viewer.setSize (800, 600);
     
      // ############################################################################
      // load point cloud
     
      printf ("  loading %s\n", pcd_file.c_str ());
      pcl::PointCloud::Ptr cloud (new pcl::PointCloud);
      pcl::PCLPointCloud2 cloud2;
      pcl::on_nurbs::NurbsDataSurface data;
     
      if (pcl::io::loadPCDFile (pcd_file, cloud2) == -1)
        throw std::runtime_error ("  PCD file not found.");
     
      fromPCLPointCloud2 (cloud2, *cloud);
      PointCloud2Vector3d (cloud, data.interior);
      pcl::visualization::PointCloudColorHandlerCustom handler (cloud, 0, 255, 0);
      viewer.addPointCloud (cloud, handler, "cloud_cylinder");
      printf ("  %lu points in data set\n", cloud->size ());
     
      // ############################################################################
      // fit B-spline surface
     
      // parameters
      unsigned order (3);
      unsigned refinement (4);
      unsigned iterations (10);
      unsigned mesh_resolution (128);
      bool two_dim=true;
      parse_argument (argc, argv, "-o", order);
      parse_argument (argc, argv, "-rn", refinement);
      parse_argument (argc, argv, "-in", iterations);
      parse_argument (argc, argv, "-mr", mesh_resolution);
      parse_argument (argc, argv, "-td", two_dim);
      pcl::on_nurbs::FittingSurface::Parameter params;
      params.interior_smoothness = 0.2;
      params.interior_weight = 1.0;
      params.boundary_smoothness = 0.2;
      params.boundary_weight = 0.0;
     
      // initialize
      printf ("  surface fitting ...\n");
      ON_NurbsSurface nurbs = pcl::on_nurbs::FittingSurface::initNurbsPCABoundingBox (order, &data);
      pcl::on_nurbs::FittingSurface fit (&data, nurbs);
      //  fit.setQuiet (false); // enable/disable debug output
     
      // mesh for visualization
      pcl::PolygonMesh mesh;
      pcl::PointCloud::Ptr mesh_cloud (new pcl::PointCloud);
      std::vector mesh_vertices;
      std::string mesh_id = "mesh_nurbs";
      pcl::on_nurbs::Triangulation::convertSurface2PolygonMesh (fit.m_nurbs, mesh, mesh_resolution);
      viewer.addPolygonMesh (mesh, mesh_id);
      std::cout

关注
打赏
查看更多评论

phymat.nico

暂无认证

  • 4浏览

    0关注

    1946博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录