Search code examples
mathpoint

Doing math with PCL PointXYZ structs?


What is the usual way to do math, addition, subtraction, on PCL (Point Cloud Library) data types, i.e. PointXYZ? There don't seem to be operators defined even for the basics.

I thought maybe the PCL way was to convert to Eigen vectors, but there doesn't seem to be a constructor for that either.


Solution

  • For anyone who wants to do basic math with PointXYZ, here a quick example:

      pcl::PointXYZ a(0, 1, 2), b(10, 20, 30), c;
      c.getArray3fMap() = a.getArray3fMap() + b.getArray3fMap();
      std::cout << "c=" << c << std::endl;
      //c=(10,21,32)
    
      c.getArray3fMap() = a.getArray3fMap() * b.getArray3fMap();
      std::cout << "c=" << c << std::endl;
      //c=(0,20,60)
    

    Maybe there is a better way but at least it works.