Slow performance with many primitive shapes

Dear All,

My purpose was to testify the performance of OCCT with many primitive shapes I use MFC application with the following code to create the 4000 spheres, I don't think that 4K shapes is huge amount in nowadays computers but performance is really slow, around 3-4minutes. I also noticed that spheres are added to scene one by one without any buffering, I believe that main bottleneck is due to that. What can I do to improve it ?

void CMFC_TestView::ButtonClick()
{

for (int i= 0; i {
srand((unsigned) time(NULL));
gp_Vec loc_v(rand()%100,rand()%1000,3);
GetDocument()->DrawSphere(10, loc_v);
}
myView->FitAll();
}

void CMFC_TestDoc::DrawSphere(int Radius, gp_Vec loc_vec)
{
BRepPrimAPI_MakeSphere mkSphere(Radius);
TopoDS_Shape Sphere=mkSphere.Shape();

gp_Trsf trans; // Создаем преобразование
gp_Vec shift(-100, 20, 30.); // Вектор сдвига
trans.SetTranslation(loc_vec);// Преобразование сдвига
Sphere.Location(TopLoc_Location(trans));

myAISContext->Display(new AIS_Shape(Sphere) ); // Draw the Sphere on the Screen
myAISContext->SetLocation(new AIS_Shape(Sphere),TopLoc_Location(trans));
}

Shing Liu's picture

Hello Sonya,

I found your DrawSphere() function, it actually create ais shape twice.
I think your code could change to:

gp_Ax2 anAxis;

anAxis.Translate(loc_vec);

BRepPrimAPI_MakeSphere aMkSphere(anAxis, Radius);
TopoDS_Shape aSphere = aMkSphere.Shape();

myAISContext->Display(new AIS_Shape(aSphere), Standard_False);

Best Regards,
Shing Liu

Sonya's picture

Hi Shing,

Thank You very much in advance, your suggestion slightly improved the performance (approx 1 min for 4K spheres) but I'd expect more than that because other 3D visualization libraries(e.g. OSG) are loading huge data 10K in 5-6 secs. So I'd like to know whether it is the best OCCT can do or am I missing something obvious with performance configuration?

Regards,

Shing Liu's picture

Hi Sonya,

I think other 3D visualization libraries(such as OSG) only load the visualization data of the model and render it, so maybe faster than occ.

In occ, first take time to build the TopoDS_Shape by BRepPrimAPI_MakeSphere;
Then in order to render the shape, it should generate visualization data for
the shape(mesh the shape), this may take a longer time;
The last display the mesh data.

Best Regards,
Shing Liu

Timo Roth's picture

The problem is that you update the scene every time you add a sphere in your loop, because the second parameter of myAISContext->Display(), which controls update, defaults to true.

See http://dev.opencascade.org/doc/refman/html/class_a_i_s___interactive_con...
Display ((const Handle< AIS_InteractiveObject > &anIobj, const Standard_Boolean updateviewer=Standard_True)

So, setting this parameter to false, and calling myAISContext->UpdateCurrentViewer() or something similar after your loop should improve the performace.

Regards

Sonya's picture

Thanks for pointing out that, I noticed that and I corrected it after Shing's suggestion, this is what I meant with "slight performance improvement". It'd be a better if we talk in terms of FPS, otherwise performance may be a relative entity to compare.

Would you mind sharing your FPS for 10K, 20K, 30K simple primitives ? I'll also will testify and report it here.

Regards,

Forum supervisor's picture

Dear Sonia,
Most of time in this test is most likely spent not for display, but for tessellation of spheres. Note that OCCT uses generic tessellator which is applicable to any geometry. Other 3D visualization library (OSG or else) may tessellate sphere analytically, this will naturally work much faster.
OCCT 6.8.0 includes sample displaying and animating a scene containing 1000 spheres, tessellated with rather high quality (overall 2.5 million triangles). The test reports FPS of the viewer in different modes. To try this, launch DRAW and type "source samples/tcl/spheres.tcl"
In general, the performance of the viewer can depend drastically on how objects are displayed. The optimal way depends strongly on a nature of the model.
Best regards
FSR

Shing Liu's picture

Here is my result of spheres.tcl script in Debian OS:

Measuring FPS of display of spheres as single object...
FPS: 23.72792235464512
CPU: 0.79999999999998295 msec

Remove c
Animating movements of corner spheres (10 sec)...
(you can interact with the view during the process)
Nb Frames: 233
Duration: 10.038 s
FPS: 23.11447643718242
Elapsed time: 0 Hours 0 Minutes 10.038622 Seconds
CPU user time: 3.75 seconds
CPU system time: 0.09 seconds

Performance counters (FPS = "Frames per second"):

Spheres as separate interactive objects:
Actual FPS: 24.440585547548551
FPS estimate by CPU load: 64.93506493506497

Spheres as one interactive object (compound):
Actual FPS: 23.72792235464512
FPS estimate by CPU load: 1250.0000000000266

Animation FPS: 23.11447643718242

Scene contains 2495004 triangles

=========================================
% dversion
Open CASCADE Technology 6.8.0
TBB disabled
GL2PS disabled
FreeImage disabled
OpenCL disabled
VTK disabled
Exceptions disabled (No_Exception)
Compiler: GCC 4.7.2
Architecture: AMD64
OS: Linux

Timo Roth's picture

Measuring FPS of display of spheres as single object...
FPS: 151.68809552749468
CPU: 0.15600100000000339 msec

Remove c
Animating movements of corner spheres (10 sec)...
(you can interact with the view during the process)
Nb Frames: 1589
Duration: 10.003 s
FPS: 158.76824635072984
Elapsed time: 0 Hours 0 Minutes 10.1398588911 Seconds
CPU user time: 6.5832422 seconds
CPU system time: 1.3572087 seconds

Performance counters (FPS = "Frames per second"):

Spheres as separate interactive objects:
Actual FPS: 152.4681999591086
FPS estimate by CPU load: 427.34768794216853

Spheres as one interactive object (compound):
Actual FPS: 151.68809552749468
FPS estimate by CPU load: 6410.2153191324305

Animation FPS: 158.76824635072984

Scene contains 2495004 triangles

====================================
Draw[4]> dversion
Open CASCADE Technology 6.8.0
TBB enabled (HAVE_TBB)
GL2PS enabled (HAVE_GL2PS)
FreeImage enabled (HAVE_FREEIMAGE)
OpenCL disabled
VTK disabled
Exceptions disabled (No_Exception)
Compiler: MS Visual C++ 10.0 (_MSC_FULL_VER = 160040219)
Architecture: Intel x86
OS: Windows

Processor Intel(R) Xeon(R) CPU E31280 @ 3.50GHz