Skip to content

Commit 305090c

Browse files
committed
surfunstructured: use a better estimate of the number of vertices when importing an STL
1 parent 337d43a commit 305090c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/surfunstructured/surfunstructured.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,22 @@ int SurfUnstructured::importSTL(const std::string &filename, STLReader::Format f
465465
}
466466

467467
// Generate patch cells from STL facets
468-
reserveVertices(getVertexCount() + nFacetVertices * nFacets);
469468
reserveCells(getCellCount() + nFacets);
470469

470+
std::size_t nEstimatedVertices;
471+
if (joinFacets) {
472+
// The number of facets and the number of vertices of a triangulation
473+
// are related by the inequality nFacets <= 2 * nVertices - 4, where
474+
// the equality holds for a closed triangulation. To limit memory usage
475+
// we estimate the number of vertices assuming a closed triangulation
476+
// (this gives us the minimum number of nodes the triangulation could
477+
// possibly have).
478+
nEstimatedVertices = 0.5 * nFacets + 2;
479+
} else {
480+
nEstimatedVertices = nFacetVertices * nFacets;
481+
}
482+
reserveVertices(getVertexCount() + nEstimatedVertices);
483+
471484
vertexCache.clear();
472485

473486
for (std::size_t n = 0; n < nFacets; ++n) {

0 commit comments

Comments
 (0)