diff --git a/modules/core/include/visp3/core/vpImageTools.h b/modules/core/include/visp3/core/vpImageTools.h index fa4b5dac55..cbcb9bfc3b 100644 --- a/modules/core/include/visp3/core/vpImageTools.h +++ b/modules/core/include/visp3/core/vpImageTools.h @@ -1105,17 +1105,14 @@ void vpImageTools::resize(const vpImage &I, vpImage &Ires, const vpI const float scaleY = I.getHeight() / static_cast(Ires.getHeight()); const float scaleX = I.getWidth() / static_cast(Ires.getWidth()); const float half = 0.5f; - + const int ires_height = static_cast(Ires.getHeight()); #if defined(_OPENMP) if (nThreads > 0) { omp_set_num_threads(static_cast(nThreads)); } #pragma omp parallel for schedule(dynamic) #endif - /* - // int ires_height = static_cast(Ires.getHeight()); - */ - for (int i = 0; i < static_cast(Ires.getHeight()); ++i) { + for (int i = 0; i < ires_height; ++i) { const float v = ((i + half) * scaleY) - half; const float v0 = std::floor(v); const float yFrac = v - v0; @@ -1164,17 +1161,14 @@ inline void vpImageTools::resize(const vpImage &I, vpImage(Ires.getHeight()); const float scaleX = I.getWidth() / static_cast(Ires.getWidth()); const float half = 0.5f; - + const int ires_height = static_cast(Ires.getHeight()); #if defined(_OPENMP) if (nThreads > 0) { omp_set_num_threads(static_cast(nThreads)); } #pragma omp parallel for schedule(dynamic) #endif - /* - // int ires_height = static_cast(Ires.getHeight()); - */ - for (int i = 0; i < static_cast(Ires.getHeight()); ++i) { + for (int i = 0; i < ires_height; ++i) { float v = ((i + half) * scaleY) - half; float yFrac = v - static_cast(v); @@ -1218,17 +1212,14 @@ inline void vpImageTools::resize(const vpImage &I, vpImage &Ires const float scaleY = I.getHeight() / static_cast(Ires.getHeight()); const float scaleX = I.getWidth() / static_cast(Ires.getWidth()); const float half = 0.5f; - + const int ires_height = static_cast(Ires.getHeight()); #if defined(_OPENMP) if (nThreads > 0) { omp_set_num_threads(static_cast(nThreads)); } #pragma omp parallel for schedule(dynamic) #endif - /* - // int ires_height = static_cast(Ires.getHeight()); - */ - for (int i = 0; i < static_cast(Ires.getHeight()); ++i) { + for (int i = 0; i < ires_height; ++i) { float v = (i + half) * scaleY - half; float yFrac = v - static_cast(v); diff --git a/modules/core/src/camera/vpCameraParameters.cpp b/modules/core/src/camera/vpCameraParameters.cpp index 75f83a825a..f8fdab20d0 100644 --- a/modules/core/src/camera/vpCameraParameters.cpp +++ b/modules/core/src/camera/vpCameraParameters.cpp @@ -497,8 +497,11 @@ bool vpCameraParameters::operator==(const vpCameraParameters &c) const } std::vector::const_iterator it1 = m_fovNormals.begin(); + std::vector::const_iterator it1_end = m_fovNormals.end(); std::vector::const_iterator it2 = c.m_fovNormals.begin(); - for (; (it1 != m_fovNormals.end()) && (it2 != c.m_fovNormals.end()); ++it1, ++it2) { + std::vector::const_iterator it2_end = c.m_fovNormals.end(); + + for (; (it1 != it1_end) && (it2 != it2_end); ++it1, ++it2) { if (*it1 != *it2) { return false; } diff --git a/modules/core/src/camera/vpXmlParserCamera.cpp b/modules/core/src/camera/vpXmlParserCamera.cpp index 094e4cb742..1e1e75cadd 100644 --- a/modules/core/src/camera/vpXmlParserCamera.cpp +++ b/modules/core/src/camera/vpXmlParserCamera.cpp @@ -1138,7 +1138,6 @@ class vpXmlParserCamera::Impl node_tmp = node_model.append_child(LABEL_XML_V0); node_tmp.append_child(pugi::node_pcdata).text() = camera.get_v0(); - //, , , , std::vector distortion_coefs = camera.getKannalaBrandtDistortionCoefficients(); if (distortion_coefs.size() != requiredNbCoeff) { diff --git a/modules/core/src/display/vpDisplay_impl.h b/modules/core/src/display/vpDisplay_impl.h index 6c254a5dcc..3ba46b3fe4 100644 --- a/modules/core/src/display/vpDisplay_impl.h +++ b/modules/core/src/display/vpDisplay_impl.h @@ -450,13 +450,14 @@ void vp_display_display_polygon(const vpImage &I, const std::vectordisplayLine(vip[i], vip[(i + 1) % vip.size()], color, thickness); } } else { - for (unsigned int i = 1; i < vip.size(); ++i) { + for (unsigned int i = 1; i < vip_size; ++i) { (I.display)->displayLine(vip[i - 1], vip[i], color, thickness); } } diff --git a/modules/core/src/display/vpDisplay_uchar.cpp b/modules/core/src/display/vpDisplay_uchar.cpp index 092ecc53b6..ed4deea4bb 100644 --- a/modules/core/src/display/vpDisplay_uchar.cpp +++ b/modules/core/src/display/vpDisplay_uchar.cpp @@ -286,9 +286,10 @@ void vpDisplay::displayDotLine(const vpImage &I, const std::list< } std::list::const_iterator it = ips.begin(); + std::list::const_iterator it_end = ips.end(); vpImagePoint ip_prev = *(++it); - for (; it != ips.end(); ++it) { + for (; it != it_end; ++it) { if (vpImagePoint::distance(ip_prev, *it) > 1) { vp_display_display_dot_line(I, ip_prev, *it, color, thickness); ip_prev = *it; @@ -541,9 +542,10 @@ void vpDisplay::displayLine(const vpImage &I, const std::list::const_iterator it = ips.begin(); + std::list::const_iterator it_end = ips.end(); vpImagePoint ip_prev = *(++it); - for (; it != ips.end(); ++it) { + for (; it != it_end; ++it) { if (vpImagePoint::distance(ip_prev, *it) > 1) { vp_display_display_line(I, ip_prev, *it, color, thickness); ip_prev = *it; diff --git a/modules/core/src/image/private/vpImageConvert_impl.h b/modules/core/src/image/private/vpImageConvert_impl.h index da2188b86a..493fa91074 100644 --- a/modules/core/src/image/private/vpImageConvert_impl.h +++ b/modules/core/src/image/private/vpImageConvert_impl.h @@ -123,7 +123,7 @@ void vp_createDepthHistogram(const vpImage &src_depth, vpImage(src_depth.getSize()); + const int src_depth_size = static_cast(src_depth.getSize()); #if defined(VISP_HAVE_OPENMP) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) int nThreads = omp_get_max_threads(); @@ -144,7 +144,7 @@ void vp_createDepthHistogram(const vpImage &src_depth, vpImage(src_depth.getSize()); ++i) { + for (int i = 0; i < src_depth_size; ++i) { ++histogram[static_cast(src_depth.bitmap[i])]; } #endif diff --git a/modules/core/src/image/vpImageConvert_yuv.cpp b/modules/core/src/image/vpImageConvert_yuv.cpp index cea2ebd02a..3bd4ab23db 100644 --- a/modules/core/src/image/vpImageConvert_yuv.cpp +++ b/modules/core/src/image/vpImageConvert_yuv.cpp @@ -44,14 +44,13 @@ namespace { void vpSAT(int &c) { - if (c & (~255)) { - if (c < 0) { - c = 0; - } - else { - const unsigned int val_255 = 255; - c = val_255; - } + const int val_255 = 255; + if (c < 0) { + c = 0; + } + else if (c > val_255) { + + c = val_255; } } }; diff --git a/modules/core/src/image/vpImageTools.cpp b/modules/core/src/image/vpImageTools.cpp index cb495deea5..ad9886cc0f 100644 --- a/modules/core/src/image/vpImageTools.cpp +++ b/modules/core/src/image/vpImageTools.cpp @@ -895,11 +895,12 @@ void vpImageTools::remap(const vpImage &I, const vpArray2D & const vpArray2D &mapDu, const vpArray2D &mapDv, vpImage &Iundist) { Iundist.resize(I.getHeight(), I.getWidth()); + const int I_height = static_cast(I.getHeight()); #if defined(_OPENMP) // only to disable warning: ignoring #pragma omp parallel [-Wunknown-pragmas] #pragma omp parallel for schedule(dynamic) #endif - for (int i_ = 0; i_ < static_cast(I.getHeight()); ++i_) { + for (int i_ = 0; i_ < I_height; ++i_) { const unsigned int i = static_cast(i_); unsigned int i_width = I.getWidth(); for (unsigned int j = 0; j < i_width; ++j) { @@ -911,7 +912,7 @@ void vpImageTools::remap(const vpImage &I, const vpArray2D & float dv = mapDv[i][j]; if ((0 <= u_round) && (0 <= v_round) && (u_round < (static_cast(I.getWidth()) - 1)) && - (v_round < (static_cast(I.getHeight()) - 1))) { + (v_round < (I_height - 1))) { // process interpolation float col0 = lerp(I[v_round][u_round], I[v_round][u_round + 1], du); float col1 = lerp(I[v_round + 1][u_round], I[v_round + 1][u_round + 1], du); @@ -940,11 +941,11 @@ void vpImageTools::remap(const vpImage &I, const vpArray2D &mapU, c const vpArray2D &mapDu, const vpArray2D &mapDv, vpImage &Iundist) { Iundist.resize(I.getHeight(), I.getWidth()); - + const int I_height = static_cast(I.getHeight()); #if defined(_OPENMP) // only to disable warning: ignoring #pragma omp parallel [-Wunknown-pragmas] #pragma omp parallel for schedule(dynamic) #endif - for (int i = 0; i < static_cast(I.getHeight()); ++i) { + for (int i = 0; i < I_height; ++i) { #if defined(VISP_HAVE_SIMDLIB) SimdRemap(reinterpret_cast(I.bitmap), 4, I.getWidth(), I.getHeight(), i * I.getWidth(), mapU.data, mapV.data, mapDu.data, mapDv.data, reinterpret_cast(Iundist.bitmap)); @@ -960,7 +961,7 @@ void vpImageTools::remap(const vpImage &I, const vpArray2D &mapU, c float dv = mapDv[i_][j]; if ((0 <= u_round) && (0 <= v_round) && (u_round < (static_cast(I.getWidth()) - 1)) - && (v_round < (static_cast(I.getHeight()) - 1))) { + && (v_round < (I_height - 1))) { // process interpolation float col0 = lerp(I[v_round][u_round].R, I[v_round][u_round + 1].R, du); float col1 = lerp(I[v_round + 1][u_round].R, I[v_round + 1][u_round + 1].R, du); diff --git a/modules/core/src/math/matrix/vpMatrix.cpp b/modules/core/src/math/matrix/vpMatrix.cpp index a69882ce28..5111e52303 100644 --- a/modules/core/src/math/matrix/vpMatrix.cpp +++ b/modules/core/src/math/matrix/vpMatrix.cpp @@ -1455,7 +1455,8 @@ unsigned int vpMatrix::kernel(vpMatrix &kerAt, double svThreshold) const kerAt.resize(nbcol - rank, nbcol); if (rank != nbcol) { - for (unsigned int j = 0, k = 0; j < nbcol; ++j) { + unsigned int k = 0; + for (unsigned int j = 0; j < nbcol; ++j) { // if( v.col(j) in kernel and non zero ) if ((sv[j] <= (maxsv * svThreshold)) && (std::fabs(V.getCol(j).sumSquare()) > std::numeric_limits::epsilon())) { @@ -1524,7 +1525,8 @@ unsigned int vpMatrix::nullSpace(vpMatrix &kerA, double svThreshold) const kerA.resize(nbcol, nbcol - rank); if (rank != nbcol) { - for (unsigned int j = 0, k = 0; j < nbcol; ++j) { + unsigned int k = 0; + for (unsigned int j = 0; j < nbcol; ++j) { // if( v.col(j) in kernel and non zero ) if (sv[j] <= (maxsv * svThreshold)) { for (unsigned int i = 0; i < nbcol; ++i) { diff --git a/modules/core/src/tools/cpu-features/vpCPUFeatures.cpp b/modules/core/src/tools/cpu-features/vpCPUFeatures.cpp index 1cb6be9e37..eaf1eebe71 100644 --- a/modules/core/src/tools/cpu-features/vpCPUFeatures.cpp +++ b/modules/core/src/tools/cpu-features/vpCPUFeatures.cpp @@ -43,7 +43,7 @@ BEGIN_VISP_NAMESPACE namespace vpCPUFeatures { // TODO: try to refactor to keep only SimdCpuInfo code and remove cpu_x86 code? -static const FeatureDetector::cpu_x86 cpu_features; +static const FeatureDetector::cpuX86 cpu_features; bool checkSSE2() { return cpu_features.HW_SSE2; } diff --git a/modules/core/src/tools/cpu-features/x86/cpu_x86.cpp b/modules/core/src/tools/cpu-features/x86/cpu_x86.cpp index bcdfd083d1..06b80f741b 100644 --- a/modules/core/src/tools/cpu-features/x86/cpu_x86.cpp +++ b/modules/core/src/tools/cpu-features/x86/cpu_x86.cpp @@ -80,7 +80,7 @@ using std::memset; //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -void cpu_x86::print(const char *label, bool yes) +void cpuX86::print(const char *label, bool yes) { cout << label; cout << (yes ? "Yes" : "No") << endl; @@ -89,12 +89,12 @@ void cpu_x86::print(const char *label, bool yes) //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -cpu_x86::cpu_x86() +cpuX86::cpuX86() { memset(this, 0, sizeof(*this)); detect_host(); } -bool cpu_x86::detect_OS_AVX() +bool cpuX86::detect_OS_AVX() { #ifndef UNKNOWN_ARCH // Copied from: http://stackoverflow.com/a/22521619/922184 @@ -120,7 +120,7 @@ bool cpu_x86::detect_OS_AVX() return false; #endif } -bool cpu_x86::detect_OS_AVX512() +bool cpuX86::detect_OS_AVX512() { #ifndef UNKNOWN_ARCH if (!detect_OS_AVX()) { @@ -133,7 +133,7 @@ bool cpu_x86::detect_OS_AVX512() return false; #endif } -std::string cpu_x86::get_vendor_string() +std::string cpuX86::get_vendor_string() { #ifndef UNKNOWN_ARCH uint32_t CPUInfo[4]; @@ -158,7 +158,7 @@ std::string cpu_x86::get_vendor_string() //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -void cpu_x86::detect_host() +void cpuX86::detect_host() { #ifndef UNKNOWN_ARCH // OS Features @@ -256,7 +256,7 @@ void cpu_x86::detect_host() } #endif } -void cpu_x86::print() const +void cpuX86::print() const { cout << "CPU Vendor:" << endl; print(" AMD = ", Vendor_AMD); diff --git a/modules/core/src/tools/cpu-features/x86/cpu_x86.h b/modules/core/src/tools/cpu-features/x86/cpu_x86.h index 2559a9f331..6591fad53b 100644 --- a/modules/core/src/tools/cpu-features/x86/cpu_x86.h +++ b/modules/core/src/tools/cpu-features/x86/cpu_x86.h @@ -53,9 +53,9 @@ namespace FeatureDetector //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -struct cpu_x86 +struct cpuX86 { -// Vendor + // Vendor bool Vendor_AMD; bool Vendor_Intel; @@ -105,7 +105,7 @@ struct cpu_x86 bool HW_AVX512_VBMI; public: - cpu_x86(); + cpuX86(); void print() const; diff --git a/modules/core/src/tools/cpu-features/x86/cpu_x86_Linux.ipp b/modules/core/src/tools/cpu-features/x86/cpu_x86_Linux.ipp index 9272e6e4a8..b91fe507d6 100644 --- a/modules/core/src/tools/cpu-features/x86/cpu_x86_Linux.ipp +++ b/modules/core/src/tools/cpu-features/x86/cpu_x86_Linux.ipp @@ -1,9 +1,9 @@ /* cpu_x86_Linux.ipp - * + * * Author : Alexander J. Yee * Date Created : 04/12/2014 * Last Modified : 04/12/2014 - * + * */ //////////////////////////////////////////////////////////////////////////////// @@ -13,26 +13,34 @@ // Dependencies #include #include "cpu_x86.h" -namespace FeatureDetector{ +namespace FeatureDetector +{ //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// -void cpu_x86::cpuid(uint32_t out[4], uint32_t x){ - __cpuid_count(x, 0, out[0], out[1], out[2], out[3]); +void cpuX86::cpuid(uint32_t out[4], uint32_t x) +{ + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + const unsigned int index_3 = 3; + __cpuid_count(x, 0, out[index_0], out[index_1], out[index_2], out[index_3]); } -uint64_t xgetbv(unsigned int index){ - uint32_t eax, edx; - __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index)); - return ((uint64_t)edx << 32) | eax; +uint64_t xgetbv(unsigned int index) +{ + uint32_t eax, edx; + __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index)); + return ((uint64_t)edx << 32) | eax; } #define _XCR_XFEATURE_ENABLED_MASK 0 //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Detect 64-bit -bool cpu_x86::detect_OS_x64(){ - // We only support x64 on Linux. - return true; +bool cpuX86::detect_OS_x64() +{ +// We only support x64 on Linux. + return true; } //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// diff --git a/modules/core/src/tools/cpu-features/x86/cpu_x86_Windows.ipp b/modules/core/src/tools/cpu-features/x86/cpu_x86_Windows.ipp index b8440eed97..2f2069ec80 100644 --- a/modules/core/src/tools/cpu-features/x86/cpu_x86_Windows.ipp +++ b/modules/core/src/tools/cpu-features/x86/cpu_x86_Windows.ipp @@ -71,13 +71,17 @@ unsigned __int64 _xgetbv(unsigned int index) #if defined(__MINGW32__) void __cpuidex(unsigned int CPUInfo[4], unsigned int function_id, unsigned int subfunction_id) { + const unsigned int index_0 = 0; + const unsigned int index_1 = 1; + const unsigned int index_2 = 2; + const unsigned int index_3 = 3; __asm__ __volatile__( "cpuid" - : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) + : "=a" (CPUInfo[index_0]), "=b" (CPUInfo[index_1]), "=c" (CPUInfo[index_2]), "=d" (CPUInfo[index_3]) : "a" (function_id), "c" (subfunction_id)); } #endif -void cpu_x86::cpuid(uint32_t out[4], uint32_t x) +void cpuX86::cpuid(uint32_t out[4], uint32_t x) { #if defined(__MINGW32__) __cpuidex(out, x, 0U); @@ -119,7 +123,7 @@ BOOL IsWow64() #endif return bIsWow64; } -bool cpu_x86::detect_OS_x64() +bool cpuX86::detect_OS_x64() { #ifdef _M_X64 return true; diff --git a/modules/core/src/tools/file/vpIoTools.cpp b/modules/core/src/tools/file/vpIoTools.cpp index d476228808..39f84cb7f6 100644 --- a/modules/core/src/tools/file/vpIoTools.cpp +++ b/modules/core/src/tools/file/vpIoTools.cpp @@ -489,7 +489,8 @@ int vpIoTools::mkdir_p(const std::string &path, int mode) // Iterate over the string std::string cpy_path = path; std::string sub_path; - for (size_t pos = 0; (pos = cpy_path.find(vpIoTools::separator)) != std::string::npos;) { + size_t pos = 0; + while (pos != std::string::npos) { sub_path += cpy_path.substr(0, pos + 1); // Continue if sub_path = separator bool stop_for_loop = false; @@ -508,10 +509,11 @@ int vpIoTools::mkdir_p(const std::string &path, int mode) if (errno != EEXIST) { return -1; } - } - cpy_path.erase(0, pos + 1); } + cpy_path.erase(0, pos + 1); } + pos = cpy_path.find(vpIoTools::separator); +} if (!cpy_path.empty()) { sub_path += cpy_path; @@ -525,7 +527,7 @@ int vpIoTools::mkdir_p(const std::string &path, int mode) if (errno != EEXIST) { return -1; } - } + } } return 0; @@ -577,7 +579,7 @@ void vpIoTools::makeDirectory(const std::string &dirname) if (vpIoTools::mkdir_p(v_dirname, 0755) != 0) { throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'", dirname.c_str())); } - } +} if (checkDirectory(dirname) == false) { throw(vpIoException(vpIoException::cantCreateDirectory, "Unable to create directory '%s'", dirname.c_str())); @@ -801,7 +803,7 @@ bool vpIoTools::checkFilename(const std::string &filename) #endif { return false; - } +} if ((stbuf.st_mode & S_IFREG) == 0) { return false; } @@ -904,18 +906,18 @@ bool vpIoTools::copy(const std::string &src, const std::string &dst) std::cout << "Cannot copy: " << src << " in " << dst << std::endl; return false; } -} + } -/*! + /*! - Remove a file or a directory. + Remove a file or a directory. - \param file_or_dir : File name or directory to remove. + \param file_or_dir : File name or directory to remove. - \return true if the file or the directory was removed, false otherwise. + \return true if the file or the directory was removed, false otherwise. - \sa makeDirectory(), makeTempDirectory() -*/ + \sa makeDirectory(), makeTempDirectory() + */ bool vpIoTools::remove(const std::string &file_or_dir) { // Check if we have to consider a file or a directory @@ -969,17 +971,17 @@ bool vpIoTools::remove(const std::string &file_or_dir) std::cout << "Cannot remove: " << file_or_dir << std::endl; return false; } -} + } -/*! + /*! - Rename an existing file \e oldfilename in \e newfilename. + Rename an existing file \e oldfilename in \e newfilename. - \param oldfilename : File to rename. - \param newfilename : New file name. + \param oldfilename : File to rename. + \param newfilename : New file name. - \return true if the file was renamed, false otherwise. -*/ + \return true if the file was renamed, false otherwise. + */ bool vpIoTools::rename(const std::string &oldfilename, const std::string &newfilename) { if (::rename(oldfilename.c_str(), newfilename.c_str()) != 0) { @@ -1338,44 +1340,48 @@ std::string vpIoTools::toLowerCase(const std::string &input) { std::string out; #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98 - for (std::string::const_iterator it = input.cbegin(); it != input.cend(); ++it) { + const std::string::const_iterator it_end = input.cend(); + for (std::string::const_iterator it = input.cbegin(); it != it_end; ++it) { #else - for (std::string::const_iterator it = input.begin(); it != input.end(); ++it) { + const std::string::const_iterator it_end = input.end(); + for (std::string::const_iterator it = input.begin(); it != it_end; ++it) { #endif out += std::tolower(*it); } return out; -} + } -/** - * @brief Return a upper-case version of the string \b input . - * Numbers and special characters stay the same - * - * @param input The input string for which we want to ensure that all the characters are in upper case. - * @return std::string A upper-case version of the string \b input, where - * numbers and special characters stay the same - */ + /** + * @brief Return a upper-case version of the string \b input . + * Numbers and special characters stay the same + * + * @param input The input string for which we want to ensure that all the characters are in upper case. + * @return std::string A upper-case version of the string \b input, where + * numbers and special characters stay the same + */ std::string vpIoTools::toUpperCase(const std::string &input) { std::string out; #if VISP_CXX_STANDARD > VISP_CXX_STANDARD_98 - for (std::string::const_iterator it = input.cbegin(); it != input.cend(); ++it) { + const std::string::const_iterator it_end = input.cend(); + for (std::string::const_iterator it = input.cbegin(); it != it_end; ++it) { #else - for (std::string::const_iterator it = input.begin(); it != input.end(); ++it) { + const std::string::const_iterator it_end = input.end(); + for (std::string::const_iterator it = input.begin(); it != it_end; ++it) { #endif out += std::toupper(*it); } return out; -} + } -/*! - Returns the absolute path using realpath() on Unix systems or - GetFullPathName() on Windows systems. \return According to realpath() - manual, returns an absolute pathname that names the same file, whose - resolution does not involve '.', '..', or symbolic links for Unix systems. - According to GetFullPathName() documentation, retrieves the full path of the - specified file for Windows systems. - */ + /*! + Returns the absolute path using realpath() on Unix systems or + GetFullPathName() on Windows systems. \return According to realpath() + manual, returns an absolute pathname that names the same file, whose + resolution does not involve '.', '..', or symbolic links for Unix systems. + According to GetFullPathName() documentation, retrieves the full path of the + specified file for Windows systems. + */ std::string vpIoTools::getAbsolutePathname(const std::string &pathname) { diff --git a/modules/core/src/tools/geometry/vpPolygon.cpp b/modules/core/src/tools/geometry/vpPolygon.cpp index 876a1d2a88..5e10d986ac 100644 --- a/modules/core/src/tools/geometry/vpPolygon.cpp +++ b/modules/core/src/tools/geometry/vpPolygon.cpp @@ -499,7 +499,8 @@ bool vpPolygon::isInside(const vpImagePoint &ip, const PointInPolygonMethod &met // comment: default bool oddNodes = false; size_t v_corners_size = _corners.size(); - for (size_t i = 0, j = (v_corners_size - 1); i < v_corners_size; ++i) { + size_t j = v_corners_size - 1; + 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()); @@ -526,7 +527,8 @@ void vpPolygon::precalcValuesPnPoly() m_PnPolyMultiples.resize(_corners.size()); size_t v_corners_size = _corners.size(); - for (size_t i = 0, j = (v_corners_size - 1); i < v_corners_size; ++i) { + size_t j = v_corners_size - 1; + for (size_t i = 0; i < v_corners_size; ++i) { if (vpMath::equal(_corners[j].get_v(), _corners[i].get_v(), std::numeric_limits::epsilon())) { m_PnPolyConstants[i] = _corners[i].get_u(); m_PnPolyMultiples[i] = 0.0; diff --git a/modules/core/test/image-with-dataset/testIoPGM.cpp b/modules/core/test/image-with-dataset/testIoPGM.cpp index 20ec119e58..4498a69892 100644 --- a/modules/core/test/image-with-dataset/testIoPGM.cpp +++ b/modules/core/test/image-with-dataset/testIoPGM.cpp @@ -268,6 +268,7 @@ int main(int argc, const char **argv) catch (const vpException &e) { std::cout << "Catch an exception due to a non existing file: " << e << std::endl; } + std::cout << "Test succeed" << std::endl; return EXIT_SUCCESS; } catch (const vpException &e) { diff --git a/modules/core/test/image-with-dataset/testIoPPM.cpp b/modules/core/test/image-with-dataset/testIoPPM.cpp index 5c74740336..f8c76ace9f 100644 --- a/modules/core/test/image-with-dataset/testIoPPM.cpp +++ b/modules/core/test/image-with-dataset/testIoPPM.cpp @@ -306,6 +306,7 @@ int main(int argc, const char **argv) catch (const vpException &e) { std::cout << "Catch an exception due to a non existing file: " << e << std::endl; } + std::cout << "Test succeed" << std::endl; return EXIT_SUCCESS; } catch (const vpException &e) { diff --git a/modules/vision/src/pose-estimation/vpPoseRansac.cpp b/modules/vision/src/pose-estimation/vpPoseRansac.cpp index 7a529288cf..9d1e11a157 100644 --- a/modules/vision/src/pose-estimation/vpPoseRansac.cpp +++ b/modules/vision/src/pose-estimation/vpPoseRansac.cpp @@ -191,36 +191,39 @@ bool vpPose::vpRansacFunctor::poseRansacImpl() std::vector usedPt(size, false); vpPose poseMin; - for (unsigned int i = 0; i < nbMinRandom;) { + unsigned int i = 0; + bool stop_loop = false; + while ((i < nbMinRandom) && (stop_loop == false)) { if (static_cast(std::count(usedPt.begin(), usedPt.end(), true)) == usedPt.size()) { - // All points was picked once, break otherwise we stay in an infinite loop - break; + // All points were picked once, break otherwise we stay in an infinite loop + stop_loop = true; } + if (!stop_loop) { + // Pick a point randomly + unsigned int r_ = m_uniRand.uniform(0, size); - // Pick a point randomly - unsigned int r_ = m_uniRand.uniform(0, size); - - while (usedPt[r_]) { - // If already picked, pick another point randomly - r_ = m_uniRand.uniform(0, size); - } - // Mark this point as already picked - usedPt[r_] = true; - vpPoint pt = m_listOfUniquePoints[r_]; - - bool degenerate = false; - if (m_checkDegeneratePoints) { - if (std::find_if(poseMin.listOfPoints.begin(), poseMin.listOfPoints.end(), FindDegeneratePoint(pt)) != - poseMin.listOfPoints.end()) { - degenerate = true; + while (usedPt[r_]) { + // If already picked, pick another point randomly + r_ = m_uniRand.uniform(0, size); + } + // Mark this point as already picked + usedPt[r_] = true; + vpPoint pt = m_listOfUniquePoints[r_]; + + bool degenerate = false; + if (m_checkDegeneratePoints) { + if (std::find_if(poseMin.listOfPoints.begin(), poseMin.listOfPoints.end(), FindDegeneratePoint(pt)) != + poseMin.listOfPoints.end()) { + degenerate = true; + } } - } - if (!degenerate) { - poseMin.addPoint(pt); - cur_randoms.push_back(r_); - // Increment the number of points picked - ++i; + if (!degenerate) { + poseMin.addPoint(pt); + cur_randoms.push_back(r_); + // Increment the number of points picked + ++i; + } } }