Skip to content

Commit

Permalink
Fix warnings detected with msvc17, mainly cast issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Jan 12, 2024
1 parent 69f82d7 commit 137454d
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 37 deletions.
6 changes: 3 additions & 3 deletions modules/core/include/visp3/core/vpImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ class VISP_EXPORT vpImageFilter
const float &lowerThresholdRatio = 0.6, const float &upperThresholdRatio = 0.8,
const vpCannyFilteringAndGradientType &filteringType = CANNY_GBLUR_SOBEL_FILTERING)
{
double w = I.getWidth();
double h = I.getHeight();
unsigned int w = static_cast<unsigned int>(I.getWidth());
unsigned int h = static_cast<unsigned int>(I.getHeight());

vpImage<unsigned char> dI(h, w);
vpImage<OutType> dIx(h, w), dIy(h, w);
Expand Down Expand Up @@ -327,7 +327,7 @@ class VISP_EXPORT vpImageFilter
float t = (float)(upperThresholdRatio * w * h);
float bon = 0;
for (unsigned int i = 0; i < nbBins; ++i) {
float tf = hist[i];
float tf = static_cast<float>(hist[i]);

Check warning on line 330 in modules/core/include/visp3/core/vpImageFilter.h

View check run for this annotation

Codecov / codecov/patch

modules/core/include/visp3/core/vpImageFilter.h#L330

Added line #L330 was not covered by tests
accu = accu + tf;
if (accu > t) {
bon = (float)i;
Expand Down
16 changes: 8 additions & 8 deletions modules/core/src/image/vpImageCircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,16 +910,16 @@ float vpImageCircle::computeAngularCoverageInRoI(const vpRect &roi, const float
{
float delta_theta = 0.f;
vpImagePoint center = m_center;
float u_c = center.get_u();
float v_c = center.get_v();
float u_c = static_cast<float>(center.get_u());
float v_c = static_cast<float>(center.get_v());
float radius = m_radius;
float roi_w = roi.getWidth();
float roi_h = roi.getHeight();
float roi_w = static_cast<float>(roi.getWidth());
float roi_h = static_cast<float>(roi.getHeight());
vpImagePoint topLeft = roi.getTopLeft();
float umin_roi = topLeft.get_u();
float vmin_roi = topLeft.get_v();
float umax_roi = topLeft.get_u() + roi_w;
float vmax_roi = topLeft.get_v() + roi_h;
float umin_roi = static_cast<float>(topLeft.get_u());
float vmin_roi = static_cast<float>(topLeft.get_v());
float umax_roi = umin_roi + roi_w;
float vmax_roi = vmin_roi + roi_h;
bool touchLeftBorder = (u_c - radius) <= umin_roi;
bool touchRightBorder = (u_c + radius) >= umax_roi;
bool touchTopBorder = (v_c - radius) <= vmin_roi;
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/image/vpImageFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ void vpImageFilter::canny(const vpImage<unsigned char> &Isrc, vpImage<unsigned c
cannyFilteringSteps);
}
else if (lowerCannyThresh < 0.f) {
lowerCannyThresh = upperCannyThresh / 3.;
lowerCannyThresh = upperCannyThresh / 3.f;

Check warning on line 1078 in modules/core/src/image/vpImageFilter.cpp

View check run for this annotation

Codecov / codecov/patch

modules/core/src/image/vpImageFilter.cpp#L1078

Added line #L1078 was not covered by tests
}
vpCannyEdgeDetection edgeDetector(gaussianFilterSize, gaussianStdev, apertureGradient, lowerCannyThresh, upperCannyThresh,
lowerThresholdRatio, upperThresholdRatio, cannyFilteringSteps);
Expand Down
2 changes: 2 additions & 0 deletions modules/imgproc/include/visp3/imgproc/vpContours.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ struct vpDirection
*/
vpDirection()
{
m_direction = NORTH;

m_dirx[0] = 0;
m_dirx[1] = 1;
m_dirx[2] = 1;
Expand Down
6 changes: 3 additions & 3 deletions modules/imgproc/src/vpCircleHoughTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ vpCircleHoughTransform::computeCenterCandidates()
}
}

unsigned int nbPeaks = peak_positions_votes.size();
unsigned int nbPeaks = static_cast<unsigned int>(peak_positions_votes.size());

Check warning on line 610 in modules/imgproc/src/vpCircleHoughTransform.cpp

View check run for this annotation

Codecov / codecov/patch

modules/imgproc/src/vpCircleHoughTransform.cpp#L610

Added line #L610 was not covered by tests
if (nbPeaks > 0) {
std::vector<bool> has_been_merged(nbPeaks, false);
std::vector<std::pair<std::pair<float, float>, float>> merged_peaks_position_votes;
Expand Down Expand Up @@ -672,7 +672,7 @@ vpCircleHoughTransform::computeCenterCandidates()

std::sort(merged_peaks_position_votes.begin(), merged_peaks_position_votes.end(), sortingCenters);

nbPeaks = merged_peaks_position_votes.size();
nbPeaks = static_cast<unsigned int>(merged_peaks_position_votes.size());
int nbPeaksToKeep = (m_algoParams.m_expectedNbCenters > 0 ? m_algoParams.m_expectedNbCenters : nbPeaks);
nbPeaksToKeep = std::min<int>(nbPeaksToKeep, (int)nbPeaks);
for (int i = 0; i < nbPeaksToKeep; i++) {
Expand Down Expand Up @@ -793,7 +793,7 @@ vpCircleHoughTransform::computeCircleCandidates()
}
}

unsigned int nbCandidates = v_r_effective.size();
unsigned int nbCandidates = static_cast<unsigned int>(v_r_effective.size());

Check warning on line 796 in modules/imgproc/src/vpCircleHoughTransform.cpp

View check run for this annotation

Codecov / codecov/patch

modules/imgproc/src/vpCircleHoughTransform.cpp#L796

Added line #L796 was not covered by tests
for (unsigned int idBin = 0; idBin < nbCandidates; ++idBin) {
// If the circle of center CeC_i and radius RCB_k has enough votes, it is added to the list
// of Circle Candidates
Expand Down
14 changes: 7 additions & 7 deletions modules/robot/src/real-robot/pololu-maestro/vpRobotPololuPtu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ vpRobotPololuPtu::vpRobotPololuPtu(const std::string &device, int baudrate, bool
nDof = 2;
m_pan.connect(device, baudrate, 0);
m_pan.setPwmRange(4095, 7905);
m_pan.setAngularRange(vpMath::rad(-45), vpMath::rad(45));
m_pan.setAngularRange(static_cast<float>(vpMath::rad(-45)), static_cast<float>(vpMath::rad(45)));
m_pan.setVerbose(verbose);

m_tilt.connect(device, baudrate, 1);
m_tilt.setPwmRange(4095, 7905);
m_tilt.setAngularRange(vpMath::rad(-45), vpMath::rad(45));
m_tilt.setAngularRange(static_cast<float>(vpMath::rad(-45)), static_cast<float>(vpMath::rad(45)));
m_tilt.setVerbose(verbose);
}

Expand Down Expand Up @@ -151,9 +151,9 @@ void vpRobotPololuPtu::setPosition(const vpRobot::vpControlFrameType frame, cons
break;
}

float pos_vel = m_positioning_velocity_percentage * getMaxRotationVelocity();
m_pan.setAngularPosition(q[0], pos_vel);
m_tilt.setAngularPosition(q[1], pos_vel);
float pos_vel = m_positioning_velocity_percentage * static_cast<float>(getMaxRotationVelocity());
m_pan.setAngularPosition(static_cast<float>(q[0]), pos_vel);
m_tilt.setAngularPosition(static_cast<float>(q[1]), pos_vel);
}

void vpRobotPololuPtu::setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &q_dot)
Expand Down Expand Up @@ -227,8 +227,8 @@ void vpRobotPololuPtu::setVelocity(const vpRobot::vpControlFrameType frame, cons

std::cout << "Send velocity: " << q_dot_sat.t() << std::endl;

m_pan.setAngularVelocity(q_dot_sat[0]);
m_tilt.setAngularVelocity(q_dot_sat[1]);
m_pan.setAngularVelocity(static_cast<float>(q_dot_sat[0]));
m_tilt.setAngularVelocity(static_cast<float>(q_dot_sat[1]));
}

vpRobot::vpRobotStateType vpRobotPololuPtu::setRobotState(vpRobot::vpRobotStateType newState)
Expand Down
6 changes: 3 additions & 3 deletions modules/robot/test/servo-pololu/testPololuPosition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ int main(int argc, const char **argv)
bool opt_calibrate = false;
unsigned short opt_pwm_min = 4000;
unsigned short opt_pwm_max = 8000;
float opt_angle_min = vpMath::rad(-45);
float opt_angle_max = vpMath::rad(45);
float opt_positioning_velocity = vpMath::rad(10);
float opt_angle_min = static_cast<float>(vpMath::rad(-45));
float opt_angle_max = static_cast<float>(vpMath::rad(45));
float opt_positioning_velocity = static_cast<float>(vpMath::rad(10));
float last_angle = 0;
int time_s = 0;

Expand Down
6 changes: 3 additions & 3 deletions modules/robot/test/servo-pololu/testPololuVelocity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ int main(int argc, const char **argv)
bool opt_calibrate = false;
unsigned short opt_pwm_min = 4000;
unsigned short opt_pwm_max = 8000;
float opt_angle_min = vpMath::rad(-45);
float opt_angle_max = vpMath::rad(45);
float opt_velocity = vpMath::rad(5);
float opt_angle_min = static_cast<float>(vpMath::rad(-45));
float opt_angle_max = static_cast<float>(vpMath::rad(45));
float opt_velocity = static_cast<float>(vpMath::rad(5));
float last_angle = 0;

for (int i = 1; i < argc; i++) {
Expand Down
12 changes: 6 additions & 6 deletions tutorial/image/tutorial-canny.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void computeMeanMaxStdev(const vpImage<T> &I, float &mean, float &max, float &st
stdev = 0.;
unsigned int nbRows = I.getRows();
unsigned int nbCols = I.getCols();
float scale = 1. / ((float)nbRows * (float)nbCols);
float scale = 1.f / (static_cast<float>(nbRows) * static_cast<float>(nbCols));
for (unsigned int r = 0; r < nbRows; r++) {
for (unsigned int c = 0; c < nbCols; c++) {
mean += I[r][c];
Expand Down Expand Up @@ -178,12 +178,12 @@ int main(int argc, const char *argv[])
else if ((argv_str == "-g" || argv_str == "--gradient") && i + 2 < argc) {
opt_gradientOutsideClass = true;
opt_gaussianKernelSize = atoi(argv[i + 1]);
opt_gaussianStdev = atoi(argv[i + 2]);
opt_gaussianStdev = static_cast<float>(atof(argv[i + 2]));
i += 2;
}
else if ((argv_str == "-t" || argv_str == "--thresh") && i + 2 < argc) {
opt_lowerThresh = atof(argv[i + 1]);
opt_upperThresh = atof(argv[i + 2]);
opt_lowerThresh = static_cast<float>(atof(argv[i + 1]));
opt_upperThresh = static_cast<float>(atof(argv[i + 2]));
i += 2;
}
else if ((argv_str == "-a" || argv_str == "--aperture") && i + 1 < argc) {
Expand All @@ -195,8 +195,8 @@ int main(int argc, const char *argv[])
i++;
}
else if ((argv_str == "-r" || argv_str == "--ratio") && i + 2 < argc) {
opt_lowerThreshRatio = std::atof(argv[i + 1]);
opt_upperThreshRatio = std::atof(argv[i + 2]);
opt_lowerThreshRatio = static_cast<float>(std::atof(argv[i + 1]));
opt_upperThreshRatio = static_cast<float>(std::atof(argv[i + 2]));
i += 2;
}
else if ((argv_str == "-b" || argv_str == "--backend") && i + 1 < argc) {
Expand Down
6 changes: 3 additions & 3 deletions tutorial/imgproc/hough-transform/tutorial-circle-hough.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ int main(int argc, char **argv)
i++;
}
else if (argName == "--lower-canny-ratio" && i + 1 < argc) {
opt_lowerCannyThreshRatio = atof(argv[i + 1]);
opt_lowerCannyThreshRatio = static_cast<float>(atof(argv[i + 1]));
i++;
}
else if (argName == "--upper-canny-ratio" && i + 1 < argc) {
opt_upperCannyThreshRatio = atof(argv[i + 1]);
opt_upperCannyThreshRatio = static_cast<float>(atof(argv[i + 1]));
i++;
}
else if (argName == "--expected-nb-centers" && i + 1 < argc) {
Expand Down Expand Up @@ -247,7 +247,7 @@ int main(int argc, char **argv)
std::cout << "DESCRIPTION" << std::endl
<< "\t--input" << std::endl
<< "\t\tPermit to choose the input of the Hough Circle Algorithm." << std::endl
<< "\t\tIf you want to use a succession of images as video, their name must be in the format ${BASENAME}\%d.{jpg, png}." << std::endl
<< "\t\tIf you want to use a succession of images as video, their name must be in the format ${BASENAME}%d.{jpg, png}." << std::endl
<< "\t\tDefault: " << def_input << std::endl
<< std::endl
#ifdef VISP_HAVE_NLOHMANN_JSON
Expand Down

0 comments on commit 137454d

Please sign in to comment.