【问题标题】:How to exchange pointcloud between functions?如何在函数之间交换点云?
【发布时间】:2018-11-28 21:26:43
【问题描述】:

我想编写一个函数,它将一个点云作为输入,并提供两个点云作为参数的输出,如下所示。

void func(pointcloud<T> p1,pointcloud<T> p2,pointcloud<T> p3)
{
//this is function definition
//input pointcloud = p1
//process here
//output pointcloud = p2 & p3
}

.
.
.


func(pa, pb, pc);//this is function call

void func(pointcloud<T>& p1,pointcloud<T>& p2,pointcloud<T>& p3)
{
//this definition is not working.
}

如何使用引用调用(不复制)在函数之间发送和接收点云?请提供代码 sn-p 的帮助。

提前致谢。

【问题讨论】:

    标签: point-cloud-library


    【解决方案1】:

    我建议您使用共享指针。所有(或至少大多数)PCL 类都已经包含共享指针定义(当前基于 boost 的共享指针)。

    template<T>
    void func(PointCloud<T>::Ptr p1, PointCloud<T>::Ptr p2, PointCloud<T>::Pr p3)
    {
    ...
    }
    

    你初始化一个指向点云的指针:

    PointCloud&lt;PointXYZ&gt;::Ptr cloud(new PointCloud&lt;PointXYZ&gt;);

    注意:使用引用调用也应该有效。你得到了什么错误?您的 sn-p 使用 pointcloud 而不是 PointCloud 并且缺少模板类型名定义。

    【讨论】:

    • 我使用了PointCloud&lt;PointXYZ&gt;。当我使用引用调用时,我没有收到任何错误。但是,该程序并没有按预期的方式工作。 没有观察到语法错误。
    • 那么你为什么决定问题出在你的函数定义上?
    • 对函数内部数据所做的更改未反映。
    【解决方案2】:

    人们使用 Boost 库的约定是返回 std::pair 以输出多个可能是不同类型的结果。即类似于:

    using namespace pcl;
    
    std::pair<PointCloud::Ptr, PointCloud::Ptr> foo(PointCloud::Ptr &input){
        ...
        PointCloud::Ptr output1, output2;
        output1 = boost::make_shared<PointCloud>();
        output2 = boost::make_shared<PointCloud>();
        // fill outputX here
        // ...
        return std::make_pair(output1, output2);
    }
    

    通过使用Ptr,您可以避免复制点云,只需将包装器boost::shared_ptr 复制到实际的点数据容器周围,这要轻得多。您可以通过将std::pair 替换为适当大小的std::tuple 来更改输出数量。

    这只是满足您需求的两种方式。如果返回集是同质的,任何其他标准库容器也可以完成这项工作,例如std::vector&lt;PointCloud::Ptr&gt;。选择权在你...

    【讨论】:

      猜你喜欢
      • 2013-11-23
      • 1970-01-01
      • 1970-01-01
      • 2019-06-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      • 2020-07-06
      相关资源
      最近更新 更多