Skip to content

Commit

Permalink
Merge pull request #1673 from Idclip/stencil_minmax
Browse files Browse the repository at this point in the history
Fixed a compilation issue with min() and max() methods on the stencils
  • Loading branch information
Idclip committed Sep 28, 2023
2 parents d41e3a5 + a7fd213 commit a6064e8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
5 changes: 2 additions & 3 deletions openvdb/openvdb/math/Stencils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class BaseStencil
typedef typename GridT::ValueType ValueType;
typedef tree::ValueAccessor<const TreeType, IsSafe> AccessorType;
typedef std::vector<ValueType> BufferType;
typedef typename BufferType::iterator IterType;

/// @brief Initialize the stencil buffer with the values of voxel (i, j, k)
/// and its neighbors.
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions openvdb/openvdb/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ else()
TestQuat.cc
TestRay.cc
TestStats.cc
TestStencils.cc
TestStream.cc
TestStreamCompression.cc
TestStringMetadata.cc
Expand Down
40 changes: 40 additions & 0 deletions openvdb/openvdb/unittest/TestStencils.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: MPL-2.0

#include <openvdb/openvdb.h>
#include <openvdb/math/Stencils.h>

#include <gtest/gtest.h>


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<Int32Grid> 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);
}
5 changes: 5 additions & 0 deletions pendingchanges/stencil_minmax.txt
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit a6064e8

Please sign in to comment.