Skip to content

Commit 5ec6c90

Browse files
committed
Fix MSVC warning C26814: "The const variable 'variable' can be computed at compile time. Consider using constexpr.."
1 parent 58f9cfb commit 5ec6c90

File tree

53 files changed

+168
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+168
-168
lines changed

apps/in_hand_scanner/src/icp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pcl::ihs::ICP::findTransformation(const MeshConstPtr& mesh_model,
161161
{
162162
// Check the input
163163
// TODO: Double check the minimum number of points necessary for icp
164-
const std::size_t n_min = 4;
164+
constexpr std::size_t n_min = 4;
165165

166166
if (mesh_model->sizeVertices() < n_min || cloud_data->size() < n_min) {
167167
std::cerr << "ERROR in icp.cpp: Not enough input points!\n";

apps/in_hand_scanner/src/main_window.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pcl::ihs::MainWindow::MainWindow(QWidget* parent)
7070
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
7171
ui_->toolBar->insertWidget(ui_->actionHelp, spacer);
7272

73-
const double max = std::numeric_limits<double>::max();
73+
constexpr double max = std::numeric_limits<double>::max();
7474

7575
// In hand scanner
7676
QHBoxLayout* layout = new QHBoxLayout(ui_->placeholder_in_hand_scanner);

apps/in_hand_scanner/src/opengl_viewer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ pcl::ihs::OpenGLViewer::addMesh(const CloudXYZRGBNormalConstPtr& cloud,
484484
const int h = cloud->height;
485485
const int offset_1 = -w;
486486
const int offset_2 = -w - 1;
487-
const int offset_3 = -1;
487+
constexpr int offset_3 = -1;
488488

489489
FaceVertexMeshPtr mesh(new FaceVertexMesh());
490490
mesh->transformation = T;
@@ -1083,7 +1083,7 @@ pcl::ihs::OpenGLViewer::initializeGL()
10831083
void
10841084
pcl::ihs::OpenGLViewer::setupViewport(const int w, const int h)
10851085
{
1086-
const float aspect_ratio = 4. / 3.;
1086+
constexpr float aspect_ratio = 4. / 3.;
10871087

10881088
// Use the biggest possible area of the window to draw to
10891089
// case 1 (w < w_scaled): case 2 (w >= w_scaled):

apps/src/openni_mobile_server.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ CopyPointCloudToBuffers(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr& clou
7979
point.x > bounds_max.x || point.y > bounds_max.y || point.z > bounds_max.z)
8080
continue;
8181

82-
const int conversion_factor = 500;
82+
constexpr int conversion_factor = 500;
8383

8484
cloud_buffers.points[j * 3 + 0] = static_cast<short>(point.x * conversion_factor);
8585
cloud_buffers.points[j * 3 + 1] = static_cast<short>(point.y * conversion_factor);

apps/src/pyramid_surface_matching.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using namespace pcl;
99
#include <iostream>
1010

1111
const Eigen::Vector4f subsampling_leaf_size(0.02f, 0.02f, 0.02f, 0.0f);
12-
const float normal_estimation_search_radius = 0.05f;
12+
constexpr float normal_estimation_search_radius = 0.05f;
1313

1414
void
1515
subsampleAndCalculateNormals(PointCloud<PointXYZ>::Ptr& cloud,

common/include/pcl/common/impl/eigen.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ computeRoots (const Matrix& m, Roots& roots)
8989
computeRoots2 (c2, c1, roots);
9090
else
9191
{
92-
const Scalar s_inv3 = Scalar (1.0 / 3.0);
92+
constexpr Scalar s_inv3 = Scalar(1.0 / 3.0);
9393
const Scalar s_sqrt3 = std::sqrt (Scalar (3.0));
9494
// Construct the parameters used in classifying the roots of the equation
9595
// and in solving the equation for the roots in closed form.

common/include/pcl/point_representation.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ namespace pcl
250250
template<typename Key> inline void operator() ()
251251
{
252252
using FieldT = typename pcl::traits::datatype<PointDefault, Key>::type;
253-
const int NrDims = pcl::traits::datatype<PointDefault, Key>::size;
253+
constexpr int NrDims = pcl::traits::datatype<PointDefault, Key>::size;
254254
Helper<Key, FieldT, NrDims>::copyPoint (p1_, p2_, f_idx_);
255255
}
256256

common/include/pcl/register_point_struct.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace pcl
100100
plus (std::remove_const_t<T> &l, const T &r)
101101
{
102102
using type = std::remove_all_extents_t<T>;
103-
static const std::uint32_t count = sizeof (T) / sizeof (type);
103+
constexpr std::uint32_t count = sizeof(T) / sizeof(type);
104104
for (std::uint32_t i = 0; i < count; ++i)
105105
l[i] += r[i];
106106
}
@@ -117,7 +117,7 @@ namespace pcl
117117
plusscalar (T1 &p, const T2 &scalar)
118118
{
119119
using type = std::remove_all_extents_t<T1>;
120-
static const std::uint32_t count = sizeof (T1) / sizeof (type);
120+
constexpr std::uint32_t count = sizeof(T1) / sizeof(type);
121121
for (std::uint32_t i = 0; i < count; ++i)
122122
p[i] += scalar;
123123
}
@@ -134,7 +134,7 @@ namespace pcl
134134
minus (std::remove_const_t<T> &l, const T &r)
135135
{
136136
using type = std::remove_all_extents_t<T>;
137-
static const std::uint32_t count = sizeof (T) / sizeof (type);
137+
constexpr std::uint32_t count = sizeof(T) / sizeof(type);
138138
for (std::uint32_t i = 0; i < count; ++i)
139139
l[i] -= r[i];
140140
}
@@ -151,7 +151,7 @@ namespace pcl
151151
minusscalar (T1 &p, const T2 &scalar)
152152
{
153153
using type = std::remove_all_extents_t<T1>;
154-
static const std::uint32_t count = sizeof (T1) / sizeof (type);
154+
constexpr std::uint32_t count = sizeof(T1) / sizeof(type);
155155
for (std::uint32_t i = 0; i < count; ++i)
156156
p[i] -= scalar;
157157
}
@@ -168,7 +168,7 @@ namespace pcl
168168
mulscalar (T1 &p, const T2 &scalar)
169169
{
170170
using type = std::remove_all_extents_t<T1>;
171-
static const std::uint32_t count = sizeof (T1) / sizeof (type);
171+
constexpr std::uint32_t count = sizeof(T1) / sizeof(type);
172172
for (std::uint32_t i = 0; i < count; ++i)
173173
p[i] *= scalar;
174174
}
@@ -185,7 +185,7 @@ namespace pcl
185185
divscalar (T1 &p, const T2 &scalar)
186186
{
187187
using type = std::remove_all_extents_t<T1>;
188-
static const std::uint32_t count = sizeof (T1) / sizeof (type);
188+
constexpr std::uint32_t count = sizeof (T1) / sizeof (type);
189189
for (std::uint32_t i = 0; i < count; ++i)
190190
p[i] /= scalar;
191191
}
@@ -202,7 +202,7 @@ namespace pcl
202202
divscalar2 (ArrayT &p, const ScalarT &scalar)
203203
{
204204
using type = std::remove_all_extents_t<ArrayT>;
205-
static const std::uint32_t count = sizeof (ArrayT) / sizeof (type);
205+
constexpr std::uint32_t count = sizeof (ArrayT) / sizeof (type);
206206
for (std::uint32_t i = 0; i < count; ++i)
207207
p[i] = scalar / p[i];
208208
}

examples/features/example_difference_of_normals.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int main (int argc, char *argv[])
9999

100100
// Create downsampled point cloud for DoN NN search with large scale
101101
large_cloud_downsampled = PointCloud<PointT>::Ptr(new pcl::PointCloud<PointT>);
102-
const float largedownsample = float (scale2/decimation);
102+
constexpr float largedownsample = float(scale2 / decimation);
103103
sor.setLeafSize (largedownsample, largedownsample, largedownsample);
104104
sor.filter (*large_cloud_downsampled);
105105
std::cout << "Using leaf size of " << largedownsample << " for large scale, " << large_cloud_downsampled->size() << " points" << std::endl;

examples/keypoints/example_sift_z_keypoint_estimation.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ main(int, char** argv)
7575
std::cout << "points: " << cloud_xyz->size () <<std::endl;
7676

7777
// Parameters for sift computation
78-
const float min_scale = 0.005f;
79-
const int n_octaves = 6;
80-
const int n_scales_per_octave = 4;
81-
const float min_contrast = 0.005f;
78+
constexpr float min_scale = 0.005f;
79+
constexpr int n_octaves = 6;
80+
constexpr int n_scales_per_octave = 4;
81+
constexpr float min_contrast = 0.005f;
8282

8383
// Estimate the sift interest points using z values from xyz as the Intensity variants
8484
pcl::SIFTKeypoint<pcl::PointXYZ, pcl::PointWithScale> sift;

examples/segmentation/example_extract_clusters_normals.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ main (int argc, char **argv)
7979

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

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

gpu/kinfu/tools/record_tsdfvolume.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ DeviceVolume::createFromDepth (const pcl::device::PtrStepSz<const unsigned short
138138

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

141-
const int rows = 480;
142-
const int cols = 640;
141+
constexpr int rows = 480;
142+
constexpr int cols = 640;
143143

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

202202
// point buffer on the device
203203
pcl::gpu::DeviceArray<pcl::PointXYZ> device_cloud_buffer (DEFAULT_VOLUME_CLOUD_BUFFER_SIZE);

gpu/kinfu_large_scale/tools/kinfuLS_app.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ struct KinFuLSApp
790790
{
791791
if(registration_)
792792
{
793-
const int max_color_integration_weight = 2;
793+
constexpr int max_color_integration_weight = 2;
794794
kinfu_->initColorIntegration(max_color_integration_weight);
795795
integrate_colors_ = true;
796796
}

gpu/people/include/pcl/gpu/people/tree.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace pcl
5353
namespace trees
5454
{
5555
// this has nothing to do here...
56-
static const double focal = 1000.;
56+
constexpr double focal = 1000.;
5757

5858
// ###############################################
5959
// compile type values

gpu/people/src/cuda/nvidia/NCV.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ NCV_CT_ASSERT(sizeof(NcvPoint2D32u) == 2 * sizeof(Ncv32u));
212212
//
213213
//==============================================================================
214214

215-
const Ncv32u K_WARP_SIZE = 32;
216-
const Ncv32u K_LOG2_WARP_SIZE = 5;
215+
constexpr Ncv32u K_WARP_SIZE = 32;
216+
constexpr Ncv32u K_LOG2_WARP_SIZE = 5;
217217

218218
//==============================================================================
219219
//

io/include/pcl/compression/impl/entropy_range_coder.hpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ pcl::AdaptiveRangeCoder::encodeCharVectorToStream (const std::vector<char>& inpu
5454
DWord freq[257];
5555

5656
// define limits
57-
const DWord top = static_cast<DWord> (1) << 24;
58-
const DWord bottom = static_cast<DWord> (1) << 16;
59-
const DWord maxRange = static_cast<DWord> (1) << 16;
57+
constexpr DWord top = static_cast<DWord>(1) << 24;
58+
constexpr DWord bottom = static_cast<DWord>(1) << 16;
59+
constexpr DWord maxRange = static_cast<DWord>(1) << 16;
6060

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

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

134134
// define limits
135-
const DWord top = static_cast<DWord> (1) << 24;
136-
const DWord bottom = static_cast<DWord> (1) << 16;
137-
const DWord maxRange = static_cast<DWord> (1) << 16;
135+
constexpr DWord top = static_cast<DWord>(1) << 24;
136+
constexpr DWord bottom = static_cast<DWord>(1) << 16;
137+
constexpr DWord maxRange = static_cast<DWord>(1) << 16;
138138

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

@@ -222,9 +222,9 @@ pcl::StaticRangeCoder::encodeIntVectorToStream (std::vector<unsigned int>& input
222222
std::ostream& outputByteStream_arg)
223223
{
224224
// define numerical limits
225-
const std::uint64_t top = static_cast<std::uint64_t> (1) << 56;
226-
const std::uint64_t bottom = static_cast<std::uint64_t> (1) << 48;
227-
const std::uint64_t maxRange = static_cast<std::uint64_t> (1) << 48;
225+
constexpr std::uint64_t top = static_cast<std::uint64_t>(1) << 56;
226+
constexpr std::uint64_t bottom = static_cast<std::uint64_t>(1) << 48;
227+
constexpr std::uint64_t maxRange = static_cast<std::uint64_t>(1) << 48;
228228

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

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

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

447447
// define numerical limits
448-
const DWord top = static_cast<DWord> (1) << 24;
449-
const DWord bottom = static_cast<DWord> (1) << 16;
450-
const DWord maxRange = static_cast<DWord> (1) << 16;
448+
constexpr DWord top = static_cast<DWord>(1) << 24;
449+
constexpr DWord bottom = static_cast<DWord>(1) << 16;
450+
constexpr DWord maxRange = static_cast<DWord>(1) << 16;
451451

452452
DWord low, range;
453453

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

545545
// define range limits
546-
const DWord top = static_cast<DWord> (1) << 24;
547-
const DWord bottom = static_cast<DWord> (1) << 16;
546+
constexpr DWord top = static_cast<DWord>(1) << 24;
547+
constexpr DWord bottom = static_cast<DWord>(1) << 16;
548548

549549
DWord low, range;
550550
DWord code;

keypoints/include/pcl/keypoints/impl/sift_keypoint.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pcl::SIFTKeypoint<PointInT, PointOutT>::detectKeypoints (PointCloudOut &output)
128128
cloud = temp;
129129

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

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

octree/include/pcl/octree/impl/octree_pointcloud.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pcl::octree::OctreePointCloud<PointT, LeafContainerT, BranchContainerT, OctreeT>
475475
adoptBoundingBoxToPoint(const PointT& point_arg)
476476
{
477477

478-
const float minValue = std::numeric_limits<float>::epsilon();
478+
constexpr float minValue = std::numeric_limits<float>::epsilon();
479479

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

684684
// find maximum key values for x, y, z
685685
const auto max_key_x =

octree/include/pcl/octree/octree_search.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ class OctreePointCloudSearch
534534
unsigned char& a) const
535535
{
536536
// Account for division by zero when direction vector is 0.0
537-
const float epsilon = 1e-10f;
537+
constexpr float epsilon = 1e-10f;
538538
if (direction.x() == 0.0)
539539
direction.x() = epsilon;
540540
if (direction.y() == 0.0)

recognition/include/pcl/recognition/color_gradient_modality.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ computeGaussianKernel (const std::size_t kernel_size, const float sigma, std::ve
295295
{
296296
// code taken from OpenCV
297297
const int n = int (kernel_size);
298-
const int SMALL_GAUSSIAN_SIZE = 7;
298+
constexpr int SMALL_GAUSSIAN_SIZE = 7;
299299
static const float small_gaussian_tab[][SMALL_GAUSSIAN_SIZE] =
300300
{
301301
{1.f},
@@ -340,7 +340,7 @@ pcl::ColorGradientModality<PointInT>::
340340
processInputData ()
341341
{
342342
// compute gaussian kernel values
343-
const std::size_t kernel_size = 7;
343+
constexpr std::size_t kernel_size = 7;
344344
std::vector<float> kernel_values;
345345
computeGaussianKernel (kernel_size, 0.0f, kernel_values);
346346

@@ -971,7 +971,7 @@ quantizeColorGradients ()
971971

972972
quantized_color_gradients_.resize (width, height);
973973

974-
const float angleScale = 16.0f/360.0f;
974+
constexpr float angleScale = 16.0f / 360.0f;
975975

976976
//float min_angle = std::numeric_limits<float>::max ();
977977
//float max_angle = -std::numeric_limits<float>::max ();

recognition/include/pcl/recognition/ransac_based/obj_rec_ransac.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,9 @@ namespace pcl
329329
{
330330
// 'p_obj' is the probability that given that the first sample point belongs to an object,
331331
// the second sample point will belong to the same object
332-
const double p_obj = 0.25f;
332+
constexpr double p_obj = 0.25f;
333333
// old version: p = p_obj*relative_obj_size_*fraction_of_pairs_in_hash_table_;
334-
const double p = p_obj*relative_obj_size_;
334+
const double p = p_obj * relative_obj_size_;
335335

336336
if ( 1.0 - p <= 0.0 )
337337
return 1;

0 commit comments

Comments
 (0)