Skip to content

Commit

Permalink
STYLE: Replace std::min, std::max calls in "Colormap" with std::clamp
Browse files Browse the repository at this point in the history
Found by Notepad++ regular expression `(.+) = std::m..\(.+;\r\n\1 = std::m..\(`.

Follow-up to pull request #3992
commit fa667eb
"STYLE: Replace `std::min` and `std::max` calls with C++17 `std::clamp`"
  • Loading branch information
N-Dekker committed Nov 14, 2023
1 parent fd076e4 commit 83613f7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
4 changes: 1 addition & 3 deletions Modules/Filtering/Colormap/include/itkColormapFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ class ColormapFunction : public Object

auto d = static_cast<RealType>(maxInputValue - minInputValue);
RealType value = (static_cast<RealType>(v) - static_cast<RealType>(minInputValue)) / d;

value = std::max(0.0, value);
value = std::min(1.0, value);
value = std::clamp(value, 0.0, 1.0);
return value;
}

Expand Down
10 changes: 3 additions & 7 deletions Modules/Filtering/Colormap/include/itkHSVColormapFunction.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ HSVColormapFunction<TScalar, TRGBPixel>::operator()(const TScalar & v) const ->
// Apply the color mapping.
// Apply the color mapping.
RealType red = itk::Math::abs(5.0 * (value - 0.5)) - 5.0 / 6.0;

red = std::min(red, 1.0);
red = std::max(0.0, red);
red = std::clamp(red, 0.0, 1.0);

RealType green = -itk::Math::abs(5.0 * (value - 11.0 / 30.0)) + 11.0 / 6.0;
green = std::min(green, 1.0);
green = std::max(0.0, green);
green = std::clamp(green, 0.0, 1.0);

RealType blue = -itk::Math::abs(5.0 * (value - 19.0 / 30.0)) + 11.0 / 6.0;
blue = std::min(blue, 1.0);
blue = std::max(0.0, blue);
blue = std::clamp(blue, 0.0, 1.0);

// Set the rgb components after rescaling the values.
RGBPixelType pixel;
Expand Down
10 changes: 3 additions & 7 deletions Modules/Filtering/Colormap/include/itkHotColormapFunction.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ HotColormapFunction<TScalar, TRGBPixel>::operator()(const TScalar & v) const ->

// Apply the color mapping.
RealType red = 63.0 / 26.0 * value - 1.0 / 13.0;

red = std::max(0.0, red);
red = std::min(1.0, red);
red = std::clamp(red, 0.0, 1.0);

RealType green = 63.0 / 26.0 * value - 11.0 / 13.0;
green = std::max(0.0, green);
green = std::min(1.0, green);
green = std::clamp(green, 0.0, 1.0);

RealType blue = 4.5 * value - 3.5;
blue = std::max(0.0, blue);
blue = std::min(1.0, blue);
blue = std::clamp(blue, 0.0, 1.0);

// Set the rgb components after rescaling the values.
RGBPixelType pixel;
Expand Down
10 changes: 3 additions & 7 deletions Modules/Filtering/Colormap/include/itkJetColormapFunction.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ JetColormapFunction<TScalar, TRGBPixel>::operator()(const TScalar & v) const ->

// Apply the color mapping.
RealType red = -itk::Math::abs(3.95 * (value - 0.7460)) + 1.5;

red = std::min(red, 1.0);
red = std::max(0.0, red);
red = std::clamp(red, 0.0, 1.0);

RealType green = -itk::Math::abs(3.95 * (value - 0.492)) + 1.5;
green = std::min(green, 1.0);
green = std::max(0.0, green);
green = std::clamp(green, 0.0, 1.0);

RealType blue = -itk::Math::abs(3.95 * (value - 0.2385)) + 1.5;
blue = std::min(blue, 1.0);
blue = std::max(0.0, blue);
blue = std::clamp(blue, 0.0, 1.0);

// Set the rgb components after rescaling the values.
RGBPixelType pixel;
Expand Down

0 comments on commit 83613f7

Please sign in to comment.