PointCloudLibrary / pcl

Point Cloud Library (PCL)
https://pointclouds.org/
Other
9.98k stars 4.62k forks source link

About point types: What is the benefit by packing curvature/intensity/RGB... etc. in float[4] #3165

Closed dogod621 closed 5 years ago

dogod621 commented 5 years ago

For example:

struct EIGEN_ALIGN16 _PointNormal
  {
    PCL_ADD_POINT4D; // This adds the members x,y,z which can also be accessed using the point (which is float[4])
    PCL_ADD_NORMAL4D; // This adds the member normal[3] which can also be accessed using the point (which is float[4])
    union
    {
      struct
      {
        float curvature;
      };
      float data_c[4];
    };
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  };

struct EIGEN_ALIGN16 _PointXYZINormal
  {
    PCL_ADD_POINT4D; // This adds the members x,y,z which can also be accessed using the point (which is float[4])
    PCL_ADD_NORMAL4D; // This adds the member normal[3] which can also be accessed using the point (which is float[4])
    union
    {
      struct
      {
        float intensity;
        float curvature;
      };
      float data_c[4];
    };
    EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  };

Why put 1~3 float in float 4 struct and leave some space unused? Is there any cache issue or any reason @@?

Your Environment

Context

Expected Behavior

Current Behavior

Code to Reproduce

Possible Solution

SergioRAgostinho commented 5 years ago

Data alignment to enable SIMD instructions. Taken from that same page

Programming with particular SIMD instruction sets can involve numerous low-level challenges.

  • SIMD may have restrictions on data alignment; programmers familiar with one particular architecture may not expect this.

Edit: One more for you to read on https://en.wikipedia.org/wiki/Data_structure_alignment

dogod621 commented 5 years ago

Thanks