@@ -264,10 +264,27 @@ PolySoupToLevelSet<GridType>::PolySoupToLevelSet(PolySoup &&poly, int dim, float
264264 if constexpr (!std::is_floating_point<typename GridType::ValueType>::value) {
265265 OPENVDB_THROW (TypeError, " polySoupToLevelSet: supported only for scalar floating-point grids" );
266266 }
267+ if (!(mHalfWidth > 0 .0f )) {
268+ OPENVDB_THROW (ValueError, " polySoupToLevelSet: halfWidth must be positive" );
269+ }
267270 if (!mPoly .bbox ) mPoly .bbox = PolySoupToLevelSet::getBBox (mPoly .vtx );
271+ // The largest extent is what the algorithm divides by; requiring it to be
272+ // positive rejects both empty geometry (an unpopulated bbox has a negative
273+ // extent) and a single degenerate point, while still allowing a flat/planar
274+ // mesh (zero extent along one axis is fine for shrink wrapping).
268275 const float maxLength = mPoly .bbox .extents ()[mPoly .bbox .maxExtent ()];
276+ if (!(maxLength > 0 .0f )) {
277+ OPENVDB_THROW (ValueError, " polySoupToLevelSet: bounding box has non-positive extent (no input geometry?)" );
278+ }
269279 mMinVoxelSize = maxLength/(float (dim) - 2 .0f *(mHalfWidth + 1 .0f ));// +1 since final surface is dilated by dx
270280 mMaxVoxelSize = maxLength / 2 .0f ;
281+ // A too-small dim relative to halfWidth drives the denominator above to zero
282+ // or negative, yielding a non-finite or non-positive voxel size.
283+ if (!math::isFinite (mMinVoxelSize ) || !(mMinVoxelSize > 0 .0f ) ||
284+ !math::isFinite (mMaxVoxelSize ) || !(mMaxVoxelSize > 0 .0f )) {
285+ OPENVDB_THROW (ArithmeticError, " polySoupToLevelSet: computed voxel size is not "
286+ " finite and positive (is dim too small for the given halfWidth?)" );
287+ }
271288 OPENVDB_ASSERT (2 *mMinVoxelSize <= mMaxVoxelSize );
272289}// tools::PolySoupToLevelSet::PolySoupToLevelSet()
273290
@@ -280,9 +297,23 @@ PolySoupToLevelSet<GridType>::PolySoupToLevelSet(PolySoup &&poly, float voxelSiz
280297 if constexpr (!std::is_floating_point<typename GridType::ValueType>::value) {
281298 OPENVDB_THROW (TypeError, " polySoupToLevelSet: supported only for scalar floating-point grids" );
282299 }
300+ if (!(mHalfWidth > 0 .0f )) {
301+ OPENVDB_THROW (ValueError, " polySoupToLevelSet: halfWidth must be positive" );
302+ }
303+ if (!math::isFinite (mMinVoxelSize ) || !(mMinVoxelSize > 0 .0f )) {
304+ OPENVDB_THROW (ValueError, " polySoupToLevelSet: voxelSize must be finite and positive" );
305+ }
283306 if (!mPoly .bbox ) mPoly .bbox = PolySoupToLevelSet::getBBox (mPoly .vtx );
307+ // See note in the dim-based constructor: the largest extent must be positive
308+ // (rejects empty/degenerate geometry) but a flat/planar mesh is allowed.
284309 const float maxLength = mPoly .bbox .extents ()[mPoly .bbox .maxExtent ()];
310+ if (!(maxLength > 0 .0f )) {
311+ OPENVDB_THROW (ValueError, " polySoupToLevelSet: bounding box has non-positive extent (no input geometry?)" );
312+ }
285313 mMaxVoxelSize = maxLength / 2 .0f ;
314+ if (!math::isFinite (mMaxVoxelSize ) || !(mMaxVoxelSize > 0 .0f )) {
315+ OPENVDB_THROW (ArithmeticError, " polySoupToLevelSet: computed voxel size is not finite and positive" );
316+ }
286317 OPENVDB_ASSERT (2 *mMinVoxelSize <= mMaxVoxelSize );
287318}// tools::PolySoupToLevelSet::PolySoupToLevelSet()
288319
0 commit comments