StlMesh_MeshExplorer slow destructor?


I have a STL file with 379836 triangles. I use "StlMesh_MeshExplorer" to iterate through the triangles. When my StlMesh_MeshExplorer leaves the scope it takes ~1-2 Minutes until the debugger returns and moves on. Why takes the destructor of "StlMesh_MeshExplorer" so long?

Here is my sample code:

const Handle_StlMesh_Mesh & aStlMesh = _Mesh;
Standard_Integer NumberDomains = aStlMesh->NbDomains();
Standard_Real x1, x2, x3, y1, y2, y3, z1, z2, z3,xn,yn,zn;
StlMesh_MeshExplorer aMExp(aStlMesh);
for(int i=1; i {
for(aMExp.InitTriangle(i); aMExp.MoreTriangle(); aMExp.NextTriangle())

I am using oce-0.11 (based on OCCT 6.5.4)


jelle's picture

StlMesh is suboptimal if you just want to render some mesh.
It converts the mesh to BRep, which is why its *so* slow...
Take a look at this thread
And the XSDRAWSTL* classes...

In my experience you'll be able to load / render an order of magnitude faster, so worth to take a look into this matter


Thorsten H's picture

I enumerate the vertices in order to calculate the gravity center an some other data. No need to render anything. The solution I have found is to completly set StlMesh_MeshExplorer aside:

int domainCount = aStlMesh->NbDomains();
for(int domainIndex = 1; domainIndex <= domainCount; domainIndex++)
int triangleCount = aStlMesh->NbTriangles(domainIndex);
const StlMesh_SequenceOfMeshTriangle & triangles = aStlMesh->Triangles(domainIndex);
const TColgp_SequenceOfXYZ & vertices = aStlMesh->Vertices(domainIndex);
for (int triangleIndex = 1; triangleIndex <= triangleCount; triangleIndex++)
const Handle_StlMesh_MeshTriangle & triangle = triangles.Value(triangleIndex);
int v1, v2, v3;
triangle->GetVertexAndOrientation(v1, v2, v3, xn, yn, zn);
const gp_XYZ & p1 = vertices.Value(v1);
const gp_XYZ & p2 = vertices.Value(v2);
const gp_XYZ & p3 = vertices.Value(v3);

// and so on...