Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for NANs when computing distances to avoid infinite loops #3

Merged
merged 1 commit into from
Feb 8, 2019
Merged
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
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