Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use constexpr variables if possible #5522

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/in_hand_scanner/src/icp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ pcl::ihs::ICP::findTransformation(const MeshConstPtr& mesh_model,
{
// Check the input
// TODO: Double check the minimum number of points necessary for icp
const std::size_t n_min = 4;
constexpr std::size_t n_min = 4;

if (mesh_model->sizeVertices() < n_min || cloud_data->size() < n_min) {
std::cerr << "ERROR in icp.cpp: Not enough input points!\n";
Expand Down
4 changes: 2 additions & 2 deletions apps/in_hand_scanner/src/integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pcl::ihs::Integration::reconstructMesh(const CloudXYZRGBNormalConstPtr& cloud_da
// * 3 - 0 //
const int offset_1 = -width;
const int offset_2 = -width - 1;
const int offset_3 = -1;
constexpr int offset_3 = -1;
const int offset_4 = -width - 2;

for (int r = 1; r < height; ++r) {
Expand Down Expand Up @@ -262,7 +262,7 @@ pcl::ihs::Integration::merge(const CloudXYZRGBNormalConstPtr& cloud_data,
// * 3 - 0 //
const int offset_1 = -width;
const int offset_2 = -width - 1;
const int offset_3 = -1;
constexpr int offset_3 = -1;
const int offset_4 = -width - 2;

const float dot_min = std::cos(max_angle_ * 17.45329252e-3); // deg to rad
Expand Down
2 changes: 1 addition & 1 deletion apps/in_hand_scanner/src/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pcl::ihs::MainWindow::MainWindow(QWidget* parent)
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
ui_->toolBar->insertWidget(ui_->actionHelp, spacer);

const double max = std::numeric_limits<double>::max();
constexpr double max = std::numeric_limits<double>::max();

// In hand scanner
QHBoxLayout* layout = new QHBoxLayout(ui_->placeholder_in_hand_scanner);
Expand Down
4 changes: 2 additions & 2 deletions apps/in_hand_scanner/src/opengl_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ pcl::ihs::OpenGLViewer::addMesh(const CloudXYZRGBNormalConstPtr& cloud,
const int h = cloud->height;
const int offset_1 = -w;
const int offset_2 = -w - 1;
const int offset_3 = -1;
constexpr int offset_3 = -1;

FaceVertexMeshPtr mesh(new FaceVertexMesh());
mesh->transformation = T;
Expand Down Expand Up @@ -1083,7 +1083,7 @@ pcl::ihs::OpenGLViewer::initializeGL()
void
pcl::ihs::OpenGLViewer::setupViewport(const int w, const int h)
{
const float aspect_ratio = 4. / 3.;
constexpr float aspect_ratio = 4. / 3.;

// Use the biggest possible area of the window to draw to
// case 1 (w < w_scaled): case 2 (w >= w_scaled):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,25 +167,25 @@ struct IncIndex
/// A helpful const representing the number of elements in our vectors.
/// This is used for all operations that require the copying of the vector.
/// Although this is used in a fairly generic way, the display requires 3D.
const unsigned int XYZ_SIZE = 3;
constexpr unsigned int XYZ_SIZE = 3;

/// A helpful const representing the number of elements in each row/col in
/// our matrices. This is used for all operations that require the copying of
/// the matrix.
const unsigned int MATRIX_SIZE_DIM = 4;
constexpr unsigned int MATRIX_SIZE_DIM = 4;

/// A helpful const representing the number of elements in our matrices.
/// This is used for all operations that require the copying of the matrix.
const unsigned int MATRIX_SIZE = MATRIX_SIZE_DIM * MATRIX_SIZE_DIM;
constexpr unsigned int MATRIX_SIZE = MATRIX_SIZE_DIM * MATRIX_SIZE_DIM;

/// The default window width
const unsigned int WINDOW_WIDTH = 1200;
constexpr unsigned int WINDOW_WIDTH = 1200;
/// The default window height
const unsigned int WINDOW_HEIGHT = 1000;
constexpr unsigned int WINDOW_HEIGHT = 1000;

/// The default z translation used to push the world origin in front of the
/// display
const float DISPLAY_Z_TRANSLATION = -2.0f;
constexpr float DISPLAY_Z_TRANSLATION = -2.0f;

/// The radius of the trackball given as a percentage of the screen width
const float TRACKBALL_RADIUS_SCALE = 0.4f;
constexpr float TRACKBALL_RADIUS_SCALE = 0.4f;
2 changes: 1 addition & 1 deletion apps/src/feature_matching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ ICCVTutorial<FeatureType>::findCorrespondences(

// Find the index of the best match for each keypoint, and store it in
// "correspondences_out"
const int k = 1;
constexpr int k = 1;
pcl::Indices k_indices(k);
std::vector<float> k_squared_distances(k);
for (int i = 0; i < static_cast<int>(source->size()); ++i) {
Expand Down
2 changes: 1 addition & 1 deletion apps/src/multiscale_feature_persistence_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
using namespace pcl;

const Eigen::Vector4f subsampling_leaf_size(0.01f, 0.01f, 0.01f, 0.0f);
const float normal_estimation_search_radius = 0.05f;
constexpr float normal_estimation_search_radius = 0.05f;

void
subsampleAndCalculateNormals(PointCloud<PointXYZ>::Ptr& cloud,
Expand Down
6 changes: 3 additions & 3 deletions apps/src/openni_feature_persistence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ using namespace std::chrono_literals;
} while (false)
// clang-format on

const float default_subsampling_leaf_size = 0.02f;
const float default_normal_search_radius = 0.041f;
constexpr float default_subsampling_leaf_size = 0.02f;
constexpr float default_normal_search_radius = 0.041f;
const double aux[] = {0.21, 0.32};
const std::vector<double> default_scales_vector(aux, aux + 2);
const float default_alpha = 1.2f;
constexpr float default_alpha = 1.2f;

template <typename PointType>
class OpenNIFeaturePersistence {
Expand Down
2 changes: 1 addition & 1 deletion apps/src/openni_mobile_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ CopyPointCloudToBuffers(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr& clou
point.x > bounds_max.x || point.y > bounds_max.y || point.z > bounds_max.z)
continue;

const int conversion_factor = 500;
constexpr int conversion_factor = 500;

cloud_buffers.points[j * 3 + 0] = static_cast<short>(point.x * conversion_factor);
cloud_buffers.points[j * 3 + 1] = static_cast<short>(point.y * conversion_factor);
Expand Down
2 changes: 1 addition & 1 deletion apps/src/openni_organized_edge_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class OpenNIOrganizedEdgeDetection {
*this);
viewer->resetCameraViewpoint("cloud");

const int point_size = 2;
constexpr int point_size = 2;
viewer->addPointCloud<PointT>(cloud, "nan boundary edges");
viewer->setPointCloudRenderingProperties(
pcl::visualization::PCL_VISUALIZER_POINT_SIZE,
Expand Down
2 changes: 1 addition & 1 deletion apps/src/openni_shift_to_depth_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class SimpleOpenNIViewer {
int centerY = static_cast<int>(height_arg / 2);

const float fl_const = 1.0f / focalLength_arg;
static const float bad_point = std::numeric_limits<float>::quiet_NaN();
constexpr float bad_point = std::numeric_limits<float>::quiet_NaN();

std::size_t i = 0;
for (int y = -centerY; y < +centerY; ++y)
Expand Down
2 changes: 1 addition & 1 deletion apps/src/pcd_organized_edge_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ compute(const pcl::PCLPointCloud2::ConstPtr& input,
pcl::copyPointCloud(*cloud, label_indices[3].indices, *high_curvature_edges);
pcl::copyPointCloud(*cloud, label_indices[4].indices, *rgb_edges);

const int point_size = 2;
constexpr int point_size = 2;
viewer.addPointCloud<pcl::PointXYZRGBA>(nan_boundary_edges, "nan boundary edges");
viewer.setPointCloudRenderingProperties(
pcl::visualization::PCL_VISUALIZER_POINT_SIZE, point_size, "nan boundary edges");
Expand Down
2 changes: 1 addition & 1 deletion apps/src/ppf_object_recognition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using namespace pcl;
using namespace std::chrono_literals;

const Eigen::Vector4f subsampling_leaf_size(0.02f, 0.02f, 0.02f, 0.0f);
const float normal_estimation_search_radius = 0.05f;
constexpr float normal_estimation_search_radius = 0.05f;

PointCloud<PointNormal>::Ptr
subsampleAndCalculateNormals(const PointCloud<PointXYZ>::Ptr& cloud)
Expand Down
2 changes: 1 addition & 1 deletion apps/src/pyramid_surface_matching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using namespace pcl;
#include <iostream>

const Eigen::Vector4f subsampling_leaf_size(0.02f, 0.02f, 0.02f, 0.0f);
const float normal_estimation_search_radius = 0.05f;
constexpr float normal_estimation_search_radius = 0.05f;

void
subsampleAndCalculateNormals(PointCloud<PointXYZ>::Ptr& cloud,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@

using namespace pcl;

const float subsampling_leaf_size = 0.003f;
const float base_scale = 0.005f;
constexpr float subsampling_leaf_size = 0.003f;
constexpr float base_scale = 0.005f;

int
main(int, char** argv)
Expand Down
4 changes: 2 additions & 2 deletions common/include/pcl/common/impl/copy_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ struct CopyPointHelper<PointInT, PointOutT,
using FieldListInT = typename pcl::traits::fieldList<PointInT>::type;
using FieldListOutT = typename pcl::traits::fieldList<PointOutT>::type;
using FieldList = typename pcl::intersect<FieldListInT, FieldListOutT>::type;
const std::uint32_t offset_in = boost::mpl::if_<pcl::traits::has_field<PointInT, pcl::fields::rgb>,
constexpr std::uint32_t offset_in = boost::mpl::if_<pcl::traits::has_field<PointInT, pcl::fields::rgb>,
pcl::traits::offset<PointInT, pcl::fields::rgb>,
pcl::traits::offset<PointInT, pcl::fields::rgba> >::type::value;
const std::uint32_t offset_out = boost::mpl::if_<pcl::traits::has_field<PointOutT, pcl::fields::rgb>,
constexpr std::uint32_t offset_out = boost::mpl::if_<pcl::traits::has_field<PointOutT, pcl::fields::rgb>,
pcl::traits::offset<PointOutT, pcl::fields::rgb>,
pcl::traits::offset<PointOutT, pcl::fields::rgba> >::type::value;
pcl::for_each_type <FieldList> (pcl::NdConcatenateFunctor <PointInT, PointOutT> (point_in, point_out));
Expand Down
2 changes: 1 addition & 1 deletion common/include/pcl/common/impl/eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ computeRoots (const Matrix& m, Roots& roots)
computeRoots2 (c2, c1, roots);
else
{
const Scalar s_inv3 = Scalar (1.0 / 3.0);
constexpr Scalar s_inv3 = Scalar(1.0 / 3.0);
const Scalar s_sqrt3 = std::sqrt (Scalar (3.0));
// Construct the parameters used in classifying the roots of the equation
// and in solving the equation for the roots in closed form.
Expand Down
2 changes: 1 addition & 1 deletion common/include/pcl/point_representation.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ namespace pcl
template<typename Key> inline void operator() ()
{
using FieldT = typename pcl::traits::datatype<PointDefault, Key>::type;
const int NrDims = pcl::traits::datatype<PointDefault, Key>::size;
constexpr int NrDims = pcl::traits::datatype<PointDefault, Key>::size;
Helper<Key, FieldT, NrDims>::copyPoint (p1_, p2_, f_idx_);
}

Expand Down
14 changes: 7 additions & 7 deletions common/include/pcl/register_point_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ namespace pcl
plus (std::remove_const_t<T> &l, const T &r)
{
using type = std::remove_all_extents_t<T>;
static const std::uint32_t count = sizeof (T) / sizeof (type);
constexpr std::uint32_t count = sizeof(T) / sizeof(type);
for (std::uint32_t i = 0; i < count; ++i)
l[i] += r[i];
}
Expand All @@ -117,7 +117,7 @@ namespace pcl
plusscalar (T1 &p, const T2 &scalar)
{
using type = std::remove_all_extents_t<T1>;
static const std::uint32_t count = sizeof (T1) / sizeof (type);
constexpr std::uint32_t count = sizeof(T1) / sizeof(type);
for (std::uint32_t i = 0; i < count; ++i)
p[i] += scalar;
}
Expand All @@ -134,7 +134,7 @@ namespace pcl
minus (std::remove_const_t<T> &l, const T &r)
{
using type = std::remove_all_extents_t<T>;
static const std::uint32_t count = sizeof (T) / sizeof (type);
constexpr std::uint32_t count = sizeof(T) / sizeof(type);
for (std::uint32_t i = 0; i < count; ++i)
l[i] -= r[i];
}
Expand All @@ -151,7 +151,7 @@ namespace pcl
minusscalar (T1 &p, const T2 &scalar)
{
using type = std::remove_all_extents_t<T1>;
static const std::uint32_t count = sizeof (T1) / sizeof (type);
constexpr std::uint32_t count = sizeof(T1) / sizeof(type);
for (std::uint32_t i = 0; i < count; ++i)
p[i] -= scalar;
}
Expand All @@ -168,7 +168,7 @@ namespace pcl
mulscalar (T1 &p, const T2 &scalar)
{
using type = std::remove_all_extents_t<T1>;
static const std::uint32_t count = sizeof (T1) / sizeof (type);
constexpr std::uint32_t count = sizeof(T1) / sizeof(type);
for (std::uint32_t i = 0; i < count; ++i)
p[i] *= scalar;
}
Expand All @@ -185,7 +185,7 @@ namespace pcl
divscalar (T1 &p, const T2 &scalar)
{
using type = std::remove_all_extents_t<T1>;
static const std::uint32_t count = sizeof (T1) / sizeof (type);
constexpr std::uint32_t count = sizeof (T1) / sizeof (type);
for (std::uint32_t i = 0; i < count; ++i)
p[i] /= scalar;
}
Expand All @@ -202,7 +202,7 @@ namespace pcl
divscalar2 (ArrayT &p, const ScalarT &scalar)
{
using type = std::remove_all_extents_t<ArrayT>;
static const std::uint32_t count = sizeof (ArrayT) / sizeof (type);
constexpr std::uint32_t count = sizeof (ArrayT) / sizeof (type);
for (std::uint32_t i = 0; i < count; ++i)
p[i] = scalar / p[i];
}
Expand Down
2 changes: 1 addition & 1 deletion examples/features/example_difference_of_normals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int main (int argc, char *argv[])

// Create downsampled point cloud for DoN NN search with large scale
large_cloud_downsampled = PointCloud<PointT>::Ptr(new pcl::PointCloud<PointT>);
const float largedownsample = float (scale2/decimation);
constexpr float largedownsample = float(scale2 / decimation);
sor.setLeafSize (largedownsample, largedownsample, largedownsample);
sor.filter (*large_cloud_downsampled);
std::cout << "Using leaf size of " << largedownsample << " for large scale, " << large_cloud_downsampled->size() << " points" << std::endl;
Expand Down
8 changes: 4 additions & 4 deletions examples/keypoints/example_sift_keypoint_estimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ main(int, char** argv)
std::cout << "points: " << cloud->size () <<std::endl;

// Parameters for sift computation
const float min_scale = 0.1f;
const int n_octaves = 6;
const int n_scales_per_octave = 10;
const float min_contrast = 0.5f;
constexpr float min_scale = 0.1f;
constexpr int n_octaves = 6;
constexpr int n_scales_per_octave = 10;
constexpr float min_contrast = 0.5f;


// Estimate the sift interest points using Intensity values from RGB values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ main(int, char** argv)
std::cout << "points: " << cloud_xyz->size () <<std::endl;

// Parameters for sift computation
const float min_scale = 0.01f;
const int n_octaves = 3;
const int n_scales_per_octave = 4;
const float min_contrast = 0.001f;
constexpr float min_scale = 0.01f;
constexpr int n_octaves = 3;
constexpr int n_scales_per_octave = 4;
constexpr float min_contrast = 0.001f;

// Estimate the normals of the cloud_xyz
pcl::NormalEstimation<pcl::PointXYZ, pcl::PointNormal> ne;
Expand Down
8 changes: 4 additions & 4 deletions examples/keypoints/example_sift_z_keypoint_estimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ main(int, char** argv)
std::cout << "points: " << cloud_xyz->size () <<std::endl;

// Parameters for sift computation
const float min_scale = 0.005f;
const int n_octaves = 6;
const int n_scales_per_octave = 4;
const float min_contrast = 0.005f;
constexpr float min_scale = 0.005f;
constexpr int n_octaves = 6;
constexpr int n_scales_per_octave = 4;
constexpr float min_contrast = 0.005f;

// Estimate the sift interest points using z values from xyz as the Intensity variants
pcl::SIFTKeypoint<pcl::PointXYZ, pcl::PointWithScale> sift;
Expand Down
6 changes: 3 additions & 3 deletions examples/segmentation/example_extract_clusters_normals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ main (int argc, char **argv)

// Extracting Euclidean clusters using cloud and its normals
std::vector<pcl::PointIndices> cluster_indices;
const float tolerance = 0.5f; // 50cm tolerance in (x, y, z) coordinate system
const double eps_angle = 5 * (M_PI / 180.0); // 5degree tolerance in normals
const unsigned int min_cluster_size = 50;
constexpr float tolerance = 0.5f; // 50cm tolerance in (x, y, z) coordinate system
constexpr double eps_angle = 5 * (M_PI / 180.0); // 5degree tolerance in normals
constexpr unsigned int min_cluster_size = 50;

pcl::extractEuclideanClusters (*cloud_ptr, *cloud_normals, tolerance, tree_ec, cluster_indices, eps_angle, min_cluster_size);

Expand Down
2 changes: 1 addition & 1 deletion features/include/pcl/features/impl/brisk_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ BRISK2DEstimation<PointInT, PointOutT, KeypointT, IntensityT>::generateKernel (
scale_list_ = new float[scales_];
size_list_ = new unsigned int[scales_];

const float sigma_scale = 1.3f;
constexpr float sigma_scale = 1.3f;

for (unsigned int scale = 0; scale < scales_; ++scale)
{
Expand Down
2 changes: 1 addition & 1 deletion gpu/kinfu/tools/kinfu_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ struct KinFuApp
{
if(registration_)
{
const int max_color_integration_weight = 2;
constexpr int max_color_integration_weight = 2;
kinfu_.initColorIntegration(max_color_integration_weight);
integrate_colors_ = true;
}
Expand Down
6 changes: 3 additions & 3 deletions gpu/kinfu/tools/record_tsdfvolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ DeviceVolume::createFromDepth (const pcl::device::PtrStepSz<const unsigned short

using Matrix3frm = Eigen::Matrix<float, 3, 3, Eigen::RowMajor>;

const int rows = 480;
const int cols = 640;
constexpr int rows = 480;
constexpr int cols = 640;

// scale depth values
gpu::DeviceArray2D<float> device_depth_scaled;
Expand Down Expand Up @@ -197,7 +197,7 @@ DeviceVolume::getVolume (pcl::TSDFVolume<VoxelT, WeightT>::Ptr &volume)
bool
DeviceVolume::getCloud (pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud)
{
const int DEFAULT_VOLUME_CLOUD_BUFFER_SIZE = 10 * 1000 * 1000;
constexpr int DEFAULT_VOLUME_CLOUD_BUFFER_SIZE = 10 * 1000 * 1000;

// point buffer on the device
pcl::gpu::DeviceArray<pcl::PointXYZ> device_cloud_buffer (DEFAULT_VOLUME_CLOUD_BUFFER_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion gpu/kinfu_large_scale/tools/kinfuLS_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ struct KinFuLSApp
{
if(registration_)
{
const int max_color_integration_weight = 2;
constexpr int max_color_integration_weight = 2;
kinfu_->initColorIntegration(max_color_integration_weight);
integrate_colors_ = true;
}
Expand Down
Loading