Very slow extrusion speed and too much memory consumption


I am testing "opencascade-7.0.0-vc12-64" for large models. As a test I extrude a closed polygonal face with 24 vertices using the BRepPrimAPI_MakePrism class. Creating and displaying 24000 translated version of the same entity takes about 14 minutes and the program uses about 5.5GB of memory.  With another geometric kernel it only takes about 13 seconds and 1 GB of memory to create and display exactly the same 3D model.

The code to create a single solid object is below. I call it in a loop for a lattice of nonoverlapping 3D positions. I wrote the code based on the samples in the package and in this forum. I need some help on creating the model in a faster way.

void CreateBeam(const std::vector<FPoint2d> &points, double x, double y, double z, double thickness, COcDocument &ocDocument)

 BRepBuilderAPI_MakePolygon polygon;
 for (size_t i = 0; i < points.size(); ++i)
  polygon.Add(gp_Pnt(points[i].x, points[i].y, 0));
 TopoDS_Wire wire = polygon.Wire();
 TopoDS_Face face = BRepBuilderAPI_MakeFace(wire, Standard_True);
 TopoDS_Shape shape = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, 1 * thickness), Standard_False, Standard_False);

 gp_Trsf trans;
 trans.SetTranslationPart(gp_Vec(x, y, z));
 TopLoc_Location location(trans);

 Handle(AIS_Shape) ais1 = new AIS_Shape(shape);
 ocDocument.GetAISContext()->Display(ais1, Standard_False);

Laszlo Kudela's picture

Hi Ali,

If you are trying to display 24000 shapes one by one, it is for sure going to be a performance penalty. I would separate the creation of the shapes from actually displaying.

Try the following:

- First create the 24000 shapes, and merge them into a TopoDS_Compound

- Then pass the resulting compound shape to the AIS context for displaying

I'm sure it would still require a lot of resource (both CPU- and memorywise), but it might run a bit faster this way.


Forum supervisor's picture

Dear Ali,

You can see our CAD Assistant application efficiently processing complex assemblies and communicate us via Contact Form for support in your projects.

Additionally to the answer of Laszlo Kudela please see some suggestion and test results. If all objects are geometrically same then it is more correct to create only one prism object and then make its instancing using location.

Our test TCL script for your case using this approach and actual OCCT from master branch gives the following timing and memory usage (see below output). Creation of compound from 24000 instances of the same object (solid prism built from 24 polygon face) takes less than a second. Visualization of the compound of all objects takes about 26 seconds. 

Output :

creating single compound of translated prisms

Elapsed time: 0 Hours 0 Minutes 0.283153153025 Seconds

CPU user time: 0.28125 seconds

CPU system time: 0 seconds

  Private memory:     50 MiB

  Working Set:        73 MiB (peak: 73 MiB)

  Pagefile usage:     50 MiB (peak: 50 MiB)

  Virtual memory:     245 MiB

  Heap memory:     15 MiB



Elapsed time: 0 Hours 0 Minutes 27.0920447665 Seconds

CPU user time: 25.984375 seconds

CPU system time: 1.140625 seconds

  Private memory:     775 MiB

  Working Set:        697 MiB (peak: 2240 MiB)

  Pagefile usage:     775 MiB (peak: 2266 MiB)

  Virtual memory:     1412 MiB

  Heap memory:     540 MiB


Best regards, FSR

ry rys's picture

how to "create only one prism object and then make its instancing using location"? i can not find the function to set coordinate,,,
There are 3,000 circles and their center coordinates and radius.How to do?

occt noob need help!

Ali Erol's picture

Thanks for the replies. I am working on a new implementation based on your suggestions. The 24000 instances are not all the same. The length of extrusion and the polygons shape changes but I will try to group them into different shapes. I don't expect to get more than 1000 different prisms.

Thanks and Regards