PCL Own Point Type can't use pcl functions and operators

huangapple go评论70阅读模式
英文:

PCL Own Point Type can't use pcl functions and operators

问题

#define PCL_NO_PRECOMPILE
#include <pcl/pcl_macros.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <Eigen/Geometry> 
#include <Eigen/Dense>
#include <Eigen/Core>

struct PointXYZIR
  {
    PCL_ADD_POINT4D;                    // 宏定义四维 XYZ
    float intensity;                    // 激光强度
    uint16_t ring;                      // 激光环编号
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW     // 确保正确对齐
  } EIGEN_ALIGN16;
}

POINT_CLOUD_REGISTER_POINT_STRUCT(PointXYZIR,
                                  (float, x, x)
                                  (float, y, y)
                                  (float, z, z)
                                  (float, intensity, intensity)
                                  (uint16_t, ring, ring)
)

typedef pcl::PointCloud<pcl::PointXYZIR>::Ptr pcXYZIRPtr;
typedef pcl::PointCloud<pcl::PointXYZIR> pcXYZIR;

pcXYZIRPtr test1(new pcXYZIR);
pcXYZIRPtr test2(new pcXYZIR);
pcl::PointXYZIR test_p(1.0f,1.0f,1.0f,1.0f,1);

test1->push_back(test_p);
test2->push_back(test_p);

test1 += test2;
英文:
#define PCL_NO_PRECOMPILE
#include &lt;pcl/pcl_macros.h&gt;
#include &lt;pcl/point_types.h&gt;
#include &lt;pcl/point_cloud.h&gt;
#include &lt;Eigen/Geometry&gt; 
#include &lt;Eigen/Dense&gt;
#include &lt;Eigen/Core&gt;

namespace pcl{

struct PointXYZIR
  {
    PCL_ADD_POINT4D;                    // Macro quad-word XYZ
    float intensity;                    // Laser intensity
    uint16_t ring;                      // Laser ring number
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW     // Ensure proper alignment
  } EIGEN_ALIGN16;
}

POINT_CLOUD_REGISTER_POINT_STRUCT(PointXYZIR,
                                  (float, x, x)
                                  (float, y, y)
                                  (float, z, z)
                                  (float, intensity, intensity)
                                  (uint16_t, ring, ring)
)

typedef pcl::PointCloud&lt;pcl::PointXYZIR&gt;::Ptr    pcXYZIRPtr;
typedef pcl::PointCloud&lt;pcl::PointXYZIR&gt;         pcXYZIR;

And then this Code:

pcXYZIRPtr test1(new pcXYZIR);
pcXYZIRPtr test2(new pcXYZIR);
pcl::PointXYZIR test_p(1.0f,1.0f,1.0f,1.0f,1);

test1-&gt;push_back(test_p);
test2-&gt;push_back(test_p);

test1 += test2;

However, this results in these errors:

error: no matching function for call to ‘pcl::PointXYZIR::PointXYZIR(float, float, float, float, int)’
error: no match for ‘operator+=’ (operand types are ‘pcXYZIRPtr’ {aka ‘boost::shared_ptr&lt;pcl::PointCloud&lt;pcl::PointXYZIR&gt; &gt;’} and ‘pcXYZIRPtr’ {aka ‘boost::shared_ptr&lt;pcl::PointCloud&lt;pcl::PointXYZIR&gt; &gt;’})
   92 |     test1 += test2;

This means that i can't use my own custom point type like any normal point type, e.g. pcl::PointXYZI.

What do i need to change in order for this to work? I tried without namespace pcl and with, but it does not work in both ways.

答案1

得分: 2

错误: 没有匹配的operator+=(操作数类型分别为pcXYZIRPtr {即 boost::shared_ptr<pcl::PointCloud<pcl::PointXYZIR>>} 和 pcXYZIRPtr {即 boost::shared_ptr<pcl::PointCloud<pcl::PointXYZIR>>})

你正在添加共享指针。这是什么意思?你可能知道这些共享指针是有效的,并指向元素类型(PointXYZIR)的对象。如果它们允许相加,你可以改为这样相加它们:

*test1 += *test2;

这个错误似乎与其他错误没有关系,但也许你的真实代码(你没有展示它)都有相同的原因。

实际上,看起来你混淆了 pcXYZIRpcXYZIRPtr

英文:

> error: no match for operator+= (operand types are pcXYZIRPtr {aka boost::shared_ptr&lt;pcl::PointCloud&lt;pcl::PointXYZIR&gt; &gt;} and pcXYZIRPtr {aka boost::shared_ptr&lt;pcl::PointCloud&lt;pcl::PointXYZIR&gt; &gt;})

You are adding shared pointers. What does that mean? You might know that the shared-pointers are valid and point to objects of the element type (PointXYZIR). If they allow addition, you can instead add them:

 *test1 += *test2;

This error does not seems to have any relation to the other one, but perhaps your real code (you don't show it) it all has the same cause.

In essence it appears you're mixing up pcXYZIR and pcXYZIRPtr

答案2

得分: 0

所以我最终用这段新代码修复了第一个错误信息(也调整了新整数变量的名称):

#define PCL_NO_PRECOMPILE
#include <pcl/pcl_macros.h>
#include <pcl/point_types.h>

namespace pcl {
struct PointXYZIL
{
  PCL_ADD_POINT4D;                    // 首选的添加 XYZ+填充 的方式
  float intensity;
  int label;
  PointXYZIL(float x, float y, float z, float intensity, int label) : x(x), y(y), z(z), intensity(intensity), label(label) {}
  PointXYZIL() : x(0.0), y(0.0), z(0.0), intensity(0.0), label(0) {}
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW     // 确保我们的新分配器是对齐的
} EIGEN_ALIGN16;                      // 强制 SSE 填充以正确对齐内存
}

POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PointXYZIL,
                                   (float, x, x)
                                   (float, y, y)
                                   (float, z, z)
                                   (float, intensity, intensity)
                                   (int, label, label)
)

对于第二个错误信息,我采纳了 @sehe 的答案。

英文:

So i eventually fixed the first error message with this new code (adapted the name of the new integer variable as well):

#define PCL_NO_PRECOMPILE
#include &lt;pcl/pcl_macros.h&gt;
#include &lt;pcl/point_types.h&gt;

namespace pcl {
struct PointXYZIL
{
  PCL_ADD_POINT4D;                    // preferred way of adding a XYZ+padding
  float intensity;
  int label;
  PointXYZIL(float x, float y, float z, float intensity, int label) : x(x), y(y), z(z), intensity(intensity), label(label) {}
  PointXYZIL() : x(0.0), y(0.0), z(0.0), intensity(0.0), label(0) {}
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW     // make sure our new allocators are aligned
} EIGEN_ALIGN16;                      // enforce SSE padding for correct memory alignment
}

POINT_CLOUD_REGISTER_POINT_STRUCT (pcl::PointXYZIL,
                                   (float, x, x)
                                   (float, y, y)
                                   (float, z, z)
                                   (float, intensity, intensity)
                                   (int, label, label)
)

For the second error message i adopted the answer by @sehe.

huangapple
  • 本文由 发表于 2023年5月24日 18:40:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322627.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定