What is the best approach for cutting out many objects from one?

Cut in pairs, using the previous result at each iteration? Combine all the set of objects first into some kind of structure?

Mikhail Sazonov's picture

If you ensure all cutting objects have no intersection between each other you can add all them into one compound and use it as a tool.

Otherwise, you can add all tools one by one into the algorithm, and then call one calculation. This way the algorithm will resolve all intersections between objects.

W W's picture

Thanks.
Are there any differences in execution speed?

Mikhail Sazonov's picture

The most long part of computations is intersection. Please make your conclusion. And, please, share here your results.

W W's picture

I'm using WebAssembly port. And the result is the same for both cases (seems that internally the framework also processes element by element) and much longer (~ 10 times) than in CAD Builder (instant) with the same objects.

SetRunParrallel() has no effect.

In theory, the speed should be comparable, but it might be a parallel issue. Or does CAD Builder preprocess a Shapes list somehow?

The scene is simple, Box and Cylinders looks like this :

image

Kirill Gavrilov's picture

I'm using WebAssembly port.
SetRunParrallel() has no effect.

Have you built OCCT with -pthreads option by Emscripten? Though I have no idea if CAD Builder uses multithreading here and if it has any effect in this specific case.

Mikhail Sazonov's picture

In such small example there should be no difference if you cut one by one or in one operation. In side the objects intersect each other only if their boxes intersect. The pairs of intersecting boxes are selected using the boxes tree. So, If there are huge number of objects you should notice the difference. As for parallel flag, I would first tried to perform the algorithm without parallelization on both platforms to compare pure algorithm flow. I suspect that the code generated with emscripten is slower.

W W's picture

I used 20 cylinders. Yes, a small amount, but even in this example, the difference in speed is huge. Not 85% of native performance, not 2-3 times, but 10 or more.

I can't test C++ source code, only CADBuilder, so my question is rather this: does CADBuilder boolen operations somehow speed up or does the JS port slow them down?

Can you test a similar scene with SetRunParrallel(false)?

Mikhail Sazonov's picture

To test the scene I need the input shapes.

Also, I can test only in native code. I have no web assembly with OCCT to compare the results on the same computer.

W W's picture
Mikhail Sazonov's picture

I have created 3 scripts,

1)  Cutting compound of cylinders

2) Adding each cylinder as a separate tool and cutting in one operation

3) Cutting sequentially one by one.

Here are the results:

Draw[111]> source test1.txt
Elapsed time: 0 Hours 0 Minutes 0.0722072001081 Seconds
CPU user time: 0.0625 seconds
CPU system time: 0.015625 seconds

Draw[112]> source test2.txt
Elapsed time: 0 Hours 0 Minutes 0.0915191001259 Seconds
CPU user time: 0.078125 seconds
CPU system time: 0.015625 seconds

Draw[113]> source test3.txt
Elapsed time: 0 Hours 0 Minutes 0.373747200007 Seconds
CPU user time: 0.140625 seconds
CPU system time: 0.234375 seconds

Parallelization was turned off.

Kirill Gavrilov's picture

My results (using DRAW), Script 1:

jsupload . -path box.step
jsupload . -path cylinders.step

pload MODELING XDE
testreadstep box.step a
testreadstep cylinders.step b

bclearobjects
bcleartools

chrono h reset start

baddobjects a
baddtools b
bfillds
bbop r cut

chrono h stop show
Native (vc14): 0.739 s
Firefox 95:    1.044 s
Edge 97:       0.677 s

Script 3:

jsupload . -path box.step
jsupload . -path cylinders.step

pload MODELING XDE
testreadstep box.step a
testreadstep cylinders.step b

chrono h reset start
copy a r
foreach s [explode b] { bcut r r $s }
chrono h stop show
Native (vc14): 0.419 s
Firefox 95:    2.323 s
Edge 97:       1.399 s

It doesn't look "slower in 10 times" to me.

W W's picture

I tested opencascade.js

What framework is used in your example? Can it be used alongside JavaScript? I mean, is it possible to write something like:

    const box = new framework.BRepPrimAPI_MakeBox(aSizeX, aSizeY, aSizeZ).Shape();

?

Is it possible to use this port without built-in renderer? i.e. get all necessary triangulation data.

Kirill Gavrilov's picture

Draw Harness is a Tcl wrapper for OCCT C++ functionality coming with OCCT itself. It doesn't export OCCT C++ classes into JavaScript (in contrary to opencascade.js), only an interface to call Tcl commands / scripts (including commands working with 3D Viewer from ViewerTest plugin) is exposed at JavaScript level.

W W's picture

Does Tcl cover all possible C++ methods? That is, is it possible, using the Tcl, to do the same thing as calling C++ methods directly?

Why, in your opinion, does opencascade.js work so slowly for Boolean (at least)?

CascadeStudio.

Kirill Gavrilov's picture

W W wrote:

Does Tcl cover all possible C++ methods? That is, is it possible, using the Tcl, to do the same thing as calling C++ methods directly?

Draw Harness doesn't wrap C++ classes and their methods, it implements a dedicated procedural interface to OCCT functionality. I'm not advertising using DRAW for application development - it is just the most straightforward way to test OCCT framework functionality, as it comes with OCCT itself, covers major part of functionality and available across most platforms (including WebAssembly - hence, it is possible to compare performance / behavior within the same conditions).

Why, in your opinion, does opencascade.js work so slowly for Boolean (at least)?

I cannot say if it is slower or not as I never used it - there might be different building options, differences in code performing Boolean operations, or something else. The very way opencascade.js exposes functionality (wrapping a lot of C++ classes and their methods into JavaScript) might be an extra reason for slowing down, as well as an origin of memory leaks (due to the lack of finalizers in JavaScript, you have to delete C++ classes manually).

W W's picture

Thanks. What are the results with parallelization enabled?

Mikhail Sazonov's picture

It has no sense for this small example. Overheads exceed any benefits here.