Skip to content

Commit

Permalink
Fix MSVC warning C26814: "The const variable 'variable' can be comput…
Browse files Browse the repository at this point in the history
…ed at compile time. Consider using constexpr.."
  • Loading branch information
SunBlack committed Nov 21, 2022
1 parent 58f9cfb commit 5ec6c90
Show file tree
Hide file tree
Showing 53 changed files with 168 additions and 168 deletions.
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
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
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/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
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_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
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
2 changes: 1 addition & 1 deletion gpu/people/include/pcl/gpu/people/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace pcl
namespace trees
{
// this has nothing to do here...
static const double focal = 1000.;
constexpr double focal = 1000.;

// ###############################################
// compile type values
Expand Down
4 changes: 2 additions & 2 deletions gpu/people/src/cuda/nvidia/NCV.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ NCV_CT_ASSERT(sizeof(NcvPoint2D32u) == 2 * sizeof(Ncv32u));
//
//==============================================================================

const Ncv32u K_WARP_SIZE = 32;
const Ncv32u K_LOG2_WARP_SIZE = 5;
constexpr Ncv32u K_WARP_SIZE = 32;
constexpr Ncv32u K_LOG2_WARP_SIZE = 5;

//==============================================================================
//
Expand Down
32 changes: 16 additions & 16 deletions io/include/pcl/compression/impl/entropy_range_coder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ pcl::AdaptiveRangeCoder::encodeCharVectorToStream (const std::vector<char>& inpu
DWord freq[257];

// define limits
const DWord top = static_cast<DWord> (1) << 24;
const DWord bottom = static_cast<DWord> (1) << 16;
const DWord maxRange = static_cast<DWord> (1) << 16;
constexpr DWord top = static_cast<DWord>(1) << 24;
constexpr DWord bottom = static_cast<DWord>(1) << 16;
constexpr DWord maxRange = static_cast<DWord>(1) << 16;

auto input_size = static_cast<unsigned> (inputByteVector_arg.size ());

Expand Down Expand Up @@ -132,9 +132,9 @@ pcl::AdaptiveRangeCoder::decodeStreamToCharVector (std::istream& inputByteStream
DWord freq[257];

// define limits
const DWord top = static_cast<DWord> (1) << 24;
const DWord bottom = static_cast<DWord> (1) << 16;
const DWord maxRange = static_cast<DWord> (1) << 16;
constexpr DWord top = static_cast<DWord>(1) << 24;
constexpr DWord bottom = static_cast<DWord>(1) << 16;
constexpr DWord maxRange = static_cast<DWord>(1) << 16;

auto output_size = static_cast<unsigned> (outputByteVector_arg.size ());

Expand Down Expand Up @@ -222,9 +222,9 @@ pcl::StaticRangeCoder::encodeIntVectorToStream (std::vector<unsigned int>& input
std::ostream& outputByteStream_arg)
{
// define numerical limits
const std::uint64_t top = static_cast<std::uint64_t> (1) << 56;
const std::uint64_t bottom = static_cast<std::uint64_t> (1) << 48;
const std::uint64_t maxRange = static_cast<std::uint64_t> (1) << 48;
constexpr std::uint64_t top = static_cast<std::uint64_t>(1) << 56;
constexpr std::uint64_t bottom = static_cast<std::uint64_t>(1) << 48;
constexpr std::uint64_t maxRange = static_cast<std::uint64_t>(1) << 48;

auto input_size = static_cast<unsigned long> (inputIntVector_arg.size ());

Expand Down Expand Up @@ -353,8 +353,8 @@ pcl::StaticRangeCoder::decodeStreamToIntVector (std::istream& inputByteStream_ar
std::vector<unsigned int>& outputIntVector_arg)
{
// define range limits
const std::uint64_t top = static_cast<std::uint64_t> (1) << 56;
const std::uint64_t bottom = static_cast<std::uint64_t> (1) << 48;
constexpr std::uint64_t top = static_cast<std::uint64_t>(1) << 56;
constexpr std::uint64_t bottom = static_cast<std::uint64_t>(1) << 48;

std::uint64_t frequencyTableSize;
unsigned char frequencyTableByteSize;
Expand Down Expand Up @@ -445,9 +445,9 @@ pcl::StaticRangeCoder::encodeCharVectorToStream (const std::vector<char>& inputB
DWord freq[257];

// define numerical limits
const DWord top = static_cast<DWord> (1) << 24;
const DWord bottom = static_cast<DWord> (1) << 16;
const DWord maxRange = static_cast<DWord> (1) << 16;
constexpr DWord top = static_cast<DWord>(1) << 24;
constexpr DWord bottom = static_cast<DWord>(1) << 16;
constexpr DWord maxRange = static_cast<DWord>(1) << 16;

DWord low, range;

Expand Down Expand Up @@ -543,8 +543,8 @@ pcl::StaticRangeCoder::decodeStreamToCharVector (std::istream& inputByteStream_a
DWord freq[257];

// define range limits
const DWord top = static_cast<DWord> (1) << 24;
const DWord bottom = static_cast<DWord> (1) << 16;
constexpr DWord top = static_cast<DWord>(1) << 24;
constexpr DWord bottom = static_cast<DWord>(1) << 16;

DWord low, range;
DWord code;
Expand Down
4 changes: 2 additions & 2 deletions keypoints/include/pcl/keypoints/impl/sift_keypoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pcl::SIFTKeypoint<PointInT, PointOutT>::detectKeypoints (PointCloudOut &output)
cloud = temp;

// Make sure the downsampled cloud still has enough points
const std::size_t min_nr_points = 25;
constexpr std::size_t min_nr_points = 25;
if (cloud->size () < min_nr_points)
break;

Expand Down Expand Up @@ -261,7 +261,7 @@ pcl::SIFTKeypoint<PointInT, PointOutT>::findScaleSpaceExtrema (
const PointCloudIn &input, KdTree &tree, const Eigen::MatrixXf &diff_of_gauss,
pcl::Indices &extrema_indices, std::vector<int> &extrema_scales)
{
const int k = 25;
constexpr int k = 25;
pcl::Indices nn_indices (k);
std::vector<float> nn_dist (k);

Expand Down
4 changes: 2 additions & 2 deletions octree/include/pcl/octree/impl/octree_pointcloud.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pcl::octree::OctreePointCloud<PointT, LeafContainerT, BranchContainerT, OctreeT>
adoptBoundingBoxToPoint(const PointT& point_arg)
{

const float minValue = std::numeric_limits<float>::epsilon();
constexpr float minValue = std::numeric_limits<float>::epsilon();

// increase octree size until point fits into bounding box
while (true) {
Expand Down Expand Up @@ -679,7 +679,7 @@ void
pcl::octree::OctreePointCloud<PointT, LeafContainerT, BranchContainerT, OctreeT>::
getKeyBitSize()
{
const float minValue = std::numeric_limits<float>::epsilon();
constexpr float minValue = std::numeric_limits<float>::epsilon();

// find maximum key values for x, y, z
const auto max_key_x =
Expand Down
2 changes: 1 addition & 1 deletion octree/include/pcl/octree/octree_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ class OctreePointCloudSearch
unsigned char& a) const
{
// Account for division by zero when direction vector is 0.0
const float epsilon = 1e-10f;
constexpr float epsilon = 1e-10f;
if (direction.x() == 0.0)
direction.x() = epsilon;
if (direction.y() == 0.0)
Expand Down
6 changes: 3 additions & 3 deletions recognition/include/pcl/recognition/color_gradient_modality.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ computeGaussianKernel (const std::size_t kernel_size, const float sigma, std::ve
{
// code taken from OpenCV
const int n = int (kernel_size);
const int SMALL_GAUSSIAN_SIZE = 7;
constexpr int SMALL_GAUSSIAN_SIZE = 7;
static const float small_gaussian_tab[][SMALL_GAUSSIAN_SIZE] =
{
{1.f},
Expand Down Expand Up @@ -340,7 +340,7 @@ pcl::ColorGradientModality<PointInT>::
processInputData ()
{
// compute gaussian kernel values
const std::size_t kernel_size = 7;
constexpr std::size_t kernel_size = 7;
std::vector<float> kernel_values;
computeGaussianKernel (kernel_size, 0.0f, kernel_values);

Expand Down Expand Up @@ -971,7 +971,7 @@ quantizeColorGradients ()

quantized_color_gradients_.resize (width, height);

const float angleScale = 16.0f/360.0f;
constexpr float angleScale = 16.0f / 360.0f;

//float min_angle = std::numeric_limits<float>::max ();
//float max_angle = -std::numeric_limits<float>::max ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ namespace pcl
{
// 'p_obj' is the probability that given that the first sample point belongs to an object,
// the second sample point will belong to the same object
const double p_obj = 0.25f;
constexpr double p_obj = 0.25f;
// old version: p = p_obj*relative_obj_size_*fraction_of_pairs_in_hash_table_;
const double p = p_obj*relative_obj_size_;
const double p = p_obj * relative_obj_size_;

if ( 1.0 - p <= 0.0 )
return 1;
Expand Down
Loading

0 comments on commit 5ec6c90

Please sign in to comment.