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

Improve code quality by fixing issues reported by Sonarqube #1510

Merged
merged 5 commits into from
Nov 28, 2024
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 3rdparty/stb_image/stb_image_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f
#ifdef __STDC_LIB_EXT1__
len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
#else
len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
len = snprintf(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
#endif
s->func(s->context, buffer, len);

Expand Down
4 changes: 2 additions & 2 deletions modules/core/include/visp3/core/vpCannyEdgeDetection.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class VISP_EXPORT vpCannyEdgeDetection
}

/**
* \brief Set the minimum stack size, expressed in bytes, due to the recursivity of the algorithm.
* \brief Set the minimum stack size, expressed in bytes, due to the recursive algorithm.
*
* \note The stack size is changed back to its original value after
* before leaving the detect() function.
Expand All @@ -299,7 +299,7 @@ class VISP_EXPORT vpCannyEdgeDetection
(void)requiredStackSize;
static bool hasNotBeenDisplayed = true;
if (hasNotBeenDisplayed) {
std::cerr << "setStackSize has no effect on non-POSIX systems. The stack size is defined during compilation." << std::endl;
std::cerr << "vpCannyEdgeDetection::setStackSize() has no effect on non-POSIX systems. The stack size is defined during compilation." << std::endl;
hasNotBeenDisplayed = false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion modules/core/include/visp3/core/vpEigenConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void eigen2visp(const Eigen::Quaternion<Type> &src, vpQuaternionVector &dst)
template <typename Type>
void eigen2visp(const Eigen::AngleAxis<Type> &src, vpThetaUVector &dst)
{
dst.buildFrom(src.angle() * src.axis()(0), src.angle() * src.axis()(1), src.angle() * src.axis()(2));
const unsigned int val_2 = 2;
dst.buildFrom(src.angle() * src.axis()(0), src.angle() * src.axis()(1), src.angle() * src.axis()(val_2));
}

VISP_EXPORT void eigen2visp(const Eigen::VectorXd &src, vpColVector &dst);
Expand Down
2 changes: 2 additions & 0 deletions modules/core/include/visp3/core/vpForceTwistMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ class VISP_EXPORT vpForceTwistMatrix : public vpArray2D<double>
throw(vpException(vpException::fatalError, "Cannot resize a velocity twist matrix"));
}

private:
static const unsigned int constr_value_6;
#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
/*!
@name Deprecated functions
Expand Down
11 changes: 7 additions & 4 deletions modules/core/include/visp3/core/vpGaussRand.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
* Generation of random number with uniform and normal probability density.
*/

#ifndef vpGaussRand_hh
#define vpGaussRand_hh
#ifndef VP_GAUSSRAND_H
#define VP_GAUSSRAND_H

#include <visp3/core/vpConfig.h>
#include <visp3/core/vpUniRand.h>
Expand Down Expand Up @@ -149,12 +149,15 @@ class VISP_EXPORT vpGaussRand

\param seed_val : New seed.
*/
void seed(long seed_val) { m_rng.setSeed(seed_val, 0x123465789ULL); }
void seed(long seed_val) {
const unsigned long long val_ull = 0x123465789ULL;
m_rng.setSeed(seed_val, val_ull);
}

/*!
Return a random value from the Gaussian noise generator.
*/
double operator()() { return m_sigma * gaussianDraw() + m_mean; }
double operator()() { return (m_sigma * gaussianDraw()) + m_mean; }

private:
double gaussianDraw();
Expand Down
1 change: 1 addition & 0 deletions modules/core/include/visp3/core/vpHistogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ class VISP_EXPORT vpHistogram
unsigned m_size; /*!< Histogram size (max allowed 256).*/
const vpImage<bool> *mp_mask; /*!< Mask that permits to consider only the pixels for which the mask is true.*/
unsigned int m_total; /*!< Cumulated number of pixels in the input image. */
static const unsigned int constr_val_256;
};
END_VISP_NAMESPACE
#endif
2 changes: 2 additions & 0 deletions modules/core/include/visp3/core/vpHomogeneousMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ class VISP_EXPORT vpHomogeneousMatrix : public vpArray2D<double>

protected:
unsigned int m_index;
private:
static const unsigned int constr_value_4;
};

#ifdef VISP_HAVE_NLOHMANN_JSON
Expand Down
2 changes: 2 additions & 0 deletions modules/core/include/visp3/core/vpImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ template <class Type> class vpImage
friend std::ostream &operator<<(std::ostream &s, const vpImage<double> &I);

// Perform a look-up table transformation
// static const unsigned int val_256 = 256;
// void performLut(const Type(&lut)[val_256], unsigned int nbThreads = 1); // Doesn't pass CI
void performLut(const Type(&lut)[256], unsigned int nbThreads = 1);

// Returns a new image that's a quarter size of the current image
Expand Down
2 changes: 2 additions & 0 deletions modules/core/include/visp3/core/vpPoseVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ class VISP_EXPORT vpPoseVector : public vpArray2D<double>
public:
#endif

private:
static const unsigned int constr_value_6;
#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
/*!
@name Deprecated functions
Expand Down
1 change: 1 addition & 0 deletions modules/core/include/visp3/core/vpQuaternionVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class VISP_EXPORT vpQuaternionVector : public vpRotationVector

private:
static const double minimum;
static const unsigned int constr_val_4;

};
END_VISP_NAMESPACE
Expand Down
2 changes: 2 additions & 0 deletions modules/core/include/visp3/core/vpRotationMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ class VISP_EXPORT vpRotationMatrix : public vpArray2D<double>

protected:
unsigned int m_index;
private:
static const unsigned int constr_val_3;
};

#ifndef DOXYGEN_SHOULD_SKIP_THIS
Expand Down
2 changes: 2 additions & 0 deletions modules/core/include/visp3/core/vpRxyzVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class VISP_EXPORT vpRxyzVector : public vpRotationVector
vpRxyzVector &operator=(const vpRxyzVector &) = default;
vpRxyzVector &operator=(const std::initializer_list<double> &list);
#endif
private:
static const unsigned int constr_val_3;
};
END_VISP_NAMESPACE
#endif
2 changes: 2 additions & 0 deletions modules/core/include/visp3/core/vpRzyxVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ class VISP_EXPORT vpRzyxVector : public vpRotationVector
vpRzyxVector &operator=(const vpRzyxVector &) = default;
vpRzyxVector &operator=(const std::initializer_list<double> &list);
#endif
private:
static const unsigned int constr_val_3;
};
END_VISP_NAMESPACE
#endif
2 changes: 2 additions & 0 deletions modules/core/include/visp3/core/vpRzyzVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class VISP_EXPORT vpRzyzVector : public vpRotationVector
vpRzyzVector &operator=(const vpRzyzVector &) = default;
vpRzyzVector &operator=(const std::initializer_list<double> &list);
#endif
private:
static const unsigned int constr_val_3;
};
END_VISP_NAMESPACE
#endif
1 change: 1 addition & 0 deletions modules/core/include/visp3/core/vpThetaUVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class VISP_EXPORT vpThetaUVector : public vpRotationVector

private:
static const double minimum;
static const unsigned int constr_val_3;

};
END_VISP_NAMESPACE
Expand Down
2 changes: 2 additions & 0 deletions modules/core/include/visp3/core/vpTranslationVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class VISP_EXPORT vpTranslationVector : public vpArray2D<double>

protected:
unsigned int m_index; // index used for operator<< and operator, to fill a vector
private:
static const unsigned int constr_val_3;
};
END_VISP_NAMESPACE
#endif
2 changes: 2 additions & 0 deletions modules/core/include/visp3/core/vpVelocityTwistMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ class VISP_EXPORT vpVelocityTwistMatrix : public vpArray2D<double>
VP_DEPRECATED void setIdentity();
//@}
#endif
private:
static const unsigned constr_val_6;
};
END_VISP_NAMESPACE
#endif
6 changes: 4 additions & 2 deletions modules/core/src/camera/vpCameraParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,16 @@ void vpCameraParameters::printParameters()
std::ios::fmtflags original_flags(std::cout.flags());
switch (m_projModel) {
case vpCameraParameters::perspectiveProjWithoutDistortion: {
std::cout.precision(10);
const unsigned int precision = 10;
std::cout.precision(precision);
std::cout << "Camera parameters for perspective projection without distortion:" << std::endl;
std::cout << " px = " << m_px << "\t py = " << m_py << std::endl;
std::cout << " u0 = " << m_u0 << "\t v0 = " << m_v0 << std::endl;
break;
}
case vpCameraParameters::perspectiveProjWithDistortion: {
std::cout.precision(10);
const unsigned int precision = 10;
std::cout.precision(precision);
std::cout << "Camera parameters for perspective projection with distortion:" << std::endl;
std::cout << " px = " << m_px << "\t py = " << m_py << std::endl;
std::cout << " u0 = " << m_u0 << "\t v0 = " << m_v0 << std::endl;
Expand Down
10 changes: 5 additions & 5 deletions modules/core/src/camera/vpXmlParserCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class vpXmlParserCamera::Impl
}

if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITHOUT_DISTORTION)) {
if (nb != 5 || validation != 0x001F) {
if ((nb != 5) || (validation != 0x001F)) {
std::cout << "ERROR in 'model' field:\n";
std::cout << "it must contain 5 parameters\n";

Expand All @@ -481,7 +481,7 @@ class vpXmlParserCamera::Impl
cam_tmp.initPersProjWithoutDistortion(px, py, u0, v0);
}
else if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITH_DISTORTION)) {
if (nb != 7 || validation != 0x7F) {
if ((nb != 7) || (validation != 0x7F)) {
std::cout << "ERROR in 'model' field:\n";
std::cout << "it must contain 7 parameters\n";

Expand All @@ -490,7 +490,7 @@ class vpXmlParserCamera::Impl
cam_tmp.initPersProjWithDistortion(px, py, u0, v0, kud, kdu);
}
else if (!strcmp(model_type.c_str(), LABEL_XML_MODEL_WITH_KANNALA_BRANDT_DISTORTION)) {
if (nb != 10 || validation != 0x3FF) { // at least one coefficient is missing. We should know which one
if ((nb != 10) || (validation != 0x3FF)) { // at least one coefficient is missing. We should know which one
std::cout << "ERROR in 'model' field:\n";
std::cout << "it must contain 10 parameters\n";

Expand Down Expand Up @@ -807,7 +807,7 @@ class vpXmlParserCamera::Impl
node_tmp.append_child(pugi::node_pcdata).set_value(cam_name.c_str());
}

if (im_width != 0 || im_height != 0) {
if ((im_width != 0) || (im_height != 0)) {
node_tmp = node_camera.append_child(pugi::node_comment);
node_tmp.set_value("Size of the image on which camera "
"calibration was performed");
Expand All @@ -819,7 +819,7 @@ class vpXmlParserCamera::Impl
//<image_height>
node_tmp = node_camera.append_child(LABEL_XML_HEIGHT);
node_tmp.append_child(pugi::node_pcdata).text() = im_height;
if (subsampling_width != 0 || subsampling_height != 0) {
if ((subsampling_width != 0) || (subsampling_height != 0)) {
node_tmp = node_camera.append_child(pugi::node_comment);
node_tmp.set_value("Subsampling used to obtain the "
"current size of the image.");
Expand Down
32 changes: 21 additions & 11 deletions modules/core/src/image/private/vpImageConvert_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ BEGIN_VISP_NAMESPACE
}
#endif

for (int i = 2; i < 0x10000; ++i) {
const unsigned int val_0x10000 = 0x10000;
for (unsigned int i = 2; i < val_0x10000; ++i) {
histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF]
}
dest_depth.resize(src_depth.getHeight(), src_depth.getWidth());
Expand Down Expand Up @@ -149,7 +150,8 @@ void vp_createDepthHistogram(const vpImage<uint16_t> &src_depth, vpImage<unsigne
}
#endif

for (int i = 2; i < 0x10000; ++i) {
const unsigned int val_0x10000 = 0x10000;
for (unsigned int i = 2; i < val_0x10000; ++i) {
histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF]
}
dest_depth.resize(src_depth.getHeight(), src_depth.getWidth());
Expand Down Expand Up @@ -193,24 +195,29 @@ void vp_createDepthHistogram(const vpImage<float> &src_depth, vpImage<vpRGBa> &d
}
}

for (int i = 2; i < 0x10000; ++i) {
const unsigned int val_0x10000 = 0x10000;
for (unsigned int i = 2; i < val_0x10000; ++i) {
histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF]
}

const unsigned char val_uc_5 = 5;
const unsigned char val_uc_20 = 20;
const unsigned char val_uc_255 = 255;
#ifdef VISP_HAVE_OPENMP
#pragma omp parallel for
#endif
for (int i = 0; i < src_depth_size; ++i) {
uint16_t d = static_cast<uint16_t>(src_depth.bitmap[i]);
if (d) {
unsigned char f = static_cast<unsigned char>((histogram[d] * 255) / histogram[0xFFFF]); // 0-255 based on histogram location
dest_depth.bitmap[i].R = 255 - f;
dest_depth.bitmap[i].R = val_uc_255 - f;
dest_depth.bitmap[i].G = 0;
dest_depth.bitmap[i].B = f;
dest_depth.bitmap[i].A = vpRGBa::alpha_default;
}
else {
dest_depth.bitmap[i].R = 20;
dest_depth.bitmap[i].G = 5;
dest_depth.bitmap[i].R = val_uc_20;
dest_depth.bitmap[i].G = val_uc_5;
dest_depth.bitmap[i].B = 0;
dest_depth.bitmap[i].A = vpRGBa::alpha_default;
}
Expand All @@ -237,26 +244,29 @@ void vp_createDepthHistogram(const vpImage<uint16_t> &src_depth, vpImage<vpRGBa>
++histogram[static_cast<uint32_t>(src_depth.bitmap[i])];
}

for (unsigned int i = 2; i < 0x10000; ++i) {
const unsigned int val_0x10000 = 0x10000;
for (unsigned int i = 2; i < val_0x10000; ++i) {
histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF]
}

const unsigned char val_uc_5 = 5;
const unsigned char val_uc_20 = 20;
const unsigned char val_uc_255 = 255;
#ifdef VISP_HAVE_OPENMP
#pragma omp parallel for
#endif

for (int i = 0; i < src_depth_size; ++i) {
uint16_t d = src_depth.bitmap[i];
if (d) {
unsigned char f = static_cast<unsigned char>((histogram[d] * 255) / histogram[0xFFFF]); // 0-255 based on histogram location
dest_depth.bitmap[i].R = 255 - f;
dest_depth.bitmap[i].R = val_uc_255 - f;
dest_depth.bitmap[i].G = 0;
dest_depth.bitmap[i].B = f;
dest_depth.bitmap[i].A = vpRGBa::alpha_default;
}
else {
dest_depth.bitmap[i].R = 20;
dest_depth.bitmap[i].G = 5;
dest_depth.bitmap[i].R = val_uc_20;
dest_depth.bitmap[i].G = val_uc_5;
dest_depth.bitmap[i].B = 0;
dest_depth.bitmap[i].A = vpRGBa::alpha_default;
}
Expand Down
Loading
Loading