For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings

 

Need to speed up your development?
Have a look at our:

Samples & Tools

 

Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Stl Import

Teguetio's picture
Forums: 

Hey!!
i'm currently working with .stl Format and i would be very thankful if anyone helps with tips about importing a STL file in Opencascade as fast as possible. i've used the STLReader from the OCC library,but it seems very slow and use a lot of memory.
Thanks for any advice.

QbProg's picture

1) The STL file format is *VERY* simple, you should be able to read it by yourself.
2) Put the data you read into a Poly_Triangulation structure (easy to manage) and use as you want!

:) Bye

Teguetio's picture

Hallo Thomas..
Thanks for your advices.please could u give me more infos about it?i have never worked with the Poly_Triangulation structure you've talked about.
Thanks and best regards.

QbProg's picture

The poly_triangulation stores 2 informations: the vertexs of the triangles (Nodes array) and the triangles. Each triangle contains three indexs, one per vertex, that refer to the vertexs array.
You need to create a [Handle]Poly_Triangulation passing the number of the triangles and vertexs (triangles *3). Then you just load the vertexs and then the triangles with the right values.
A simple-unoptimized way if you don't need poly_connect:
Handle(Poly_Triangulation) T = new Poly_Triangulation(Tri_Num, TriNum*3); (or inverted)
for (i = 1; i T->Nodes(i*3)->SetValue(STLTriangle[i]) [i-1 if it is 0 based]
T->Nodes(i*3+1)->SetValue(STLTriangle[i])
T->Nodes(i*3+2)->SetValue(STLTriangle[i])
T->Triangles(i)->Set(i*3,i*3+1,i*3+2)
}

It's the same old Vertexs-Indexs structure :O)
If you have time, do it in the right way : instead of adding each vertex, try to avoid to insert it if it is duplicate.Doing so allow you to use Poly_Connect that gives some usefoul informations (like the triangles belonging to a vertex).

Creating a TOPODS_Shell or Compound using the facets it's possible (and easier to display), but ... why ? :)

Sorry for my english, I hope you understand this !

Teguetio's picture

hi Thomas..

Thanks....I'll try!!don't worry about your english.I'm also not that good..:-)

Patrik Müller's picture

Hi Thomas,

you could also just use Handle(StlMesh_Mesh) and RWStl to read STL files. After that you can get the triangles with an StlMesh_MeshExplorer. So there is no need to use a Poly_Triangulation structure!

Greets,

Patrik

Teguetio's picture

Hi Patrick...

Some codes would be welcome.:-)

Thanks!

Patrik Müller's picture

No problem - just look here:

http://www.opencascade.org/org/forum/thread_3145/

there should be enough infos how to use it ;-)

Greets,

Patrik

Teguetio's picture

Hey Patrick....

Thanks a lot..that's what i initially used. I'm trying now to improved it by using the Poly_Triangulation.Some argue it could be faster!

best regards.

Patrik Müller's picture

Hi,

if you just need it for visualization I would recommend other ways:
1) use a MeshVS structure (I haven't used it - but you find a good example in the "ros\src\XSDRAWSTLVRML" folder
2) derive a class from AIS_InteractiveObject for meshes - thats the way I've done it

Greets,

Patrik

QbProg's picture

MeshVS works really great on 6.1 , and deriving the MeshVS_DataSource is simplier than it appears on the example :) you need just 20 lines of code! (in 5.2.0 didn't worked very well!)

A standard implementation (based on Poly_Triangulation) would be usefoul since that format is the result of the Mesh function !
It seems that MeshVS is much more advanced , but the lack of detailed documentation makes it impossible to use :(

Yogesh Dhakad's picture

Hi Patrik,

My app needs to just visualize the STL file read in. I compared the timings and the method you suggested (RWStl::ReadFile) refer forum http://www.opencascade.org/org/forum/thread_3145/ works just fine and is much faster that than StlAPI::Read(). I also checked the timings with OMF (OpenCascade Mesh Framework) and it was significantly low. Here are my readings.
For a STL file of size 20MB;
StlAPI::Read() is just hopeless and does not come out for 10+ mins.
RWStl::ReadFile() does the job in @2 mins
OMF does the same job in 16 secs.

If you don't mind, could you share the code / implementation ideas on #2 mentioned (derive a class from AIS_InteractiveObject). What is the gain in the speed of opening the STL file?

Thanks in Advance,
Yogesh

Patrik Müller's picture

Hi Yogesh,

as I wrote my kind of "AIS_Mesh" there was no OMF and no MeshVS - so its old code. I use it also for displaying other formats like 3DS.
It wasn't only the displaying speed - my main interest was reducing memory size.
I'm not sure about sharing code - what exactly are oyu interested in?

Greets,

Patrik