Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion openvdb/openvdb/math/Stencils.h
Original file line number Diff line number Diff line change
Expand Up @@ -1627,7 +1627,9 @@ class CurvatureStencil: public BaseStencil<CurvatureStencil<GridT, IsSafe>, Grid
Real alphaM, alphaG, normGrad;
if (this->curvatures(alphaM, alphaG, normGrad)) {
const Real mean = alphaM*mInv2Dx/math::Pow3(normGrad);
const Real tmp = std::sqrt(mean*mean - alphaG*mInvDx2/math::Pow4(normGrad));
const Real base = mean*mean - alphaG*mInvDx2/math::Pow4(normGrad);
const Real clampVal = 0;
const Real tmp = std::sqrt(std::max(base, clampVal));
pair.first = ValueType(mean - tmp);
pair.second = ValueType(mean + tmp);
}
Expand Down
3 changes: 2 additions & 1 deletion openvdb/openvdb/points/IndexFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class RandomLeafFilter
currentPoints += iter->pointCount();
}

const float factor = targetPoints > currentPoints ? 1.0f : float(targetPoints) / float(currentPoints);
const float denom = currentPoints > 0 ? float(currentPoints) : 1.0f; // Do not divide by zero.
const float factor = targetPoints > currentPoints ? 1.0f : float(targetPoints) / denom;

std::mt19937 generator(seed);
std::uniform_int_distribution<unsigned int> dist(0, std::numeric_limits<unsigned int>::max() - 1);
Expand Down
20 changes: 16 additions & 4 deletions openvdb/openvdb/tools/impl/ConvexVoxelizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,10 @@ class ConvexVoxelizer
circleBottom(const ValueT& x0, const ValueT& y0,
const ValueT& r, const ValueT& x)
{
return y0 - math::Sqrt(math::Pow2(r) - math::Pow2(x-x0));
const ValueT base = math::Pow2(r) - math::Pow2(x-x0);
return base <= 0
? y0
: y0 - math::Sqrt(base);
}

/// @brief Computes the top y-coordinate of a circle at a given x position.
Expand All @@ -402,7 +405,10 @@ class ConvexVoxelizer
circleTop(const ValueT& x0, const ValueT& y0,
const ValueT& r, const ValueT& x)
{
return y0 + math::Sqrt(math::Pow2(r) - math::Pow2(x-x0));
const ValueT base = math::Pow2(r) - math::Pow2(x-x0);
return base <= 0
? y0
: y0 + math::Sqrt(base);
}

/// @brief Computes the bottom z-coordinate of a sphere at a given (x, y) position.
Expand All @@ -417,7 +423,10 @@ class ConvexVoxelizer
sphereBottom(const ValueT& x0, const ValueT& y0, const ValueT& z0,
const ValueT& r, const ValueT& x, const ValueT& y)
{
return z0 - math::Sqrt(math::Pow2(r) - math::Pow2(x-x0) - math::Pow2(y-y0));
const ValueT base = math::Pow2(r) - math::Pow2(x-x0) - math::Pow2(y-y0);
return base <= 0 // Do not take square root of negative numbers.
? z0
: z0 - math::Sqrt(base);
}

/// @brief Computes the top z-coordinate of a sphere at a given (x, y) position.
Expand All @@ -432,7 +441,10 @@ class ConvexVoxelizer
sphereTop(const ValueT& x0, const ValueT& y0, const ValueT& z0,
const ValueT& r, const ValueT& x, const ValueT& y)
{
return z0 + math::Sqrt(math::Pow2(r) - math::Pow2(x-x0) - math::Pow2(y-y0));
const ValueT base = math::Pow2(r) - math::Pow2(x-x0) - math::Pow2(y-y0);
return base <= 0 // Do not take square root of negative numbers.
? z0
: z0 + math::Sqrt(base);
}

// ------------ nested classes ------------
Expand Down
6 changes: 6 additions & 0 deletions openvdb/openvdb/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set(OPENVDB_TESTS "" CACHE STRING [=[
\"Activate;NodeManager\" would build just the TestActivate.cc and TestNodeManager.cc
unit tests.]=])

option(OPENVDB_TESTS_FPE "Enable FP exceptions in unit tests (linux only)" FALSE)

##########################################################################

message(STATUS "----------------------------------------------------")
Expand Down Expand Up @@ -196,6 +198,10 @@ else()
)
endif()

if (OPENVDB_TESTS_FPE)
add_compile_definitions(OPENVDB_TESTS_FPE)
endif()

add_executable(vdb_test ${UNITTEST_SOURCE_FILES})

# Blosc and ZLib are hidden dependencies for the core library
Expand Down
14 changes: 14 additions & 0 deletions openvdb/openvdb/unittest/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,25 @@
#include <string>
#include <vector>

#if defined(__linux__) && defined(OPENVDB_TESTS_FPE)
#include <fenv.h>
#endif

#include <gtest/gtest.h>

int
main(int argc, char *argv[])
{
::testing::InitGoogleTest(&argc, argv);

#if defined(__linux__) && defined(OPENVDB_TESTS_FPE)
int excepts = FE_DIVBYZERO | FE_INVALID;
if (getenv("OPENVDB_TEST_OVERFLOW")) {
// when set, test for FP overflow as well.
excepts = excepts | FE_OVERFLOW;
}
feenableexcept(excepts);
#endif

return RUN_ALL_TESTS();
}