Skip to content

Commit

Permalink
Merge pull request #3 from sideeffects/ovdb_27
Browse files Browse the repository at this point in the history
Check for NANs when computing distances to avoid infinite loops
  • Loading branch information
jmlait authored Feb 8, 2019
2 parents e4a8211 + 45a9d11 commit ca07bac
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions openvdb/tools/MeshToVolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -2137,7 +2137,10 @@ class VoxelizePolygons
ijk = Coord::floor(prim.a);
coordList.push_back(ijk);

computeDistance(ijk, prim, data);
// The first point may not be quite in bounds, and rely
// on one of the neighbours to have the first valid seed,
// so we cannot early-exit here.
updateDistance(ijk, prim, data);

unsigned char primId = data.getNewPrimId();
data.primIdAcc.setValueOnly(ijk, primId);
Expand All @@ -2150,13 +2153,13 @@ class VoxelizePolygons
nijk = ijk + util::COORD_OFFSETS[i];
if (primId != data.primIdAcc.getValue(nijk)) {
data.primIdAcc.setValueOnly(nijk, primId);
if(computeDistance(nijk, prim, data)) coordList.push_back(nijk);
if(updateDistance(nijk, prim, data)) coordList.push_back(nijk);
}
}
}
}

static bool computeDistance(const Coord& ijk, const Triangle& prim, VoxelizationDataType& data)
static bool updateDistance(const Coord& ijk, const Triangle& prim, VoxelizationDataType& data)
{
Vec3d uvw, voxelCenter(ijk[0], ijk[1], ijk[2]);

Expand All @@ -2165,6 +2168,11 @@ class VoxelizePolygons
const ValueType dist = ValueType((voxelCenter -
closestPointOnTriangleToPoint(prim.a, prim.c, prim.b, voxelCenter, uvw)).lengthSqr());

// Either the points may be NAN, or they could be far enough from
// the origin that computing distance fails.
if (std::isnan(dist))
return false;

const ValueType oldDist = data.distAcc.getValue(ijk);

if (dist < oldDist) {
Expand Down

0 comments on commit ca07bac

Please sign in to comment.