Skip to content

Commit

Permalink
More sonarqube fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Jul 4, 2024
1 parent ba2d618 commit cf32cfd
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 145 deletions.
21 changes: 6 additions & 15 deletions modules/core/include/visp3/core/vpImageTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -1105,17 +1105,14 @@ void vpImageTools::resize(const vpImage<Type> &I, vpImage<Type> &Ires, const vpI
const float scaleY = I.getHeight() / static_cast<float>(Ires.getHeight());
const float scaleX = I.getWidth() / static_cast<float>(Ires.getWidth());
const float half = 0.5f;

const int ires_height = static_cast<int>(Ires.getHeight());
#if defined(_OPENMP)
if (nThreads > 0) {
omp_set_num_threads(static_cast<int>(nThreads));
}
#pragma omp parallel for schedule(dynamic)
#endif
/*
// int ires_height = static_cast<int>(Ires.getHeight());
*/
for (int i = 0; i < static_cast<int>(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;
Expand Down Expand Up @@ -1164,17 +1161,14 @@ inline void vpImageTools::resize(const vpImage<unsigned char> &I, vpImage<unsign
const float scaleY = I.getHeight() / static_cast<float>(Ires.getHeight());
const float scaleX = I.getWidth() / static_cast<float>(Ires.getWidth());
const float half = 0.5f;

const int ires_height = static_cast<int>(Ires.getHeight());
#if defined(_OPENMP)
if (nThreads > 0) {
omp_set_num_threads(static_cast<int>(nThreads));
}
#pragma omp parallel for schedule(dynamic)
#endif
/*
// int ires_height = static_cast<int>(Ires.getHeight());
*/
for (int i = 0; i < static_cast<int>(Ires.getHeight()); ++i) {
for (int i = 0; i < ires_height; ++i) {
float v = ((i + half) * scaleY) - half;
float yFrac = v - static_cast<int>(v);

Expand Down Expand Up @@ -1218,17 +1212,14 @@ inline void vpImageTools::resize(const vpImage<vpRGBa> &I, vpImage<vpRGBa> &Ires
const float scaleY = I.getHeight() / static_cast<float>(Ires.getHeight());
const float scaleX = I.getWidth() / static_cast<float>(Ires.getWidth());
const float half = 0.5f;

const int ires_height = static_cast<int>(Ires.getHeight());
#if defined(_OPENMP)
if (nThreads > 0) {
omp_set_num_threads(static_cast<int>(nThreads));
}
#pragma omp parallel for schedule(dynamic)
#endif
/*
// int ires_height = static_cast<int>(Ires.getHeight());
*/
for (int i = 0; i < static_cast<int>(Ires.getHeight()); ++i) {
for (int i = 0; i < ires_height; ++i) {
float v = (i + half) * scaleY - half;
float yFrac = v - static_cast<int>(v);

Expand Down
5 changes: 4 additions & 1 deletion modules/core/src/camera/vpCameraParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,11 @@ bool vpCameraParameters::operator==(const vpCameraParameters &c) const
}

std::vector<vpColVector>::const_iterator it1 = m_fovNormals.begin();
std::vector<vpColVector>::const_iterator it1_end = m_fovNormals.end();
std::vector<vpColVector>::const_iterator it2 = c.m_fovNormals.begin();
for (; (it1 != m_fovNormals.end()) && (it2 != c.m_fovNormals.end()); ++it1, ++it2) {
std::vector<vpColVector>::const_iterator it2_end = c.m_fovNormals.end();

for (; (it1 != it1_end) && (it2 != it2_end); ++it1, ++it2) {
if (*it1 != *it2) {
return false;
}
Expand Down
1 change: 0 additions & 1 deletion modules/core/src/camera/vpXmlParserCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

//<k1>, <k2>, <k3>, <k4>, <k5>
std::vector<double> distortion_coefs = camera.getKannalaBrandtDistortionCoefficients();

if (distortion_coefs.size() != requiredNbCoeff) {
Expand Down
5 changes: 3 additions & 2 deletions modules/core/src/display/vpDisplay_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,14 @@ void vp_display_display_polygon(const vpImage<Type> &I, const std::vector<vpImag
unsigned int thickness, bool closed = true)
{
if (I.display != nullptr) {
const size_t vip_size = vip.size();
if (closed) {
for (unsigned int i = 0; i < vip.size(); ++i) {
for (unsigned int i = 0; i < vip_size; ++i) {
(I.display)->displayLine(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);
}
}
Expand Down
6 changes: 4 additions & 2 deletions modules/core/src/display/vpDisplay_uchar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,10 @@ void vpDisplay::displayDotLine(const vpImage<unsigned char> &I, const std::list<
}

std::list<vpImagePoint>::const_iterator it = ips.begin();
std::list<vpImagePoint>::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;
Expand Down Expand Up @@ -541,9 +542,10 @@ void vpDisplay::displayLine(const vpImage<unsigned char> &I, const std::list<vpI
}

std::list<vpImagePoint>::const_iterator it = ips.begin();
std::list<vpImagePoint>::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;
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/image/private/vpImageConvert_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void vp_createDepthHistogram(const vpImage<uint16_t> &src_depth, vpImage<unsigne
{
uint32_t histogram[0x10000];
memset(histogram, 0, sizeof(histogram));
int src_depth_size = static_cast<int>(src_depth.getSize());
const int src_depth_size = static_cast<int>(src_depth.getSize());

#if defined(VISP_HAVE_OPENMP) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
int nThreads = omp_get_max_threads();
Expand All @@ -144,7 +144,7 @@ void vp_createDepthHistogram(const vpImage<uint16_t> &src_depth, vpImage<unsigne
}
}
#else
for (int i = 0; i < static_cast<int>(src_depth.getSize()); ++i) {
for (int i = 0; i < src_depth_size; ++i) {
++histogram[static_cast<uint32_t>(src_depth.bitmap[i])];
}
#endif
Expand Down
11 changes: 6 additions & 5 deletions modules/core/src/image/vpImageTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,11 +895,12 @@ void vpImageTools::remap(const vpImage<unsigned char> &I, const vpArray2D<int> &
const vpArray2D<float> &mapDu, const vpArray2D<float> &mapDv, vpImage<unsigned char> &Iundist)
{
Iundist.resize(I.getHeight(), I.getWidth());
const int I_height = static_cast<int>(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<int>(I.getHeight()); ++i_) {
for (int i_ = 0; i_ < I_height; ++i_) {
const unsigned int i = static_cast<unsigned int>(i_);
unsigned int i_width = I.getWidth();
for (unsigned int j = 0; j < i_width; ++j) {
Expand All @@ -911,7 +912,7 @@ void vpImageTools::remap(const vpImage<unsigned char> &I, const vpArray2D<int> &
float dv = mapDv[i][j];

if ((0 <= u_round) && (0 <= v_round) && (u_round < (static_cast<int>(I.getWidth()) - 1)) &&
(v_round < (static_cast<int>(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);
Expand Down Expand Up @@ -940,11 +941,11 @@ void vpImageTools::remap(const vpImage<vpRGBa> &I, const vpArray2D<int> &mapU, c
const vpArray2D<float> &mapDu, const vpArray2D<float> &mapDv, vpImage<vpRGBa> &Iundist)
{
Iundist.resize(I.getHeight(), I.getWidth());

const int I_height = static_cast<int>(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<int>(I.getHeight()); ++i) {
for (int i = 0; i < I_height; ++i) {
#if defined(VISP_HAVE_SIMDLIB)
SimdRemap(reinterpret_cast<unsigned char *>(I.bitmap), 4, I.getWidth(), I.getHeight(), i * I.getWidth(), mapU.data,
mapV.data, mapDu.data, mapDv.data, reinterpret_cast<unsigned char *>(Iundist.bitmap));
Expand All @@ -960,7 +961,7 @@ void vpImageTools::remap(const vpImage<vpRGBa> &I, const vpArray2D<int> &mapU, c
float dv = mapDv[i_][j];

if ((0 <= u_round) && (0 <= v_round) && (u_round < (static_cast<int>(I.getWidth()) - 1))
&& (v_round < (static_cast<int>(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);
Expand Down
6 changes: 4 additions & 2 deletions modules/core/src/math/matrix/vpMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>::epsilon())) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/tools/cpu-features/vpCPUFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
14 changes: 7 additions & 7 deletions modules/core/src/tools/cpu-features/x86/cpu_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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()) {
Expand All @@ -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];
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions modules/core/src/tools/cpu-features/x86/cpu_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ namespace FeatureDetector
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
struct cpu_x86
struct cpuX86
{
// Vendor
// Vendor
bool Vendor_AMD;
bool Vendor_Intel;

Expand Down Expand Up @@ -105,7 +105,7 @@ struct cpu_x86
bool HW_AVX512_VBMI;

public:
cpu_x86();
cpuX86();

void print() const;

Expand Down
32 changes: 20 additions & 12 deletions modules/core/src/tools/cpu-features/x86/cpu_x86_Linux.ipp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* cpu_x86_Linux.ipp
*
*
* Author : Alexander J. Yee
* Date Created : 04/12/2014
* Last Modified : 04/12/2014
*
*
*/

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -13,26 +13,34 @@
// Dependencies
#include <cpuid.h>
#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;
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit cf32cfd

Please sign in to comment.