Skip to content

Commit b865fbd

Browse files
authored
Merge pull request #1563 from danrbailey/fix_gcc9_warnings
Fix all the int-in-bool-context warnings with GCC9
2 parents fae88a8 + 7c3aa5a commit b865fbd

File tree

6 files changed

+62
-39
lines changed

6 files changed

+62
-39
lines changed

openvdb/openvdb/tools/Composite.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,14 @@ compMul(GridOrTreeT& aTree, GridOrTreeT& bTree)
796796
{
797797
using Adapter = TreeAdapter<GridOrTreeT>;
798798
using TreeT = typename Adapter::TreeType;
799+
using ValueT = typename GridOrTreeT::ValueType;
799800
struct Local {
800801
static inline void op(CombineArgs<typename TreeT::ValueType>& args) {
801-
args.setResult(args.a() * args.b());
802+
if constexpr(std::is_same<ValueT, bool>::value) {
803+
args.setResult(args.a() && args.b());
804+
} else {
805+
args.setResult(args.a() * args.b());
806+
}
802807
}
803808
};
804809
Adapter::tree(aTree).combineExtended(Adapter::tree(bTree), Local::op, /*prune=*/false);

openvdb/openvdb/tools/Filter.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,14 @@ Filter<GridT, MaskT, InterruptT>::Avg<Axis>::operator()(Coord xyz)
507507
ValueType sum = zeroVal<ValueType>();
508508
Int32 &i = xyz[Axis], j = i + width;
509509
for (i -= width; i <= j; ++i) filter_internal::accum(sum, acc.getValue(xyz));
510-
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
511-
ValueType value = static_cast<ValueType>(sum * frac);
512-
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
513-
return value;
510+
if constexpr(std::is_same<ValueType, bool>::value) {
511+
return sum && frac > 0.0f;
512+
} else {
513+
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
514+
ValueType value = static_cast<ValueType>(sum * frac);
515+
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
516+
return value;
517+
}
514518
}
515519

516520

openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Combine.cc

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -868,9 +868,13 @@ struct Blend1
868868
aMult(a), bMult(b), ONE(openvdb::zeroVal<ValueT>() + 1) {}
869869
void operator()(const ValueT& a, const ValueT& b, ValueT& out) const
870870
{
871-
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
872-
out = ValueT((ONE - aMult * a) * bMult * b);
873-
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
871+
if constexpr(std::is_same<ValueT, bool>::value) {
872+
out = a && !b;
873+
} else {
874+
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
875+
out = ValueT((ONE - aMult * a) * bMult * b);
876+
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
877+
}
874878
}
875879
};
876880

@@ -888,9 +892,14 @@ struct Blend2
888892
aMult(a), bMult(b), ONE(openvdb::zeroVal<ValueT>() + 1) {}
889893
void operator()(const ValueT& a, const ValueT& b, ValueT& out) const
890894
{
891-
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
892-
out = ValueT(a*aMult); out = out + ValueT((ONE - out) * bMult*b);
893-
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
895+
if constexpr(std::is_same<ValueT, bool>::value) {
896+
out = !a && !b;
897+
} else {
898+
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
899+
out = ValueT(a*aMult);
900+
out = out + ValueT((ONE - out) * bMult*b);
901+
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
902+
}
894903
}
895904
};
896905

@@ -996,36 +1005,39 @@ struct SOP_OpenVDB_Combine::CombineOp
9961005
typename GridT::Ptr resampleToMatch(const GridT& src, const hvdb::Grid& ref, int order)
9971006
{
9981007
using ValueT = typename GridT::ValueType;
999-
const ValueT ZERO = openvdb::zeroVal<ValueT>();
10001008

10011009
const openvdb::math::Transform& refXform = ref.constTransform();
10021010

10031011
typename GridT::Ptr dest;
10041012
if (src.getGridClass() == openvdb::GRID_LEVEL_SET) {
1005-
// For level set grids, use the level set rebuild tool to both resample the
1006-
// source grid to match the reference grid and to rebuild the resulting level set.
1007-
const bool refIsLevelSet = ref.getGridClass() == openvdb::GRID_LEVEL_SET;
1008-
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
1009-
const ValueT halfWidth = refIsLevelSet
1010-
? ValueT(ZERO + this->getScalarBackgroundValue(ref) * (1.0 / ref.voxelSize()[0]))
1011-
: ValueT(src.background() * (1.0 / src.voxelSize()[0]));
1012-
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
1013-
1014-
if (!openvdb::math::isFinite(halfWidth)) {
1015-
std::stringstream msg;
1016-
msg << "Resample to match: Illegal narrow band width = " << halfWidth
1017-
<< ", caused by grid '" << src.getName() << "' with background "
1018-
<< this->getScalarBackgroundValue(ref);
1019-
throw std::invalid_argument(msg.str());
1020-
}
1013+
if constexpr(std::is_floating_point<ValueT>::value) {
1014+
const ValueT ZERO = openvdb::zeroVal<ValueT>();
1015+
1016+
// For level set grids, use the level set rebuild tool to both resample the
1017+
// source grid to match the reference grid and to rebuild the resulting level set.
1018+
const bool refIsLevelSet = ref.getGridClass() == openvdb::GRID_LEVEL_SET;
1019+
OPENVDB_NO_TYPE_CONVERSION_WARNING_BEGIN
1020+
const ValueT halfWidth = refIsLevelSet
1021+
? ValueT(ZERO + this->getScalarBackgroundValue(ref) * (1.0 / ref.voxelSize()[0]))
1022+
: ValueT(src.background() * (1.0 / src.voxelSize()[0]));
1023+
OPENVDB_NO_TYPE_CONVERSION_WARNING_END
1024+
1025+
if (!openvdb::math::isFinite(halfWidth)) {
1026+
std::stringstream msg;
1027+
msg << "Resample to match: Illegal narrow band width = " << halfWidth
1028+
<< ", caused by grid '" << src.getName() << "' with background "
1029+
<< this->getScalarBackgroundValue(ref);
1030+
throw std::invalid_argument(msg.str());
1031+
}
10211032

1022-
try {
1023-
dest = openvdb::tools::doLevelSetRebuild(src, /*iso=*/ZERO,
1024-
/*exWidth=*/halfWidth, /*inWidth=*/halfWidth, &refXform, &interrupt.interrupter());
1025-
} catch (openvdb::TypeError&) {
1026-
self->addWarning(SOP_MESSAGE, ("skipped rebuild of level set grid "
1027-
+ src.getName() + " of type " + src.type()).c_str());
1028-
dest.reset();
1033+
try {
1034+
dest = openvdb::tools::doLevelSetRebuild(src, /*iso=*/ZERO,
1035+
/*exWidth=*/halfWidth, /*inWidth=*/halfWidth, &refXform, &interrupt.interrupter());
1036+
} catch (openvdb::TypeError&) {
1037+
self->addWarning(SOP_MESSAGE, ("skipped rebuild of level set grid "
1038+
+ src.getName() + " of type " + src.type()).c_str());
1039+
dest.reset();
1040+
}
10291041
}
10301042
}
10311043
if (!dest && src.constTransform() != refXform) {

openvdb_houdini/openvdb_houdini/SOP_OpenVDB_Diagnostics.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ struct TestCollection
11861186

11871187
if (mTest.testMinimumBandWidth) {
11881188

1189-
if (std::is_floating_point<ValueType>::value) {
1189+
if constexpr (std::is_floating_point<ValueType>::value) {
11901190
const ValueType width = ValueType(mTest.minBandWidth) * ValueType(voxelSize);
11911191

11921192
AbsLessThan<ValueType> test(width);

openvdb_houdini/openvdb_houdini/SOP_OpenVDB_LOD.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ SOP_OpenVDB_LOD::Cache::cookVDBSop(OP_Context& context)
322322
continue;
323323
}
324324

325-
hvdb::GEOvdbApply<hvdb::VolumeGridTypes>(**it, op);
325+
hvdb::GEOvdbApply<hvdb::NumericGridTypes>(**it, op);
326326

327327
if (boss.wasInterrupted()) return error();
328328

@@ -358,7 +358,7 @@ SOP_OpenVDB_LOD::Cache::cookVDBSop(OP_Context& context)
358358
continue;
359359
}
360360

361-
hvdb::GEOvdbApply<hvdb::VolumeGridTypes>(**it, op);
361+
hvdb::GEOvdbApply<hvdb::NumericGridTypes>(**it, op);
362362

363363
if (boss.wasInterrupted()) return error();
364364

@@ -383,7 +383,7 @@ SOP_OpenVDB_LOD::Cache::cookVDBSop(OP_Context& context)
383383
continue;
384384
}
385385

386-
hvdb::GEOvdbApply<hvdb::VolumeGridTypes>(**it, op);
386+
hvdb::GEOvdbApply<hvdb::NumericGridTypes>(**it, op);
387387

388388
if (boss.wasInterrupted()) return error();
389389

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improvements:
2+
- Fix int-in-bool-context GCC9+ warnings by switching to use constexpr if.

0 commit comments

Comments
 (0)