From 9a29a69803e2a5aef62687e7cc825a947f5bf8ae Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 27 Nov 2024 14:16:09 +0100 Subject: [PATCH 1/5] Fix warning around sprintf() usage that is deprecated --- 3rdparty/stb_image/stb_image_write.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty/stb_image/stb_image_write.h b/3rdparty/stb_image/stb_image_write.h index e4b32ed1bc..151eacaacd 100644 --- a/3rdparty/stb_image/stb_image_write.h +++ b/3rdparty/stb_image/stb_image_write.h @@ -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); From 86c8d68939eb385c3aa80e6130447af62d000140 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 27 Nov 2024 14:19:01 +0100 Subject: [PATCH 2/5] Fix missing initialization of m_minStackSize var Improve quality by fixing issues reported by sonarqube --- .../core/src/image/vpCannyEdgeDetection.cpp | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/modules/core/src/image/vpCannyEdgeDetection.cpp b/modules/core/src/image/vpCannyEdgeDetection.cpp index 5d8222b963..0dbf7c2dc4 100644 --- a/modules/core/src/image/vpCannyEdgeDetection.cpp +++ b/modules/core/src/image/vpCannyEdgeDetection.cpp @@ -26,8 +26,7 @@ * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - * -*****************************************************************************/ + */ #include @@ -103,17 +102,21 @@ vpCannyEdgeDetection::vpCannyEdgeDetection() , m_lowerThresholdRatio(0.6f) , m_upperThreshold(-1.f) , m_upperThresholdRatio(0.8f) +#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX + , m_minStackSize(65532000) // Maximum stack size on MacOS, see https://stackoverflow.com/a/13261334 +#endif , mp_mask(nullptr) { initGaussianFilters(); initGradientFilters(); } -vpCannyEdgeDetection::vpCannyEdgeDetection(const int &gaussianKernelSize, const float &gaussianStdev - , const unsigned int &sobelAperture, const float &lowerThreshold, const float &upperThreshold - , const float &lowerThresholdRatio, const float &upperThresholdRatio - , const vpImageFilter::vpCannyFilteringAndGradientType &filteringType - , const bool &storeEdgePoints +vpCannyEdgeDetection::vpCannyEdgeDetection(const int &gaussianKernelSize, const float &gaussianStdev, + const unsigned int &sobelAperture, const float &lowerThreshold, + const float &upperThreshold, const float &lowerThresholdRatio, + const float &upperThresholdRatio, + const vpImageFilter::vpCannyFilteringAndGradientType &filteringType, + const bool &storeEdgePoints ) : m_filteringAndGradientType(filteringType) , m_gaussianKernelSize(gaussianKernelSize) @@ -138,7 +141,10 @@ vpCannyEdgeDetection::vpCannyEdgeDetection(const int &gaussianKernelSize, const using json = nlohmann::json; -vpCannyEdgeDetection::vpCannyEdgeDetection(const std::string &jsonPath) +vpCannyEdgeDetection::vpCannyEdgeDetection(const std::string &jsonPath) : +#if !defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))) // UNIX + m_minStackSize(65532000) // Maximum stack size on MacOS, see https://stackoverflow.com/a/13261334 +#endif { initFromJSON(jsonPath); } @@ -173,7 +179,8 @@ vpCannyEdgeDetection::initFromJSON(const std::string &jsonPath) void vpCannyEdgeDetection::initGaussianFilters() { - if ((m_gaussianKernelSize % 2) == 0) { + const int val_2 = 2; + if ((m_gaussianKernelSize % val_2) == 0) { throw(vpException(vpException::badValue, "The Gaussian kernel size should be odd")); } m_fg.resize(1, (m_gaussianKernelSize + 1) / 2); @@ -183,7 +190,8 @@ vpCannyEdgeDetection::initGaussianFilters() void vpCannyEdgeDetection::initGradientFilters() { - if ((m_gradientFilterKernelSize % 2) != 1) { + const int val_2 = 2; + if ((m_gradientFilterKernelSize % val_2) != 1) { throw vpException(vpException::badValue, "Gradient filters kernel size should be odd."); } m_gradientFilterX.resize(m_gradientFilterKernelSize, m_gradientFilterKernelSize); @@ -205,13 +213,13 @@ vpCannyEdgeDetection::initGradientFilters() float scaleY = 1.f; if (m_filteringAndGradientType == vpImageFilter::CANNY_GBLUR_SOBEL_FILTERING) { - scaleX = vpImageFilter::getSobelKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1) / 2); - scaleY = vpImageFilter::getSobelKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1) / 2); + scaleX = vpImageFilter::getSobelKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1) / val_2); + scaleY = vpImageFilter::getSobelKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1) / val_2); } else if (m_filteringAndGradientType == vpImageFilter::CANNY_GBLUR_SCHARR_FILTERING) { // Compute the Scharr filters - scaleX = vpImageFilter::getScharrKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1) / 2); - scaleY = vpImageFilter::getScharrKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1) / 2); + scaleX = vpImageFilter::getScharrKernelX(m_gradientFilterX.data, (m_gradientFilterKernelSize - 1) / val_2); + scaleY = vpImageFilter::getScharrKernelY(m_gradientFilterY.data, (m_gradientFilterKernelSize - 1) / val_2); } else { std::string errMsg = "[vpCannyEdgeDetection::initGradientFilters] Error: gradient filtering method \""; @@ -266,7 +274,7 @@ vpCannyEdgeDetection::detect(const vpImage &I) throw(vpException(vpException::fatalError, "getrlimit returned result = %d\n", result)); } #endif -// // Clearing the previous results + // // Clearing the previous results m_edgeMap.resize(I.getHeight(), I.getWidth(), 0); m_edgeCandidateAndGradient.clear(); m_edgePointsCandidates.clear(); @@ -530,11 +538,12 @@ vpCannyEdgeDetection::performHysteresisThresholding(const float &lowerThreshold, void vpCannyEdgeDetection::performEdgeTracking() { + const unsigned char var_uc_255 = 255; std::map, EdgeType>::iterator it; std::map, EdgeType>::iterator m_edgePointsCandidates_end = m_edgePointsCandidates.end(); for (it = m_edgePointsCandidates.begin(); it != m_edgePointsCandidates_end; ++it) { if (it->second == STRONG_EDGE) { - m_edgeMap[it->first.first][it->first.second] = 255; + m_edgeMap[it->first.first][it->first.second] = var_uc_255; if (m_storeListEdgePoints) { m_edgePointsList.push_back(vpImagePoint(it->first.first, it->first.second)); } @@ -599,9 +608,10 @@ vpCannyEdgeDetection::recursiveSearchForStrongEdge(const std::pair Date: Wed, 27 Nov 2024 14:20:19 +0100 Subject: [PATCH 3/5] Improve quality by fixing issues reported by sonarqube --- .../include/visp3/core/vpCannyEdgeDetection.h | 4 +- .../include/visp3/core/vpEigenConversion.h | 3 +- .../include/visp3/core/vpForceTwistMatrix.h | 2 + modules/core/include/visp3/core/vpGaussRand.h | 11 +- modules/core/include/visp3/core/vpHistogram.h | 1 + .../include/visp3/core/vpHomogeneousMatrix.h | 2 + modules/core/include/visp3/core/vpImage.h | 3 +- .../core/include/visp3/core/vpPoseVector.h | 2 + .../include/visp3/core/vpQuaternionVector.h | 1 + .../include/visp3/core/vpRotationMatrix.h | 2 + .../core/include/visp3/core/vpRxyzVector.h | 2 + .../core/include/visp3/core/vpRzyxVector.h | 2 + .../core/include/visp3/core/vpRzyzVector.h | 2 + .../core/include/visp3/core/vpThetaUVector.h | 1 + .../include/visp3/core/vpTranslationVector.h | 2 + .../visp3/core/vpVelocityTwistMatrix.h | 2 + .../core/src/camera/vpCameraParameters.cpp | 6 +- modules/core/src/camera/vpXmlParserCamera.cpp | 10 +- .../src/image/private/vpImageConvert_impl.h | 31 +-- modules/core/src/image/vpImageCircle.cpp | 21 ++- modules/core/src/image/vpImageConvert.cpp | 177 +++++++++++------- modules/core/src/image/vpImageConvert_hsv.cpp | 59 ++++-- modules/core/src/image/vpImageConvert_yuv.cpp | 46 +++-- modules/core/src/image/vpImageFilter_xy.cpp | 18 +- modules/core/src/image/vpImageTools.cpp | 30 +-- modules/core/src/image/vpRGBa.cpp | 3 +- modules/core/src/math/matrix/vpColVector.cpp | 28 ++- .../src/math/matrix/vpEigenConversion.cpp | 3 +- modules/core/src/math/matrix/vpMatrix.cpp | 6 +- .../src/math/matrix/vpMatrix_covariance.cpp | 5 +- modules/core/src/math/matrix/vpMatrix_lu.cpp | 16 +- .../src/math/matrix/vpMatrix_operations.cpp | 19 +- .../src/math/matrix/vpMatrix_operators.cpp | 16 +- .../math/matrix/vpMatrix_pseudo_inverse.cpp | 2 +- modules/core/src/math/matrix/vpRowVector.cpp | 9 +- modules/core/src/math/misc/vpMath.cpp | 10 +- .../src/math/random-generator/vpGaussRand.cpp | 9 +- .../src/math/random-generator/vpUniRand.cpp | 14 +- .../math/transformation/vpExponentialMap.cpp | 5 +- .../transformation/vpForceTwistMatrix.cpp | 39 ++-- .../transformation/vpHomogeneousMatrix.cpp | 73 +++++--- .../src/math/transformation/vpPoseVector.cpp | 25 ++- .../transformation/vpQuaternionVector.cpp | 25 +-- .../math/transformation/vpRotationMatrix.cpp | 55 +++--- .../src/math/transformation/vpRxyzVector.cpp | 25 +-- .../src/math/transformation/vpRzyxVector.cpp | 28 +-- .../src/math/transformation/vpRzyzVector.cpp | 25 +-- .../math/transformation/vpThetaUVector.cpp | 47 ++--- .../transformation/vpTranslationVector.cpp | 23 ++- .../transformation/vpVelocityTwistMatrix.cpp | 36 ++-- modules/core/src/tools/geometry/vpPlane.cpp | 6 +- modules/core/src/tools/geometry/vpPolygon.cpp | 27 ++- .../src/tools/geometry/vpRectOriented.cpp | 34 ++-- .../core/src/tools/histogram/vpHistogram.cpp | 32 ++-- .../tracking/forward-projection/vpCircle.cpp | 35 ++-- .../tracking/forward-projection/vpLine.cpp | 28 +-- .../tracking/forward-projection/vpPoint.cpp | 14 +- .../tracking/forward-projection/vpSphere.cpp | 14 +- 58 files changed, 709 insertions(+), 467 deletions(-) diff --git a/modules/core/include/visp3/core/vpCannyEdgeDetection.h b/modules/core/include/visp3/core/vpCannyEdgeDetection.h index 1a0d898e1b..74de78efdf 100644 --- a/modules/core/include/visp3/core/vpCannyEdgeDetection.h +++ b/modules/core/include/visp3/core/vpCannyEdgeDetection.h @@ -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. @@ -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; } } diff --git a/modules/core/include/visp3/core/vpEigenConversion.h b/modules/core/include/visp3/core/vpEigenConversion.h index 08a6f6b564..c614fa5a5d 100644 --- a/modules/core/include/visp3/core/vpEigenConversion.h +++ b/modules/core/include/visp3/core/vpEigenConversion.h @@ -57,7 +57,8 @@ void eigen2visp(const Eigen::Quaternion &src, vpQuaternionVector &dst) template void eigen2visp(const Eigen::AngleAxis &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); diff --git a/modules/core/include/visp3/core/vpForceTwistMatrix.h b/modules/core/include/visp3/core/vpForceTwistMatrix.h index eb50c386dc..4bf00470a0 100644 --- a/modules/core/include/visp3/core/vpForceTwistMatrix.h +++ b/modules/core/include/visp3/core/vpForceTwistMatrix.h @@ -230,6 +230,8 @@ class VISP_EXPORT vpForceTwistMatrix : public vpArray2D 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 diff --git a/modules/core/include/visp3/core/vpGaussRand.h b/modules/core/include/visp3/core/vpGaussRand.h index 00f594e6cf..723f55efda 100644 --- a/modules/core/include/visp3/core/vpGaussRand.h +++ b/modules/core/include/visp3/core/vpGaussRand.h @@ -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 #include @@ -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(); diff --git a/modules/core/include/visp3/core/vpHistogram.h b/modules/core/include/visp3/core/vpHistogram.h index df4aeb99ae..415ff60534 100644 --- a/modules/core/include/visp3/core/vpHistogram.h +++ b/modules/core/include/visp3/core/vpHistogram.h @@ -314,6 +314,7 @@ class VISP_EXPORT vpHistogram unsigned m_size; /*!< Histogram size (max allowed 256).*/ const vpImage *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 diff --git a/modules/core/include/visp3/core/vpHomogeneousMatrix.h b/modules/core/include/visp3/core/vpHomogeneousMatrix.h index 41bde6a97e..9f4b86b7f9 100644 --- a/modules/core/include/visp3/core/vpHomogeneousMatrix.h +++ b/modules/core/include/visp3/core/vpHomogeneousMatrix.h @@ -434,6 +434,8 @@ class VISP_EXPORT vpHomogeneousMatrix : public vpArray2D protected: unsigned int m_index; +private: + static const unsigned int constr_value_4; }; #ifdef VISP_HAVE_NLOHMANN_JSON diff --git a/modules/core/include/visp3/core/vpImage.h b/modules/core/include/visp3/core/vpImage.h index 59177f746f..7fb88c3bc4 100644 --- a/modules/core/include/visp3/core/vpImage.h +++ b/modules/core/include/visp3/core/vpImage.h @@ -330,7 +330,8 @@ template class vpImage friend std::ostream &operator<<(std::ostream &s, const vpImage &I); // Perform a look-up table transformation - void performLut(const Type(&lut)[256], unsigned int nbThreads = 1); + static const unsigned int val_256 = 256; + void performLut(const Type(&lut)[val_256], unsigned int nbThreads = 1); // Returns a new image that's a quarter size of the current image void quarterSizeImage(vpImage &res) const; diff --git a/modules/core/include/visp3/core/vpPoseVector.h b/modules/core/include/visp3/core/vpPoseVector.h index 4863901810..12e3e1c03a 100644 --- a/modules/core/include/visp3/core/vpPoseVector.h +++ b/modules/core/include/visp3/core/vpPoseVector.h @@ -316,6 +316,8 @@ class VISP_EXPORT vpPoseVector : public vpArray2D public: #endif +private: + static const unsigned int constr_value_6; #if defined(VISP_BUILD_DEPRECATED_FUNCTIONS) /*! @name Deprecated functions diff --git a/modules/core/include/visp3/core/vpQuaternionVector.h b/modules/core/include/visp3/core/vpQuaternionVector.h index 5b7488eb26..8ed138c013 100644 --- a/modules/core/include/visp3/core/vpQuaternionVector.h +++ b/modules/core/include/visp3/core/vpQuaternionVector.h @@ -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 diff --git a/modules/core/include/visp3/core/vpRotationMatrix.h b/modules/core/include/visp3/core/vpRotationMatrix.h index eda483ea94..2c669d422d 100644 --- a/modules/core/include/visp3/core/vpRotationMatrix.h +++ b/modules/core/include/visp3/core/vpRotationMatrix.h @@ -228,6 +228,8 @@ class VISP_EXPORT vpRotationMatrix : public vpArray2D protected: unsigned int m_index; +private: + static const unsigned int constr_val_3; }; #ifndef DOXYGEN_SHOULD_SKIP_THIS diff --git a/modules/core/include/visp3/core/vpRxyzVector.h b/modules/core/include/visp3/core/vpRxyzVector.h index aa7de3223f..12f93eb7c7 100644 --- a/modules/core/include/visp3/core/vpRxyzVector.h +++ b/modules/core/include/visp3/core/vpRxyzVector.h @@ -210,6 +210,8 @@ class VISP_EXPORT vpRxyzVector : public vpRotationVector vpRxyzVector &operator=(const vpRxyzVector &) = default; vpRxyzVector &operator=(const std::initializer_list &list); #endif +private: + static const unsigned int constr_val_3; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpRzyxVector.h b/modules/core/include/visp3/core/vpRzyxVector.h index 810d66c333..4236f02434 100644 --- a/modules/core/include/visp3/core/vpRzyxVector.h +++ b/modules/core/include/visp3/core/vpRzyxVector.h @@ -211,6 +211,8 @@ class VISP_EXPORT vpRzyxVector : public vpRotationVector vpRzyxVector &operator=(const vpRzyxVector &) = default; vpRzyxVector &operator=(const std::initializer_list &list); #endif +private: + static const unsigned int constr_val_3; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpRzyzVector.h b/modules/core/include/visp3/core/vpRzyzVector.h index b9177b86f8..86aa46b427 100644 --- a/modules/core/include/visp3/core/vpRzyzVector.h +++ b/modules/core/include/visp3/core/vpRzyzVector.h @@ -210,6 +210,8 @@ class VISP_EXPORT vpRzyzVector : public vpRotationVector vpRzyzVector &operator=(const vpRzyzVector &) = default; vpRzyzVector &operator=(const std::initializer_list &list); #endif +private: + static const unsigned int constr_val_3; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/include/visp3/core/vpThetaUVector.h b/modules/core/include/visp3/core/vpThetaUVector.h index 438e4026b0..ef0e6c4fad 100644 --- a/modules/core/include/visp3/core/vpThetaUVector.h +++ b/modules/core/include/visp3/core/vpThetaUVector.h @@ -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 diff --git a/modules/core/include/visp3/core/vpTranslationVector.h b/modules/core/include/visp3/core/vpTranslationVector.h index 7d50768a9f..df89ef4be8 100644 --- a/modules/core/include/visp3/core/vpTranslationVector.h +++ b/modules/core/include/visp3/core/vpTranslationVector.h @@ -206,6 +206,8 @@ class VISP_EXPORT vpTranslationVector : public vpArray2D 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 diff --git a/modules/core/include/visp3/core/vpVelocityTwistMatrix.h b/modules/core/include/visp3/core/vpVelocityTwistMatrix.h index 18700db24f..feda1e6e62 100644 --- a/modules/core/include/visp3/core/vpVelocityTwistMatrix.h +++ b/modules/core/include/visp3/core/vpVelocityTwistMatrix.h @@ -244,6 +244,8 @@ class VISP_EXPORT vpVelocityTwistMatrix : public vpArray2D VP_DEPRECATED void setIdentity(); //@} #endif + private: + static const unsigned constr_val_6; }; END_VISP_NAMESPACE #endif diff --git a/modules/core/src/camera/vpCameraParameters.cpp b/modules/core/src/camera/vpCameraParameters.cpp index f8fdab20d0..4f04070727 100644 --- a/modules/core/src/camera/vpCameraParameters.cpp +++ b/modules/core/src/camera/vpCameraParameters.cpp @@ -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; diff --git a/modules/core/src/camera/vpXmlParserCamera.cpp b/modules/core/src/camera/vpXmlParserCamera.cpp index 1e1e75cadd..f2e39cdabb 100644 --- a/modules/core/src/camera/vpXmlParserCamera.cpp +++ b/modules/core/src/camera/vpXmlParserCamera.cpp @@ -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"; @@ -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"; @@ -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"; @@ -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"); @@ -819,7 +819,7 @@ class vpXmlParserCamera::Impl // 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."); diff --git a/modules/core/src/image/private/vpImageConvert_impl.h b/modules/core/src/image/private/vpImageConvert_impl.h index 493fa91074..f5d7a17485 100644 --- a/modules/core/src/image/private/vpImageConvert_impl.h +++ b/modules/core/src/image/private/vpImageConvert_impl.h @@ -92,7 +92,8 @@ BEGIN_VISP_NAMESPACE } #endif - for (int i = 2; i < 0x10000; ++i) { + const unsigned int val_0x10000 = 0x10000; + for (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()); @@ -149,7 +150,8 @@ void vp_createDepthHistogram(const vpImage &src_depth, vpImage &src_depth, vpImage &d } } - for (int i = 2; i < 0x10000; ++i) { + const unsigned int val_0x10000 = 0x10000; + for (int i = 2; i < val_0x10000; ++i) { histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF] } #ifdef VISP_HAVE_OPENMP #pragma omp parallel for #endif + const unsigned char val_uc_5 = 5; + const unsigned char val_uc_20 = 20; + const unsigned char val_uc_255 = 255; for (int i = 0; i < src_depth_size; ++i) { uint16_t d = static_cast(src_depth.bitmap[i]); if (d) { unsigned char f = static_cast((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; } @@ -237,26 +243,29 @@ void vp_createDepthHistogram(const vpImage &src_depth, vpImage ++histogram[static_cast(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] } - #ifdef VISP_HAVE_OPENMP #pragma omp parallel for #endif + const unsigned char val_uc_5 = 5; + const unsigned char val_uc_20 = 20; + const unsigned char val_uc_255 = 255; for (int i = 0; i < src_depth_size; ++i) { uint16_t d = src_depth.bitmap[i]; if (d) { unsigned char f = static_cast((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; } diff --git a/modules/core/src/image/vpImageCircle.cpp b/modules/core/src/image/vpImageCircle.cpp index 1e3ce0d3c7..cb75dac8db 100644 --- a/modules/core/src/image/vpImageCircle.cpp +++ b/modules/core/src/image/vpImageCircle.cpp @@ -74,13 +74,14 @@ void computeIntersectionsLeftBorder(const float &u_c, const float &umin_roi, con { // --comment: umin_roi = u_c + r cos(theta) // --comment: theta = acos of of umin_roi - u_c endof / r endof + const int val_2 = 2; float theta1 = std::acos((umin_roi - u_c) / radius); theta1 = vpMath::getAngleBetweenMinPiAndPi(theta1); float theta2 = -1.f * theta1; float theta_min = std::min(theta1, theta2); float theta_max = std::max(theta1, theta2); delta_theta = theta_max - theta_min; - if ((u_c < umin_roi) && (std::abs(delta_theta - (2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { + if ((u_c < umin_roi) && (std::abs(delta_theta - (val_2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { delta_theta = 0.f; } } @@ -99,13 +100,14 @@ void computeIntersectionsRightBorder(const float &u_c, const float &umax_roi, co { // --comment: u = u_c + r cos(theta) // --comment: theta = acos of of u - u_c endof / r endof + const int val_2 = 2; float theta1 = std::acos((umax_roi - u_c) / radius); theta1 = vpMath::getAngleBetweenMinPiAndPi(theta1); float theta2 = -1.f * theta1; float theta_min = std::min(theta1, theta2); float theta_max = std::max(theta1, theta2); delta_theta = (2.f * M_PI_FLOAT) - (theta_max - theta_min); - if ((u_c > umax_roi) && (std::abs(delta_theta - (2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { + if ((u_c > umax_roi) && (std::abs(delta_theta - (val_2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { delta_theta = 0.f; } } @@ -124,6 +126,7 @@ void computeIntersectionsTopBorder(const float &v_c, const float &vmin_roi, cons { // v = vc - r sin(theta) because the v-axis goes down // theta = asin((vc - v)/r) + const int val_2 = 2; float theta1 = std::asin((v_c - vmin_roi) / radius); theta1 = vpMath::getAngleBetweenMinPiAndPi(theta1); @@ -147,7 +150,7 @@ void computeIntersectionsTopBorder(const float &v_c, const float &vmin_roi, cons else { delta_theta = theta_max - theta_min; } - if ((v_c < vmin_roi) && (std::abs(delta_theta - (2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { + if ((v_c < vmin_roi) && (std::abs(delta_theta - (val_2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { delta_theta = 0.f; } } @@ -166,6 +169,7 @@ void computeIntersBottomBorder(const float &v_c, const float &vmax_roi, const fl { // v = vc - r sin(theta) because the v-axis goes down // theta = asin((vc - v)/r) + const int val_2 = 2; float theta1 = std::asin((v_c - vmax_roi) / radius); theta1 = vpMath::getAngleBetweenMinPiAndPi(theta1); @@ -189,7 +193,7 @@ void computeIntersBottomBorder(const float &v_c, const float &vmax_roi, const fl else { delta_theta = (2.f * M_PI_FLOAT) - (theta_max - theta_min); } - if ((v_c > vmax_roi) && (std::abs(delta_theta - (2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { + if ((v_c > vmax_roi) && (std::abs(delta_theta - (val_2 * M_PI_FLOAT)) < (2.f * std::numeric_limits::epsilon()))) { delta_theta = 0.f; } } @@ -332,6 +336,7 @@ void computeIntersectionsTopLeft(const float &u_c, const float &v_c, const float void computeIntersectionsTopRight(const float &u_c, const float &v_c, const float &vmin_roi, const float &umax_roi, const float &radius, float &delta_theta) { + const int val_2 = 2; std::pair crossing_theta_u_min, crossing_theta_u_max; std::pair crossing_theta_v_min, crossing_theta_v_max; computePerpendicularAxesInters(u_c, v_c, radius, vmin_roi, umax_roi, @@ -355,7 +360,7 @@ void computeIntersectionsTopRight(const float &u_c, const float &v_c, const floa else if ((u_umin <= umax_roi) && (v_vmin >= vmin_roi) && (u_umax <= umax_roi) && (v_vmax >= vmin_roi)) { // The circle crosses twice each axis //Case crossing twice - delta_theta = (2 * M_PI_FLOAT) - ((theta_u_min - theta_u_max) + (theta_v_min - theta_v_max)); + delta_theta = (val_2 * M_PI_FLOAT) - ((theta_u_min - theta_u_max) + (theta_v_min - theta_v_max)); } else if ((u_umin >= umax_roi) && (v_vmin >= vmin_roi) && (u_umax >= umax_roi) && (v_vmax >= vmin_roi)) { // The circle crosses the u-axis outside the roi @@ -1158,12 +1163,14 @@ vpRect vpImageCircle::getBBox() const float vpImageCircle::get_n20() const { - return (m_radius * m_radius) / 4; + const int val_4 = 4; + return (m_radius * m_radius) / val_4; } float vpImageCircle::get_n02() const { - return (m_radius * m_radius) / 4; + const int val_4 = 4; + return (m_radius * m_radius) / val_4; } float vpImageCircle::get_n11() const diff --git a/modules/core/src/image/vpImageConvert.cpp b/modules/core/src/image/vpImageConvert.cpp index 4886152dbe..e76a5bc68d 100644 --- a/modules/core/src/image/vpImageConvert.cpp +++ b/modules/core/src/image/vpImageConvert.cpp @@ -107,13 +107,14 @@ void vpImageConvert::convert(const vpImage &src, vpImage & src.getMinMaxValue(min, max); + const unsigned char var_uc_255 = 255; for (unsigned int i = 0; i < max_xy; ++i) { float val = 255.f * ((src.bitmap[i] - min) / (max - min)); if (val < 0) { dest.bitmap[i] = 0; } - else if (val > 255) { - dest.bitmap[i] = 255; + else if (val > 255.f) { + dest.bitmap[i] = var_uc_255; } else { dest.bitmap[i] = static_cast(val); @@ -134,16 +135,18 @@ void vpImageConvert::convert(const vpImage &src, vpImage &dest) vpRGBf min, max; src.getMinMaxValue(min, max); + const unsigned int val_3 = 3; + const unsigned char var_uc_255 = 255; for (unsigned int i = 0; i < srcHeight; ++i) { for (unsigned int j = 0; j < srcWidth; ++j) { - for (unsigned int c = 0; c < 3; ++c) { + for (unsigned int c = 0; c < val_3; ++c) { float val = 255.f * ((reinterpret_cast(&(src[i][j]))[c] - reinterpret_cast(&min)[c]) / (reinterpret_cast(&max)[c] - reinterpret_cast(&min)[c])); if (val < 0) { reinterpret_cast(&(dest[i][j]))[c] = 0; } - else if (val > 255) { - reinterpret_cast(&(dest[i][j]))[c] = 255; + else if (val > 255.f) { + reinterpret_cast(&(dest[i][j]))[c] = var_uc_255; } else { reinterpret_cast(&(dest[i][j]))[c] = static_cast(val); @@ -182,13 +185,14 @@ void vpImageConvert::convert(const vpImage &src, vpImage src.getMinMaxValue(min, max); + const unsigned char var_uc_255 = 255; for (unsigned int i = 0; i < max_xy; ++i) { double val = 255. * ((src.bitmap[i] - min) / (max - min)); if (val < 0) { dest.bitmap[i] = 0; } - else if (val > 255) { - dest.bitmap[i] = 255; + else if (val > 255.0) { + dest.bitmap[i] = var_uc_255; } else { dest.bitmap[i] = static_cast(val); @@ -511,13 +515,15 @@ void vpImageConvert::RGBaToGrey(unsigned char *rgba, unsigned char *grey, unsign #if defined(VISP_HAVE_SIMDLIB) SimdRgbaToGray(rgba, size, 1, size * 4, grey, size); #else + const unsigned int val_2 = 2; + const unsigned int val_4 = 4; unsigned char *pt_input = rgba; unsigned char *pt_end = rgba + (size * 4); unsigned char *pt_output = grey; while (pt_input != pt_end) { - *pt_output = static_cast((0.2126 * (*pt_input)) + (0.7152 * (*(pt_input + 1))) + (0.0722 * (*(pt_input + 2)))); - pt_input += 4; + *pt_output = static_cast((0.2126 * (*pt_input)) + (0.7152 * (*(pt_input + 1))) + (0.0722 * (*(pt_input + val_2)))); + pt_input += val_4; ++pt_output; } #endif @@ -560,6 +566,9 @@ void vpImageConvert::GreyToRGBa(unsigned char *grey, unsigned char *rgba, unsign #if defined(VISP_HAVE_SIMDLIB) GreyToRGBa(grey, rgba, size, 1); #else + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; + const unsigned int val_4 = 4; unsigned char *pt_input = grey; unsigned char *pt_end = grey + size; unsigned char *pt_output = rgba; @@ -568,11 +577,11 @@ void vpImageConvert::GreyToRGBa(unsigned char *grey, unsigned char *rgba, unsign unsigned char p = *pt_input; *pt_output = p; // R *(pt_output + 1) = p; // G - *(pt_output + 2) = p; // B - *(pt_output + 3) = vpRGBa::alpha_default; // A + *(pt_output + val_2) = p; // B + *(pt_output + val_3) = vpRGBa::alpha_default; // A ++pt_input; - pt_output += 4; + pt_output += val_4; } #endif } @@ -592,6 +601,8 @@ void vpImageConvert::GreyToRGB(unsigned char *grey, unsigned char *rgb, unsigned #if defined(VISP_HAVE_SIMDLIB) SimdGrayToBgr(grey, size, 1, size, rgb, size * 3); #else + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; unsigned char *pt_input = grey; unsigned char *pt_end = grey + size; unsigned char *pt_output = rgb; @@ -600,10 +611,10 @@ void vpImageConvert::GreyToRGB(unsigned char *grey, unsigned char *rgb, unsigned unsigned char p = *pt_input; *pt_output = p; // R *(pt_output + 1) = p; // G - *(pt_output + 2) = p; // B + *(pt_output + val_2) = p; // B ++pt_input; - pt_output += 3; + pt_output += val_3; } #endif } @@ -634,6 +645,8 @@ void vpImageConvert::BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned #endif // if we have to flip the image, we start from the end last scanline so the // step is negative + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; int lineStep = flip ? -static_cast(width * 3) : static_cast(width * 3); // starting source address = last line if we need to flip the image @@ -642,12 +655,12 @@ void vpImageConvert::BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned for (unsigned int i = 0; i < height; ++i) { unsigned char *line = src; for (unsigned int j = 0; j < width; ++j) { - *rgba++ = *(line + 2); + *rgba++ = *(line + val_2); *rgba++ = *(line + 1); *rgba++ = *(line + 0); *rgba++ = vpRGBa::alpha_default; - line += 3; + line += val_3; } // go to the next line src += lineStep; @@ -682,20 +695,23 @@ void vpImageConvert::BGRaToRGBa(unsigned char *bgra, unsigned char *rgba, unsign #endif // if we have to flip the image, we start from the end last scanline so the // step is negative + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; + const unsigned int val_4 = 4; int lineStep = flip ? -static_cast(width * 4) : static_cast(width * 4); // starting source address = last line if we need to flip the image - unsigned char *src = flip ? (bgra + (width * height * 4) + lineStep) : bgra; + unsigned char *src = flip ? (bgra + (width * height * val_4) + lineStep) : bgra; for (unsigned int i = 0; i < height; ++i) { unsigned char *line = src; for (unsigned int j = 0; j < width; ++j) { - *rgba++ = *(line + 2); + *rgba++ = *(line + val_2); *rgba++ = *(line + 1); *rgba++ = *(line + 0); - *rgba++ = *(line + 3); + *rgba++ = *(line + val_3); - line += 4; + line += val_4; } // go to the next line src += lineStep; @@ -744,6 +760,8 @@ void vpImageConvert::BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned #endif // if we have to flip the image, we start from the end last scanline so // the step is negative + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; int lineStep = flip ? -static_cast(width * 3) : static_cast(width * 3); // starting source address = last line if we need to flip the image @@ -752,8 +770,8 @@ void vpImageConvert::BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned for (unsigned int i = 0; i < height; ++i) { unsigned char *line = src; for (unsigned int j = 0; j < width; ++j) { - *grey++ = static_cast((0.2126 * *(line + 2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0))); - line += 3; + *grey++ = static_cast((0.2126 * *(line + val_2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0))); + line += val_3; } // go to the next line @@ -806,6 +824,8 @@ void vpImageConvert::BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsign #endif // if we have to flip the image, we start from the end last scanline so // the step is negative + const unsigned int val_2 = 2; + const unsigned int val_4 = 4; int lineStep = flip ? -static_cast(width * 4) : static_cast(width * 4); // starting source address = last line if we need to flip the image @@ -814,8 +834,8 @@ void vpImageConvert::BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsign for (unsigned int i = 0; i < height; ++i) { unsigned char *line = src; for (unsigned int j = 0; j < width; ++j) { - *grey++ = static_cast((0.2126 * *(line + 2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0))); - line += 4; + *grey++ = static_cast((0.2126 * *(line + val_2)) + (0.7152 * *(line + 1)) + (0.0722 * *(line + 0))); + line += val_4; } // go to the next line @@ -835,15 +855,16 @@ void vpImageConvert::BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsign void vpImageConvert::computeYCbCrLUT() { if (YCbCrLUTcomputed == false) { + const int val_256 = 256; int index = 256; while (index--) { int aux = index - 128; - vpImageConvert::vpCrr[index] = static_cast((364.6610 * aux) / 256); - vpImageConvert::vpCgb[index] = static_cast((-89.8779 * aux) / 256); - vpImageConvert::vpCgr[index] = static_cast((-185.8154 * aux) / 256); - vpImageConvert::vpCbb[index] = static_cast((460.5724 * aux) / 256); + vpImageConvert::vpCrr[index] = static_cast((364.6610 * aux) / val_256); + vpImageConvert::vpCgb[index] = static_cast((-89.8779 * aux) / val_256); + vpImageConvert::vpCgr[index] = static_cast((-185.8154 * aux) / val_256); + vpImageConvert::vpCbb[index] = static_cast((460.5724 * aux) / val_256); } YCbCrLUTcomputed = true; @@ -873,12 +894,16 @@ void vpImageConvert::computeYCbCrLUT() */ void vpImageConvert::YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb, unsigned int size) { + const unsigned val_2 = 2; + const unsigned val_3 = 3; + const int val_255 = 255; + const unsigned int val_255u = 255u; unsigned char *cbv; unsigned char *crv; unsigned char *pt_ycbcr = ycbcr; unsigned char *pt_rgb = rgb; cbv = pt_ycbcr + 1; - crv = pt_ycbcr + 3; + crv = pt_ycbcr + val_3; vpImageConvert::computeYCbCrLUT(); @@ -886,20 +911,20 @@ void vpImageConvert::YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb, unsign while (size--) { int val_r, val_g, val_b; - if (!(col % 2)) { + if (!(col % val_2)) { cbv = pt_ycbcr + 1; - crv = pt_ycbcr + 3; + crv = pt_ycbcr + val_3; } val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv]; val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv]; val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv]; - *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : static_cast(val_r)); // Red component. - *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : static_cast(val_g)); // Green component. - *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : static_cast(val_b)); // Blue component. + *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > val_255) ? val_255u : static_cast(val_r)); // Red component. + *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > val_255) ? val_255u : static_cast(val_g)); // Green component. + *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > val_255) ? val_255u : static_cast(val_b)); // Blue component. - pt_ycbcr += 2; + pt_ycbcr += val_2; ++col; } } @@ -931,12 +956,16 @@ void vpImageConvert::YCbCrToRGB(unsigned char *ycbcr, unsigned char *rgb, unsign */ void vpImageConvert::YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgba, unsigned int size) { + const unsigned val_2 = 2; + const unsigned val_3 = 3; + const int val_255 = 255; + const unsigned int val_255u = 255u; unsigned char *cbv; unsigned char *crv; unsigned char *pt_ycbcr = ycbcr; unsigned char *pt_rgba = rgba; cbv = pt_ycbcr + 1; - crv = pt_ycbcr + 3; + crv = pt_ycbcr + val_3; vpImageConvert::computeYCbCrLUT(); @@ -944,21 +973,21 @@ void vpImageConvert::YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgba, unsi while (size--) { int val_r, val_g, val_b; - if (!(col % 2)) { + if (!(col % val_2)) { cbv = pt_ycbcr + 1; - crv = pt_ycbcr + 3; + crv = pt_ycbcr + val_3; } val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv]; val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv]; val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv]; - *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : static_cast(val_r)); // Red component. - *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : static_cast(val_g)); // Green component. - *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : static_cast(val_b)); // Blue component. + *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > val_255) ? val_255u : static_cast(val_r)); // Red component. + *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > val_255) ? val_255u : static_cast(val_g)); // Green component. + *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > val_255) ? val_255u : static_cast(val_b)); // Blue component. *pt_rgba++ = vpRGBa::alpha_default; - pt_ycbcr += 2; + pt_ycbcr += val_2; ++col; } } @@ -984,12 +1013,14 @@ void vpImageConvert::YCbCrToRGBa(unsigned char *ycbcr, unsigned char *rgba, unsi */ void vpImageConvert::YCbCrToGrey(unsigned char *ycbcr, unsigned char *grey, unsigned int size) { + const unsigned val_2 = 2; + const unsigned val_4 = 4; unsigned int i = 0, j = 0; const unsigned int doubleSize = size * 2; while (j < doubleSize) { grey[i++] = ycbcr[j]; - grey[i++] = ycbcr[j + 2]; - j += 4; + grey[i++] = ycbcr[j + val_2]; + j += val_4; } } @@ -1016,12 +1047,16 @@ void vpImageConvert::YCbCrToGrey(unsigned char *ycbcr, unsigned char *grey, unsi */ void vpImageConvert::YCrCbToRGB(unsigned char *ycrcb, unsigned char *rgb, unsigned int size) { + const unsigned val_2 = 2; + const unsigned val_3 = 3; + const int val_255 = 255; + const unsigned int val_255u = 255u; unsigned char *cbv; unsigned char *crv; unsigned char *pt_ycbcr = ycrcb; unsigned char *pt_rgb = rgb; crv = pt_ycbcr + 1; - cbv = pt_ycbcr + 3; + cbv = pt_ycbcr + val_3; vpImageConvert::computeYCbCrLUT(); @@ -1029,20 +1064,20 @@ void vpImageConvert::YCrCbToRGB(unsigned char *ycrcb, unsigned char *rgb, unsign while (size--) { int val_r, val_g, val_b; - if (!(col % 2)) { + if (!(col % val_2)) { crv = pt_ycbcr + 1; - cbv = pt_ycbcr + 3; + cbv = pt_ycbcr + val_3; } val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv]; val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv]; val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv]; - *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : static_cast(val_r)); // Red component. - *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : static_cast(val_g)); // Green component. - *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : static_cast(val_b)); // Blue component. + *pt_rgb++ = (val_r < 0) ? 0u : ((val_r > val_255) ? val_255u : static_cast(val_r)); // Red component. + *pt_rgb++ = (val_g < 0) ? 0u : ((val_g > val_255) ? val_255u : static_cast(val_g)); // Green component. + *pt_rgb++ = (val_b < 0) ? 0u : ((val_b > val_255) ? val_255u : static_cast(val_b)); // Blue component. - pt_ycbcr += 2; + pt_ycbcr += val_2; ++col; } } @@ -1073,12 +1108,16 @@ void vpImageConvert::YCrCbToRGB(unsigned char *ycrcb, unsigned char *rgb, unsign */ void vpImageConvert::YCrCbToRGBa(unsigned char *ycrcb, unsigned char *rgba, unsigned int size) { + const unsigned val_2 = 2; + const unsigned val_3 = 3; + const int val_255 = 255; + const unsigned int val_255u = 255u; unsigned char *cbv; unsigned char *crv; unsigned char *pt_ycbcr = ycrcb; unsigned char *pt_rgba = rgba; crv = pt_ycbcr + 1; - cbv = pt_ycbcr + 3; + cbv = pt_ycbcr + val_3; vpImageConvert::computeYCbCrLUT(); @@ -1086,21 +1125,21 @@ void vpImageConvert::YCrCbToRGBa(unsigned char *ycrcb, unsigned char *rgba, unsi while (size--) { int val_r, val_g, val_b; - if (!(col % 2)) { + if (!(col % val_2)) { crv = pt_ycbcr + 1; - cbv = pt_ycbcr + 3; + cbv = pt_ycbcr + val_3; } val_r = *pt_ycbcr + vpImageConvert::vpCrr[*crv]; val_g = *pt_ycbcr + vpImageConvert::vpCgb[*cbv] + vpImageConvert::vpCgr[*crv]; val_b = *pt_ycbcr + vpImageConvert::vpCbb[*cbv]; - *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > 255) ? 255u : static_cast(val_r)); // Red component. - *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > 255) ? 255u : static_cast(val_g)); // Green component. - *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > 255) ? 255u : static_cast(val_b)); // Blue component. + *pt_rgba++ = (val_r < 0) ? 0u : ((val_r > val_255) ? val_255u : static_cast(val_r)); // Red component. + *pt_rgba++ = (val_g < 0) ? 0u : ((val_g > val_255) ? val_255u : static_cast(val_g)); // Green component. + *pt_rgba++ = (val_b < 0) ? 0u : ((val_b > val_255) ? val_255u : static_cast(val_b)); // Blue component. *pt_rgba++ = vpRGBa::alpha_default; - pt_ycbcr += 2; + pt_ycbcr += val_2; ++col; } } @@ -1206,6 +1245,7 @@ void vpImageConvert::split(const vpImage &src, vpImage *p tabChannel[index_3] = pa; size_t i; /* ordre */ + const unsigned int val_3 = 3; const unsigned int val_4 = 4; for (unsigned int j = 0; j < val_4; ++j) { if (tabChannel[j] != nullptr) { @@ -1217,28 +1257,28 @@ void vpImageConvert::split(const vpImage &src, vpImage *p input = (unsigned char *)src.bitmap + j; i = 0; // optimization - if (n >= 4) { - n -= 3; - for (; i < n; i += 4) { + if (n >= val_4) { + n -= val_3; + for (; i < n; i += val_4) { *dst = *input; - input += 4; + input += val_4; ++dst; *dst = *input; - input += 4; + input += val_4; ++dst; *dst = *input; - input += 4; + input += val_4; ++dst; *dst = *input; - input += 4; + input += val_4; ++dst; } - n += 3; + n += val_3; } for (; i < n; ++i) { *dst = *input; - input += 4; + input += val_4; ++dst; } } @@ -1334,12 +1374,13 @@ void vpImageConvert::merge(const vpImage *R, const vpImage(size) * 2) - 1; int j = static_cast(size) - 1; while (i >= 0) { int y = grey16[i--]; - grey[j--] = static_cast((y + (grey16[i] * 256)) / 256); + grey[j--] = static_cast((y + (grey16[i] * val_256)) / val_256); --i; } } diff --git a/modules/core/src/image/vpImageConvert_hsv.cpp b/modules/core/src/image/vpImageConvert_hsv.cpp index 88888f5856..fd08d11ce4 100644 --- a/modules/core/src/image/vpImageConvert_hsv.cpp +++ b/modules/core/src/image/vpImageConvert_hsv.cpp @@ -84,6 +84,9 @@ BEGIN_VISP_NAMESPACE double q = v * (1.0 - (s * f)); double t = v * (1.0 - (s * (1.0 - f))); + const int val_2 = 2; + const int val_3 = 3; + const int val_4 = 4; switch (static_cast(h)) { case 0: hue = v; @@ -97,19 +100,19 @@ BEGIN_VISP_NAMESPACE value = p; break; - case 2: + case val_2: hue = p; saturation = v; value = t; break; - case 3: + case val_3: hue = p; saturation = q; value = v; break; - case 4: + case val_4: hue = t; saturation = p; value = v; @@ -127,7 +130,9 @@ BEGIN_VISP_NAMESPACE rgb[i_step] = static_cast(vpMath::round(hue * 255.0)); rgb[++i_step] = static_cast(vpMath::round(saturation * 255.0)); rgb[++i_step] = static_cast(vpMath::round(value * 255.0)); - if ((++i_step) == 3) { // alpha + const int val_3 = 3; + if (i_step == val_3) { // alpha + ++i_step; rgb[i_step] = vpRGBa::alpha_default; } } @@ -148,6 +153,9 @@ BEGIN_VISP_NAMESPACE void vpImageConvert::HSV2RGB(const unsigned char *hue_, const unsigned char *saturation_, const unsigned char *value_, unsigned char *rgb, unsigned int size, unsigned int step, bool h_full) { + const int val_2 = 2; + const int val_3 = 3; + const int val_4 = 4; float h_max; if (h_full) { h_max = 255.f; @@ -194,19 +202,19 @@ void vpImageConvert::HSV2RGB(const unsigned char *hue_, const unsigned char *sat value = p; break; - case 2: + case val_2: hue = p; saturation = v; value = t; break; - case 3: + case val_3: hue = p; saturation = q; value = v; break; - case 4: + case val_4: hue = t; saturation = p; value = v; @@ -224,7 +232,8 @@ void vpImageConvert::HSV2RGB(const unsigned char *hue_, const unsigned char *sat rgb[i_step] = static_cast(hue * 255.f); rgb[++i_step] = static_cast(saturation * 255.0f); rgb[++i_step] = static_cast(value * 255.0f); - if ((++i_step) == 3) { // alpha + if (i_step == val_3) { // alpha + ++i_step; rgb[i_step] = vpRGBa::alpha_default; } } @@ -257,8 +266,10 @@ void vpImageConvert::RGB2HSV(const unsigned char *rgb, double *hue, double *satu int i_ = i * step; red = rgb[i_] / 255.0; - green = rgb[++i_] / 255.0; - blue = rgb[++i_] / 255.0; + ++i_; + green = rgb[i_] / 255.0; + ++i_; + blue = rgb[i_] / 255.0; if (red > green) { max = std::max(red, blue); @@ -288,10 +299,10 @@ void vpImageConvert::RGB2HSV(const unsigned char *rgb, double *hue, double *satu h = (green - blue) / delta; } else if (vpMath::equal(green, max, std::numeric_limits::epsilon())) { - h = 2 + ((blue - red) / delta); + h = 2.0 + ((blue - red) / delta); } else { - h = 4 + ((red - green) / delta); + h = 4.0 + ((red - green) / delta); } h /= 6.0; @@ -418,7 +429,8 @@ void vpImageConvert::RGB2HSV(const unsigned char *rgb, unsigned char *hue, unsig void vpImageConvert::HSVToRGBa(const double *hue, const double *saturation, const double *value, unsigned char *rgba, unsigned int size) { - vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, 4); + const unsigned int val_4 = 4; + vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, val_4); } /*! @@ -438,7 +450,8 @@ void vpImageConvert::HSVToRGBa(const double *hue, const double *saturation, cons void vpImageConvert::HSVToRGBa(const unsigned char *hue, const unsigned char *saturation, const unsigned char *value, unsigned char *rgba, unsigned int size, bool h_full) { - vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, 4, h_full); + const unsigned int val_4 = 4; + vpImageConvert::HSV2RGB(hue, saturation, value, rgba, size, val_4, h_full); } /*! @@ -457,7 +470,8 @@ void vpImageConvert::HSVToRGBa(const unsigned char *hue, const unsigned char *sa void vpImageConvert::RGBaToHSV(const unsigned char *rgba, double *hue, double *saturation, double *value, unsigned int size) { - vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, 4); + const unsigned int val_4 = 4; + vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, val_4); } /*! @@ -479,7 +493,8 @@ void vpImageConvert::RGBaToHSV(const unsigned char *rgba, double *hue, double *s void vpImageConvert::RGBaToHSV(const unsigned char *rgba, unsigned char *hue, unsigned char *saturation, unsigned char *value, unsigned int size, bool h_full) { - vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, 4, h_full); + const unsigned int val_4 = 4; + vpImageConvert::RGB2HSV(rgba, hue, saturation, value, size, val_4, h_full); } /*! @@ -498,7 +513,8 @@ void vpImageConvert::RGBaToHSV(const unsigned char *rgba, unsigned char *hue, un void vpImageConvert::HSVToRGB(const double *hue, const double *saturation, const double *value, unsigned char *rgb, unsigned int size) { - vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, 3); + const unsigned int val_3 = 3; + vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, val_3); } /*! @@ -518,7 +534,8 @@ void vpImageConvert::HSVToRGB(const double *hue, const double *saturation, const void vpImageConvert::HSVToRGB(const unsigned char *hue, const unsigned char *saturation, const unsigned char *value, unsigned char *rgb, unsigned int size, bool h_full) { - vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, 3, h_full); + const unsigned int val_3 = 3; + vpImageConvert::HSV2RGB(hue, saturation, value, rgb, size, val_3, h_full); } /*! @@ -536,7 +553,8 @@ void vpImageConvert::HSVToRGB(const unsigned char *hue, const unsigned char *sat void vpImageConvert::RGBToHSV(const unsigned char *rgb, double *hue, double *saturation, double *value, unsigned int size) { - vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, 3); + const unsigned int val_3 = 3; + vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, val_3); } /*! @@ -557,6 +575,7 @@ void vpImageConvert::RGBToHSV(const unsigned char *rgb, double *hue, double *sat void vpImageConvert::RGBToHSV(const unsigned char *rgb, unsigned char *hue, unsigned char *saturation, unsigned char *value, unsigned int size, bool h_full) { - vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, 3, h_full); + const unsigned int val_3 = 3; + vpImageConvert::RGB2HSV(rgb, hue, saturation, value, size, val_3, h_full); } END_VISP_NAMESPACE diff --git a/modules/core/src/image/vpImageConvert_yuv.cpp b/modules/core/src/image/vpImageConvert_yuv.cpp index 6005982cb1..1b10f06a6d 100644 --- a/modules/core/src/image/vpImageConvert_yuv.cpp +++ b/modules/core/src/image/vpImageConvert_yuv.cpp @@ -206,12 +206,14 @@ void vpImageConvert::YUYVToRGB(unsigned char *yuyv, unsigned char *rgb, unsigned */ void vpImageConvert::YUYVToGrey(unsigned char *yuyv, unsigned char *grey, unsigned int size) { + const unsigned int val_2 = 2; + const unsigned int val_4 = 4; unsigned int i = 0, j = 0; const unsigned int doubleSize = size * 2; while (j < doubleSize) { grey[i++] = yuyv[j]; - grey[i++] = yuyv[j + 2]; - j += 4; + grey[i++] = yuyv[j + val_2]; + j += val_4; } } @@ -382,16 +384,20 @@ void vpImageConvert::YUV411ToGrey(unsigned char *yuv, unsigned char *grey, unsig { unsigned int i = 0, j = 0; const unsigned int val_2 = 2; - const unsigned int iterLimit = (size * 3) / val_2; + const unsigned int val_3 = 3; + const unsigned int val_4 = 4; + const unsigned int val_5 = 5; + const unsigned int val_6 = 6; + const unsigned int iterLimit = (size * val_3) / val_2; while (j < iterLimit) { grey[i] = yuv[j + 1]; - grey[i + 1] = yuv[j + 2]; - grey[i + 2] = yuv[j + 4]; - grey[i + 3] = yuv[j + 5]; + grey[i + 1] = yuv[j + val_2]; + grey[i + val_2] = yuv[j + val_4]; + grey[i + val_3] = yuv[j + val_5]; - i += 4; + i += val_4; - j += 6; + j += val_6; } } @@ -464,13 +470,15 @@ void vpImageConvert::YUV422ToRGB(unsigned char *yuv, unsigned char *rgb, unsigne */ void vpImageConvert::YUV422ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size) { + const unsigned int val_3 = 3; + const unsigned int val_4 = 4; unsigned int i = 0, j = 0; const unsigned int doubleSize = size * 2; while (j < doubleSize) { grey[i++] = yuv[j + 1]; - grey[i++] = yuv[j + 3]; - j += 4; + grey[i++] = yuv[j + val_3]; + j += val_4; } } @@ -775,7 +783,7 @@ void vpImageConvert::YUV420ToRGB(unsigned char *yuv, unsigned char *rgb, unsigne rgb = (rgb - (val_3 * width)) + 1; } yuv += width; - rgb += 3 * width; + rgb += val_3 * width; } } @@ -886,10 +894,11 @@ void vpImageConvert::YUV444ToRGB(unsigned char *yuv, unsigned char *rgb, unsigne */ void vpImageConvert::YUV444ToGrey(unsigned char *yuv, unsigned char *grey, unsigned int size) { + const unsigned int val_3 = 3; ++yuv; for (unsigned int i = 0; i < size; ++i) { *grey++ = *yuv; - yuv = yuv + 3; + yuv = yuv + val_3; } } @@ -920,10 +929,10 @@ void vpImageConvert::YV12ToRGBa(unsigned char *yuv, unsigned char *rgba, unsigne for (unsigned int j = 0; j < halfWidth; ++j) { U = static_cast(((*iU) - val_128) * 0.354); ++iU; - U5 = 5 * U; + U5 = val_5 * U; V = static_cast(((*iV) - val_128) * 0.707); ++iV; - V2 = 2 * V; + V2 = val_2 * V; UV = -U - V; Y0 = *yuv; ++yuv; @@ -1073,7 +1082,7 @@ void vpImageConvert::YV12ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned *rgb++ = static_cast(R); *rgb++ = static_cast(G); *rgb = static_cast(B); - rgb = rgb + ((val_3 * width) - 5); + rgb = rgb + ((val_3 * width) - val_5); //--- R = Y2 + V2; @@ -1344,6 +1353,7 @@ void vpImageConvert::YVU9ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned const unsigned int val_4 = 4; const unsigned int val_5 = 5; const unsigned int val_9 = 9; + const unsigned int val_11 = 11; const unsigned int val_16 = 16; const unsigned int val_17 = 17; unsigned int size = width * height; @@ -1419,7 +1429,7 @@ void vpImageConvert::YVU9ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned G = Y3 + UV; B = Y3 + U5; YVU9ToRGBsubroutine(rgb, R, G, B); - rgb = rgb + ((val_3 * width) - 11); + rgb = rgb + ((val_3 * width) - val_11); R = Y4 + V2; G = Y4 + UV; @@ -1443,7 +1453,7 @@ void vpImageConvert::YVU9ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned G = Y7 + UV; B = Y7 + U5; YVU9ToRGBsubroutine(rgb, R, G, B); - rgb = rgb + ((val_3 * width) - 11); + rgb = rgb + ((val_3 * width) - val_11); R = Y8 + V2; G = Y8 + UV; @@ -1467,7 +1477,7 @@ void vpImageConvert::YVU9ToRGB(unsigned char *yuv, unsigned char *rgb, unsigned G = Y11 + UV; B = Y11 + U5; YVU9ToRGBsubroutine(rgb, R, G, B); - rgb = (rgb + (val_3 * width)) - 11; + rgb = (rgb + (val_3 * width)) - val_11; R = Y12 + V2; G = Y12 + UV; diff --git a/modules/core/src/image/vpImageFilter_xy.cpp b/modules/core/src/image/vpImageFilter_xy.cpp index fd1f946a07..0da41ffc1d 100644 --- a/modules/core/src/image/vpImageFilter_xy.cpp +++ b/modules/core/src/image/vpImageFilter_xy.cpp @@ -123,6 +123,7 @@ double vpImageFilter::filterXLeftBorderB(const vpImage &I, unsigned int double vpImageFilter::filterXRightBorderR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int stop = (size - 1) / 2; const unsigned int width = I.getWidth(); double result = 0.; @@ -132,7 +133,7 @@ double vpImageFilter::filterXRightBorderR(const vpImage &I, unsigned int result += filter[i] * static_cast(I[r][c + i].R + I[r][c - i].R); } else { - result += filter[i] * static_cast(I[r][((2 * width) - c) - i - 1].R + I[r][c - i].R); + result += filter[i] * static_cast(I[r][((val_2 * width) - c) - i - 1].R + I[r][c - i].R); } } return result + (filter[0] * static_cast(I[r][c].R)); @@ -141,6 +142,7 @@ double vpImageFilter::filterXRightBorderR(const vpImage &I, unsigned int double vpImageFilter::filterXRightBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int stop = (size - 1) / 2; const unsigned int width = I.getWidth(); double result = 0.; @@ -150,7 +152,7 @@ double vpImageFilter::filterXRightBorderG(const vpImage &I, unsigned int result += filter[i] * static_cast(I[r][c + i].G + I[r][c - i].G); } else { - result += filter[i] * static_cast(I[r][((2 * width) - c) - i - 1].G + I[r][c - i].G); + result += filter[i] * static_cast(I[r][((val_2 * width) - c) - i - 1].G + I[r][c - i].G); } } return result + (filter[0] * static_cast(I[r][c].G)); @@ -159,6 +161,7 @@ double vpImageFilter::filterXRightBorderG(const vpImage &I, unsigned int double vpImageFilter::filterXRightBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int stop = (size - 1) / 2; const unsigned int width = I.getWidth(); double result = 0.; @@ -168,7 +171,7 @@ double vpImageFilter::filterXRightBorderB(const vpImage &I, unsigned int result += filter[i] * static_cast(I[r][c + i].B + I[r][c - i].B); } else { - result += filter[i] * static_cast(I[r][(2 * width) - c - i - 1].B + I[r][c - i].B); + result += filter[i] * static_cast(I[r][(val_2 * width) - c - i - 1].B + I[r][c - i].B); } } return result + (filter[0] * static_cast(I[r][c].B)); @@ -258,6 +261,7 @@ double vpImageFilter::filterYTopBorderB(const vpImage &I, unsigned int r double vpImageFilter::filterYBottomBorderR(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int height = I.getHeight(); const unsigned int stop = (size - 1) / 2; double result = 0.; @@ -267,7 +271,7 @@ double vpImageFilter::filterYBottomBorderR(const vpImage &I, unsigned in result += filter[i] * static_cast(I[r + i][c].R + I[r - i][c].R); } else { - result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].R + I[r - i][c].R); + result += filter[i] * static_cast(I[((val_2 * height) - r) - i - 1][c].R + I[r - i][c].R); } } return result + (filter[0] * static_cast(I[r][c].R)); @@ -276,6 +280,7 @@ double vpImageFilter::filterYBottomBorderR(const vpImage &I, unsigned in double vpImageFilter::filterYBottomBorderG(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int height = I.getHeight(); const unsigned int stop = (size - 1) / 2; double result = 0.; @@ -285,7 +290,7 @@ double vpImageFilter::filterYBottomBorderG(const vpImage &I, unsigned in result += filter[i] * static_cast(I[r + i][c].G + I[r - i][c].G); } else { - result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].G + I[r - i][c].G); + result += filter[i] * static_cast(I[((val_2 * height) - r) - i - 1][c].G + I[r - i][c].G); } } return result + (filter[0] * static_cast(I[r][c].G)); @@ -294,6 +299,7 @@ double vpImageFilter::filterYBottomBorderG(const vpImage &I, unsigned in double vpImageFilter::filterYBottomBorderB(const vpImage &I, unsigned int r, unsigned int c, const double *filter, unsigned int size) { + const unsigned int val_2 = 2; const unsigned int height = I.getHeight(); const unsigned int stop = (size - 1) / 2; double result = 0.; @@ -303,7 +309,7 @@ double vpImageFilter::filterYBottomBorderB(const vpImage &I, unsigned in result += filter[i] * static_cast(I[r + i][c].B + I[r - i][c].B); } else { - result += filter[i] * static_cast(I[((2 * height) - r) - i - 1][c].B + I[r - i][c].B); + result += filter[i] * static_cast(I[((val_2 * height) - r) - i - 1][c].B + I[r - i][c].B); } } return result + (filter[0] * static_cast(I[r][c].B)); diff --git a/modules/core/src/image/vpImageTools.cpp b/modules/core/src/image/vpImageTools.cpp index ad9886cc0f..8056c746cd 100644 --- a/modules/core/src/image/vpImageTools.cpp +++ b/modules/core/src/image/vpImageTools.cpp @@ -157,9 +157,11 @@ void vpImageTools::imageDifference(const vpImage &I1, const vpIma #if defined(VISP_HAVE_SIMDLIB) SimdImageDifference(I1.bitmap, I2.bitmap, I1.getSize(), Idiff.bitmap); #else - for (unsigned int i = 0; i < I1.getSize(); ++i) { + const int val_255 = 255; + unsigned int i1_size = I1.getSize(); + for (unsigned int i = 0; i < i1_size; ++i) { int diff = (I1.bitmap[i] - I2.bitmap[i]) + 128; - Idiff.bitmap[i] = static_cast(std::max(std::min(diff, 255), 0)); + Idiff.bitmap[i] = static_cast(std::max(std::min(diff, val_255), 0)); } #endif } @@ -194,16 +196,18 @@ void vpImageTools::imageDifference(const vpImage &I1, const vpImage(I1.bitmap), reinterpret_cast(I2.bitmap), I1.getSize() * 4, reinterpret_cast(Idiff.bitmap)); #else + const unsigned int val_4 = 4; + const int val_255 = 255; unsigned int i1_size = I1.getSize(); - for (unsigned int i = 0; i < (i1_size * 4); ++i) { + for (unsigned int i = 0; i < (i1_size * val_4); ++i) { int diffR = (I1.bitmap[i].R - I2.bitmap[i].R) + 128; int diffG = (I1.bitmap[i].G - I2.bitmap[i].G) + 128; int diffB = (I1.bitmap[i].B - I2.bitmap[i].B) + 128; int diffA = (I1.bitmap[i].A - I2.bitmap[i].A) + 128; - Idiff.bitmap[i].R = static_cast(vpMath::maximum(vpMath::minimum(diffR, 255), 0)); - Idiff.bitmap[i].G = static_cast(vpMath::maximum(vpMath::minimum(diffG, 255), 0)); - Idiff.bitmap[i].B = static_cast(vpMath::maximum(vpMath::minimum(diffB, 255), 0)); - Idiff.bitmap[i].A = static_cast(vpMath::maximum(vpMath::minimum(diffA, 255), 0)); + Idiff.bitmap[i].R = static_cast(vpMath::maximum(vpMath::minimum(diffR, val_255), 0)); + Idiff.bitmap[i].G = static_cast(vpMath::maximum(vpMath::minimum(diffG, val_255), 0)); + Idiff.bitmap[i].B = static_cast(vpMath::maximum(vpMath::minimum(diffB, val_255), 0)); + Idiff.bitmap[i].A = static_cast(vpMath::maximum(vpMath::minimum(diffA, val_255), 0)); } #endif } @@ -1128,11 +1132,12 @@ int vpImageTools::inMask(const vpImage &I, const vpImage(hsv_range[index_0]); unsigned char h_high = static_cast(hsv_range[index_1]); unsigned char s_low = static_cast(hsv_range[index_2]); @@ -1158,7 +1164,7 @@ int vpImageTools::inRange(const unsigned char *hue, const unsigned char *saturat bool check_s_low_high_saturation = (s_low <= saturation[i]) && (saturation[i] <= s_high); bool check_v_low_high_value = (v_low <= value[i]) && (value[i] <= v_high); if (check_h_low_high_hue && check_s_low_high_saturation && check_v_low_high_value) { - mask[i] = 255; + mask[i] = val_uchar_255; ++cpt_in_range; } else { @@ -1188,11 +1194,12 @@ int vpImageTools::inRange(const unsigned char *hue, const unsigned char *saturat int vpImageTools::inRange(const unsigned char *hue, const unsigned char *saturation, const unsigned char *value, const std::vector &hsv_range, unsigned char *mask, unsigned int size) { + const std::size_t val_6 = 6; if ((hue == nullptr) || (saturation == nullptr) || (value == nullptr)) { throw(vpImageException(vpImageException::notInitializedError, "Error in vpImageTools::inRange(): hsv pointer are empty")); } - else if (hsv_range.size() != 6) { + else if (hsv_range.size() != val_6) { throw(vpImageException(vpImageException::notInitializedError, "Error in vpImageTools::inRange(): wrong values vector size (%d)", hsv_range.size())); } @@ -1213,12 +1220,13 @@ int vpImageTools::inRange(const unsigned char *hue, const unsigned char *saturat #if defined(_OPENMP) #pragma omp parallel for reduction(+:cpt_in_range) #endif + const unsigned char val_uc_255 = 255; for (int i = 0; i < size_; ++i) { bool check_h_low_high_hue = (h_low <= hue[i]) && (hue[i] <= h_high); bool check_s_low_high_saturation = (s_low <= saturation[i]) && (saturation[i] <= s_high); bool check_v_low_high_value = (v_low <= value[i]) && (value[i] <= v_high); if (check_h_low_high_hue && check_s_low_high_saturation && check_v_low_high_value) { - mask[i] = 255; + mask[i] = val_uc_255; ++cpt_in_range; } else { diff --git a/modules/core/src/image/vpRGBa.cpp b/modules/core/src/image/vpRGBa.cpp index 1a894a2de3..5a106ff9c0 100644 --- a/modules/core/src/image/vpRGBa.cpp +++ b/modules/core/src/image/vpRGBa.cpp @@ -123,7 +123,8 @@ vpRGBa &vpRGBa::operator=(const vpRGBa &&v) */ vpRGBa &vpRGBa::operator=(const vpColVector &v) { - if (v.getRows() != 4) { + const unsigned int val_4 = 4; + if (v.getRows() != val_4) { throw(vpException(vpException::dimensionError, "Bad vector dimension ")); } const unsigned int index_0 = 0; diff --git a/modules/core/src/math/matrix/vpColVector.cpp b/modules/core/src/math/matrix/vpColVector.cpp index 0894d3e798..9321b18dda 100644 --- a/modules/core/src/math/matrix/vpColVector.cpp +++ b/modules/core/src/math/matrix/vpColVector.cpp @@ -73,13 +73,13 @@ vpColVector vpColVector::operator+(const vpColVector &v) const vpTranslationVector vpColVector::operator+(const vpTranslationVector &t) const { - if (getRows() != 3) { + const unsigned int val_3 = 3; + if (getRows() != val_3) { throw(vpException(vpException::dimensionError, "Cannot add %d-dimension column vector to a translation vector", getRows())); } vpTranslationVector s; - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { s[i] = (*this)[i] + t[i]; } @@ -285,7 +285,9 @@ vpColVector vpColVector::operator-() const for (unsigned int i = 0; i < rowNum; ++i) { // move the d++ increment/decrement into a dedicated expression-statement - *(vd++) = -(*d++); + *vd = -(*d); + ++vd; + ++d; } return A; @@ -300,7 +302,9 @@ vpColVector vpColVector::operator*(double x) const for (unsigned int i = 0; i < rowNum; ++i) { // move the d++ increment/decrement into a dedicated expression-statement - *(vd++) = (*d++) * x; + *vd = (*d) * x; + ++vd; + ++d; } return v; } @@ -330,7 +334,9 @@ vpColVector vpColVector::operator/(double x) const for (unsigned int i = 0; i < rowNum; ++i) { // move the d++ increment/decrement into a dedicated expression-statement - *(vd++) = (*d++) / x; + *vd = (*d) / x; + ++vd; + ++d; } return v; } @@ -557,7 +563,9 @@ double vpColVector::dotProd(const vpColVector &a, const vpColVector &b) unsigned int a_rows_nbr = a.getRows(); for (unsigned int i = 0; i < a_rows_nbr; ++i) { // Move the ad++ and bd++ increment/decrement into a dedicated expression-statement - c += *(ad++) * *(bd++); + c += (*ad) * (*bd); + ++ad; + ++bd; } return c; @@ -713,7 +721,8 @@ double vpColVector::stdev(const vpColVector &v, bool useBesselCorrection) #else double mean_value = v.sum() / v.size(); double sum_squared_diff = 0.0; - for (size_t i = 0; i < v.size(); i++) { + unsigned int v_size = v.size(); + for (size_t i = 0; i < v_size; ++i) { sum_squared_diff += (v[i] - mean_value) * (v[i] - mean_value); } @@ -735,7 +744,7 @@ vpMatrix vpColVector::skew(const vpColVector &v) v.getRows())); } - M.resize(3, 3, false, false); + M.resize(rows_size, rows_size, false, false); const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; @@ -754,7 +763,8 @@ vpMatrix vpColVector::skew(const vpColVector &v) vpColVector vpColVector::crossProd(const vpColVector &a, const vpColVector &b) { - if ((a.getRows() != 3) || (b.getRows() != 3)) { + const unsigned int val_3 = 3; + if ((a.getRows() != val_3) || (b.getRows() != val_3)) { throw(vpException(vpException::dimensionError, "Cannot compute the cross product between column " "vector with dimension %d and %d", diff --git a/modules/core/src/math/matrix/vpEigenConversion.cpp b/modules/core/src/math/matrix/vpEigenConversion.cpp index 2aed2b6a62..bf04754142 100644 --- a/modules/core/src/math/matrix/vpEigenConversion.cpp +++ b/modules/core/src/math/matrix/vpEigenConversion.cpp @@ -46,7 +46,8 @@ void eigen2visp(const Eigen::MatrixXd &src, vpMatrix &dst) void eigen2visp(const Eigen::MatrixXd &src, vpHomogeneousMatrix &dst) { - if ((src.rows() != 4) || (src.cols() != 4)) { + const Eigen::Index index_4 = 4; + if ((src.rows() != index_4) || (src.cols() != index_4)) { throw vpException(vpException::dimensionError, "Input Eigen Matrix must be of size (4,4)!"); } diff --git a/modules/core/src/math/matrix/vpMatrix.cpp b/modules/core/src/math/matrix/vpMatrix.cpp index 5111e52303..87893fa09e 100644 --- a/modules/core/src/math/matrix/vpMatrix.cpp +++ b/modules/core/src/math/matrix/vpMatrix.cpp @@ -1253,10 +1253,8 @@ vpColVector vpMatrix::eigenValues() const } #endif #else - { throw(vpException(vpException::functionNotImplementedError, "Eigen values computation is not implemented. " "You should install Lapack 3rd party")); - } #endif return evalue; } @@ -1388,10 +1386,8 @@ void vpMatrix::eigenValues(vpColVector &evalue, vpMatrix &evector) const } #endif // defined(VISP_HAVE_GSL) #else - { throw(vpException(vpException::functionNotImplementedError, "Eigen values computation is not implemented. " "You should install Lapack 3rd party")); - } #endif } @@ -1729,7 +1725,7 @@ vpMatrix vpMatrix::expm() const v_expE = (c * exp) + v_eye; v_expD = (-c * exp) + v_eye; for (int k = 2; k <= q; ++k) { - c = (c * (static_cast((q - k) + 1))) / (static_cast(k * (((2 * q) - k) + 1))); + c = (c * (static_cast((q - k) + 1))) / (static_cast(k * (((2.0 * q) - k) + 1))); v_expcX = exp * v_expX; v_expX = v_expcX; v_expcX = c * v_expX; diff --git a/modules/core/src/math/matrix/vpMatrix_covariance.cpp b/modules/core/src/math/matrix/vpMatrix_covariance.cpp index 942d143f34..85cc9e6925 100644 --- a/modules/core/src/math/matrix/vpMatrix_covariance.cpp +++ b/modules/core/src/math/matrix/vpMatrix_covariance.cpp @@ -213,15 +213,16 @@ void vpMatrix::computeCovarianceMatrixVVS(const vpHomogeneousMatrix &cMo, const ctoInitSkew = ctoInitSkew * LthetauInvAnalytic; + const unsigned int index_3 = 3; for (unsigned int a = 0; a < val_3; ++a) { for (unsigned int b = 0; b < val_3; ++b) { - LpInv[a][b + 3] = ctoInitSkew[a][b]; + LpInv[a][b + index_3] = ctoInitSkew[a][b]; } } for (unsigned int a = 0; a < val_3; ++a) { for (unsigned int b = 0; b < val_3; ++b) { - LpInv[a + 3][b + 3] = LthetauInvAnalytic[a][b]; + LpInv[a + index_3][b + index_3] = LthetauInvAnalytic[a][b]; } } diff --git a/modules/core/src/math/matrix/vpMatrix_lu.cpp b/modules/core/src/math/matrix/vpMatrix_lu.cpp index 5b6e8d67f8..52620bcd51 100644 --- a/modules/core/src/math/matrix/vpMatrix_lu.cpp +++ b/modules/core/src/math/matrix/vpMatrix_lu.cpp @@ -129,6 +129,8 @@ BEGIN_VISP_NAMESPACE */ vpMatrix vpMatrix::inverseByLU() const { + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; if ((colNum == 1) && (rowNum == 1)) { vpMatrix inv; inv.resize(1, 1, false); @@ -140,9 +142,9 @@ vpMatrix vpMatrix::inverseByLU() const inv[0][0] = 1. / d; return inv; } - else if ((colNum == 2) && (rowNum == 2)) { + else if ((colNum == val_2) && (rowNum == val_2)) { vpMatrix inv; - inv.resize(2, 2, false); + inv.resize(val_2, val_2, false); double d = det(); if (std::fabs(d) < std::numeric_limits::epsilon()) { throw(vpException(vpException::fatalError, "Cannot inverse matrix %d by %d by LU. Matrix determinant is 0.", @@ -155,9 +157,9 @@ vpMatrix vpMatrix::inverseByLU() const inv[1][0] = -(*this)[1][0] * d; return inv; } - else if ((colNum == 3) && (rowNum == 3)) { + else if ((colNum == val_3) && (rowNum == val_3)) { vpMatrix inv; - inv.resize(3, 3, false); + inv.resize(val_3, val_3, false); double d = det(); if (std::fabs(d) < std::numeric_limits::epsilon()) { throw(vpException(vpException::fatalError, "Cannot inverse matrix %d by %d by LU. Matrix determinant is 0.", @@ -233,13 +235,15 @@ vpMatrix vpMatrix::inverseByLU() const */ double vpMatrix::detByLU() const { + const unsigned int val_2 = 2; + const unsigned int val_3 = 3; if ((rowNum == 1) && (colNum == 1)) { return (*this)[0][0]; } - else if ((rowNum == 2) && (colNum == 2)) { + else if ((rowNum == val_2) && (colNum == val_2)) { return (((*this)[0][0] * (*this)[1][1]) - ((*this)[0][1] * (*this)[1][0])); } - else if ((rowNum == 3) && (colNum == 3)) { + else if ((rowNum == val_3) && (colNum == val_3)) { const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; diff --git a/modules/core/src/math/matrix/vpMatrix_operations.cpp b/modules/core/src/math/matrix/vpMatrix_operations.cpp index 8d9f029e00..45e57ebb10 100644 --- a/modules/core/src/math/matrix/vpMatrix_operations.cpp +++ b/modules/core/src/math/matrix/vpMatrix_operations.cpp @@ -66,7 +66,8 @@ void vpMatrix::transpose(vpMatrix &At) const { At.resize(colNum, rowNum, false, false); - if ((rowNum <= 16) || (colNum <= 16)) { + const unsigned int val_16 = 16; + if ((rowNum <= val_16) || (colNum <= val_16)) { for (unsigned int i = 0; i < rowNum; ++i) { for (unsigned int j = 0; j < colNum; ++j) { At[j][i] = (*this)[i][j]; @@ -209,7 +210,8 @@ void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpMatrix &C) */ void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMatrix &C) { - if ((A.colNum != 3) || (A.rowNum != 3) || (B.colNum != 3) || (B.rowNum != 3)) { + const unsigned int val_3 = 3; + if ((A.colNum != val_3) || (A.rowNum != val_3) || (B.colNum != val_3) || (B.rowNum != val_3)) { throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a " "rotation matrix", @@ -246,7 +248,8 @@ void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpRotationMat */ void vpMatrix::mult2Matrices(const vpMatrix &A, const vpMatrix &B, vpHomogeneousMatrix &C) { - if ((A.colNum != 4) || (A.rowNum != 4) || (B.colNum != 4) || (B.rowNum != 4)) { + const unsigned int val_4 = 4; + if ((A.colNum != val_4) || (A.rowNum != val_4) || (B.colNum != val_4) || (B.rowNum != val_4)) { throw(vpException(vpException::dimensionError, "Cannot multiply (%dx%d) matrix by (%dx%d) matrix as a " "rotation matrix", @@ -560,7 +563,9 @@ void vpMatrix::AAt(vpMatrix &B) const // sum (row i .* row j) double ssum = 0; for (unsigned int k = 0; k < colNum; ++k) { - ssum += *(pi++) * *(pj++); + ssum += (*pi) * (*pj); + ++pi; + ++pj; } B[i][j] = ssum; // upper triangle @@ -841,7 +846,8 @@ void vpMatrix::kron(const vpMatrix &m1, const vpMatrix &m2, vpMatrix &out) unsigned int coffset = c * c2; for (unsigned int rr = 0; rr < r2; ++rr) { for (unsigned int cc = 0; cc < c2; ++cc) { - out[roffset + rr][coffset + cc] = alpha * *(m2ptr++); + out[roffset + rr][coffset + cc] = alpha * (*m2ptr); + ++m2ptr; } } } @@ -880,7 +886,8 @@ vpMatrix vpMatrix::kron(const vpMatrix &m1, const vpMatrix &m2) unsigned int coffset = c * c2; for (unsigned int rr = 0; rr < r2; ++rr) { for (unsigned int cc = 0; cc < c2; ++cc) { - out[roffset + rr][coffset + cc] = alpha * *(m2ptr++); + out[roffset + rr][coffset + cc] = alpha * (*m2ptr); + ++m2ptr; } } } diff --git a/modules/core/src/math/matrix/vpMatrix_operators.cpp b/modules/core/src/math/matrix/vpMatrix_operators.cpp index cbb4559f67..2137c2c6c9 100644 --- a/modules/core/src/math/matrix/vpMatrix_operators.cpp +++ b/modules/core/src/math/matrix/vpMatrix_operators.cpp @@ -397,12 +397,12 @@ vpTranslationVector vpMatrix::operator*(const vpTranslationVector &tv) const { vpTranslationVector t_out; - if ((rowNum != 3) || (colNum != 3)) { + const unsigned int val_3 = 3; + if ((rowNum != val_3) || (colNum != val_3)) { throw(vpException(vpException::dimensionError, "Cannot multiply a (%dx%d) matrix by a (%dx%d) translation vector", rowNum, colNum, tv.getRows(), tv.getCols())); } - const unsigned int val_3 = 3; for (unsigned int j = 0; j < val_3; ++j) { t_out[j] = 0; } @@ -451,7 +451,8 @@ vpMatrix vpMatrix::operator*(const vpRotationMatrix &R) const colNum)); } vpMatrix C; - C.resize(rowNum, 3, false, false); + const unsigned int val_3 = 3; + C.resize(rowNum, val_3, false, false); unsigned int RcolNum = R.getCols(); unsigned int RrowNum = R.getRows(); @@ -481,7 +482,8 @@ vpMatrix vpMatrix::operator*(const vpHomogeneousMatrix &M) const colNum)); } vpMatrix C; - C.resize(rowNum, 4, false, false); + const unsigned int val_4 = 4; + C.resize(rowNum, val_4, false, false); const unsigned int McolNum = M.getCols(); const unsigned int MrowNum = M.getRows(); @@ -512,7 +514,8 @@ vpMatrix vpMatrix::operator*(const vpVelocityTwistMatrix &V) const rowNum, colNum)); } vpMatrix M; - M.resize(rowNum, 6, false, false); + const unsigned int val_6 = 6; + M.resize(rowNum, val_6, false, false); // Considering perfMatrixMultiplication.cpp benchmark, // using either MKL, OpenBLAS, or Netlib can slow down this function with respect to the naive code. @@ -568,7 +571,8 @@ vpMatrix vpMatrix::operator*(const vpForceTwistMatrix &V) const rowNum, colNum)); } vpMatrix M; - M.resize(rowNum, 6, false, false); + const unsigned int val_6 = 6; + M.resize(rowNum, val_6, false, false); // Considering perfMatrixMultiplication.cpp benchmark, // using either MKL, OpenBLAS, or Netlib can slow down this function with respect to the naive code. diff --git a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp index d6eee1f0f2..c91e7e7869 100644 --- a/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp +++ b/modules/core/src/math/matrix/vpMatrix_pseudo_inverse.cpp @@ -1031,7 +1031,7 @@ vpMatrix vpMatrix::dampedInverse(const double &ratioOfMaxSvd) const vpMatrix I; I.eye(this->colNum); double lambda = ratioOfMaxSvd * maxSingularValue; - vpMatrix dampedInv = (lambda * I + this->transpose() * *this).inverseByLU()* this->transpose(); + vpMatrix dampedInv = ((lambda * I) + (this->transpose() * (*this))).inverseByLU()* this->transpose(); return dampedInv; } diff --git a/modules/core/src/math/matrix/vpRowVector.cpp b/modules/core/src/math/matrix/vpRowVector.cpp index ef1d0bcb67..bbbb9dd4dd 100644 --- a/modules/core/src/math/matrix/vpRowVector.cpp +++ b/modules/core/src/math/matrix/vpRowVector.cpp @@ -292,7 +292,8 @@ vpRowVector vpRowVector::operator*(double x) const double *d = data; for (unsigned int i = 0; i < colNum; ++i) { - *(vd++) = (*d++) * x; + *(vd++) = (*d) * x; + ++d; } return v; } @@ -349,7 +350,8 @@ vpRowVector vpRowVector::operator/(double x) const double *d = data; for (unsigned int i = 0; i < colNum; ++i) { - *(vd++) = (*d++) / x; + *(vd++) = (*d) / x; + ++d; } return v; } @@ -398,7 +400,8 @@ vpRowVector vpRowVector::operator-() const double *d = data; for (unsigned int i = 0; i < colNum; ++i) { - *(vd++) = -(*d++); + *(vd++) = -(*d); + ++d; } return A; diff --git a/modules/core/src/math/misc/vpMath.cpp b/modules/core/src/math/misc/vpMath.cpp index 4b08463903..eaabc82615 100644 --- a/modules/core/src/math/misc/vpMath.cpp +++ b/modules/core/src/math/misc/vpMath.cpp @@ -324,7 +324,7 @@ double vpMath::getMedian(const std::vector &v) if (v.empty()) { throw vpException(vpException::notInitialized, "Empty vector !"); } - + const size_t val_2 = 2; std::vector v_copy = v; size_t size = v_copy.size(); @@ -332,7 +332,7 @@ double vpMath::getMedian(const std::vector &v) std::nth_element(v_copy.begin(), v_copy.begin() + n, v_copy.end()); double val_n = v_copy[n]; - if ((size % 2) == 1) { + if ((size % val_2) == 1) { return val_n; } else { @@ -389,7 +389,8 @@ double vpMath::getStdev(const std::vector &v, bool useBesselCorrection) */ double vpMath::lineFitting(const std::vector &imPts, double &a, double &b, double &c) { - if (imPts.size() < 3) { + const unsigned int val_3 = 3; + if (imPts.size() < val_3) { throw vpException(vpException::dimensionError, "Number of image points must be greater or equal to 3."); } @@ -723,7 +724,8 @@ vpHomogeneousMatrix vpMath::lookAt(const vpColVector &from, const vpColVector &t */ vpColVector vpMath::deg(const vpRotationVector &r) { - if (r.size() == 4) { + const unsigned int val_4 = 4; + if (r.size() == val_4) { throw(vpException(vpException::fatalError, "Cannot convert angles of a quaternion vector in degrees!")); } vpColVector r_deg(r.size()); diff --git a/modules/core/src/math/random-generator/vpGaussRand.cpp b/modules/core/src/math/random-generator/vpGaussRand.cpp index 255947965d..429df6c03f 100644 --- a/modules/core/src/math/random-generator/vpGaussRand.cpp +++ b/modules/core/src/math/random-generator/vpGaussRand.cpp @@ -52,14 +52,15 @@ double vpGaussRand::gaussianDraw() } else { + const int val_2 = 2; double v1 = 0, v2 = 0, rsq = 0; do { - v1 = 2 * m_rng.uniform(0.0, 1.0) - 1; - v2 = 2 * m_rng.uniform(0.0, 1.0) - 1; - rsq = v1 * v1 + v2 * v2; + v1 = (val_2 * m_rng.uniform(0.0, 1.0)) - 1; + v2 = (val_2 * m_rng.uniform(0.0, 1.0)) - 1; + rsq = (v1 * v1) + (v2 * v2); } while (rsq >= 1); - double fac = sqrt(-2 * log(rsq) / rsq); + double fac = sqrt((-2 * log(rsq)) / rsq); m_x2 = v2 * fac; m_AlreadyDone = true; return v1 * fac; diff --git a/modules/core/src/math/random-generator/vpUniRand.cpp b/modules/core/src/math/random-generator/vpUniRand.cpp index b6829b8c3a..5098f6bd71 100644 --- a/modules/core/src/math/random-generator/vpUniRand.cpp +++ b/modules/core/src/math/random-generator/vpUniRand.cpp @@ -29,8 +29,8 @@ * * Description: * Pseudo random number generator. - * -*****************************************************************************/ + */ + /* * PCG Random Number Generation for C. * @@ -100,8 +100,8 @@ double vpUniRand::operator()() { return uniform(0.0, 1.0); } \note Some programmers may think that they can just run rng.next() % bound, - but doing so introduces nonuniformity when bound is not a power of two. - The code for boundedRand() avoids the nonuniformity by dropping a portion + but doing so introduces non uniformity when bound is not a power of two. + The code for boundedRand() avoids the non uniformity by dropping a portion of the RNG's output. */ @@ -144,11 +144,13 @@ uint32_t vpUniRand::boundedRand(uint32_t bound) */ uint32_t vpUniRand::next() { + const unsigned long long val_ll = 6364136223846793005ULL; + const uint32_t val_31 = 31; uint64_t oldstate = m_rng.state; - m_rng.state = (oldstate * 6364136223846793005ULL) + m_rng.inc; + m_rng.state = (oldstate * val_ll) + m_rng.inc; uint32_t xorshifted = static_cast(((oldstate >> 18u) ^ oldstate) >> 27u); uint32_t rot = oldstate >> 59u; - return (xorshifted >> rot) | (xorshifted << (static_cast((-static_cast(rot)) & 31))); + return (xorshifted >> rot) | (xorshifted << (static_cast((-static_cast(rot)) & val_31))); } /*! diff --git a/modules/core/src/math/transformation/vpExponentialMap.cpp b/modules/core/src/math/transformation/vpExponentialMap.cpp index 15c6506654..91e86b0e18 100644 --- a/modules/core/src/math/transformation/vpExponentialMap.cpp +++ b/modules/core/src/math/transformation/vpExponentialMap.cpp @@ -169,11 +169,12 @@ vpColVector vpExponentialMap::inverse(const vpHomogeneousMatrix &M, const double const unsigned int index_1 = 1; const unsigned int index_2 = 2; const unsigned int index_3 = 3; + const unsigned int val_3 = 3; M.extract(Rd); u.buildFrom(Rd); - for (i = 0; i < 3; ++i) { - v[3 + i] = u[i]; + for (i = 0; i < val_3; ++i) { + v[index_3 + i] = u[i]; } theta = sqrt((u[index_0] * u[index_0]) + (u[index_1] * u[index_1]) + (u[index_2] * u[index_2])); diff --git a/modules/core/src/math/transformation/vpForceTwistMatrix.cpp b/modules/core/src/math/transformation/vpForceTwistMatrix.cpp index e3e54d9802..fc05636c84 100644 --- a/modules/core/src/math/transformation/vpForceTwistMatrix.cpp +++ b/modules/core/src/math/transformation/vpForceTwistMatrix.cpp @@ -30,8 +30,7 @@ * Description: * Twist transformation matrix that allows to transform forces from one * frame to an other. - * -*****************************************************************************/ + **/ /*! \file vpForceTwistMatrix.cpp @@ -49,6 +48,8 @@ BEGIN_VISP_NAMESPACE +const unsigned int vpForceTwistMatrix::constr_value_6 = 6; + /*! Copy operator. @@ -56,8 +57,9 @@ BEGIN_VISP_NAMESPACE */ vpForceTwistMatrix &vpForceTwistMatrix::operator=(const vpForceTwistMatrix &M) { - for (int i = 0; i < 6; ++i) { - for (int j = 0; j < 6; ++j) { + const int val_6 = 6; + for (int i = 0; i < val_6; ++i) { + for (int j = 0; j < val_6; ++j) { rowPtrs[i][j] = M.rowPtrs[i][j]; } } @@ -86,7 +88,7 @@ void vpForceTwistMatrix::eye() /*! Initialize a force/torque twist transformation matrix to identity. */ -vpForceTwistMatrix::vpForceTwistMatrix() : vpArray2D(6, 6) { eye(); } +vpForceTwistMatrix::vpForceTwistMatrix() : vpArray2D(constr_value_6, constr_value_6) { eye(); } /*! @@ -95,7 +97,7 @@ vpForceTwistMatrix::vpForceTwistMatrix() : vpArray2D(6, 6) { eye(); } \param F : Force/torque twist matrix used as initializer. */ -vpForceTwistMatrix::vpForceTwistMatrix(const vpForceTwistMatrix &F) : vpArray2D(6, 6) { *this = F; } +vpForceTwistMatrix::vpForceTwistMatrix(const vpForceTwistMatrix &F) : vpArray2D(constr_value_6, constr_value_6) { *this = F; } /*! @@ -126,7 +128,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpForceTwistMatrix &F) : vpArray2D< \f] */ -vpForceTwistMatrix::vpForceTwistMatrix(const vpHomogeneousMatrix &M, bool full) : vpArray2D(6, 6) +vpForceTwistMatrix::vpForceTwistMatrix(const vpHomogeneousMatrix &M, bool full) : vpArray2D(constr_value_6, constr_value_6) { if (full) { buildFrom(M); @@ -156,7 +158,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpHomogeneousMatrix &M, bool full) */ vpForceTwistMatrix::vpForceTwistMatrix(const vpTranslationVector &t, const vpThetaUVector &thetau) - : vpArray2D(6, 6) + : vpArray2D(constr_value_6, constr_value_6) { buildFrom(t, thetau); } @@ -178,7 +180,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpTranslationVector &t, const vpThe \param thetau : \f$\theta u\f$ rotation vector used to initialize \f$R\f$. */ -vpForceTwistMatrix::vpForceTwistMatrix(const vpThetaUVector &thetau) : vpArray2D(6, 6) { buildFrom(thetau); } +vpForceTwistMatrix::vpForceTwistMatrix(const vpThetaUVector &thetau) : vpArray2D(constr_value_6, constr_value_6) { buildFrom(thetau); } /*! @@ -200,7 +202,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpThetaUVector &thetau) : vpArray2D */ vpForceTwistMatrix::vpForceTwistMatrix(const vpTranslationVector &t, const vpRotationMatrix &R) - : vpArray2D(6, 6) + : vpArray2D(constr_value_6, constr_value_6) { buildFrom(t, R); } @@ -222,7 +224,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpTranslationVector &t, const vpRot \param R : Rotation matrix. */ -vpForceTwistMatrix::vpForceTwistMatrix(const vpRotationMatrix &R) : vpArray2D(6, 6) { buildFrom(R); } +vpForceTwistMatrix::vpForceTwistMatrix(const vpRotationMatrix &R) : vpArray2D(constr_value_6, constr_value_6) { buildFrom(R); } /*! @@ -245,7 +247,7 @@ vpForceTwistMatrix::vpForceTwistMatrix(const vpRotationMatrix &R) : vpArray2D(6, 6) + : vpArray2D(constr_value_6, constr_value_6) { vpTranslationVector T(tx, ty, tz); vpThetaUVector tu(tux, tuy, tuz); @@ -368,10 +370,11 @@ vpMatrix vpForceTwistMatrix::operator*(const vpMatrix &M) const */ vpColVector vpForceTwistMatrix::operator*(const vpColVector &H) const { + const unsigned int val_6 = 6; const unsigned int nparam = 6; vpColVector Hout(nparam); - if (6 != H.getRows()) { + if (val_6 != H.getRows()) { throw(vpException(vpException::dimensionError, "Cannot multiply a (6x6) force/torque twist matrix by " "a %d dimension column vector", @@ -412,11 +415,12 @@ vpForceTwistMatrix &vpForceTwistMatrix::buildFrom(const vpTranslationVector &t, vpMatrix skewaR = t.skew(t) * R; const unsigned int val_3 = 3; + const unsigned int index_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { for (unsigned int j = 0; j < val_3; ++j) { (*this)[i][j] = R[i][j]; - (*this)[i + 3][j + 3] = R[i][j]; - (*this)[i + 3][j] = skewaR[i][j]; + (*this)[i + index_3][j + index_3] = R[i][j]; + (*this)[i + index_3][j] = skewaR[i][j]; } } return *this; @@ -440,12 +444,13 @@ vpForceTwistMatrix &vpForceTwistMatrix::buildFrom(const vpTranslationVector &t, */ vpForceTwistMatrix &vpForceTwistMatrix::buildFrom(const vpRotationMatrix &R) { + const unsigned int index_3 = 3; const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { for (unsigned int j = 0; j < val_3; ++j) { (*this)[i][j] = R[i][j]; - (*this)[i + 3][j + 3] = R[i][j]; - (*this)[i + 3][j] = 0; + (*this)[i + index_3][j + index_3] = R[i][j]; + (*this)[i + index_3][j] = 0; } } return *this; diff --git a/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp b/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp index e0d071229a..289a730f98 100644 --- a/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp +++ b/modules/core/src/math/transformation/vpHomogeneousMatrix.cpp @@ -44,27 +44,29 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpHomogeneousMatrix::constr_value_4 = 4; /*! Construct an homogeneous matrix from a translation vector and quaternion rotation vector. */ - vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpQuaternionVector &q) - : vpArray2D(4, 4) +vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpQuaternionVector &q) + : vpArray2D(constr_value_4, constr_value_4) { + const unsigned int index_3 = 3; buildFrom(t, q); - (*this)[3][3] = 1.; + (*this)[index_3][index_3] = 1.; } /*! Default constructor that initialize an homogeneous matrix as identity. */ -vpHomogeneousMatrix::vpHomogeneousMatrix() : vpArray2D(4, 4), m_index(0) { eye(); } +vpHomogeneousMatrix::vpHomogeneousMatrix() : vpArray2D(constr_value_4, constr_value_4), m_index(0) { eye(); } /*! Copy constructor that initialize an homogeneous matrix from another homogeneous matrix. */ -vpHomogeneousMatrix::vpHomogeneousMatrix(const vpHomogeneousMatrix &M) : vpArray2D(4, 4), m_index(0) +vpHomogeneousMatrix::vpHomogeneousMatrix(const vpHomogeneousMatrix &M) : vpArray2D(constr_value_4, constr_value_4), m_index(0) { *this = M; } @@ -74,10 +76,11 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const vpHomogeneousMatrix &M) : vpArray u}\f$ rotation vector. */ vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpThetaUVector &tu) - : vpArray2D(4, 4), m_index(0) + : vpArray2D(constr_value_4, constr_value_4), m_index(0) { + const unsigned int index_3 = 3; buildFrom(t, tu); - (*this)[3][3] = 1.; + (*this)[index_3][index_3] = 1.; } /*! @@ -85,7 +88,7 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpT matrix. */ vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpRotationMatrix &R) - : vpArray2D(4, 4), m_index(0) + : vpArray2D(constr_value_4, constr_value_4), m_index(0) { const unsigned int index_3 = 3; insert(R); @@ -96,7 +99,7 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const vpTranslationVector &t, const vpR /*! Construct an homogeneous matrix from a pose vector. */ -vpHomogeneousMatrix::vpHomogeneousMatrix(const vpPoseVector &p) : vpArray2D(4, 4), m_index(0) +vpHomogeneousMatrix::vpHomogeneousMatrix(const vpPoseVector &p) : vpArray2D(constr_value_4, constr_value_4), m_index(0) { const unsigned int index_0 = 0; const unsigned int index_1 = 1; @@ -151,10 +154,11 @@ v: 0 -1 0 0.3 1 0 0 0.4 0 0 -1 0.5 0 0 0 1 \endcode */ -vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector &v) : vpArray2D(4, 4), m_index(0) +vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector &v) : vpArray2D(constr_value_4, constr_value_4), m_index(0) { + const unsigned int index_3 = 3; buildFrom(v); - (*this)[3][3] = 1.; + (*this)[index_3][index_3] = 1.; } #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) @@ -308,10 +312,11 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const std::initializer_list &li 0 0 0 1 \endcode */ -vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector &v) : vpArray2D(4, 4), m_index(0) +vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector &v) : vpArray2D(constr_value_4, constr_value_4), m_index(0) { + const unsigned int index_3 = 3; buildFrom(v); - (*this)[3][3] = 1.; + (*this)[index_3][index_3] = 1.; } /*! @@ -320,10 +325,11 @@ vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector &v) : vpArray u_z)^T\f$ rotation vector. */ vpHomogeneousMatrix::vpHomogeneousMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz) - : vpArray2D(4, 4), m_index(0) + : vpArray2D(constr_value_4, constr_value_4), m_index(0) { + const unsigned int index_3 = 3; buildFrom(tx, ty, tz, tux, tuy, tuz); - (*this)[3][3] = 1.; + (*this)[index_3][index_3] = 1.; } /*! @@ -439,11 +445,14 @@ vpHomogeneousMatrix &vpHomogeneousMatrix::buildFrom(const double &tx, const doub */ vpHomogeneousMatrix &vpHomogeneousMatrix::buildFrom(const std::vector &v) { - if ((v.size() != 12) && (v.size() != 16)) { + const std::size_t val_12 = 12; + const std::size_t val_16 = 16; + const unsigned int val_12ui = 12; + if ((v.size() != val_12) && (v.size() != val_16)) { throw(vpException(vpException::dimensionError, "Cannot convert std::vector to vpHomogeneousMatrix")); } - for (unsigned int i = 0; i < 12; ++i) { + for (unsigned int i = 0; i < val_12ui; ++i) { this->data[i] = static_cast(v[i]); } return *this; @@ -495,11 +504,14 @@ vpHomogeneousMatrix &vpHomogeneousMatrix::buildFrom(const std::vector &v) */ vpHomogeneousMatrix &vpHomogeneousMatrix::buildFrom(const std::vector &v) { - if ((v.size() != 12) && (v.size() != 16)) { + const std::size_t val_12 = 12; + const std::size_t val_16 = 16; + const unsigned int val_12ui = 12; + if ((v.size() != val_12) && (v.size() != val_16)) { throw(vpException(vpException::dimensionError, "Cannot convert std::vector to vpHomogeneousMatrix")); } - for (unsigned int i = 0; i < 12; ++i) { + for (unsigned int i = 0; i < val_12ui; ++i) { this->data[i] = v[i]; } return *this; @@ -512,8 +524,9 @@ vpHomogeneousMatrix &vpHomogeneousMatrix::buildFrom(const std::vector &v */ vpHomogeneousMatrix &vpHomogeneousMatrix::operator=(const vpHomogeneousMatrix &M) { - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) { + const int val_4 = 4; + for (int i = 0; i < val_4; ++i) { + for (int j = 0; j < val_4; ++j) { rowPtrs[i][j] = M.rowPtrs[i][j]; } } @@ -652,7 +665,7 @@ vpPoint vpHomogeneousMatrix::operator*(const vpPoint &bP) const v1[index_2] = ((*this)[index_2][0] * v[0]) + ((*this)[index_2][1] * v[1]) + ((*this)[index_2][index_2] * v[index_2]) + ((*this)[index_2][index_3] * v[index_3]); v1[index_3] = ((*this)[index_3][0] * v[0]) + ((*this)[index_3][1] * v[1]) + ((*this)[index_3][index_2] * v[index_2]) + ((*this)[index_3][index_3] * v[index_3]); - v1 /= v1[3]; + v1 /= v1[index_3]; // --comment: v1 equals M multiplied by v aP.set_X(v1[index_0]); @@ -1114,8 +1127,10 @@ void vpHomogeneousMatrix::print() const */ void vpHomogeneousMatrix::convert(std::vector &M) { - M.resize(12); - for (unsigned int i = 0; i < 12; ++i) { + const std::size_t val_12 = 12; + const unsigned int val_12ui = 12; + M.resize(val_12); + for (unsigned int i = 0; i < val_12ui; ++i) { M[i] = static_cast(this->data[i]); } } @@ -1126,8 +1141,10 @@ void vpHomogeneousMatrix::convert(std::vector &M) */ void vpHomogeneousMatrix::convert(std::vector &M) { - M.resize(12); - for (unsigned int i = 0; i < 12; ++i) { + const std::size_t val_12 = 12; + const unsigned int val_12ui = 12; + M.resize(val_12); + for (unsigned int i = 0; i < val_12ui; ++i) { M[i] = this->data[i]; } } @@ -1287,8 +1304,8 @@ vpHomogeneousMatrix vpHomogeneousMatrix::mean(const std::vector(R); + meanT += static_cast(vec_M[i].getTranslationVector()); } meanR /= static_cast(vec_M.size()); meanT /= static_cast(vec_M.size()); diff --git a/modules/core/src/math/transformation/vpPoseVector.cpp b/modules/core/src/math/transformation/vpPoseVector.cpp index c64a207e0d..fbbf9aeb94 100644 --- a/modules/core/src/math/transformation/vpPoseVector.cpp +++ b/modules/core/src/math/transformation/vpPoseVector.cpp @@ -30,8 +30,7 @@ * Description: * Pose object. A pose is a size 6 vector [t, tu]^T where tu is * a rotation vector (theta u representation) and t is a translation vector. - * -*****************************************************************************/ + */ /*! \file vpPoseVector.cpp @@ -49,6 +48,7 @@ BEGIN_VISP_NAMESPACE +const unsigned int vpPoseVector::constr_value_6 = 6; /*! Default constructor that construct a 6 dimension pose vector \f$ [\bf t, @@ -59,7 +59,7 @@ BEGIN_VISP_NAMESPACE The pose vector is initialized to zero. */ -vpPoseVector::vpPoseVector() : vpArray2D(6, 1) { } +vpPoseVector::vpPoseVector() : vpArray2D(constr_value_6, 1) { } /*! @@ -77,7 +77,7 @@ vpPoseVector::vpPoseVector() : vpArray2D(6, 1) { } */ vpPoseVector::vpPoseVector(double tx, double ty, double tz, double tux, double tuy, double tuz) - : vpArray2D(6, 1) + : vpArray2D(constr_value_6, 1) { const unsigned int index_0 = 0; const unsigned int index_1 = 1; @@ -104,7 +104,7 @@ vpPoseVector::vpPoseVector(double tx, double ty, double tz, double tux, double t \param tu : \f$\theta \bf u\f$ rotation vector. */ -vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpThetaUVector &tu) : vpArray2D(6, 1) +vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpThetaUVector &tu) : vpArray2D(constr_value_6, 1) { buildFrom(tv, tu); } @@ -121,7 +121,7 @@ vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpThetaUVector & u\f$ vector is extracted to initialise the pose vector. */ -vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpRotationMatrix &R) : vpArray2D(6, 1) +vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpRotationMatrix &R) : vpArray2D(constr_value_6, 1) { buildFrom(tv, R); } @@ -136,7 +136,7 @@ vpPoseVector::vpPoseVector(const vpTranslationVector &tv, const vpRotationMatrix initialize the pose vector. */ -vpPoseVector::vpPoseVector(const vpHomogeneousMatrix &M) : vpArray2D(6, 1) { buildFrom(M); } +vpPoseVector::vpPoseVector(const vpHomogeneousMatrix &M) : vpArray2D(constr_value_6, 1) { buildFrom(M); } /*! @@ -239,9 +239,10 @@ vpPoseVector &vpPoseVector::buildFrom(const vpHomogeneousMatrix &M) vpPoseVector &vpPoseVector::buildFrom(const vpTranslationVector &tv, const vpThetaUVector &tu) { const unsigned int val_3 = 3; + const unsigned int index_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { (*this)[i] = tv[i]; - (*this)[i + 3] = tu[i]; + (*this)[i + index_3] = tu[i]; } return *this; } @@ -307,7 +308,13 @@ void vpPoseVector::extract(vpQuaternionVector &q) const /*! Extract the rotation as a rotation matrix. */ -void vpPoseVector::extract(vpRotationMatrix &R) const { R.buildFrom((*this)[3], (*this)[4], (*this)[5]); } +void vpPoseVector::extract(vpRotationMatrix &R) const +{ + const unsigned int index_3 = 3; + const unsigned int index_4 = 4; + const unsigned int index_5 = 5; + R.buildFrom((*this)[index_3], (*this)[index_4], (*this)[index_5]); +} /*! Return the translation vector that corresponds to the translation part of the pose vector. diff --git a/modules/core/src/math/transformation/vpQuaternionVector.cpp b/modules/core/src/math/transformation/vpQuaternionVector.cpp index 5586a60059..20fd1717d7 100644 --- a/modules/core/src/math/transformation/vpQuaternionVector.cpp +++ b/modules/core/src/math/transformation/vpQuaternionVector.cpp @@ -41,6 +41,7 @@ BEGIN_VISP_NAMESPACE // minimum value of sine const double vpQuaternionVector::minimum = 0.0001; +const unsigned int vpQuaternionVector::constr_val_4 = 4; /*! \file vpQuaternionVector.cpp @@ -48,29 +49,29 @@ const double vpQuaternionVector::minimum = 0.0001; */ /*! Default constructor that initialize all the 4 angles to zero. */ -vpQuaternionVector::vpQuaternionVector() : vpRotationVector(4) { } +vpQuaternionVector::vpQuaternionVector() : vpRotationVector(constr_val_4) { } /*! Copy constructor. */ vpQuaternionVector::vpQuaternionVector(const vpQuaternionVector &q) : vpRotationVector(q) { } //! Constructor from doubles. -vpQuaternionVector::vpQuaternionVector(double x_, double y_, double z_, double w_) : vpRotationVector(4) +vpQuaternionVector::vpQuaternionVector(double x_, double y_, double z_, double w_) : vpRotationVector(constr_val_4) { set(x_, y_, z_, w_); } //! Constructor from a 4-dimension vector of doubles. -vpQuaternionVector::vpQuaternionVector(const vpColVector &q) : vpRotationVector(4) { buildFrom(q); } +vpQuaternionVector::vpQuaternionVector(const vpColVector &q) : vpRotationVector(constr_val_4) { buildFrom(q); } //! Constructor from a 4-dimension vector of doubles. -vpQuaternionVector::vpQuaternionVector(const std::vector &q) : vpRotationVector(4) { buildFrom(q); } +vpQuaternionVector::vpQuaternionVector(const std::vector &q) : vpRotationVector(constr_val_4) { buildFrom(q); } /*! Constructs a quaternion from a rotation matrix. \param R : Matrix containing a rotation. */ -vpQuaternionVector::vpQuaternionVector(const vpRotationMatrix &R) : vpRotationVector(4) { buildFrom(R); } +vpQuaternionVector::vpQuaternionVector(const vpRotationMatrix &R) : vpRotationVector(constr_val_4) { buildFrom(R); } /*! Constructor that initialize \f$R_{xyz}=(\varphi,\theta,\psi)\f$ Euler @@ -78,7 +79,7 @@ vpQuaternionVector::vpQuaternionVector(const vpRotationMatrix &R) : vpRotationVe \param tu : \f$\theta {\bf u}\f$ representation of a rotation used here as input to initialize the Euler angles. */ -vpQuaternionVector::vpQuaternionVector(const vpThetaUVector &tu) : vpRotationVector(4) { buildFrom(tu); } +vpQuaternionVector::vpQuaternionVector(const vpThetaUVector &tu) : vpRotationVector(constr_val_4) { buildFrom(tu); } /*! Manually change values of a quaternion. @@ -133,11 +134,11 @@ vpQuaternionVector &vpQuaternionVector::buildFrom(const vpThetaUVector &tu) */ vpQuaternionVector &vpQuaternionVector::buildFrom(const vpColVector &q) { - if (q.size() != 4) { + const unsigned int val_4 = 4; + if (q.size() != val_4) { throw(vpException(vpException::dimensionError, "Cannot construct a quaternion vector from a %d-dimension col vector", q.size())); } - const unsigned int val_4 = 4; for (unsigned int i = 0; i < val_4; ++i) { data[i] = q[i]; } @@ -150,12 +151,12 @@ vpQuaternionVector &vpQuaternionVector::buildFrom(const vpColVector &q) */ vpQuaternionVector &vpQuaternionVector::buildFrom(const std::vector &q) { - if (q.size() != 4) { + const unsigned int val_4 = 4; + if (q.size() != val_4) { throw(vpException(vpException::dimensionError, "Cannot construct a quaternion vector from a %d-dimension std::vector", q.size())); } - const unsigned int val_4 = 4; for (unsigned int i = 0; i < val_4; ++i) { data[i] = q[i]; } @@ -266,11 +267,11 @@ vpQuaternionVector vpQuaternionVector::operator/(double l) const */ vpQuaternionVector &vpQuaternionVector::operator=(const vpColVector &q) { - if (q.size() != 4) { + const unsigned int val_4 = 4; + if (q.size() != val_4) { throw(vpException(vpException::dimensionError, "Cannot set a quaternion vector from a %d-dimension col vector", q.size())); } - const unsigned int val_4 = 4; for (unsigned int i = 0; i < val_4; ++i) { data[i] = q[i]; } diff --git a/modules/core/src/math/transformation/vpRotationMatrix.cpp b/modules/core/src/math/transformation/vpRotationMatrix.cpp index 8f23a4df38..d7ef975c10 100644 --- a/modules/core/src/math/transformation/vpRotationMatrix.cpp +++ b/modules/core/src/math/transformation/vpRotationMatrix.cpp @@ -50,6 +50,7 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpRotationMatrix::constr_val_3 = 3; /*! Initialize the rotation matrix as identity. @@ -161,12 +162,12 @@ vpRotationMatrix &vpRotationMatrix::operator=(const std::initializer_list(3, 3), m_index(0) { eye(); } +vpRotationMatrix::vpRotationMatrix() : vpArray2D(constr_val_3, constr_val_3), m_index(0) { eye(); } /*! Copy constructor that construct a 3-by-3 rotation matrix from another rotation matrix. */ -vpRotationMatrix::vpRotationMatrix(const vpRotationMatrix &M) : vpArray2D(3, 3), m_index(0) { (*this) = M; } +vpRotationMatrix::vpRotationMatrix(const vpRotationMatrix &M) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { (*this) = M; } /*! Construct a 3-by-3 rotation matrix from an homogeneous matrix. */ -vpRotationMatrix::vpRotationMatrix(const vpHomogeneousMatrix &M) : vpArray2D(3, 3), m_index(0) { buildFrom(M); } +vpRotationMatrix::vpRotationMatrix(const vpHomogeneousMatrix &M) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(M); } /*! Construct a 3-by-3 rotation matrix from \f$ \theta {\bf u}\f$ angle representation. */ -vpRotationMatrix::vpRotationMatrix(const vpThetaUVector &tu) : vpArray2D(3, 3), m_index(0) { buildFrom(tu); } +vpRotationMatrix::vpRotationMatrix(const vpThetaUVector &tu) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(tu); } /*! Construct a 3-by-3 rotation matrix from a pose vector. */ -vpRotationMatrix::vpRotationMatrix(const vpPoseVector &p) : vpArray2D(3, 3), m_index(0) { buildFrom(p); } +vpRotationMatrix::vpRotationMatrix(const vpPoseVector &p) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(p); } /*! Construct a 3-by-3 rotation matrix from \f$ R(z,y,z) \f$ Euler angle representation. */ -vpRotationMatrix::vpRotationMatrix(const vpRzyzVector &euler) : vpArray2D(3, 3), m_index(0) +vpRotationMatrix::vpRotationMatrix(const vpRzyzVector &euler) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(euler); } @@ -542,24 +543,24 @@ vpRotationMatrix::vpRotationMatrix(const vpRzyzVector &euler) : vpArray2D(3, 3), m_index(0) { buildFrom(Rxyz); } +vpRotationMatrix::vpRotationMatrix(const vpRxyzVector &Rxyz) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(Rxyz); } /*! Construct a 3-by-3 rotation matrix from \f$ R(z,y,x) \f$ Euler angle representation. */ -vpRotationMatrix::vpRotationMatrix(const vpRzyxVector &Rzyx) : vpArray2D(3, 3), m_index(0) { buildFrom(Rzyx); } +vpRotationMatrix::vpRotationMatrix(const vpRzyxVector &Rzyx) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(Rzyx); } /*! Construct a 3-by-3 rotation matrix from a matrix that contains values corresponding to a rotation matrix. */ -vpRotationMatrix::vpRotationMatrix(const vpMatrix &R) : vpArray2D(3, 3), m_index(0) { *this = R; } +vpRotationMatrix::vpRotationMatrix(const vpMatrix &R) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { *this = R; } /*! Construct a 3-by-3 rotation matrix from \f$ \theta {\bf u}=(\theta u_x, \theta u_y, \theta u_z)^T\f$ angle representation. */ -vpRotationMatrix::vpRotationMatrix(double tux, double tuy, double tuz) : vpArray2D(3, 3), m_index(0) +vpRotationMatrix::vpRotationMatrix(double tux, double tuy, double tuz) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(tux, tuy, tuz); } @@ -567,7 +568,7 @@ vpRotationMatrix::vpRotationMatrix(double tux, double tuy, double tuz) : vpArray /*! Construct a 3-by-3 rotation matrix from quaternion angle representation. */ -vpRotationMatrix::vpRotationMatrix(const vpQuaternionVector &q) : vpArray2D(3, 3), m_index(0) { buildFrom(q); } +vpRotationMatrix::vpRotationMatrix(const vpQuaternionVector &q) : vpArray2D(constr_val_3, constr_val_3), m_index(0) { buildFrom(q); } #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) /*! @@ -880,15 +881,15 @@ vpRotationMatrix &vpRotationMatrix::buildFrom(const vpQuaternionVector &q) const unsigned int index_1 = 1; const unsigned int index_2 = 2; (*this)[index_0][index_0] = (((a * a) + (b * b)) - (c * c)) - (d * d); - (*this)[index_0][index_1] = (2 * b * c) - (2 * a * d); - (*this)[index_0][index_2] = (2 * a * c) + (2 * b * d); + (*this)[index_0][index_1] = (2.0 * b * c) - (2.0 * a * d); + (*this)[index_0][index_2] = (2.0 * a * c) + (2.0 * b * d); - (*this)[index_1][index_0] = (2 * a * d) + (2 * b * c); + (*this)[index_1][index_0] = (2.0 * a * d) + (2.0 * b * c); (*this)[index_1][index_1] = (((a * a) - (b * b)) + (c * c)) - (d * d); - (*this)[index_1][index_2] = (2 * c * d) - (2 * a * b); + (*this)[index_1][index_2] = (2.0 * c * d) - (2.0 * a * b); - (*this)[index_2][index_0] = (2 * b * d) - (2 * a * c); - (*this)[index_2][index_1] = (2 * a * b) + (2 * c * d); + (*this)[index_2][index_0] = (2.0 * b * d) - (2.0 * a * c); + (*this)[index_2][index_1] = (2.0 * a * b) + (2.0 * c * d); (*this)[index_2][index_2] = ((a * a) - (b * b) - (c * c)) + (d * d); return *this; } @@ -964,7 +965,7 @@ vpRotationMatrix vpRotationMatrix::mean(const std::vector & size_t vec_m_size = vec_M.size(); for (size_t i = 0; i < vec_m_size; ++i) { R = vec_M[i].getRotationMatrix(); - meanR += (vpMatrix)R; + meanR += static_cast(R); } meanR /= static_cast(vec_M.size()); @@ -1006,7 +1007,7 @@ vpRotationMatrix vpRotationMatrix::mean(const std::vector &vec vpRotationMatrix R; size_t vec_r_size = vec_R.size(); for (size_t i = 0; i < vec_r_size; ++i) { - meanR += (vpMatrix)vec_R[i]; + meanR += static_cast(vec_R[i]); } meanR /= static_cast(vec_R.size()); diff --git a/modules/core/src/math/transformation/vpRxyzVector.cpp b/modules/core/src/math/transformation/vpRxyzVector.cpp index ff10108495..41eddfc80d 100644 --- a/modules/core/src/math/transformation/vpRxyzVector.cpp +++ b/modules/core/src/math/transformation/vpRxyzVector.cpp @@ -43,8 +43,9 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpRxyzVector::constr_val_3 = 3; /*! Default constructor that initialize all the 3 angles to zero. */ -vpRxyzVector::vpRxyzVector() : vpRotationVector(3) { } +vpRxyzVector::vpRxyzVector() : vpRotationVector(constr_val_3) { } /*! Copy constructor. */ vpRxyzVector::vpRxyzVector(const vpRxyzVector &rxyz) : vpRotationVector(rxyz) { } @@ -55,14 +56,14 @@ vpRxyzVector::vpRxyzVector(const vpRxyzVector &rxyz) : vpRotationVector(rxyz) { \param theta : \f$\theta\f$ angle around the \f$y\f$ axis. \param psi : \f$\psi\f$ angle around the \f$z\f$ axis. */ -vpRxyzVector::vpRxyzVector(double phi, double theta, double psi) : vpRotationVector(3) { buildFrom(phi, theta, psi); } +vpRxyzVector::vpRxyzVector(double phi, double theta, double psi) : vpRotationVector(constr_val_3) { buildFrom(phi, theta, psi); } /*! Constructor that initialize \f$R_{xyz}=(\varphi,\theta,\psi)\f$ Euler angles from a rotation matrix. \param R : Rotation matrix used to initialize the Euler angles. */ -vpRxyzVector::vpRxyzVector(const vpRotationMatrix &R) : vpRotationVector(3) { buildFrom(R); } +vpRxyzVector::vpRxyzVector(const vpRotationMatrix &R) : vpRotationVector(constr_val_3) { buildFrom(R); } /*! Constructor that initialize \f$R_{xyz}=(\varphi,\theta,\psi)\f$ Euler @@ -70,13 +71,13 @@ vpRxyzVector::vpRxyzVector(const vpRotationMatrix &R) : vpRotationVector(3) { bu \param tu : \f$\theta {\bf u}\f$ representation of a rotation used here as input to initialize the Euler angles. */ -vpRxyzVector::vpRxyzVector(const vpThetaUVector &tu) : vpRotationVector(3) { buildFrom(tu); } +vpRxyzVector::vpRxyzVector(const vpThetaUVector &tu) : vpRotationVector(constr_val_3) { buildFrom(tu); } /*! Copy constructor from a 3-dimension vector. */ -vpRxyzVector::vpRxyzVector(const vpColVector &rxyz) : vpRotationVector(3) { buildFrom(rxyz); } +vpRxyzVector::vpRxyzVector(const vpColVector &rxyz) : vpRotationVector(constr_val_3) { buildFrom(rxyz); } /*! Copy constructor from a 3-dimension vector. */ -vpRxyzVector::vpRxyzVector(const std::vector &rxyz) : vpRotationVector(3) { buildFrom(rxyz); } +vpRxyzVector::vpRxyzVector(const std::vector &rxyz) : vpRotationVector(constr_val_3) { buildFrom(rxyz); } /*! Convert a rotation matrix into a \f$R_{xyz}=(\varphi,\theta,\psi)\f$ Euler @@ -147,11 +148,11 @@ vpRxyzVector &vpRxyzVector::buildFrom(const double &phi, const double &theta, co */ vpRxyzVector &vpRxyzVector::buildFrom(const vpColVector &rxyz) { - if (rxyz.size() != 3) { + const unsigned int val_3 = 3; + if (rxyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-xyz vector from a %d-dimension col vector", rxyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rxyz[i]; } @@ -164,11 +165,11 @@ vpRxyzVector &vpRxyzVector::buildFrom(const vpColVector &rxyz) */ vpRxyzVector &vpRxyzVector::buildFrom(const std::vector &rxyz) { - if (rxyz.size() != 3) { + const unsigned int val_3 = 3; + if (rxyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-xyz vector from a %d-dimension std::vector", rxyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rxyz[i]; } @@ -236,11 +237,11 @@ vpRxyzVector &vpRxyzVector::operator=(double v) */ vpRxyzVector &vpRxyzVector::operator=(const vpColVector &rxyz) { - if (rxyz.size() != 3) { + const unsigned int val_3 = 3; + if (rxyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot set a R-xyz vector from a %d-dimension col vector", rxyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rxyz[i]; } diff --git a/modules/core/src/math/transformation/vpRzyxVector.cpp b/modules/core/src/math/transformation/vpRzyxVector.cpp index 7f5b30ad9f..ea6c5ec817 100644 --- a/modules/core/src/math/transformation/vpRzyxVector.cpp +++ b/modules/core/src/math/transformation/vpRzyxVector.cpp @@ -30,8 +30,7 @@ * Description: * Rzyx angle parameterization for the rotation. * Rzyx(phi,theta,psi) = Rot(z,phi)Rot(y,theta)Rot(x,psi) - * -*****************************************************************************/ + */ /*! \file vpRzyxVector.cpp @@ -44,8 +43,9 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpRzyxVector::constr_val_3 = 3; /*! Default constructor that initialize all the 3 angles to zero. */ -vpRzyxVector::vpRzyxVector() : vpRotationVector(3) { } +vpRzyxVector::vpRzyxVector() : vpRotationVector(constr_val_3) { } /*! Copy constructor. */ vpRzyxVector::vpRzyxVector(const vpRzyxVector &rzyx) : vpRotationVector(rzyx) { } @@ -56,14 +56,14 @@ vpRzyxVector::vpRzyxVector(const vpRzyxVector &rzyx) : vpRotationVector(rzyx) { \param theta : \f$\theta\f$ angle around the \f$y\f$ axis. \param psi : \f$\psi\f$ angle around the \f$x\f$ axis. */ -vpRzyxVector::vpRzyxVector(double phi, double theta, double psi) : vpRotationVector(3) { buildFrom(phi, theta, psi); } +vpRzyxVector::vpRzyxVector(double phi, double theta, double psi) : vpRotationVector(constr_val_3) { buildFrom(phi, theta, psi); } /*! Constructor that initialize \f$R_{zyx}=(\varphi,\theta,\psi)\f$ Euler angles from a rotation matrix. \param R : Rotation matrix used to initialize the Euler angles. */ -vpRzyxVector::vpRzyxVector(const vpRotationMatrix &R) : vpRotationVector(3) { buildFrom(R); } +vpRzyxVector::vpRzyxVector(const vpRotationMatrix &R) : vpRotationVector(constr_val_3) { buildFrom(R); } /*! Constructor that initialize \f$R_{zyx}=(\varphi,\theta,\psi)\f$ Euler @@ -71,13 +71,13 @@ vpRzyxVector::vpRzyxVector(const vpRotationMatrix &R) : vpRotationVector(3) { bu \param tu : \f$\theta {\bf u}\f$ representation of a rotation used here as input to initialize the Euler angles. */ -vpRzyxVector::vpRzyxVector(const vpThetaUVector &tu) : vpRotationVector(3) { buildFrom(tu); } +vpRzyxVector::vpRzyxVector(const vpThetaUVector &tu) : vpRotationVector(constr_val_3) { buildFrom(tu); } /*! Copy constructor from a 3-dimension vector. */ -vpRzyxVector::vpRzyxVector(const vpColVector &rzyx) : vpRotationVector(3) { buildFrom(rzyx); } +vpRzyxVector::vpRzyxVector(const vpColVector &rzyx) : vpRotationVector(constr_val_3) { buildFrom(rzyx); } /*! Copy constructor from a 3-dimension vector. */ -vpRzyxVector::vpRzyxVector(const std::vector &rzyx) : vpRotationVector(3) { buildFrom(rzyx); } +vpRzyxVector::vpRzyxVector(const std::vector &rzyx) : vpRotationVector(constr_val_3) { buildFrom(rzyx); } /*! Convert a rotation matrix into a \f$R_{zyx}=(\varphi,\theta,\psi)\f$ Euler @@ -161,11 +161,11 @@ vpRzyxVector &vpRzyxVector::buildFrom(const double &phi, const double &theta, co */ vpRzyxVector &vpRzyxVector::buildFrom(const vpColVector &rzyx) { - if (rzyx.size() != 3) { + const unsigned int val_3 = 3; + if (rzyx.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension col vector", rzyx.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyx[i]; } @@ -178,11 +178,11 @@ vpRzyxVector &vpRzyxVector::buildFrom(const vpColVector &rzyx) */ vpRzyxVector &vpRzyxVector::buildFrom(const std::vector &rzyx) { - if (rzyx.size() != 3) { + const unsigned int val_3 = 3; + if (rzyx.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension std::vector", rzyx.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyx[i]; } @@ -250,11 +250,11 @@ vpRzyxVector &vpRzyxVector::operator=(double v) */ vpRzyxVector &vpRzyxVector::operator=(const vpColVector &rzyx) { - if (rzyx.size() != 3) { + const unsigned int val_3 = 3; + if (rzyx.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot set a R-zyx vector from a %d-dimension col vector", rzyx.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyx[i]; } diff --git a/modules/core/src/math/transformation/vpRzyzVector.cpp b/modules/core/src/math/transformation/vpRzyzVector.cpp index 72d6cfba7a..2f448a9754 100644 --- a/modules/core/src/math/transformation/vpRzyzVector.cpp +++ b/modules/core/src/math/transformation/vpRzyzVector.cpp @@ -42,8 +42,9 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpRzyzVector::constr_val_3 = 3; /*! Default constructor that initialize all the 3 angles to zero. */ -vpRzyzVector::vpRzyzVector() : vpRotationVector(3) { } +vpRzyzVector::vpRzyzVector() : vpRotationVector(constr_val_3) { } /*! Copy constructor. */ vpRzyzVector::vpRzyzVector(const vpRzyzVector &rzyz) : vpRotationVector(rzyz) { } @@ -53,14 +54,14 @@ vpRzyzVector::vpRzyzVector(const vpRzyzVector &rzyz) : vpRotationVector(rzyz) { \param theta : \f$\theta\f$ angle around the \f$y\f$ axis. \param psi : \f$\psi\f$ angle around the \f$z\f$ axis. */ -vpRzyzVector::vpRzyzVector(double phi, double theta, double psi) : vpRotationVector(3) { buildFrom(phi, theta, psi); } +vpRzyzVector::vpRzyzVector(double phi, double theta, double psi) : vpRotationVector(constr_val_3) { buildFrom(phi, theta, psi); } /*! Constructor that initialize \f$R_{zyz}=(\varphi,\theta,\psi)\f$ Euler angles from a rotation matrix. \param R : Rotation matrix used to initialize the Euler angles. */ -vpRzyzVector::vpRzyzVector(const vpRotationMatrix &R) : vpRotationVector(3) { buildFrom(R); } +vpRzyzVector::vpRzyzVector(const vpRotationMatrix &R) : vpRotationVector(constr_val_3) { buildFrom(R); } /*! Constructor that initialize \f$R_{zyz}=(\varphi,\theta,\psi)\f$ Euler @@ -68,13 +69,13 @@ vpRzyzVector::vpRzyzVector(const vpRotationMatrix &R) : vpRotationVector(3) { bu \param tu : \f$\theta {\bf u}\f$ representation of a rotation used here as input to initialize the Euler angles. */ -vpRzyzVector::vpRzyzVector(const vpThetaUVector &tu) : vpRotationVector(3) { buildFrom(tu); } +vpRzyzVector::vpRzyzVector(const vpThetaUVector &tu) : vpRotationVector(constr_val_3) { buildFrom(tu); } /*! Copy constructor from a 3-dimension vector. */ -vpRzyzVector::vpRzyzVector(const vpColVector &rzyz) : vpRotationVector(3) { buildFrom(rzyz); } +vpRzyzVector::vpRzyzVector(const vpColVector &rzyz) : vpRotationVector(constr_val_3) { buildFrom(rzyz); } /*! Copy constructor from a 3-dimension vector. */ -vpRzyzVector::vpRzyzVector(const std::vector &rzyz) : vpRotationVector(3) { buildFrom(rzyz); } +vpRzyzVector::vpRzyzVector(const std::vector &rzyz) : vpRotationVector(constr_val_3) { buildFrom(rzyz); } /*! Convert a rotation matrix into a \f$R_{zyz}=(\varphi,\theta,\psi)\f$ Euler @@ -127,11 +128,11 @@ vpRzyzVector &vpRzyzVector::buildFrom(const vpThetaUVector &tu) */ vpRzyzVector &vpRzyzVector::buildFrom(const vpColVector &rzyz) { - if (rzyz.size() != 3) { + const unsigned int val_3 = 3; + if (rzyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-zyz vector from a %d-dimension col vector", rzyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyz[i]; } @@ -144,11 +145,11 @@ vpRzyzVector &vpRzyzVector::buildFrom(const vpColVector &rzyz) */ vpRzyzVector &vpRzyzVector::buildFrom(const std::vector &rzyz) { - if (rzyz.size() != 3) { + const unsigned int val_3 = 3; + if (rzyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a R-zyx vector from a %d-dimension std::vector", rzyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyz[i]; } @@ -233,11 +234,11 @@ vpRzyzVector &vpRzyzVector::operator=(double v) */ vpRzyzVector &vpRzyzVector::operator=(const vpColVector &rzyz) { - if (rzyz.size() != 3) { + const unsigned int val_3 = 3; + if (rzyz.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot set a R-zyz vector from a %d-dimension col vector", rzyz.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = rzyz[i]; } diff --git a/modules/core/src/math/transformation/vpThetaUVector.cpp b/modules/core/src/math/transformation/vpThetaUVector.cpp index 2530e2c296..e510ee542c 100644 --- a/modules/core/src/math/transformation/vpThetaUVector.cpp +++ b/modules/core/src/math/transformation/vpThetaUVector.cpp @@ -42,43 +42,45 @@ #include BEGIN_VISP_NAMESPACE + const double vpThetaUVector::minimum = 0.0001; +const unsigned int vpThetaUVector::constr_val_3 = 3; /*! Default constructor that initialize all the 3 angles to zero. */ -vpThetaUVector::vpThetaUVector() : vpRotationVector(3) { } +vpThetaUVector::vpThetaUVector() : vpRotationVector(constr_val_3) { } /*! Copy constructor. */ vpThetaUVector::vpThetaUVector(const vpThetaUVector &tu) : vpRotationVector(tu) { } /*! Copy constructor from a 3-dimension vector. */ -vpThetaUVector::vpThetaUVector(const vpColVector &tu) : vpRotationVector(3) { buildFrom(tu); } +vpThetaUVector::vpThetaUVector(const vpColVector &tu) : vpRotationVector(constr_val_3) { buildFrom(tu); } /*! Initialize a \f$\theta {\bf u}\f$ vector from an homogeneous matrix. */ -vpThetaUVector::vpThetaUVector(const vpHomogeneousMatrix &M) : vpRotationVector(3) { buildFrom(M); } +vpThetaUVector::vpThetaUVector(const vpHomogeneousMatrix &M) : vpRotationVector(constr_val_3) { buildFrom(M); } /*! Initialize a \f$\theta {\bf u}\f$ vector from a pose vector. */ -vpThetaUVector::vpThetaUVector(const vpPoseVector &p) : vpRotationVector(3) { buildFrom(p); } +vpThetaUVector::vpThetaUVector(const vpPoseVector &p) : vpRotationVector(constr_val_3) { buildFrom(p); } /*! Initialize a \f$\theta {\bf u}\f$ vector from a rotation matrix. */ -vpThetaUVector::vpThetaUVector(const vpRotationMatrix &R) : vpRotationVector(3) { buildFrom(R); } +vpThetaUVector::vpThetaUVector(const vpRotationMatrix &R) : vpRotationVector(constr_val_3) { buildFrom(R); } /*! Initialize a \f$\theta {\bf u}\f$ vector from an Euler z-y-x representation vector. */ -vpThetaUVector::vpThetaUVector(const vpRzyxVector &rzyx) : vpRotationVector(3) { buildFrom(rzyx); } +vpThetaUVector::vpThetaUVector(const vpRzyxVector &rzyx) : vpRotationVector(constr_val_3) { buildFrom(rzyx); } /*! Initialize a \f$\theta {\bf u}\f$ vector from an Euler z-y-z representation vector. */ -vpThetaUVector::vpThetaUVector(const vpRzyzVector &rzyz) : vpRotationVector(3) { buildFrom(rzyz); } +vpThetaUVector::vpThetaUVector(const vpRzyzVector &rzyz) : vpRotationVector(constr_val_3) { buildFrom(rzyz); } /*! Initialize a \f$\theta {\bf u}\f$ vector from an Euler x-y-z representation vector. */ -vpThetaUVector::vpThetaUVector(const vpRxyzVector &rxyz) : vpRotationVector(3) { buildFrom(rxyz); } +vpThetaUVector::vpThetaUVector(const vpRxyzVector &rxyz) : vpRotationVector(constr_val_3) { buildFrom(rxyz); } /*! Initialize a \f$\theta {\bf u}\f$ vector from a quaternion representation vector. */ -vpThetaUVector::vpThetaUVector(const vpQuaternionVector &q) : vpRotationVector(3) { buildFrom(q); } +vpThetaUVector::vpThetaUVector(const vpQuaternionVector &q) : vpRotationVector(constr_val_3) { buildFrom(q); } /*! Build a \f$\theta {\bf u}\f$ vector from 3 angles in radians. @@ -100,12 +102,12 @@ vpThetaUVector::vpThetaUVector(const vpQuaternionVector &q) : vpRotationVector(3 tu: 0 1.570796327 3.141592654 \endcode */ -vpThetaUVector::vpThetaUVector(double tux, double tuy, double tuz) : vpRotationVector(3) { buildFrom(tux, tuy, tuz); } +vpThetaUVector::vpThetaUVector(double tux, double tuy, double tuz) : vpRotationVector(constr_val_3) { buildFrom(tux, tuy, tuz); } /*! Build a \f$\theta {\bf u}\f$ vector from a vector of 3 angles in radian. */ -vpThetaUVector::vpThetaUVector(const std::vector &tu) : vpRotationVector(3) { buildFrom(tu); } +vpThetaUVector::vpThetaUVector(const std::vector &tu) : vpRotationVector(constr_val_3) { buildFrom(tu); } /*! Converts an homogeneous matrix into a \f$\theta {\bf u}\f$ vector. @@ -126,8 +128,9 @@ vpThetaUVector &vpThetaUVector::buildFrom(const vpHomogeneousMatrix &M) vpThetaUVector &vpThetaUVector::buildFrom(const vpPoseVector &p) { const unsigned int val_3 = 3; + const unsigned int index_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { - data[i] = p[i + 3]; + data[i] = p[i + index_3]; } return *this; @@ -154,9 +157,9 @@ vpThetaUVector &vpThetaUVector::buildFrom(const vpRotationMatrix &R) { double sinc = vpMath::sinc(s, theta); - data[index_0] = (R[index_2][index_1] - R[index_1][index_2]) / (2 * sinc); - data[index_1] = (R[index_0][index_2] - R[index_2][index_0]) / (2 * sinc); - data[index_2] = (R[index_1][index_0] - R[index_0][index_1]) / (2 * sinc); + data[index_0] = (R[index_2][index_1] - R[index_1][index_2]) / (2.0 * sinc); + data[index_1] = (R[index_0][index_2] - R[index_2][index_0]) / (2.0 * sinc); + data[index_2] = (R[index_1][index_0] - R[index_0][index_1]) / (2.0 * sinc); } else /* theta near PI */ { @@ -262,11 +265,11 @@ vpThetaUVector &vpThetaUVector::buildFrom(const vpQuaternionVector &q) */ vpThetaUVector &vpThetaUVector::buildFrom(const std::vector &tu) { - if (tu.size() != 3) { + const unsigned int val_3 = 3; + if (tu.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a theta-u vector from a %d-dimension std::vector", tu.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = tu[i]; } @@ -279,11 +282,11 @@ vpThetaUVector &vpThetaUVector::buildFrom(const std::vector &tu) */ vpThetaUVector &vpThetaUVector::buildFrom(const vpColVector &tu) { - if (tu.size() != 3) { + const unsigned int val_3 = 3; + if (tu.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a theta-u vector from a %d-dimension std::vector", tu.size())); } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { data[i] = tu[i]; } @@ -413,7 +416,8 @@ vpThetaUVector &vpThetaUVector::operator=(const vpColVector &tu) */ void vpThetaUVector::extract(double &theta, vpColVector &u) const { - u.resize(3); + const unsigned int val_3 = 3; + u.resize(val_3); theta = getTheta(); // --comment: if theta equals 0 @@ -421,7 +425,6 @@ void vpThetaUVector::extract(double &theta, vpColVector &u) const u = 0; return; } - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { u[i] = data[i] / theta; } @@ -521,7 +524,7 @@ vpThetaUVector vpThetaUVector::operator*(const vpThetaUVector &tu_b) const double c = 2 * std::acos((std::cos(a_2) * std::cos(b_2)) - (vpColVector::dotProd(a_hat_sin_2, b_hat_sin_2))); vpColVector d = ((std::sin(a_2) * std::cos(b_2) * a_hat) + (std::cos(a_2) * std::sin(b_2) * b_hat)) + (std::sin(a_2) * std::sin(b_2) * vpColVector::crossProd(a_hat, b_hat)); - d = (c * d) / std::sin(c / 2); + d = (c * d) / std::sin(c / 2.0); return vpThetaUVector(d); } diff --git a/modules/core/src/math/transformation/vpTranslationVector.cpp b/modules/core/src/math/transformation/vpTranslationVector.cpp index ab41fde0d5..620fa91287 100644 --- a/modules/core/src/math/transformation/vpTranslationVector.cpp +++ b/modules/core/src/math/transformation/vpTranslationVector.cpp @@ -42,6 +42,7 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpTranslationVector::constr_val_3 = 3; /*! Construct a translation vector \f$ \bf t \f$ from 3 doubles. @@ -49,7 +50,7 @@ BEGIN_VISP_NAMESPACE in meters. */ -vpTranslationVector::vpTranslationVector(double tx, double ty, double tz) : vpArray2D(3, 1), m_index(0) +vpTranslationVector::vpTranslationVector(double tx, double ty, double tz) : vpArray2D(constr_val_3, 1), m_index(0) { const unsigned int index_0 = 0; const unsigned int index_1 = 1; @@ -66,7 +67,7 @@ vpTranslationVector::vpTranslationVector(double tx, double ty, double tz) : vpAr \param M : Homogeneous matrix where translations are in meters. */ -vpTranslationVector::vpTranslationVector(const vpHomogeneousMatrix &M) : vpArray2D(3, 1), m_index(0) +vpTranslationVector::vpTranslationVector(const vpHomogeneousMatrix &M) : vpArray2D(constr_val_3, 1), m_index(0) { M.extract(*this); } @@ -78,7 +79,7 @@ vpTranslationVector::vpTranslationVector(const vpHomogeneousMatrix &M) : vpArray \param p : Pose vector where translations are in meters. */ -vpTranslationVector::vpTranslationVector(const vpPoseVector &p) : vpArray2D(3, 1), m_index(0) +vpTranslationVector::vpTranslationVector(const vpPoseVector &p) : vpArray2D(constr_val_3, 1), m_index(0) { const unsigned int index_0 = 0; const unsigned int index_1 = 1; @@ -116,7 +117,8 @@ vpTranslationVector::vpTranslationVector(const vpTranslationVector &tv) : vpArra */ vpTranslationVector::vpTranslationVector(const vpColVector &v) : vpArray2D(v), m_index(0) { - if (v.size() != 3) { + const unsigned int val_3 = 3; + if (v.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot construct a translation vector from a " "%d-dimension column vector", @@ -269,13 +271,13 @@ vpTranslationVector vpTranslationVector::operator+(const vpTranslationVector &tv */ vpTranslationVector vpTranslationVector::operator+(const vpColVector &v) const { - if (v.size() != 3) { + const unsigned int val_3 = 3; + if (v.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot add translation vector to a %d-dimension column vector", v.size())); } vpTranslationVector s; - const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { s[i] = (*this)[i] + v[i]; } @@ -459,7 +461,8 @@ vpTranslationVector vpTranslationVector::operator/(double x) const */ vpTranslationVector &vpTranslationVector::operator=(const vpColVector &tv) { - if (tv.size() != 3) { + const unsigned int val_3 = 3; + if (tv.size() != val_3) { throw(vpException(vpException::dimensionError, "Cannot initialize a translation vector from a " "%d-dimension col vector", @@ -524,7 +527,8 @@ vpTranslationVector &vpTranslationVector::operator=(double x) { double *d = data; - for (int i = 0; i < 3; ++i) { + const int val_3 = 3; + for (int i = 0; i < val_3; ++i) { *(d++) = x; } @@ -662,7 +666,8 @@ void vpTranslationVector::skew(const vpTranslationVector &tv, vpMatrix &M) const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; - M.resize(3, 3); + const unsigned int val_3 = 3; + M.resize(val_3, val_3); M[index_0][index_0] = 0; M[index_0][index_1] = -tv[index_2]; M[index_0][index_2] = tv[index_1]; diff --git a/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp b/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp index 2dcf398bfa..1281262390 100644 --- a/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp +++ b/modules/core/src/math/transformation/vpVelocityTwistMatrix.cpp @@ -29,8 +29,7 @@ * * Description: * Velocity twist transformation matrix. - * -*****************************************************************************/ + */ /*! \file vpVelocityTwistMatrix.cpp @@ -47,6 +46,7 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpVelocityTwistMatrix::constr_val_6 = 6; /*! Copy operator that allow to set a velocity twist matrix from an other one. @@ -54,8 +54,10 @@ BEGIN_VISP_NAMESPACE */ vpVelocityTwistMatrix &vpVelocityTwistMatrix::operator=(const vpVelocityTwistMatrix &V) { - for (int i = 0; i < 6; ++i) { - for (int j = 0; j < 6; ++j) { + // why not unsigned int + const int val_6 = 6; + for (int i = 0; i < val_6; ++i) { + for (int j = 0; j < val_6; ++j) { rowPtrs[i][j] = V.rowPtrs[i][j]; } } @@ -84,7 +86,7 @@ void vpVelocityTwistMatrix::eye() /*! Initialize a velocity twist transformation matrix as identity. */ -vpVelocityTwistMatrix::vpVelocityTwistMatrix() : vpArray2D(6, 6) { eye(); } +vpVelocityTwistMatrix::vpVelocityTwistMatrix() : vpArray2D(constr_val_6, constr_val_6) { eye(); } /*! Initialize a velocity twist transformation matrix from another velocity @@ -92,7 +94,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix() : vpArray2D(6, 6) { eye() \param V : Velocity twist matrix used as initializer. */ -vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpVelocityTwistMatrix &V) : vpArray2D(6, 6) { *this = V; } +vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpVelocityTwistMatrix &V) : vpArray2D(constr_val_6, constr_val_6) { *this = V; } /*! @@ -112,7 +114,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpVelocityTwistMatrix &V) : v {\bf 0}_{3\times 3} & {\bf R} \end{array} \right] \f] */ -vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpHomogeneousMatrix &M, bool full) : vpArray2D(6, 6) +vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpHomogeneousMatrix &M, bool full) : vpArray2D(constr_val_6, constr_val_6) { if (full) { buildFrom(M); @@ -137,7 +139,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpHomogeneousMatrix &M, bool */ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpTranslationVector &t, const vpThetaUVector &thetau) - : vpArray2D(6, 6) + : vpArray2D(constr_val_6, constr_val_6) { buildFrom(t, thetau); } @@ -154,7 +156,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpTranslationVector &t, const vector \f$R\f$ . */ -vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpThetaUVector &thetau) : vpArray2D(6, 6) +vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpThetaUVector &thetau) : vpArray2D(constr_val_6, constr_val_6) { buildFrom(thetau); } @@ -173,7 +175,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpThetaUVector &thetau) : vpA */ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpTranslationVector &t, const vpRotationMatrix &R) - : vpArray2D(6, 6) + : vpArray2D(constr_val_6, constr_val_6) { buildFrom(t, R); } @@ -189,7 +191,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpTranslationVector &t, const \param R : Rotation matrix. */ -vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpRotationMatrix &R) : vpArray2D(6, 6) { buildFrom(R); } +vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpRotationMatrix &R) : vpArray2D(constr_val_6, constr_val_6) { buildFrom(R); } /*! @@ -207,7 +209,7 @@ vpVelocityTwistMatrix::vpVelocityTwistMatrix(const vpRotationMatrix &R) : vpArra radians used to initialize \f$R\f$. */ vpVelocityTwistMatrix::vpVelocityTwistMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz) - : vpArray2D(6, 6) + : vpArray2D(constr_val_6, constr_val_6) { vpTranslationVector t(tx, ty, tz); vpThetaUVector tu(tux, tuy, tuz); @@ -348,12 +350,13 @@ vpColVector vpVelocityTwistMatrix::operator*(const vpColVector &v) const */ vpVelocityTwistMatrix &vpVelocityTwistMatrix::buildFrom(const vpRotationMatrix &R) { + const unsigned int index_3 = 3; const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { for (unsigned int j = 0; j < val_3; ++j) { (*this)[i][j] = R[i][j]; - (*this)[i + 3][j + 3] = R[i][j]; - (*this)[i][j + 3] = 0; + (*this)[i + index_3][j + index_3] = R[i][j]; + (*this)[i][j + index_3] = 0; } } return *this; @@ -377,12 +380,13 @@ vpVelocityTwistMatrix &vpVelocityTwistMatrix::buildFrom(const vpTranslationVecto { vpMatrix skewaR = t.skew(t) * R; + const unsigned int index_3 = 3; const unsigned int val_3 = 3; for (unsigned int i = 0; i < val_3; ++i) { for (unsigned int j = 0; j < val_3; ++j) { (*this)[i][j] = R[i][j]; - (*this)[i + 3][j + 3] = R[i][j]; - (*this)[i][j + 3] = skewaR[i][j]; + (*this)[i + index_3][j + index_3] = R[i][j]; + (*this)[i][j + index_3] = skewaR[i][j]; } } diff --git a/modules/core/src/tools/geometry/vpPlane.cpp b/modules/core/src/tools/geometry/vpPlane.cpp index 71d177b1cd..cf199673be 100644 --- a/modules/core/src/tools/geometry/vpPlane.cpp +++ b/modules/core/src/tools/geometry/vpPlane.cpp @@ -257,7 +257,8 @@ double vpPlane::computeZ(double x, double y) const */ vpColVector vpPlane::getNormal() const { - vpColVector n(3); + const unsigned int val_3 = 3; + vpColVector n(val_3); const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; @@ -280,7 +281,8 @@ vpColVector vpPlane::getNormal() const */ void vpPlane::getNormal(vpColVector &n) const { - n.resize(3); + const unsigned int val_3 = 3; + n.resize(val_3); const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; diff --git a/modules/core/src/tools/geometry/vpPolygon.cpp b/modules/core/src/tools/geometry/vpPolygon.cpp index 9aec00c9a5..2d8ecb9d96 100644 --- a/modules/core/src/tools/geometry/vpPolygon.cpp +++ b/modules/core/src/tools/geometry/vpPolygon.cpp @@ -126,7 +126,8 @@ vpPolygon::vpPolygon() vpPolygon::vpPolygon(const std::vector &corners) : _corners(), _center(), _area(0.), _goodPoly(true), _bbox(), m_PnPolyConstants(), m_PnPolyMultiples() { - if (corners.size() < 3) { + const unsigned int val_3 = 3; + if (corners.size() < val_3) { _goodPoly = false; } init(corners); @@ -143,7 +144,8 @@ vpPolygon::vpPolygon(const std::vector &corners) vpPolygon::vpPolygon(const std::list &corners) : _corners(), _center(), _area(0.), _goodPoly(true), _bbox(), m_PnPolyConstants(), m_PnPolyMultiples() { - if (corners.size() < 3) { + const unsigned int val_3 = 3; + if (corners.size() < val_3) { _goodPoly = false; } init(corners); @@ -399,7 +401,9 @@ bool vpPolygon::testIntersectionSegments(const vpImagePoint &ip1, const vpImageP */ bool vpPolygon::isInside(const vpImagePoint &ip, const PointInPolygonMethod &method) const { - if (_corners.size() < 3) { + const int val_1000 = 1000; + const unsigned int val_3 = 3; + if (_corners.size() < val_3) { return false; } @@ -411,8 +415,8 @@ bool vpPolygon::isInside(const vpImagePoint &ip, const PointInPolygonMethod &met // we add random since it appears that sometimes infPoint may cause a degenerated case (so relaunch and // hope that result will be different). vpUniRand generator; - infPoint.set_i(infPoint.get_i() + (1000 * generator())); - infPoint.set_j(infPoint.get_j() + (1000 * generator())); + infPoint.set_i(infPoint.get_i() + (val_1000 * generator())); + infPoint.set_j(infPoint.get_j() + (val_1000 * generator())); bool oddNbIntersections = false; size_t v_corners_size = _corners.size(); @@ -452,7 +456,7 @@ bool vpPolygon::isInside(const vpImagePoint &ip, const PointInPolygonMethod &met for (size_t i = 0; i < v_corners_size; ++i) { if (((_corners[i].get_v() < ip.get_v()) && (_corners[j].get_v() >= ip.get_v())) || ((_corners[j].get_v() < ip.get_v()) && (_corners[i].get_v() >= ip.get_v()))) { - oddNodes ^= (ip.get_v() * m_PnPolyMultiples[i] + m_PnPolyConstants[i] < ip.get_u()); + oddNodes ^= ( ((ip.get_v() * m_PnPolyMultiples[i]) + m_PnPolyConstants[i]) < ip.get_u()); } j = i; @@ -468,7 +472,8 @@ bool vpPolygon::isInside(const vpImagePoint &ip, const PointInPolygonMethod &met void vpPolygon::precalcValuesPnPoly() { - if (_corners.size() < 3) { + const std::size_t val_3 = 3; + if (_corners.size() < val_3) { return; } @@ -517,7 +522,8 @@ void vpPolygon::updateArea() _area += (_corners[i].get_j() * _corners[i_p_1].get_i()) - (_corners[i_p_1].get_j() * _corners[i].get_i()); } - _area /= 2; + const int val_2 = 2; + _area /= val_2; if (_area < 0) { _area = -_area; } @@ -554,9 +560,10 @@ void vpPolygon::updateCenter() ((_corners[i_p_1].get_i() * _corners[i].get_j()) - (_corners[i_p_1].get_j() * _corners[i].get_i())); } + const int val_6 = 6; if (_area > 0) { - _center.set_i(fabs(i_tmp / (6 * _area))); - _center.set_j(fabs(j_tmp / (6 * _area))); + _center.set_i(fabs(i_tmp / (val_6 * _area))); + _center.set_j(fabs(j_tmp / (val_6 * _area))); } else { _center = _corners[0]; diff --git a/modules/core/src/tools/geometry/vpRectOriented.cpp b/modules/core/src/tools/geometry/vpRectOriented.cpp index c7e0ebe906..e8a90620ce 100644 --- a/modules/core/src/tools/geometry/vpRectOriented.cpp +++ b/modules/core/src/tools/geometry/vpRectOriented.cpp @@ -186,16 +186,17 @@ vpImagePoint vpRectOriented::getBottomRight() const { return m_bottomRight; } /// Set the size of the rectangle : performs a homothety relatively to the rectangle center. void vpRectOriented::setSize(double width, double height) { + const int val_2 = 2; m_width = width; m_height = height; - m_topLeft.set_i(m_center.get_i() - ((m_height * cos(m_theta)) / 2.0) - ((m_width * sin(m_theta)) / 2)); - m_topLeft.set_j((m_center.get_j() + ((m_height * sin(m_theta)) / 2.0)) - ((m_width * cos(m_theta)) / 2)); - m_bottomLeft.set_i((m_center.get_i() + ((m_height * cos(m_theta)) / 2.0)) - ((m_width * sin(m_theta)) / 2)); - m_bottomLeft.set_j(m_center.get_j() - ((m_height * sin(m_theta)) / 2.0) - ((m_width * cos(m_theta)) / 2)); - m_bottomRight.set_i(m_center.get_i() + ((m_height * cos(m_theta)) / 2.0) + ((m_width * sin(m_theta)) / 2)); - m_bottomRight.set_j((m_center.get_j() - ((m_height * sin(m_theta)) / 2.0)) + ((m_width * cos(m_theta)) / 2)); - m_topRight.set_i((m_center.get_i() - ((m_height * cos(m_theta)) / 2.0)) + ((m_width * sin(m_theta)) / 2)); - m_topRight.set_j(m_center.get_j() + ((m_height * sin(m_theta)) / 2.0) + ((m_width * cos(m_theta)) / 2)); + m_topLeft.set_i(m_center.get_i() - ((m_height * cos(m_theta)) / 2.0) - ((m_width * sin(m_theta)) / val_2)); + m_topLeft.set_j((m_center.get_j() + ((m_height * sin(m_theta)) / 2.0)) - ((m_width * cos(m_theta)) / val_2)); + m_bottomLeft.set_i((m_center.get_i() + ((m_height * cos(m_theta)) / 2.0)) - ((m_width * sin(m_theta)) / val_2)); + m_bottomLeft.set_j(m_center.get_j() - ((m_height * sin(m_theta)) / 2.0) - ((m_width * cos(m_theta)) / val_2)); + m_bottomRight.set_i(m_center.get_i() + ((m_height * cos(m_theta)) / 2.0) + ((m_width * sin(m_theta)) / val_2)); + m_bottomRight.set_j((m_center.get_j() - ((m_height * sin(m_theta)) / 2.0)) + ((m_width * cos(m_theta)) / val_2)); + m_topRight.set_i((m_center.get_i() - ((m_height * cos(m_theta)) / 2.0)) + ((m_width * sin(m_theta)) / val_2)); + m_topRight.set_j(m_center.get_j() + ((m_height * sin(m_theta)) / 2.0) + ((m_width * cos(m_theta)) / val_2)); } /// Get the rectangle width. @@ -207,15 +208,16 @@ double vpRectOriented::getHeight() const { return m_height; } /// Set the rectangle orientation (rad). void vpRectOriented::setOrientation(double theta) { + const int val_2 = 2; m_theta = theta; - m_topLeft.set_i(m_center.get_i() - ((m_height * cos(m_theta)) / 2.0) - ((m_width * sin(m_theta)) / 2)); - m_topLeft.set_j((m_center.get_j() + ((m_height * sin(m_theta)) / 2.0)) - ((m_width * cos(m_theta)) / 2)); - m_bottomLeft.set_i((m_center.get_i() + ((m_height * cos(m_theta)) / 2.0)) - ((m_width * sin(m_theta)) / 2)); - m_bottomLeft.set_j(m_center.get_j() - ((m_height * sin(m_theta)) / 2.0) - ((m_width * cos(m_theta)) / 2)); - m_bottomRight.set_i(m_center.get_i() + ((m_height * cos(m_theta)) / 2.0) + ((m_width * sin(m_theta)) / 2)); - m_bottomRight.set_j((m_center.get_j() - ((m_height * sin(m_theta)) / 2.0)) + ((m_width * cos(m_theta)) / 2)); - m_topRight.set_i((m_center.get_i() - ((m_height * cos(m_theta)) / 2.0)) + ((m_width * sin(m_theta)) / 2)); - m_topRight.set_j(m_center.get_j() + ((m_height * sin(m_theta)) / 2.0) + ((m_width * cos(m_theta)) / 2)); + m_topLeft.set_i(m_center.get_i() - ((m_height * cos(m_theta)) / 2.0) - ((m_width * sin(m_theta)) / val_2)); + m_topLeft.set_j((m_center.get_j() + ((m_height * sin(m_theta)) / 2.0)) - ((m_width * cos(m_theta)) / val_2)); + m_bottomLeft.set_i((m_center.get_i() + ((m_height * cos(m_theta)) / 2.0)) - ((m_width * sin(m_theta)) / val_2)); + m_bottomLeft.set_j(m_center.get_j() - ((m_height * sin(m_theta)) / 2.0) - ((m_width * cos(m_theta)) / val_2)); + m_bottomRight.set_i(m_center.get_i() + ((m_height * cos(m_theta)) / 2.0) + ((m_width * sin(m_theta)) / val_2)); + m_bottomRight.set_j((m_center.get_j() - ((m_height * sin(m_theta)) / 2.0)) + ((m_width * cos(m_theta)) / val_2)); + m_topRight.set_i((m_center.get_i() - ((m_height * cos(m_theta)) / 2.0)) + ((m_width * sin(m_theta)) / val_2)); + m_topRight.set_j(m_center.get_j() + ((m_height * sin(m_theta)) / 2.0) + ((m_width * cos(m_theta)) / val_2)); } /// Get the rectangle orientation (rad). diff --git a/modules/core/src/tools/histogram/vpHistogram.cpp b/modules/core/src/tools/histogram/vpHistogram.cpp index 98afaa87af..46cc2a408d 100644 --- a/modules/core/src/tools/histogram/vpHistogram.cpp +++ b/modules/core/src/tools/histogram/vpHistogram.cpp @@ -47,6 +47,7 @@ #include BEGIN_VISP_NAMESPACE +const unsigned int vpHistogram::constr_val_256 = 256; #if defined(VISP_HAVE_THREADS) #include @@ -192,12 +193,12 @@ bool compare_vpHistogramPeak(vpHistogramPeak first, vpHistogramPeak second) /*! Default constructor for a gray level histogram. */ -vpHistogram::vpHistogram() : m_histogram(nullptr), m_size(256), mp_mask(nullptr), m_total(0) { init(); } +vpHistogram::vpHistogram() : m_histogram(nullptr), m_size(constr_val_256), mp_mask(nullptr), m_total(0) { init(); } /*! Copy constructor of a gray level histogram. */ -vpHistogram::vpHistogram(const vpHistogram &h) : m_histogram(nullptr), m_size(256), mp_mask(h.mp_mask), m_total(h.m_total) +vpHistogram::vpHistogram(const vpHistogram &h) : m_histogram(nullptr), m_size(constr_val_256), mp_mask(h.mp_mask), m_total(h.m_total) { init(h.m_size); memcpy(m_histogram, h.m_histogram, m_size * sizeof(unsigned)); @@ -210,7 +211,7 @@ vpHistogram::vpHistogram(const vpHistogram &h) : m_histogram(nullptr), m_size(25 \sa calculate() */ -vpHistogram::vpHistogram(const vpImage &I) : m_histogram(nullptr), m_size(256), mp_mask(nullptr), m_total(0) +vpHistogram::vpHistogram(const vpImage &I) : m_histogram(nullptr), m_size(constr_val_256), mp_mask(nullptr), m_total(0) { init(); @@ -225,7 +226,7 @@ vpHistogram::vpHistogram(const vpImage &I) : m_histogram(nullptr) and false that it should be ignored. \sa calculate() setMask() */ -vpHistogram::vpHistogram(const vpImage &I, const vpImage *p_mask) : m_histogram(nullptr), m_size(256), mp_mask(nullptr), m_total(0) +vpHistogram::vpHistogram(const vpImage &I, const vpImage *p_mask) : m_histogram(nullptr), m_size(constr_val_256), mp_mask(nullptr), m_total(0) { init(); setMask(p_mask); @@ -298,14 +299,15 @@ void vpHistogram::init(unsigned size_) */ void vpHistogram::calculate(const vpImage &I, unsigned int nbins, unsigned int nbThreads) { + const unsigned int val_256 = 256; if (m_size != nbins) { if (m_histogram != nullptr) { delete[] m_histogram; m_histogram = nullptr; } - m_size = nbins > 256 ? 256 : (nbins > 0 ? nbins : 256); - if ((nbins > 256) || (nbins == 0)) { + m_size = nbins > val_256 ? val_256 : (nbins > 0 ? nbins : val_256); + if ((nbins > val_256) || (nbins == 0)) { std::cerr << "nbins=" << nbins << " , nbins should be between ]0 ; 256] ; use by default nbins=256" << std::endl; } m_histogram = new unsigned int[m_size]; @@ -325,7 +327,7 @@ void vpHistogram::calculate(const vpImage &I, unsigned int nbins, } unsigned int lut[256]; - for (unsigned int i = 0; i < 256; ++i) { + for (unsigned int i = 0; i < val_256; ++i) { lut[i] = static_cast((i * m_size) / 256.0); } @@ -430,7 +432,8 @@ void vpHistogram::equalize(const vpImage &I, vpImage 0)) { @@ -638,6 +641,7 @@ unsigned vpHistogram::getPeaks(unsigned char dist, vpHistogramPeak &peak1, vpHis { std::list peaks; unsigned nbpeaks; // Number of peaks in the histogram (ie local maxima) + const unsigned int val_2 = 2; nbpeaks = getPeaks(peaks); sort(peaks); @@ -663,7 +667,7 @@ unsigned vpHistogram::getPeaks(unsigned char dist, vpHistogramPeak &peak1, vpHis if (abs(p.getLevel() - peak1.getLevel()) > dist) { // The second peak is found peak2 = p; - return 2; + return val_2; } } @@ -978,6 +982,8 @@ bool vpHistogram::getValey(const vpHistogramPeak &peak1, const vpHistogramPeak & unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak, vpHistogramValey &valeyl, vpHistogramValey &valeyr) { + const unsigned int val_ui_0x10 = 0x10; + const unsigned int val_ui_0x11 = 0x11; unsigned int ret = 0x11; unsigned int nbmini; // Minimum numbers unsigned int sumindmini; // Sum @@ -993,7 +999,7 @@ unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak, } if (peak.getLevel() == (m_size - 1)) { valeyr.set(static_cast(m_size - 1), 0); - ret &= 0x10; + ret &= val_ui_0x10; } if (ret >> 1) // consider the left part of the requested peak @@ -1063,7 +1069,7 @@ unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak, else { unsigned int minipos = sumindmini / nbmini; // position of the minimum valeyl.set(static_cast(minipos), m_histogram[minipos]); - ret &= 0x11; + ret &= val_ui_0x11; } } @@ -1121,12 +1127,12 @@ unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak, } if (nbmini == 0) { valeyr.set(static_cast(m_size - 1), 0); - ret &= 0x10; + ret &= val_ui_0x10; } else { unsigned int minipos = sumindmini / nbmini; // position of the minimum valeyr.set(static_cast(minipos), m_histogram[minipos]); - ret &= 0x11; + ret &= val_ui_0x11; } } diff --git a/modules/core/src/tracking/forward-projection/vpCircle.cpp b/modules/core/src/tracking/forward-projection/vpCircle.cpp index f6d47b8253..b8d58ac62e 100644 --- a/modules/core/src/tracking/forward-projection/vpCircle.cpp +++ b/modules/core/src/tracking/forward-projection/vpCircle.cpp @@ -39,10 +39,12 @@ BEGIN_VISP_NAMESPACE void vpCircle::init() { - oP.resize(7); - cP.resize(7); + const unsigned int val_7 = 7; + const unsigned int val_5 = 5; + oP.resize(val_7); + cP.resize(val_7); - p.resize(5); + p.resize(val_5); } /*! @@ -163,8 +165,12 @@ void vpCircle::projection() { projection(cP, p); } */ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const { + const int val_2 = 2; + const int val_4 = 4; + const unsigned int val_6 = 6; + const unsigned int val_5 = 5; double det_threshold = 1e-10; - p_.resize(5, false); + p_.resize(val_5, false); const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; @@ -172,7 +178,7 @@ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const const unsigned int index_4 = 4; const unsigned int index_5 = 5; - vpColVector K(6); + vpColVector K(val_6); { double A = cP_[index_0]; double B = cP_[index_1]; @@ -191,12 +197,12 @@ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const B = B / det; C = C / det; - K[index_0] = (1 - (2 * A * X0)) + (A * A * s); - K[index_1] = (1 - (2 * B * Y0)) + (B * B * s); + K[index_0] = (1 - (val_2 * A * X0)) + (A * A * s); + K[index_1] = (1 - (val_2 * B * Y0)) + (B * B * s); K[index_2] = ((-A * Y0) - (B * X0)) + (A * B * s); K[index_3] = ((-C * X0) - (A * Z0)) + (A * C * s); K[index_4] = ((-C * Y0) - (B * Z0)) + (B * C * s); - K[index_5] = (1 - (2 * C * Z0)) + (C * C * s); + K[index_5] = (1 - (val_2 * C * Z0)) + (C * C * s); } double det = (K[index_2] * K[index_2]) - (K[index_0] * K[index_1]); @@ -224,7 +230,7 @@ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const } } else { - E = ((K[1] - K[0]) + c) / (2 * K[index_2]); + E = ((K[1] - K[0]) + c) / (val_2 * K[index_2]); if (fabs(E) > 1.0) { A = sqrt(s / ((K[0] + K[1]) + c)); B = sqrt(s / ((K[0] + K[1]) - c)); @@ -237,7 +243,7 @@ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const } // Chaumette PhD Thesis 1990, eq 2.72 divided by 4 since n_ij = mu_ij_chaumette_thesis / 4 - det = 4 * (1.0 + vpMath::sqr(E)); + det = val_4 * (1.0 + vpMath::sqr(E)); double n20 = (vpMath::sqr(A) + vpMath::sqr(B * E)) / det; double n11 = ((vpMath::sqr(A) - vpMath::sqr(B)) * E) / det; double n02 = (vpMath::sqr(B) + vpMath::sqr(A * E)) / det; @@ -261,7 +267,8 @@ void vpCircle::projection(const vpColVector &cP_, vpColVector &p_) const */ void vpCircle::changeFrame(const vpHomogeneousMatrix &noMo, vpColVector &noP) const { - noP.resize(7, false); + const unsigned int val_7 = 7; + noP.resize(val_7, false); double A, B, C; const unsigned int index_0 = 0; @@ -276,9 +283,9 @@ void vpCircle::changeFrame(const vpHomogeneousMatrix &noMo, vpColVector &noP) co C = (noMo[index_2][0] * oP[0]) + (noMo[index_2][1] * oP[1]) + (noMo[index_2][index_2] * oP[index_2]); double X0, Y0, Z0; - X0 = noMo[index_0][index_3] + (noMo[index_0][0] * oP[3]) + (noMo[index_0][1] * oP[index_4]) + (noMo[index_0][index_2] * oP[index_5]); - Y0 = noMo[index_1][index_3] + (noMo[index_1][0] * oP[3]) + (noMo[index_1][1] * oP[index_4]) + (noMo[index_1][index_2] * oP[index_5]); - Z0 = noMo[index_2][index_3] + (noMo[index_2][0] * oP[3]) + (noMo[index_2][1] * oP[index_4]) + (noMo[index_2][index_2] * oP[index_5]); + X0 = noMo[index_0][index_3] + (noMo[index_0][0] * oP[index_3]) + (noMo[index_0][1] * oP[index_4]) + (noMo[index_0][index_2] * oP[index_5]); + Y0 = noMo[index_1][index_3] + (noMo[index_1][0] * oP[index_3]) + (noMo[index_1][1] * oP[index_4]) + (noMo[index_1][index_2] * oP[index_5]); + Z0 = noMo[index_2][index_3] + (noMo[index_2][0] * oP[index_3]) + (noMo[index_2][1] * oP[index_4]) + (noMo[index_2][index_2] * oP[index_5]); double R = oP[6]; noP[index_0] = A; diff --git a/modules/core/src/tracking/forward-projection/vpLine.cpp b/modules/core/src/tracking/forward-projection/vpLine.cpp index da7b23826d..11f5c8b4e3 100644 --- a/modules/core/src/tracking/forward-projection/vpLine.cpp +++ b/modules/core/src/tracking/forward-projection/vpLine.cpp @@ -122,7 +122,8 @@ void vpLine::setWorldCoordinates(const double &oA1, const double &oB1, const dou */ void vpLine::setWorldCoordinates(const vpColVector &oP_) { - if (oP_.getRows() != 8) { + const unsigned int val_8 = 8; + if (oP_.getRows() != val_8) { throw vpException(vpException::dimensionError, "Size of oP is not equal to 8 as it should be"); } this->oP = oP_; @@ -151,16 +152,16 @@ void vpLine::setWorldCoordinates(const vpColVector &oP_) */ void vpLine::setWorldCoordinates(const vpColVector &oP1, const vpColVector &oP2) { - if (oP1.getRows() != 4) { + const unsigned int val_4 = 4; + if (oP1.getRows() != val_4) { throw vpException(vpException::dimensionError, "Size of oP1 is not equal to 4 as it should be"); } - if (oP2.getRows() != 4) { + if (oP2.getRows() != val_4) { throw vpException(vpException::dimensionError, "Size of oP2 is not equal to 4 as it should be"); } - const unsigned int val_4 = 4; for (unsigned int i = 0; i < val_4; ++i) { oP[i] = oP1[i]; - oP[i + 4] = oP2[i]; + oP[i + val_4] = oP2[i]; } } @@ -219,10 +220,12 @@ void vpLine::projection() { projection(cP, p); } */ void vpLine::projection(const vpColVector &cP_, vpColVector &p_) const { - p_.resize(2, false); + const unsigned int val_2 = 2; + const unsigned int val_8 = 8; + p_.resize(val_2, false); // projection - if (cP.getRows() != 8) { + if (cP.getRows() != val_8) { throw vpException(vpException::dimensionError, "Size of cP is not equal to 8 as it should be"); } double A1, A2, B1, B2, C1, C2, D1, D2; @@ -344,7 +347,8 @@ void vpLine::changeFrame(const vpHomogeneousMatrix &cMo) { changeFrame(cMo, cP); */ void vpLine::changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP_) const { - cP_.resize(8, false); + const unsigned int val_8 = 8; + cP_.resize(val_8, false); double a1, a2, b1, b2, c1, c2, d1, d2; double A1, A2, B1, B2, C1, C2, D1, D2; @@ -437,10 +441,10 @@ void vpLine::changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP_) const D2 = -D2; } - cP_[4] = A2; - cP_[5] = B2; - cP_[6] = C2; - cP_[7] = D2; + cP_[index_4] = A2; + cP_[index_5] = B2; + cP_[index_6] = C2; + cP_[index_7] = D2; } /*! diff --git a/modules/core/src/tracking/forward-projection/vpPoint.cpp b/modules/core/src/tracking/forward-projection/vpPoint.cpp index 19d62eee9b..cc51a7d105 100644 --- a/modules/core/src/tracking/forward-projection/vpPoint.cpp +++ b/modules/core/src/tracking/forward-projection/vpPoint.cpp @@ -43,15 +43,17 @@ BEGIN_VISP_NAMESPACE void vpPoint::init() { + const unsigned int val_3 = 3; + const unsigned int val_4 = 4; const unsigned int index_2 = 2; const unsigned int index_3 = 3; - p.resize(3); + p.resize(val_3); p = 0; p[index_2] = 1.; - oP.resize(4); + oP.resize(val_4); oP = 0.; oP[index_3] = 1.; - cP.resize(4); + cP.resize(val_4); cP = 0.; cP[index_3] = 1.; @@ -246,10 +248,11 @@ vpColVector vpPoint::getWorldCoordinates(void) { return this->oP; } */ void vpPoint::projection(const vpColVector &v_cP, vpColVector &v_p) const { + const unsigned int val_3 = 3; const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; - v_p.resize(3, false); + v_p.resize(val_3, false); v_p[index_0] = v_cP[index_0] / v_cP[index_2]; v_p[index_1] = v_cP[index_1] / v_cP[index_2]; @@ -266,11 +269,12 @@ void vpPoint::projection(const vpColVector &v_cP, vpColVector &v_p) const */ void vpPoint::changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &v_cP) const { + const unsigned int val_4 = 4; const unsigned int index_0 = 0; const unsigned int index_1 = 1; const unsigned int index_2 = 2; const unsigned int index_3 = 3; - v_cP.resize(4, false); + v_cP.resize(val_4, false); v_cP[index_0] = (cMo[index_0][index_0] * oP[index_0]) + (cMo[index_0][index_1] * oP[index_1]) + (cMo[index_0][index_2] * oP[index_2]) + (cMo[index_0][index_3] * oP[index_3]); v_cP[index_1] = (cMo[index_1][index_0] * oP[index_0]) + (cMo[index_1][index_1] * oP[index_1]) + (cMo[index_1][index_2] * oP[index_2]) + (cMo[index_1][index_3] * oP[index_3]); diff --git a/modules/core/src/tracking/forward-projection/vpSphere.cpp b/modules/core/src/tracking/forward-projection/vpSphere.cpp index 4a1aebd246..68da430f3c 100644 --- a/modules/core/src/tracking/forward-projection/vpSphere.cpp +++ b/modules/core/src/tracking/forward-projection/vpSphere.cpp @@ -41,10 +41,12 @@ BEGIN_VISP_NAMESPACE */ void vpSphere::init() { - oP.resize(4); - cP.resize(4); + const unsigned int val_4 = 4; + const unsigned int val_5 = 5; + oP.resize(val_4); + cP.resize(val_4); - p.resize(5); + p.resize(val_5); } /*! @@ -138,7 +140,8 @@ void vpSphere::projection() { projection(cP, p); } */ void vpSphere::projection(const vpColVector &cP_, vpColVector &p_) const { - p_.resize(5, false); + const unsigned int val_5 = 5; + p_.resize(val_5, false); double x0, y0, z0; double E, A, B; const unsigned int index_0 = 0; @@ -217,7 +220,8 @@ void vpSphere::changeFrame(const vpHomogeneousMatrix &cMo) { changeFrame(cMo, cP */ void vpSphere::changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &cP_) const { - cP_.resize(4, false); + const unsigned int val_4 = 4; + cP_.resize(val_4, false); const unsigned int index_0 = 0; const unsigned int index_1 = 1; From 2d0712215fe38dca27e654e4dc7c4ca6ff47fb75 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 27 Nov 2024 15:50:39 +0100 Subject: [PATCH 4/5] Fix build issue detected by ci and due to previous changes --- .../src/image/private/vpImageConvert_impl.h | 19 ++++++++++--------- modules/core/src/image/vpImageTools.cpp | 3 ++- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/modules/core/src/image/private/vpImageConvert_impl.h b/modules/core/src/image/private/vpImageConvert_impl.h index f5d7a17485..b3fce17d6c 100644 --- a/modules/core/src/image/private/vpImageConvert_impl.h +++ b/modules/core/src/image/private/vpImageConvert_impl.h @@ -93,7 +93,7 @@ BEGIN_VISP_NAMESPACE #endif const unsigned int val_0x10000 = 0x10000; - for (int i = 2; i < val_0x10000; ++i) { + 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()); @@ -151,7 +151,7 @@ void vp_createDepthHistogram(const vpImage &src_depth, vpImage &src_depth, vpImage &d } const unsigned int val_0x10000 = 0x10000; - for (int i = 2; i < val_0x10000; ++i) { + for (unsigned int i = 2; i < val_0x10000; ++i) { histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF] } -#ifdef VISP_HAVE_OPENMP -#pragma omp parallel for -#endif + 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(src_depth.bitmap[i]); if (d) { @@ -247,13 +248,13 @@ void vp_createDepthHistogram(const vpImage &src_depth, vpImage for (unsigned int i = 2; i < val_0x10000; ++i) { histogram[i] += histogram[i - 1]; // Build a cumulative histogram for the indices in [1,0xFFFF] } -#ifdef VISP_HAVE_OPENMP -#pragma omp parallel for -#endif 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) { diff --git a/modules/core/src/image/vpImageTools.cpp b/modules/core/src/image/vpImageTools.cpp index 8056c746cd..9e591d7ac8 100644 --- a/modules/core/src/image/vpImageTools.cpp +++ b/modules/core/src/image/vpImageTools.cpp @@ -1217,10 +1217,11 @@ int vpImageTools::inRange(const unsigned char *hue, const unsigned char *saturat unsigned char v_high = static_cast(hsv_range[index_5]); int size_ = static_cast(size); int cpt_in_range = 0; + + const unsigned char val_uc_255 = 255; #if defined(_OPENMP) #pragma omp parallel for reduction(+:cpt_in_range) #endif - const unsigned char val_uc_255 = 255; for (int i = 0; i < size_; ++i) { bool check_h_low_high_hue = (h_low <= hue[i]) && (hue[i] <= h_high); bool check_s_low_high_saturation = (s_low <= saturation[i]) && (saturation[i] <= s_high); From 2df7042a73bcb0263770e3ccf82fad75f2c4c025 Mon Sep 17 00:00:00 2001 From: Fabien Spindler Date: Wed, 27 Nov 2024 16:13:42 +0100 Subject: [PATCH 5/5] Fix build issue in vpImage::performLut() Issue reported by CI vpImage_lut.h:176:43: error: out-of-line definition of 'performLut' does not match any declaration in 'vpImage' template void vpImage::performLut(const Type(&)[256], unsigned int) --- modules/core/include/visp3/core/vpImage.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/core/include/visp3/core/vpImage.h b/modules/core/include/visp3/core/vpImage.h index 7fb88c3bc4..a43bdada3a 100644 --- a/modules/core/include/visp3/core/vpImage.h +++ b/modules/core/include/visp3/core/vpImage.h @@ -330,8 +330,9 @@ template class vpImage friend std::ostream &operator<<(std::ostream &s, const vpImage &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); + // 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 void quarterSizeImage(vpImage &res) const;