Skip to content

Commit

Permalink
Merge pull request #1384 from fspindle/feat_quality_rules
Browse files Browse the repository at this point in the history
Apply Misra c++ quality rules
  • Loading branch information
fspindle authored Apr 19, 2024
2 parents 699e1e6 + 7bceb06 commit 76a2dc2
Show file tree
Hide file tree
Showing 22 changed files with 275 additions and 194 deletions.
6 changes: 4 additions & 2 deletions modules/core/src/display/vpDisplay_rgba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::list<vpImage
std::list<vpImagePoint>::const_iterator it = ips.begin();

vpImagePoint ip_prev = *(++it);
for (; it != ips.end(); ++it) {
std::list<vpImagePoint>::const_iterator ips_end = ips.end();
for (; it != ips_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 @@ -544,7 +545,8 @@ void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::list<vpImagePoi
std::list<vpImagePoint>::const_iterator it = ips.begin();

vpImagePoint ip_prev = *(++it);
for (; it != ips.end(); ++it) {
std::list<vpImagePoint>::const_iterator ips_end = ips.end();
for (; it != ips_end; ++it) {
if (vpImagePoint::distance(ip_prev, *it) > 1) {
vp_display_display_line(I, ip_prev, *it, color, thickness);
ip_prev = *it;
Expand Down
45 changes: 25 additions & 20 deletions modules/core/src/tools/histogram/vpHistogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ void vpHistogram::calculate(const vpImage<unsigned char> &I, unsigned int nbins,
m_total = 0;
while (ptrCurrent != ptrEnd) {
if (*ptrMaskCurrent) {
m_histogram[lut[*ptrCurrent]]++;
++m_histogram[lut[*ptrCurrent]];
++m_total;
}
++ptrCurrent;
Expand Down Expand Up @@ -543,7 +543,7 @@ void vpHistogram::smooth(unsigned int fsize)
// exploitation of the overflow to detect negative value...
if (/*(i + j) >= 0 &&*/ (i + static_cast<unsigned int>(j)) < m_size) {
sum += h.m_histogram[i + static_cast<unsigned int>(j)];
nb++;
++nb;
}
}
m_histogram[i] = sum / nb;
Expand Down Expand Up @@ -588,20 +588,20 @@ unsigned vpHistogram::getPeaks(std::list<vpHistogramPeak> &peaks)

if ((prev_slope > 0) && (next_slope == 0)) {
sum_level += i + 1;
cpt++;
++cpt;
continue;
}

// Peak detection
if ((prev_slope > 0) && (next_slope < 0)) {
sum_level += i;
cpt++;
++cpt;

unsigned int level = sum_level / cpt;
p.set(static_cast<unsigned char>(level), m_histogram[level]);
peaks.push_back(p);

nbpeaks++;
++nbpeaks;
}

prev_slope = next_slope;
Expand All @@ -611,7 +611,7 @@ unsigned vpHistogram::getPeaks(std::list<vpHistogramPeak> &peaks)
if (prev_slope > 0) {
p.set(static_cast<unsigned char>(m_size) - 1u, m_histogram[m_size - 1]);
peaks.push_back(p);
nbpeaks++;
++nbpeaks;
}

return nbpeaks;
Expand Down Expand Up @@ -657,7 +657,8 @@ unsigned vpHistogram::getPeaks(unsigned char dist, vpHistogramPeak &peak1, vpHis
// Parse the peaks list to get the peak with a distance greater
// than dist to the highest
peak1 = peaks.front();
for (std::list<vpHistogramPeak>::const_iterator it = peaks.begin(); it != peaks.end(); ++it) {
std::list<vpHistogramPeak>::const_iterator peaks_end = peaks.end();
for (std::list<vpHistogramPeak>::const_iterator it = peaks.begin(); it != peaks_end; ++it) {
vpHistogramPeak p = *it;
if (abs(p.getLevel() - peak1.getLevel()) > dist) {
// The second peak is found
Expand Down Expand Up @@ -711,8 +712,9 @@ bool vpHistogram::getPeaks(unsigned char dist, vpHistogramPeak &peakl, vpHistogr
prev_slope = 1;
for (unsigned i = 0; i < (m_size - 1); ++i) {
int next_slope = static_cast<int>(m_histogram[i + 1]) - static_cast<int>(m_histogram[i]); // Next histogram inclination
if (next_slope == 0)
if (next_slope == 0) {
continue;
}
// Peak detection
if ((prev_slope > 0) && (next_slope < 0)) {
peak[nbpeaks++] = static_cast<unsigned char>(i);
Expand Down Expand Up @@ -800,7 +802,7 @@ bool vpHistogram::getPeaks(unsigned char dist, vpHistogramPeak &peakl, vpHistogr
}
if (m_histogram[i] == mini) {
sumindmini += i;
nbmini++;
++nbmini;
}
}

Expand Down Expand Up @@ -857,20 +859,20 @@ unsigned vpHistogram::getValey(std::list<vpHistogramValey> &valey)

if ((prev_slope < 0) && (next_slope == 0)) {
sum_level += i + 1;
cpt++;
++cpt;
continue;
}

// Valey detection
if ((prev_slope < 0) && (next_slope > 0)) {
sum_level += i;
cpt++;
++cpt;

unsigned int level = sum_level / cpt;
p.set(static_cast<unsigned char>(level), m_histogram[level]);
valey.push_back(p);

nbvaley++;
++nbvaley;
}

prev_slope = next_slope;
Expand All @@ -880,7 +882,7 @@ unsigned vpHistogram::getValey(std::list<vpHistogramValey> &valey)
if (prev_slope < 0) {
p.set(static_cast<unsigned char>(m_size) - 1u, m_histogram[m_size - 1]);
valey.push_back(p);
nbvaley++;
++nbvaley;
}

return nbvaley;
Expand Down Expand Up @@ -932,7 +934,7 @@ bool vpHistogram::getValey(const vpHistogramPeak &peak1, const vpHistogramPeak &
}
if (m_histogram[i] == mini) {
sumindmini += i;
nbmini++;
++nbmini;
}
}

Expand Down Expand Up @@ -998,12 +1000,13 @@ unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak,
// Go to the requested peak in the list
std::list<vpHistogramPeak>::const_iterator it;
unsigned index = 0;
for (it = peaks.begin(); it != peaks.end(); ++it) {
std::list<vpHistogramPeak>::const_iterator peaks_end = peaks.end();
for (it = peaks.begin(); it != peaks_end; ++it) {
if (peak == *it) {
// we are on the peak.
break;
}
index++;
++index;
}

bool found = false;
Expand Down Expand Up @@ -1042,7 +1045,7 @@ unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak,
}
if (m_histogram[i] == mini) {
sumindmini += i;
nbmini++;
++nbmini;
}
}
if (nbmini == 0) {
Expand All @@ -1063,7 +1066,8 @@ unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak,
}
// Go to the requested peak in the list
std::list<vpHistogramPeak>::const_iterator it;
for (it = peaks.begin(); it != peaks.end(); ++it) {
std::list<vpHistogramPeak>::const_iterator peaks_end = peaks.end();
for (it = peaks.begin(); it != peaks_end; ++it) {
if (peak == *it) {
// we are on the peak.
break;
Expand All @@ -1073,7 +1077,8 @@ unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak,
bool found = false;
// search for the nearest peak on the right that matches the distance
std::list<vpHistogramPeak>::const_iterator rit; // right iterator
for (rit = it; rit != peaks.end(); ++rit) {
std::list<vpHistogramPeak>::const_iterator peaks_end_s = peaks.end();
for (rit = it; rit != peaks_end_s; ++rit) {

if (abs((*rit).getLevel() - peak.getLevel()) > dist) {
// peakr found
Expand Down Expand Up @@ -1101,7 +1106,7 @@ unsigned vpHistogram::getValey(unsigned char dist, const vpHistogramPeak &peak,
}
if (m_histogram[i] == mini) {
sumindmini += i;
nbmini++;
++nbmini;
}
}
if (nbmini == 0) {
Expand Down
12 changes: 6 additions & 6 deletions modules/core/src/tracking/forward-projection/vpCircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,14 @@ void vpCircle::computeIntersectionPoint(const vpCircle &circle, const vpCameraPa
double ctheta2 = vpMath::sqr(ctheta);
double m02xg = n02 * Xg;
double m11stheta = n11 * stheta;
j = ((((((n11 * Xg * sctheta) - (n20 * Yg * sctheta)) + (n20 * rho * ctheta)) - m11yg) + (m11yg * ctheta2) + m02xg -
(m02xg * ctheta2) + (m11stheta * rho)) /
((((n20 * ctheta2) + (2.0 * m11stheta * ctheta) + n02)) - (n02 * ctheta2)));
j = ((((((((n11 * Xg * sctheta) - (n20 * Yg * sctheta)) + (n20 * rho * ctheta)) - m11yg) + (m11yg * ctheta2) + m02xg) -
(m02xg * ctheta2)) + (m11stheta * rho)) /
(((n20 * ctheta2) + (2.0 * m11stheta * ctheta) + n02) - (n02 * ctheta2)));
// Optimised calculation for Y
double rhom02 = rho * n02;
double sctheta2 = stheta * ctheta2;
double ctheta3 = ctheta2 * ctheta;
i = (-((-rho * n11 * stheta * ctheta) - rhom02 + (rhom02 * ctheta2) + (n11 * Xg * sctheta2) - (n20 * Yg * sctheta2) -
(ctheta * n11 * Yg) + (ctheta3 * n11 * Yg) + (ctheta * n02 * Xg) - (ctheta3 * n02 * Xg)) /
((n20 * ctheta2) + (2.0 * n11 * stheta * ctheta) + n02 - (n02 * ctheta2)) / stheta);
i = (-(((((((-rho * n11 * stheta * ctheta) - rhom02) + (rhom02 * ctheta2) + (n11 * Xg * sctheta2)) - (n20 * Yg * sctheta2)) -
(ctheta * n11 * Yg)) + (ctheta3 * n11 * Yg) + (ctheta * n02 * Xg)) - (ctheta3 * n02 * Xg)) /
(((n20 * ctheta2) + (2.0 * n11 * stheta * ctheta) + n02) - (n02 * ctheta2)) / stheta);
}
Loading

0 comments on commit 76a2dc2

Please sign in to comment.