diff --git a/openvdb/openvdb/math/Stencils.h b/openvdb/openvdb/math/Stencils.h index 0d3c79dc10..ce6243af2e 100644 --- a/openvdb/openvdb/math/Stencils.h +++ b/openvdb/openvdb/math/Stencils.h @@ -40,7 +40,6 @@ class BaseStencil typedef typename GridT::ValueType ValueType; typedef tree::ValueAccessor AccessorType; typedef std::vector BufferType; - typedef typename BufferType::iterator IterType; /// @brief Initialize the stencil buffer with the values of voxel (i, j, k) /// and its neighbors. @@ -146,14 +145,14 @@ class BaseStencil /// @brief Return the smallest value in the stencil buffer. inline ValueType min() const { - IterType iter = std::min_element(mValues.begin(), mValues.end()); + const auto iter = std::min_element(mValues.begin(), mValues.end()); return *iter; } /// @brief Return the largest value in the stencil buffer. inline ValueType max() const { - IterType iter = std::max_element(mValues.begin(), mValues.end()); + const auto iter = std::max_element(mValues.begin(), mValues.end()); return *iter; } diff --git a/openvdb/openvdb/unittest/CMakeLists.txt b/openvdb/openvdb/unittest/CMakeLists.txt index e056f4079d..33e4431a3c 100644 --- a/openvdb/openvdb/unittest/CMakeLists.txt +++ b/openvdb/openvdb/unittest/CMakeLists.txt @@ -162,6 +162,7 @@ else() TestQuat.cc TestRay.cc TestStats.cc + TestStencils.cc TestStream.cc TestStreamCompression.cc TestStringMetadata.cc diff --git a/openvdb/openvdb/unittest/TestStencils.cc b/openvdb/openvdb/unittest/TestStencils.cc new file mode 100644 index 0000000000..804dd61fcf --- /dev/null +++ b/openvdb/openvdb/unittest/TestStencils.cc @@ -0,0 +1,40 @@ +// Copyright Contributors to the OpenVDB Project +// SPDX-License-Identifier: MPL-2.0 + +#include +#include + +#include + + +class TestStencils : public ::testing::Test +{ +}; + +TEST_F(TestStencils, testMinMax) +{ + using namespace openvdb; + + Int32Grid grid; + grid.tree().setValue(math::Coord(0,0,0), -3); + grid.tree().setValue(math::Coord(0,0,1), -2); + grid.tree().setValue(math::Coord(0,1,0), -1); + grid.tree().setValue(math::Coord(1,0,0), 0); + grid.tree().setValue(math::Coord(1,1,0), 1); + grid.tree().setValue(math::Coord(0,1,1), 2); + grid.tree().setValue(math::Coord(1,0,1), 3); + grid.tree().setValue(math::Coord(1,1,1), 4); + math::BoxStencil stencil(grid); + + stencil.moveTo(Coord(0,0,0)); + EXPECT_EQ(stencil.min(), -3); + EXPECT_EQ(stencil.max(), 4); + + stencil.moveTo(Coord(1,1,1)); + EXPECT_EQ(stencil.min(), 0); + EXPECT_EQ(stencil.max(), 4); + + stencil.moveTo(Coord(0,0,1)); + EXPECT_EQ(stencil.min(), -2); + EXPECT_EQ(stencil.max(), 4); +} diff --git a/pendingchanges/stencil_minmax.txt b/pendingchanges/stencil_minmax.txt new file mode 100644 index 0000000000..28cad098cf --- /dev/null +++ b/pendingchanges/stencil_minmax.txt @@ -0,0 +1,5 @@ +OpenVDB: + - Bug Fixes: + Fixed a compilation issue with the min() and max() methods on Stencils + in openvdb/math/Stencils.h + [Reported by Samuel Mauch]