Skip to content

Commit

Permalink
Merge pull request #1378 from fspindle/fix_quality_rules
Browse files Browse the repository at this point in the history
New fixes to match Misra c++ quality rules
  • Loading branch information
fspindle authored Apr 16, 2024
2 parents 534356c + 2770f9d commit ba5cc31
Show file tree
Hide file tree
Showing 54 changed files with 1,112 additions and 991 deletions.
16 changes: 8 additions & 8 deletions modules/core/include/visp3/core/vpExponentialMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,33 @@
The exponential map gives the relationship between the velocity of a moving
body and its displacement:
\f[ \exp({^c}{\bf v}_c(t - \Delta t)) = {^{c(t - \Delta t)}}{\bf M}_{c(t)} \f]
\f[ \exp({^c}{\bf v}_c) = {^{c(t)}}{\bf M}_{c(t+\Delta t)} \f]
where \f$ {^c}{\bf v}_c(t - \Delta t)\f$ is the velocity skew vector at the previous iteration applied during \f$\Delta t\f$
seconds at point \f$ c \f$ in frame \f$ c \f$, while \f$ {^{c(t- \Delta t)}}{\bf M}_{c(t)} \f$
where \f$ {^c}{\bf v}_c\f$ is the velocity skew vector applied during \f$\Delta t\f$
seconds at point \f$ c \f$ in frame \f$ c \f$, while \f$ {^{c(t)}}{\bf M}_{c(t+\Delta t)} \f$
is the corresponding displacement.
This class allows to compute the direct or the inverse exponential map.
- The direct exponential map allows to compute the displacement
\f${^{c(t - \Delta t)}}{\bf M}_{c(t)}\f$ using \f${^c}{\bf v}_c(t - \Delta t)\f$ as input:
\f[ {^{o}}{\bf M}_{c(t)} = {^{o}}{\bf M}_{c(t - \Delta t)} \exp({^c}{\bf v}_c(t - \Delta t)) \f]
\f${^{c(t)}}{\bf M}_{c(t+\Delta t)}\f$ using \f${^c}{\bf v}_c\f$ as input:
\f[ {^{o}}{\bf M}_{c(t+\Delta t)} = {^{o}}{\bf M}_{c(t)} \exp({^c}{\bf v}_c) \f]
where \f$ o \f$ is a reference frame.
With direct(), the velocity skew vector \f$ {^c}{\bf v}_c(t - \Delta t) \f$ is applied during 1 second
With direct(), the velocity skew vector \f$ {^c}{\bf v}_c \f$ is applied during 1 second
considering \f$ \Delta t = 1\f$. With direct(const vpColVector &, const double &)
the sampling time can be set to an other value where the second
argument is \f$ \Delta t \f$.
- The inverse exponential map allows to compute the velocity skew vector \f$
{^c}{\bf v}_c(t - \Delta t) \f$ from the displacement \f$ {^{c(t - \Delta t)}}{\bf M}_{c(t)}\f$
\bf {^c}{\bf v}_c \f$ from the displacement \f$ {^{c(t)}}{\bf M}_{c(t+\Delta t)}\f$
measured during a time interval \f$ \Delta t \f$. With inverse() the time interval
also called sampling time is set to 1 second. With
inverse(const vpHomogeneousMatrix &, const double &) the sampling time can
be set to an other value where the second
argument is \f$ \Delta t \f$.
A displacement \f$ \bf M \f$ is represented as an homogeneous matrix implemented in
vpHomogeneousMatrix. A velocity \f$ \bf v \f$ is represented as a
vpHomogeneousMatrix. A velocities \f$ \bf v \f$ is represented as a
6 dimension velocity skew vector \f$ [v, \omega] \f$, where \f$ v \f$
is a velocity translation vector with values in m/s and \f$ \omega \f$ a
velocity rotation vector with values expressed in rad/s.
Expand Down
7 changes: 0 additions & 7 deletions modules/core/include/visp3/core/vpImageConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,11 @@
#endif

#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_THREADS)
#include <mutex>

#include <visp3/core/vpColVector.h>
#include <visp3/core/vpImageException.h>
#include <visp3/core/vpPixelMeterConversion.h>

#include <pcl/pcl_config.h>
#if PCL_VERSION_COMPARE(>=,1,14,1)
#include <pcl/impl/point_types.hpp>
#else
#include <pcl/point_types.h>
#endif
#include <pcl/point_cloud.h>
#endif

Expand Down
4 changes: 2 additions & 2 deletions modules/core/include/visp3/core/vpImageTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ class VISP_EXPORT vpImageTools
static void crop(const unsigned char *bitmap, unsigned int width, unsigned int height, const vpRect &roi,
vpImage<Type> &crop, unsigned int v_scale = 1, unsigned int h_scale = 1);

static void extract(const vpImage<unsigned char> &Src, vpImage<unsigned char> &Dst, const vpRectOriented &r);
static void extract(const vpImage<unsigned char> &Src, vpImage<double> &Dst, const vpRectOriented &r);
static void extract(const vpImage<unsigned char> &src, vpImage<unsigned char> &dst, const vpRectOriented &r);
static void extract(const vpImage<unsigned char> &src, vpImage<double> &dst, const vpRectOriented &r);

template <class Type> static void flip(const vpImage<Type> &I, vpImage<Type> &newI);

Expand Down
35 changes: 21 additions & 14 deletions modules/core/src/camera/vpCameraParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,12 @@ bool vpCameraParameters::operator==(const vpCameraParameters &c) const
if ((!vpMath::equal(m_px, c.m_px, std::numeric_limits<double>::epsilon())) ||
(!vpMath::equal(m_py, c.m_py, std::numeric_limits<double>::epsilon())) ||
(!vpMath::equal(m_u0, c.m_u0, std::numeric_limits<double>::epsilon()))) {
return false;
return false;
}
if ((!vpMath::equal(m_v0, c.m_v0, std::numeric_limits<double>::epsilon())) ||
(!vpMath::equal(m_kud, c.m_kud, std::numeric_limits<double>::epsilon())) ||
(!vpMath::equal(m_kdu, c.m_kdu, std::numeric_limits<double>::epsilon()))) {
return false;
return false;
}
if ((!vpMath::equal(m_inv_px, c.m_inv_px, std::numeric_limits<double>::epsilon())) ||
(!vpMath::equal(m_inv_py, c.m_inv_py, std::numeric_limits<double>::epsilon()))) {
Expand All @@ -467,9 +467,9 @@ bool vpCameraParameters::operator==(const vpCameraParameters &c) const
}
}

if ( (m_isFov != c.m_isFov) || (!vpMath::equal(m_hFovAngle, c.m_hFovAngle, std::numeric_limits<double>::epsilon())) ||
if ((m_isFov != c.m_isFov) || (!vpMath::equal(m_hFovAngle, c.m_hFovAngle, std::numeric_limits<double>::epsilon())) ||
(!vpMath::equal(m_vFovAngle, c.m_vFovAngle, std::numeric_limits<double>::epsilon()))) {
return false;
return false;
}
if ((m_width != c.m_width) || (m_height != c.m_height)) {
return false;
Expand Down Expand Up @@ -504,7 +504,7 @@ bool vpCameraParameters::operator!=(const vpCameraParameters &c) const { return
void vpCameraParameters::computeFov(const unsigned int &w, const unsigned int &h)
{
bool cond1 = (!m_isFov) || (w != m_width) || (h != m_height);
if ( cond1 && (w != 0) && (h != 0)) {
if (cond1 && (w != 0) && (h != 0)) {
m_fovNormals = std::vector<vpColVector>(4);

m_isFov = true;
Expand Down Expand Up @@ -603,32 +603,37 @@ vpMatrix vpCameraParameters::get_K_inverse() const
*/
void vpCameraParameters::printParameters()
{
unsigned int m_dist_coefs_size = m_dist_coefs.size();
unsigned int m_dist_coefs_size = m_dist_coefs.size();
std::ios::fmtflags original_flags(std::cout.flags());
switch (m_projModel) {
case vpCameraParameters::perspectiveProjWithoutDistortion:
case vpCameraParameters::perspectiveProjWithoutDistortion: {
std::cout.precision(10);
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:
}
case vpCameraParameters::perspectiveProjWithDistortion: {
std::cout.precision(10);
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;
std::cout << " kud = " << m_kud << std::endl;
std::cout << " kdu = " << m_kdu << std::endl;
break;
case vpCameraParameters::ProjWithKannalaBrandtDistortion:
}
case vpCameraParameters::ProjWithKannalaBrandtDistortion: {
std::cout << " Coefficients: ";
// --comment: unsigned int m_dist_coefs_size = m_dist_coefs.size()
for (unsigned int i = 0; i < m_dist_coefs_size; ++i) {
std::cout << " " << m_dist_coefs[i];
}
std::cout << std::endl;
break;
}
default: {
std::cout << "projection model not identified" << std::endl;
}
}
// Restore ostream format
std::cout.flags(original_flags);
}
Expand All @@ -642,11 +647,12 @@ void vpCameraParameters::printParameters()
VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpCameraParameters &cam)
{
switch (cam.get_projModel()) {
case vpCameraParameters::perspectiveProjWithoutDistortion:
case vpCameraParameters::perspectiveProjWithoutDistortion: {
os << "Camera parameters for perspective projection without distortion:" << std::endl;
os << " px = " << cam.get_px() << "\t py = " << cam.get_py() << std::endl;
os << " u0 = " << cam.get_u0() << "\t v0 = " << cam.get_v0() << std::endl;
break;
}
case vpCameraParameters::perspectiveProjWithDistortion: {
std::ios_base::fmtflags original_flags = os.flags();
os.precision(10);
Expand All @@ -656,8 +662,8 @@ VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpCameraParameters
os << " kud = " << cam.get_kud() << std::endl;
os << " kdu = " << cam.get_kdu() << std::endl;
os.flags(original_flags); // restore os to standard state
break;
}
break;
case vpCameraParameters::ProjWithKannalaBrandtDistortion: {
os << "Camera parameters for projection with Kannala-Brandt distortion:" << std::endl;
os << " px = " << cam.get_px() << "\t py = " << cam.get_py() << std::endl;
Expand All @@ -669,10 +675,11 @@ VISP_EXPORT std::ostream &operator<<(std::ostream &os, const vpCameraParameters
os << " " << tmp_coefs[i];
}
os << std::endl;
break;
}
break;
default:
default: {
std::cout << "Unidentified camera parameters model" << std::endl;
}
}
return os;
}
5 changes: 3 additions & 2 deletions modules/core/src/camera/vpColorDepthConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,17 @@ vpImagePoint vpColorDepthConversion::projectColorToDepth(
for (auto curr_pixel = start_pixel; curr_pixel.inSegment(start_pixel, end_pixel) && (curr_pixel != end_pixel);
curr_pixel = curr_pixel.nextInSegment(start_pixel, end_pixel)) {
const auto depth = depth_scale * data[static_cast<int>((curr_pixel.get_v() * depth_width) + curr_pixel.get_u())];
if (std::fabs(depth) <= std::numeric_limits<double>::epsilon())
if (std::fabs(depth) <= std::numeric_limits<double>::epsilon()) {
continue;
}

const auto point = deproject(depth_intrinsics, curr_pixel, depth);
const auto transformed_point = transform(color_M_depth, point);
const auto projected_pixel = project(color_intrinsics, transformed_point);

const auto new_dist = vpMath::sqr(projected_pixel.get_v() - from_pixel.get_v()) +
vpMath::sqr(projected_pixel.get_u() - from_pixel.get_u());
if ( (new_dist < min_dist) || (min_dist < 0) ) {
if ((new_dist < min_dist) || (min_dist < 0)) {
min_dist = new_dist;
depth_pixel = curr_pixel;
}
Expand Down
8 changes: 6 additions & 2 deletions modules/core/src/display/vpDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ unsigned int vpDisplay::computeAutoScale(unsigned int width, unsigned int height
{
unsigned int screen_width, screen_height;
getScreenSize(screen_width, screen_height);
double wscale = std::max<double>(1., ceil(2. * static_cast<double>(width) / static_cast<double>(screen_width)));
double hscale = std::max<double>(1., ceil(2. * static_cast<double>(height) / static_cast<double>(screen_height)));
double wscale = std::max<double>(1., ceil((2. * static_cast<double>(width)) / static_cast<double>(screen_width)));
double hscale = std::max<double>(1., ceil((2. * static_cast<double>(height)) / static_cast<double>(screen_height)));
unsigned int scale = std::max<unsigned int>(1u, std::max<unsigned int>(static_cast<unsigned int>(wscale), static_cast<unsigned int>(hscale)));
return scale;
}
Expand Down Expand Up @@ -289,6 +289,10 @@ void vpDisplay::setScale(vpScaleType scaleType, unsigned int width, unsigned int
case vpDisplay::SCALE_10:
setDownScalingFactor(10);
break;
default:
{
std::cout << "undefined scaleType" << std::endl;
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions modules/core/src/display/vpDisplay_rgba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ void vpDisplay::displayDotLine(const vpImage<vpRGBa> &I, const std::vector<vpIma
if (ips.size() <= 1) {
return;
}

for (size_t i = 0; i < ips.size() - 1; ++i) {
size_t ips_size = ips.size();
for (size_t i = 0; i < (ips_size - 1); ++i) {
vp_display_display_dot_line(I, ips[i], ips[i + 1], color, thickness);
}

Expand Down Expand Up @@ -515,7 +515,8 @@ void vpDisplay::displayLine(const vpImage<vpRGBa> &I, const std::vector<vpImageP
return;
}

for (size_t i = 0; i < ips.size() - 1; ++i) {
size_t ips_size = ips.size();
for (size_t i = 0; i < (ips_size - 1); ++i) {
vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
}

Expand Down
10 changes: 6 additions & 4 deletions modules/core/src/display/vpDisplay_uchar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ void vpDisplay::displayDotLine(const vpImage<unsigned char> &I, const std::vecto
return;
}

for (size_t i = 0; i < ips.size() - 1; ++i) {
size_t ips_size = ips.size();
for (size_t i = 0; i < (ips_size - 1); ++i) {
vp_display_display_dot_line(I, ips[i], ips[i + 1], color, thickness);
}

Expand Down Expand Up @@ -466,11 +467,11 @@ void vpDisplay::displayLine(const vpImage<unsigned char> &I, int i1, int j1, int
std::vector<vpImagePoint> vip; // Image points that intersect image borders
// Test intersection with vertical line j=0
vpImagePoint ip_left(b, 0);
if (ip_left.get_i() >= 0. && ip_left.get_i() <= (I.getHeight() - 1.)) {
if ((ip_left.get_i() >= 0.) && (ip_left.get_i() <= (I.getHeight() - 1.))) {
vip.push_back(ip_left);
}
// Test intersection with vertical line j=width-1
vpImagePoint ip_right(a * (I.getWidth() - 1) + b, I.getWidth() - 1.);
vpImagePoint ip_right((a * (I.getWidth() - 1)) + b, I.getWidth() - 1.);
if ((ip_right.get_i() >= 0.) && (ip_right.get_i() <= (I.getHeight() - 1.))) {
vip.push_back(ip_right);
}
Expand Down Expand Up @@ -515,7 +516,8 @@ void vpDisplay::displayLine(const vpImage<unsigned char> &I, const std::vector<v
return;
}

for (size_t i = 0; i < ips.size() - 1; ++i) {
size_t ips_size = ips.size();
for (size_t i = 0; i < (ips_size - 1); ++i) {
vp_display_display_line(I, ips[i], ips[i + 1], color, thickness);
}

Expand Down
14 changes: 8 additions & 6 deletions modules/core/src/display/vpFeatureDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ void vpFeatureDisplay::displayPoint(double x, double y, const vpCameraParameters
void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParameters &cam,
const vpImage<unsigned char> &I, const vpColor &color, unsigned int thickness)
{
// --comment: x cos(theta) + y sin(theta) - rho = 0
// --comment: x times cos(theta) plus y times sin(theta) minus rho equals 0
double rhop, thetap;
vpMeterPixelConversion::convertLine(cam, rho, theta, rhop, thetap);

// --comment: u cos(thetap) + v sin(thetap) - rhop = 0
// --comment: u times cos thetap plus v times sin thetap minus rhop equals 0
double co = cos(thetap);
double si = sin(thetap);
double c = -rhop;
Expand All @@ -99,7 +99,8 @@ void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParam
double h = I.getHeight() - 1;
ip2.set_ij(h, (-c - (a * h)) / b);
vpDisplay::displayLine(I, ip1, ip2, color, thickness);
} else {
}
else {
ip1.set_ij((-c) / a, 0);
double w = I.getWidth() - 1;
ip2.set_ij((-c - (b * w)) / a, w);
Expand Down Expand Up @@ -193,11 +194,11 @@ void vpFeatureDisplay::displayPoint(double x, double y, const vpCameraParameters
void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParameters &cam, const vpImage<vpRGBa> &I,
const vpColor &color, unsigned int thickness)
{
// --comment: x cos(theta) + y sin(theta) - rho = 0
// --comment: x times cos of theta plus y times sin of theta minus rho equals 0
double rhop, thetap;
vpMeterPixelConversion::convertLine(cam, rho, theta, rhop, thetap);

// --comment: u cos(thetap) + v sin(thetap) - rhop = 0
// --comment: u times cos of thetap plus v times sin of thetap minus rhop equals 0
double co = cos(thetap);
double si = sin(thetap);
double c = -rhop;
Expand All @@ -211,7 +212,8 @@ void vpFeatureDisplay::displayLine(double rho, double theta, const vpCameraParam
double h = I.getHeight() - 1;
ip2.set_ij(h, (-c - (a * h)) / b);
vpDisplay::displayLine(I, ip1, ip2, color, thickness);
} else {
}
else {
ip1.set_ij((-c) / a, 0);
double w = I.getWidth() - 1;
ip2.set_ij((-c - (b * w)) / a, w);
Expand Down
10 changes: 5 additions & 5 deletions modules/core/src/framegrabber/vpFrameGrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@

#include <visp3/core/vpFrameGrabber.h>

unsigned int vpFrameGrabber::getHeight() const
unsigned int vpFrameGrabber::getHeight() const
{
return height;
return height;
}

unsigned int vpFrameGrabber::getWidth() const
{
unsigned int vpFrameGrabber::getWidth() const
{
return width;
}
}
Loading

0 comments on commit ba5cc31

Please sign in to comment.