why opencascade' speed to read stl file not as fast as freecad

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
451813447@qq.com
Posts: 2
Joined: Thu Aug 11, 2016 7:10 am

why opencascade' speed to read stl file not as fast as freecad

Post by 451813447@qq.com »

In my application now I use freecadcmd to read the stl 's width、height、volume and area, and the code is bellow:

Code: Select all

import sys, Mesh, string, json,os
from FreeCAD import Base
filename = sys.argv[2]
name_arr = filename.split('.')
mesh = Mesh.Mesh(filename)
obj["area"] = mesh.Area
obj["volume"] = mesh.Volume
as it as ap.py and call it by : freecadcmd ab.py xxxx.stl

But now I want to use occ , and the c++ code is bellow:

Code: Select all

int main(int argc, char *argv[]){
    if(argc <= 1){
        std::cout<<"occstl wrong arguments count!"<<std::endl;
        return -1;
    }
    Standard_CString aFileName = argv[1];
    TopoDS_Shape shape;
    StlAPI_Reader reader;
    reader.Read(shape,aFileName);
    GProp_GProps system;
    BRepGProp::VolumeProperties(shape, system);
    Standard_Real volume = system.Mass();
    std::cout<<"volume:"<<std::to_string(volume)<<std::endl;
    BRepGProp::SurfaceProperties(shape, system);
    Standard_Real area = system.Mass();
    std::cout<<"Area:"<<std::to_string(area)<<std::endl;
}
Then I use the same stl file , the app use freecadcmd cost three second, but the occ c++ code cost about 2 minutes.



Forgive me but I don't use c++ very well , can anyone explain why the difference of speed is so big?
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: why opencascade' speed to read stl file not as fast as freecad

Post by ickby »

FreeCAD does not use OCC for mesh handling but has its own mesh data structure. Hence you compare two totally different implementations.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: why opencascade' speed to read stl file not as fast as freecad

Post by wmayer »

StlAPI_Reader reader;
reader.Read(shape,aFileName);
This does much more than just reading in the data. It also converts the mesh into a topo shape which is a very expensive operation. You can compare with the function "Create shape from mesh" in the Part workbench.
451813447@qq.com
Posts: 2
Joined: Thu Aug 11, 2016 7:10 am

Re: why opencascade' speed to read stl file not as fast as freecad

Post by 451813447@qq.com »

Thinks you two , very very much !
Post Reply