Skip to content

Commit

Permalink
Add constexpr to static member functions for point types, add macro…
Browse files Browse the repository at this point in the history
… for `if constexpr` (PointCloudLibrary#4735)

* static mem functions returning constants made constexpr

* static mem functions returning constants made constexpr

* static mem functions returning constants made constexpr

* static mem functions returning constants made constexpr
  • Loading branch information
al-tu authored and mvieth committed Dec 27, 2021
1 parent 77ff5e4 commit 65e8829
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
36 changes: 18 additions & 18 deletions common/include/pcl/impl/point_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ namespace pcl
struct PFHSignature125
{
float histogram[125] = {0.f};
static int descriptorSize () { return 125; }
static constexpr int descriptorSize () { return 125; }

inline PFHSignature125 () = default;

Expand All @@ -1321,7 +1321,7 @@ namespace pcl
struct PFHRGBSignature250
{
float histogram[250] = {0.f};
static int descriptorSize () { return 250; }
static constexpr int descriptorSize () { return 250; }

inline PFHRGBSignature250 () = default;

Expand Down Expand Up @@ -1408,7 +1408,7 @@ namespace pcl
{
float descriptor[1980] = {0.f};
float rf[9] = {0.f};
static int descriptorSize () { return 1980; }
static constexpr int descriptorSize () { return 1980; }

inline ShapeContext1980 () = default;

Expand All @@ -1423,7 +1423,7 @@ namespace pcl
{
float descriptor[1960] = {0.f};
float rf[9] = {0.f};
static int descriptorSize () { return 1960; }
static constexpr int descriptorSize () { return 1960; }

inline UniqueShapeContext1960 () = default;

Expand All @@ -1438,7 +1438,7 @@ namespace pcl
{
float descriptor[352] = {0.f};
float rf[9] = {0.f};
static int descriptorSize () { return 352; }
static constexpr int descriptorSize () { return 352; }

inline SHOT352 () = default;

Expand All @@ -1454,7 +1454,7 @@ namespace pcl
{
float descriptor[1344] = {0.f};
float rf[9] = {0.f};
static int descriptorSize () { return 1344; }
static constexpr int descriptorSize () { return 1344; }

inline SHOT1344 () = default;

Expand Down Expand Up @@ -1519,7 +1519,7 @@ namespace pcl
struct FPFHSignature33
{
float histogram[33] = {0.f};
static int descriptorSize () { return 33; }
static constexpr int descriptorSize () { return 33; }

inline FPFHSignature33 () = default;

Expand All @@ -1533,7 +1533,7 @@ namespace pcl
struct VFHSignature308
{
float histogram[308] = {0.f};
static int descriptorSize () { return 308; }
static constexpr int descriptorSize () { return 308; }

inline VFHSignature308 () = default;

Expand All @@ -1547,7 +1547,7 @@ namespace pcl
struct GRSDSignature21
{
float histogram[21] = {0.f};
static int descriptorSize () { return 21; }
static constexpr int descriptorSize () { return 21; }

inline GRSDSignature21 () = default;

Expand All @@ -1563,7 +1563,7 @@ namespace pcl
float scale = 0.f;
float orientation = 0.f;
unsigned char descriptor[64] = {0};
static int descriptorSize () { return 64; }
static constexpr int descriptorSize () { return 64; }

inline BRISKSignature512 () = default;

Expand All @@ -1579,7 +1579,7 @@ namespace pcl
struct ESFSignature640
{
float histogram[640] = {0.f};
static int descriptorSize () { return 640; }
static constexpr int descriptorSize () { return 640; }

inline ESFSignature640 () = default;

Expand All @@ -1593,7 +1593,7 @@ namespace pcl
struct GASDSignature512
{
float histogram[512] = {0.f};
static int descriptorSize() { return 512; }
static constexpr int descriptorSize() { return 512; }

inline GASDSignature512 () = default;

Expand All @@ -1607,7 +1607,7 @@ namespace pcl
struct GASDSignature984
{
float histogram[984] = {0.f};
static int descriptorSize() { return 984; }
static constexpr int descriptorSize() { return 984; }

inline GASDSignature984 () = default;

Expand All @@ -1621,7 +1621,7 @@ namespace pcl
struct GASDSignature7992
{
float histogram[7992] = {0.f};
static int descriptorSize() { return 7992; }
static constexpr int descriptorSize() { return 7992; }

inline GASDSignature7992 () = default;

Expand All @@ -1635,7 +1635,7 @@ namespace pcl
struct GFPFHSignature16
{
float histogram[16] = {0.f};
static int descriptorSize () { return 16; }
static constexpr int descriptorSize () { return 16; }

inline GFPFHSignature16 () = default;

Expand All @@ -1650,7 +1650,7 @@ namespace pcl
{
float x = 0.f, y = 0.f, z = 0.f, roll = 0.f, pitch = 0.f, yaw = 0.f;
float descriptor[36] = {0.f};
static int descriptorSize () { return 36; }
static constexpr int descriptorSize () { return 36; }

inline Narf36 () = default;

Expand Down Expand Up @@ -1712,7 +1712,7 @@ namespace pcl
struct Histogram
{
float histogram[N];
static int descriptorSize () { return N; }
static constexpr int descriptorSize () { return N; }
};

struct EIGEN_ALIGN16 _PointWithScale
Expand Down Expand Up @@ -1861,7 +1861,7 @@ namespace pcl
operator << (std::ostream& os, const Histogram<N>& p)
{
// make constexpr
if (N > 0)
PCL_IF_CONSTEXPR(N > 0)
{
os << "(" << p.histogram[0];
std::for_each(p.histogram + 1, std::end(p.histogram),
Expand Down
6 changes: 6 additions & 0 deletions common/include/pcl/pcl_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,9 @@ aligned_free(void* ptr)
#else
#define PCL_NODISCARD
#endif

#ifdef __cpp_if_constexpr
#define PCL_IF_CONSTEXPR(x) if constexpr(x)
#else
#define PCL_IF_CONSTEXPR(x) if (x)
#endif

0 comments on commit 65e8829

Please sign in to comment.