Skip to content

Commit 45a9d11

Browse files
committed
Check for NANs when computing distances to avoid infinite loops
with bad input geometry. Rename the computeDistance to updateDistance to better reflect its behaviour. Signed-off-by: jlait <[email protected]>
1 parent e4a8211 commit 45a9d11

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

openvdb/tools/MeshToVolume.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,10 @@ class VoxelizePolygons
21372137
ijk = Coord::floor(prim.a);
21382138
coordList.push_back(ijk);
21392139

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

21422145
unsigned char primId = data.getNewPrimId();
21432146
data.primIdAcc.setValueOnly(ijk, primId);
@@ -2150,13 +2153,13 @@ class VoxelizePolygons
21502153
nijk = ijk + util::COORD_OFFSETS[i];
21512154
if (primId != data.primIdAcc.getValue(nijk)) {
21522155
data.primIdAcc.setValueOnly(nijk, primId);
2153-
if(computeDistance(nijk, prim, data)) coordList.push_back(nijk);
2156+
if(updateDistance(nijk, prim, data)) coordList.push_back(nijk);
21542157
}
21552158
}
21562159
}
21572160
}
21582161

2159-
static bool computeDistance(const Coord& ijk, const Triangle& prim, VoxelizationDataType& data)
2162+
static bool updateDistance(const Coord& ijk, const Triangle& prim, VoxelizationDataType& data)
21602163
{
21612164
Vec3d uvw, voxelCenter(ijk[0], ijk[1], ijk[2]);
21622165

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

2171+
// Either the points may be NAN, or they could be far enough from
2172+
// the origin that computing distance fails.
2173+
if (std::isnan(dist))
2174+
return false;
2175+
21682176
const ValueType oldDist = data.distAcc.getValue(ijk);
21692177

21702178
if (dist < oldDist) {

0 commit comments

Comments
 (0)