The read speed of read_stl_file(filename)

Forums: 

OCC.Extend.DataExchange module
read_stl_file(filename)
opens a stl file, reads the content, and returns a BRep topods_shape object

I thought this method is too slow to read a STL file, when it's come to 100M.

Has anyone found and solved this problem, thanks you.

Attachments: 
Kirill Gavrilov's picture

STL stores unstructured triangulation data. B-Rep generated out of triangles is very heavy and slow to process.

But if the purpose of this import is displaying mesh in 3D viewer, then you may import it as triangulation rather than B-Rep, which should be considerably faster.

#!/usr/bin/env python

import sys,os

from OCC.Display.SimpleGui import init_display
from OCC.Core.AIS import *
from OCC.Core.Aspect import *
from OCC.Core.BRep import *
from OCC.Core.Geom import *
from OCC.Core.gp import *
from OCC.Core.Graphic3d import *
from OCC.Core.Prs3d import *
from OCC.Core.RWStl import *
from OCC.Core.TopoDS import *
from OCC.Core.Quantity import *

from OCC.Display.SimpleGui import init_display

# read STL file
aTris    = rwstl_ReadFile('/home/occt-7.5.2.git/data/stl/bearing.stl')
aShape   = TopoDS_Face()
aBuilder = BRep_Builder()
aBuilder.MakeFace (aShape, aTris)

# initialize built-in viewer
aDisplay, start_display, add_menu, add_function_to_menu = init_display()

aShapePrs = AIS_Shape (aShape)
aShapePrs.Attributes().SetupOwnShadingAspect()
aShapePrs.SetColor (Quantity_Color (Quantity_NOC_CADETBLUE))
aFillAspect = aShapePrs.Attributes().ShadingAspect().Aspect()
#aFillAspect.SetShadingModel (Graphic3d_TypeOfShadingModel.Graphic3d_TOSM_FACET)
aDisplay.Context.Display (aShapePrs, False)
aDisplay.View.FitAll()

# show viewer
start_display()
joe zou's picture

Thanks you for your answer.
I found this issue in Github
https://github.com/tpaviot/pythonocc-core/issues/1021

joe zou's picture

Besides, when I run tihs file, it report ImportError: DLL load failed while importing _Aspect.
I want to know if I use the wrong version of PythonOCC.

Kirill Gavrilov's picture

My version is called "pythonocc-7.5.2". There is no yet release ported to OCCT 7.6 as far as I know.

joe zou's picture

How could I get "pythonocc-7.5.2", I notice that ''pythonocc-core 7.5.1'' is the latest release version.

Kirill Gavrilov's picture

I don't think there is a much of difference between 7.5.1/7.5.2, as 7.5.2 is just a bug-fix release. Maybe I was wrong identifying my local build as 7.5.2.

joe zou's picture

OK, thanks a lot.

joe zou's picture

hi, I found that this method always take up the main thread, which prevents us from doing anything else. no matter I use multiple threads or multiple processes that cannot be changed. I wonder if it is related to the implementation of this method, thank you!

Kirill Gavrilov's picture

I found that this method always take up the main thread

OCCT doesn't do any thread management here - whatever thread is calling this method, this thread will be busy doing the job, as calling any other algorithm.

Moving jobs into a background thread(s) should be done at application level.

Mr JohnWhite's picture