STL import

Hey...
could anybody help me???i have a Shape stored in a STL file and i would like to load it as fast as possible into a viewer.any idea?
pliz help.

Pawel's picture

Search the forum...

You could try this:
http://www.opencascade.org/org/forum/thread_9699/

PK

Anton Shabalin's picture

Thanks Pawel..i did it but its quite slow...any idea about a faster codes?
Freeman.

Pawel's picture

Reading a file is not a problem - it's fast enough. Just use:

Handle_StlMesh_Mesh theStlMesh = RWStl::ReadFile(thePath);

You can display a mesh quite fast if you use MeshVS:

Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( theStlMesh );

aMesh->SetDataSource(aDS);

aMesh->GetDrawer()->SetBoolean(MeshVS_DA_DisplayNodes,Standard_False); //MeshVS_DrawerAttribute
aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh.operator->() ), Standard_True );

myAISContext->Display(aMesh);

However it is still a wireframe model... I can't get over it. I'm planning to do some node reduction of the almost cooplanar faces in the mesh and the display it as a sewed (and possibly shaded) TopoShape (otherwise it's to slow). If someone has any other suggestions I would appreciate them.

Another issue is memory consumption either by meshes or topos... Some hints would be appreciated as well.

PK

Anton Shabalin's picture

Hi Pavel...
thanks for this approach.
Ok i'll start working on it.Another approach could be to use the PolyTriangulation class to split the Shape into an Array of triangles, and then used the sewing Class to gain a TopoDS_Shape from the array which could make things faster, and allow Boolean operations and other useful issues.I'm still exploring this possibility..the problem is that the sources of this class are not documented at all!
Freeman.

Pawel's picture

Sewing more than 20000 triangles and displaying them is not a good idea (at least with OC). It's totally slow. I've tried that. That's why I want to do the reduction of the nodes/faces.

PK

Marcel Janer's picture

I write about the reason that MeshVS_Mesh, XSDRAWSTLVRML_DataSource and MeshVS_MeshPrsBuilder aproach, only displays in WireFrame. I've token a look in occ source code (visualitzation.sln), and I've seen that can display in shade mode, the problem is that member MeshVS_Mesh::Compute(..) the argument "theMode" has lose its value, and always is 0, for this reason allways display as wireframe. Does anybody know how to solve this instead to change by a constant 2 the call of aCurrent->Build ( thePresentation, anElements, Standard_True, 2 /*theMode*/);?

the stl load and shading render is very fast!

best regards,

marcel janer.

Marcel Janer's picture

I write about the reason that MeshVS_Mesh, XSDRAWSTLVRML_DataSource and MeshVS_MeshPrsBuilder aproach, only displays in WireFrame. I've token a look in occ source code (visualitzation.sln), and I've seen that can display in shade mode, the problem is that member MeshVS_Mesh::Compute(..) the argument "theMode" has lose its value, and always is 0, for this reason allways display as wireframe. Does anybody know how to solve this instead to change by a constant 2 the call of aCurrent->Build ( thePresentation, anElements, Standard_True, 2 /*theMode*/);?

the stl load and shading render is very fast!

best regards,

marcel janer.

Marcel Janer's picture

you can do:

for fast load and render, in shade mode:
------------------------------

Handle(StlMesh_Mesh) aSTLMesh = RWStl::ReadFile(aFile);
Handle( MeshVS_Mesh ) aMesh = new MeshVS_Mesh();
Handle( XSDRAWSTLVRML_DataSource ) aDS = new XSDRAWSTLVRML_DataSource( aSTLMesh );

aMesh->SetDataSource(aDS);
aMesh->AddBuilder( new MeshVS_MeshPrsBuilder( aMesh), Standard_True );//False -> No selection

aMesh->GetDrawer()->SetBoolean(MeshVS_DA_DisplayNodes,Standard_False); //MeshVS_DrawerAttribute
aMesh->GetDrawer()->SetBoolean(MeshVS_DA_ShowEdges,Standard_False);
aMesh->GetDrawer()->SetMaterial(MeshVS_DA_FrontMaterial,DEFAULT_MATERIAL);

aMesh->SetColor(Quantity_NOC_AZURE);
aMesh->SetDisplayMode( MeshVS_DMF_Shading ); // Mode as defaut
aMesh->SetHilightMode( MeshVS_DMF_WireFrame ); // Wireframe as default hilight mode

myDoc->m_AISContext->Display(aMesh);

-----------------------

Marcel Janer.

Pawel's picture

Great post. I've been looking for it a long time.

Thanks
Pawel