1
#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>

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<pcl::PointXYZIR>::Ptr    pcXYZIRPtr;
typedef pcl::PointCloud<pcl::PointXYZIR>         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->push_back(test_p);
test2->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<pcl::PointCloud<pcl::PointXYZIR> >’} and ‘pcXYZIRPtr’ {aka ‘boost::shared_ptr<pcl::PointCloud<pcl::PointXYZIR> >’})
   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.

Kataran
  • 155
  • 7

2 Answers2

2

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

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

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thank you! You are right. Dereferencing the pointers works (I added the missing code section to the question). However: I still have problems with the struct Constructor. It seems like pcl does not recognize my point type properly. – Kataran May 25 '23 at 09:01
  • 1
    Registering your type cannot "magically" give it constructors. Likely PCL library has a factory function (create_point or make_point etc.) that does this generically for any registered point type. – sehe May 25 '23 at 10:54
  • 1
    You are right, i am still learning and got it wrong. I fixed my declaration and will post it as an answer. Thank you again! – Kataran May 25 '23 at 12:59
0

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 <pcl/pcl_macros.h>
#include <pcl/point_types.h>

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.

Kataran
  • 155
  • 7