Wed, 04/26/2017 - 09:42
In my application now I use freecadcmd to read the stl 's width、height、volume and area, and the code is bellow:
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:
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. Is there any problemes in my c++ code ?
Forgive me but I don't use c++ very well , can anyone explain why the difference of speed is so big?
Wed, 04/26/2017 - 19:43
Hi,
I assume your Python code works with the mesh data without topology creation. OCCT reads the STL file and creates a TopoDS_Shape from it. Most of the time and memory will be used by building the topology from the mesh.
Thu, 04/27/2017 - 04:43
You are right, The method RWStl::ReadFile(aFile); is read a stl file to a StlMesh_Mesh, and the other code conver StlMesh_Mesh to TopoDS_Shape so spend a lot of time. MayBe I don't need to convert StlMesh_Mesh to TopoDS_Shape, because all I need to do is calculate the volume and the area and width、height and length, but I can't find api to calculate a StlMesh_Mesh. just like BRepGProp::SurfaceProperties(shape, system);.
Thu, 04/27/2017 - 06:50
Hello, there is no such API. You have to use RWStl::ReadFile(aFile) to get mesh.
qa qa