Skip to content

Commit

Permalink
Merge pull request #1299 from OgreTransporter/cxx_standard_fix
Browse files Browse the repository at this point in the history
Fix std::min/std::max template types
  • Loading branch information
fspindle authored Jan 6, 2024
2 parents 0d2fb23 + c0be82a commit d8e831c
Show file tree
Hide file tree
Showing 66 changed files with 889 additions and 765 deletions.
20 changes: 10 additions & 10 deletions modules/core/include/visp3/core/vpImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -1629,8 +1629,8 @@ template <class Type> Type vpImage<Type>::getValue(double i, double j) const
double rfrac = 1.0 - rratio;
double cfrac = 1.0 - cratio;

unsigned int iround_1 = (std::min)(height - 1, iround + 1);
unsigned int jround_1 = (std::min)(width - 1, jround + 1);
unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);

double value =
(static_cast<double>(row[iround][jround]) * rfrac + static_cast<double>(row[iround_1][jround]) * rratio) * cfrac +
Expand Down Expand Up @@ -1661,8 +1661,8 @@ template <> inline double vpImage<double>::getValue(double i, double j) const
double rfrac = 1.0 - rratio;
double cfrac = 1.0 - cratio;

unsigned int iround_1 = (std::min)(height - 1, iround + 1);
unsigned int jround_1 = (std::min)(width - 1, jround + 1);
unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);

return (row[iround][jround] * rfrac + row[iround_1][jround] * rratio) * cfrac +
(row[iround][jround_1] * rfrac + row[iround_1][jround_1] * rratio) * cratio;
Expand Down Expand Up @@ -1732,8 +1732,8 @@ template <> inline unsigned char vpImage<unsigned char>::getValue(double i, doub
double rfrac = 1.0 - rratio;
double cfrac = 1.0 - cratio;

unsigned int iround_1 = (std::min)(height - 1, iround + 1);
unsigned int jround_1 = (std::min)(width - 1, jround + 1);
unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);

double value =
(static_cast<double>(row[iround][jround]) * rfrac + static_cast<double>(row[iround_1][jround]) * rratio) * cfrac +
Expand Down Expand Up @@ -1764,8 +1764,8 @@ template <> inline vpRGBa vpImage<vpRGBa>::getValue(double i, double j) const
double rfrac = 1.0 - rratio;
double cfrac = 1.0 - cratio;

unsigned int iround_1 = (std::min)(height - 1, iround + 1);
unsigned int jround_1 = (std::min)(width - 1, jround + 1);
unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);

double valueR =
(static_cast<double>(row[iround][jround].R) * rfrac + static_cast<double>(row[iround_1][jround].R) * rratio) *
Expand Down Expand Up @@ -1808,8 +1808,8 @@ template <> inline vpRGBf vpImage<vpRGBf>::getValue(double i, double j) const
double rfrac = 1.0 - rratio;
double cfrac = 1.0 - cratio;

unsigned int iround_1 = (std::min)(height - 1, iround + 1);
unsigned int jround_1 = (std::min)(width - 1, jround + 1);
unsigned int iround_1 = std::min<unsigned int>(height - 1, iround + 1);
unsigned int jround_1 = std::min<unsigned int>(width - 1, jround + 1);

double valueR =
(static_cast<double>(row[iround][jround].R) * rfrac + static_cast<double>(row[iround_1][jround].R) * rratio) *
Expand Down
4 changes: 2 additions & 2 deletions modules/core/include/visp3/core/vpImageFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class VISP_EXPORT vpImageFilter
float dx = static_cast<float>(dIx[r][c]);
float dy = static_cast<float>(dIy[r][c]);
float gradient = std::abs(dx) + std::abs(dy);
float gradientClamped = std::min(gradient, static_cast<float>(std::numeric_limits<unsigned char>::max()));
float gradientClamped = std::min<float>(gradient, static_cast<float>(std::numeric_limits<unsigned char>::max()));
dI[r][c] = static_cast<unsigned char>(gradientClamped);
}
}
Expand All @@ -334,7 +334,7 @@ class VISP_EXPORT vpImageFilter
break;
}
}
float upperThresh = std::max(bon, 1.f);
float upperThresh = std::max<float>(bon, 1.f);
lowerThresh = lowerThresholdRatio * bon;
return upperThresh;
}
Expand Down
28 changes: 14 additions & 14 deletions modules/core/include/visp3/core/vpImageTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ template <class Type>
void vpImageTools::crop(const vpImage<Type> &I, double roi_top, double roi_left, unsigned int roi_height,
unsigned int roi_width, vpImage<Type> &crop, unsigned int v_scale, unsigned int h_scale)
{
int i_min = (std::max)((int)(ceil(roi_top / v_scale)), 0);
int j_min = (std::max)((int)(ceil(roi_left / h_scale)), 0);
int i_max = (std::min)((int)(ceil((roi_top + roi_height)) / v_scale), (int)(I.getHeight() / v_scale));
int j_max = (std::min)((int)(ceil((roi_left + roi_width) / h_scale)), (int)(I.getWidth() / h_scale));
int i_min = std::max<int>((int)(ceil(roi_top / v_scale)), 0);
int j_min = std::max<int>((int)(ceil(roi_left / h_scale)), 0);
int i_max = std::min<int>((int)(ceil((roi_top + roi_height)) / v_scale), (int)(I.getHeight() / v_scale));
int j_max = std::min<int>((int)(ceil((roi_left + roi_width) / h_scale)), (int)(I.getWidth() / h_scale));

unsigned int i_min_u = (unsigned int)i_min;
unsigned int j_min_u = (unsigned int)j_min;
Expand Down Expand Up @@ -409,10 +409,10 @@ template <class Type>
void vpImageTools::crop(const unsigned char *bitmap, unsigned int width, unsigned int height, const vpRect &roi,
vpImage<Type> &crop, unsigned int v_scale, unsigned int h_scale)
{
int i_min = (std::max)((int)(ceil(roi.getTop() / v_scale)), 0);
int j_min = (std::max)((int)(ceil(roi.getLeft() / h_scale)), 0);
int i_max = (std::min)((int)(ceil((roi.getTop() + roi.getHeight()) / v_scale)), (int)(height / v_scale));
int j_max = (std::min)((int)(ceil((roi.getLeft() + roi.getWidth()) / h_scale)), (int)(width / h_scale));
int i_min = std::max<int>((int)(ceil(roi.getTop() / v_scale)), 0);
int j_min = std::max<int>((int)(ceil(roi.getLeft() / h_scale)), 0);
int i_max = std::min<int>((int)(ceil((roi.getTop() + roi.getHeight()) / v_scale)), (int)(height / v_scale));
int j_max = std::min<int>((int)(ceil((roi.getLeft() + roi.getWidth()) / h_scale)), (int)(width / h_scale));

unsigned int i_min_u = (unsigned int)i_min;
unsigned int j_min_u = (unsigned int)j_min;
Expand Down Expand Up @@ -892,8 +892,8 @@ template <class Type> Type vpImageTools::getPixelClamped(const vpImage<Type> &I,
{
int x = vpMath::round(u);
int y = vpMath::round(v);
x = (std::max)(0, (std::min)(x, static_cast<int>(I.getWidth()) - 1));
y = (std::max)(0, (std::min)(y, static_cast<int>(I.getHeight()) - 1));
x = std::max<int>(0, std::min<int>(x, static_cast<int>(I.getWidth()) - 1));
y = std::max<int>(0, std::min<int>(y, static_cast<int>(I.getHeight()) - 1));

return I[y][x];
}
Expand Down Expand Up @@ -994,11 +994,11 @@ void vpImageTools::resizeBilinear(const vpImage<Type> &I, vpImage<Type> &Ires, u
int u0 = static_cast<int>(u);
int v0 = static_cast<int>(v);

int u1 = (std::min)(static_cast<int>(I.getWidth()) - 1, u0 + 1);
int u1 = std::min<int>(static_cast<int>(I.getWidth()) - 1, u0 + 1);
int v1 = v0;

int u2 = u0;
int v2 = (std::min)(static_cast<int>(I.getHeight()) - 1, v0 + 1);
int v2 = std::min<int>(static_cast<int>(I.getHeight()) - 1, v0 + 1);

int u3 = u1;
int v3 = v2;
Expand All @@ -1017,11 +1017,11 @@ inline void vpImageTools::resizeBilinear(const vpImage<vpRGBa> &I, vpImage<vpRGB
int u0 = static_cast<int>(u);
int v0 = static_cast<int>(v);

int u1 = (std::min)(static_cast<int>(I.getWidth()) - 1, u0 + 1);
int u1 = std::min<int>(static_cast<int>(I.getWidth()) - 1, u0 + 1);
int v1 = v0;

int u2 = u0;
int v2 = (std::min)(static_cast<int>(I.getHeight()) - 1, v0 + 1);
int v2 = std::min<int>(static_cast<int>(I.getHeight()) - 1, v0 + 1);

int u3 = u1;
int v3 = v2;
Expand Down
22 changes: 11 additions & 11 deletions modules/core/include/visp3/core/vpMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,14 +488,14 @@ template <> inline unsigned char vpMath::saturate<unsigned char>(char v)
// On little endian arch, CHAR_MIN=-127 and CHAR_MAX=128 leading to
// (int)(char -127) = -127.
if (std::numeric_limits<char>::is_signed)
return static_cast<unsigned char>(std::max(static_cast<int>(v), 0));
return static_cast<unsigned char>(std::max<int>(static_cast<int>(v), 0));
else
return static_cast<unsigned char>(static_cast<unsigned int>(v) > SCHAR_MAX ? 0 : v);
}

template <> inline unsigned char vpMath::saturate<unsigned char>(unsigned short v)
{
return static_cast<unsigned char>(std::min(static_cast<unsigned int>(v), static_cast<unsigned int>(UCHAR_MAX)));
return static_cast<unsigned char>(std::min<unsigned int>(static_cast<unsigned int>(v), static_cast<unsigned int>(UCHAR_MAX)));
}

template <> inline unsigned char vpMath::saturate<unsigned char>(int v)
Expand All @@ -510,7 +510,7 @@ template <> inline unsigned char vpMath::saturate<unsigned char>(short v)

template <> inline unsigned char vpMath::saturate<unsigned char>(unsigned int v)
{
return static_cast<unsigned char>(std::min(v, static_cast<unsigned int>(UCHAR_MAX)));
return static_cast<unsigned char>(std::min<unsigned int>(v, static_cast<unsigned int>(UCHAR_MAX)));
}

template <> inline unsigned char vpMath::saturate<unsigned char>(float v)
Expand All @@ -528,12 +528,12 @@ template <> inline unsigned char vpMath::saturate<unsigned char>(double v)
// char
template <> inline char vpMath::saturate<char>(unsigned char v)
{
return static_cast<char>(std::min(static_cast<int>(v), SCHAR_MAX));
return static_cast<char>(std::min<int>(static_cast<int>(v), SCHAR_MAX));
}

template <> inline char vpMath::saturate<char>(unsigned short v)
{
return static_cast<char>(std::min(static_cast<unsigned int>(v), static_cast<unsigned int>(SCHAR_MAX)));
return static_cast<char>(std::min<unsigned int>(static_cast<unsigned int>(v), static_cast<unsigned int>(SCHAR_MAX)));
}

template <> inline char vpMath::saturate<char>(int v)
Expand All @@ -548,7 +548,7 @@ template <> inline char vpMath::saturate<char>(short v)

template <> inline char vpMath::saturate<char>(unsigned int v)
{
return static_cast<char>(std::min(v, static_cast<unsigned int>(SCHAR_MAX)));
return static_cast<char>(std::min<unsigned int>(v, static_cast<unsigned int>(SCHAR_MAX)));
}

template <> inline char vpMath::saturate<char>(float v)
Expand All @@ -572,14 +572,14 @@ template <> inline unsigned short vpMath::saturate<unsigned short>(char v)
// On little endian arch, CHAR_MIN=-127 and CHAR_MAX=128 leading to
// (int)(char -127) = -127.
if (std::numeric_limits<char>::is_signed)
return static_cast<unsigned short>(std::max(static_cast<int>(v), 0));
return static_cast<unsigned short>(std::max<int>(static_cast<int>(v), 0));
else
return static_cast<unsigned short>(static_cast<unsigned int>(v) > SCHAR_MAX ? 0 : v);
}

template <> inline unsigned short vpMath::saturate<unsigned short>(short v)
{
return static_cast<unsigned short>(std::max(static_cast<int>(v), 0));
return static_cast<unsigned short>(std::max<int>(static_cast<int>(v), 0));
}

template <> inline unsigned short vpMath::saturate<unsigned short>(int v)
Expand All @@ -589,7 +589,7 @@ template <> inline unsigned short vpMath::saturate<unsigned short>(int v)

template <> inline unsigned short vpMath::saturate<unsigned short>(unsigned int v)
{
return static_cast<unsigned short>(std::min(v, static_cast<unsigned int>(USHRT_MAX)));
return static_cast<unsigned short>(std::min<unsigned int>(v, static_cast<unsigned int>(USHRT_MAX)));
}

template <> inline unsigned short vpMath::saturate<unsigned short>(float v)
Expand All @@ -607,15 +607,15 @@ template <> inline unsigned short vpMath::saturate<unsigned short>(double v)
// short
template <> inline short vpMath::saturate<short>(unsigned short v)
{
return static_cast<short>(std::min(static_cast<int>(v), SHRT_MAX));
return static_cast<short>(std::min<int>(static_cast<int>(v), SHRT_MAX));
}
template <> inline short vpMath::saturate<short>(int v)
{
return static_cast<short>(static_cast<unsigned int>(v - SHRT_MIN) <= static_cast<unsigned int>(USHRT_MAX) ? v : v > 0 ? SHRT_MAX : SHRT_MIN);
}
template <> inline short vpMath::saturate<short>(unsigned int v)
{
return static_cast<short>(std::min(v, static_cast<unsigned int>(SHRT_MAX)));
return static_cast<short>(std::min<unsigned int>(v, static_cast<unsigned int>(SHRT_MAX)));
}
template <> inline short vpMath::saturate<short>(float v)
{
Expand Down
4 changes: 2 additions & 2 deletions modules/core/include/visp3/core/vpMunkres.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ template <typename Type> inline vpMunkres::STEP_T vpMunkres::stepOne(std::vector
for (auto col = 0u; col < costs.size(); ++col) {
auto minval = std::numeric_limits<Type>::max();
for (const auto &cost_row : costs) {
minval = std::min(minval, cost_row.at(col));
minval = std::min<Type>(minval, cost_row.at(col));
}

for (auto &cost_row : costs) {
Expand Down Expand Up @@ -316,7 +316,7 @@ inline std::vector<std::pair<unsigned int, unsigned int> > vpMunkres::run(std::v
{
const auto original_row_size = costs.size();
const auto original_col_size = costs.front().size();
const auto sq_size = std::max(original_row_size, original_col_size);
const auto sq_size = std::max<Type>(original_row_size, original_col_size);

auto mask = std::vector<std::vector<vpMunkres::ZERO_T> >(
sq_size, std::vector<vpMunkres::ZERO_T>(sq_size, vpMunkres::ZERO_T::NA));
Expand Down
4 changes: 2 additions & 2 deletions modules/core/include/visp3/core/vpPixelMeterConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class VISP_EXPORT vpPixelMeterConversion
double scale = 1.0;
double r_d = sqrt(vpMath::sqr(x_d) + vpMath::sqr(y_d));

r_d = std::min(std::max(-M_PI, r_d), M_PI); // FOV restricted to 180degrees.
r_d = std::min<double>(std::max<double>(-M_PI, r_d), M_PI); // FOV restricted to 180degrees.

std::vector<double> k = cam.getKannalaBrandtDistortionCoefficients();

Expand Down Expand Up @@ -327,7 +327,7 @@ class VISP_EXPORT vpPixelMeterConversion
double scale = 1.0;
double r_d = sqrt(vpMath::sqr(x_d) + vpMath::sqr(y_d));

r_d = std::min(std::max(-M_PI, r_d), M_PI); // FOV restricted to 180degrees.
r_d = std::min<double>(std::max<double>(-M_PI, r_d), M_PI); // FOV restricted to 180degrees.

std::vector<double> k = cam.getKannalaBrandtDistortionCoefficients();

Expand Down
8 changes: 4 additions & 4 deletions modules/core/include/visp3/core/vpRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ class VISP_EXPORT vpRect
*/
inline vpRect &operator&=(const vpRect &r)
{
double x1 = (std::max)(left, r.left);
double y1 = (std::max)(top, r.top);
width = (std::min)(left + width, r.left + r.width) - x1;
height = (std::min)(top + height, r.top + r.height) - y1;
double x1 = std::max<double>(left, r.left);
double y1 = std::max<double>(top, r.top);
width = std::min<double>(left + width, r.left + r.width) - x1;
height = std::min<double>(top + height, r.top + r.height) - y1;
left = x1;
top = y1;

Expand Down
6 changes: 3 additions & 3 deletions modules/core/src/display/vpDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ 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)(1., ceil(2. * (double)width / (double)screen_width));
double hscale = (std::max)(1., ceil(2. * (double)height / (double)screen_height));
unsigned int scale = (unsigned int)(std::max)(1u, (std::max)((unsigned int)wscale, (unsigned int)hscale));
double wscale = std::max<double>(1., ceil(2. * (double)width / (double)screen_width));
double hscale = std::max<double>(1., ceil(2. * (double)height / (double)screen_height));
unsigned int scale = std::max<unsigned int>(1u, std::max<unsigned int>((unsigned int)wscale, (unsigned int)hscale));
return scale;
}

Expand Down
Loading

0 comments on commit d8e831c

Please sign in to comment.