Bugfix: Fixed corrupted point field on stitch

This commit is contained in:
Hrvoje Jasak 2015-09-18 12:03:07 +01:00
parent e1b0c33611
commit 9e29f21409

View file

@ -46,17 +46,12 @@ bool triSurface::stitchTriangles
pointField newPoints; pointField newPoints;
bool hasMerged = mergePoints(rawPoints, tol, verbose, pointMap, newPoints); bool hasMerged = mergePoints(rawPoints, tol, verbose, pointMap, newPoints);
pointField& ps = storedPoints();
// Set the coordinates to the merged ones
ps.transfer(newPoints);
if (hasMerged) if (hasMerged)
{ {
if (verbose) if (verbose)
{ {
Pout<< "stitchTriangles : Merged from " << rawPoints.size() Pout<< "stitchTriangles : Merged from " << rawPoints.size()
<< " points down to " << ps.size() << endl; << " points down to " << newPoints.size() << endl;
} }
// Reset the triangle point labels to the unique points array // Reset the triangle point labels to the unique points array
@ -72,7 +67,12 @@ bool triSurface::stitchTriangles
tri.region() tri.region()
); );
if ((newTri[0] != newTri[1]) && (newTri[0] != newTri[2]) && (newTri[1] != newTri[2])) if
(
(newTri[0] != newTri[1])
&& (newTri[0] != newTri[2])
&& (newTri[1] != newTri[2])
)
{ {
operator[](newTriangleI++) = newTri; operator[](newTriangleI++) = newTri;
} }
@ -82,11 +82,12 @@ bool triSurface::stitchTriangles
<< "Removing triangle " << i << "Removing triangle " << i
<< " with non-unique vertices." << endl << " with non-unique vertices." << endl
<< " vertices :" << newTri << endl << " vertices :" << newTri << endl
<< " coordinates:" << newTri.points(ps) << " coordinates:" << newTri.points(newPoints)
<< endl; << endl;
} }
} }
// If empty triangles are detected, remove them from the list
if (newTriangleI != size()) if (newTriangleI != size())
{ {
if (verbose) if (verbose)
@ -97,12 +98,12 @@ bool triSurface::stitchTriangles
} }
setSize(newTriangleI); setSize(newTriangleI);
// And possibly compact out any unused points (since used only // Possibly compact out any unused points (since used only
// by triangles that have just been deleted) // by triangles that have just been deleted)
// Done in two passes to save memory (pointField) // Done in two passes to save memory (pointField)
// 1. Detect only // 1. Detect only
PackedBoolList pointIsUsed(ps.size()); PackedBoolList pointIsUsed(newPoints.size());
label nPoints = 0; label nPoints = 0;
@ -120,20 +121,20 @@ bool triSurface::stitchTriangles
} }
} }
if (nPoints != ps.size()) if (nPoints != newPoints.size())
{ {
// 2. Compact. // 2. Compact.
pointMap.setSize(ps.size()); pointMap.setSize(newPoints.size());
label newPointI = 0; label newPointI = 0;
forAll(pointIsUsed, pointI) forAll(pointIsUsed, pointI)
{ {
if (pointIsUsed[pointI]) if (pointIsUsed[pointI])
{ {
ps[newPointI] = ps[pointI]; newPoints[newPointI] = newPoints[pointI];
pointMap[pointI] = newPointI++; pointMap[pointI] = newPointI++;
} }
} }
ps.setSize(newPointI); newPoints.setSize(newPointI);
newTriangleI = 0; newTriangleI = 0;
forAll(*this, i) forAll(*this, i)
@ -149,6 +150,9 @@ bool triSurface::stitchTriangles
} }
} }
} }
// Set the coordinates to the merged ones
storedPoints().transfer(newPoints);
} }
return hasMerged; return hasMerged;