This repository hosts all the code examples generated while exploring different mesh libraries for fast implementation of boolean operations, collisions, etc. The focus is to find an efficient gemoetric calculation library based on C/C++/C*, that solves the iBurs problems efficiently.
Here is an index list for mesh libraries used for scientifict programming: Awesome list of mesh libraries. But rarely do they focus on boolean operation optimization.
- Possibility of using GPU or CPU, potentially their performance
- Computational efficiency
- Interface: if this package have a clear API or not
- Flexibility: what's the effort to integrate them in iBrus.
- Representing grains using point cloud vs meshes.
- Integration easiness with iBrus.
Simulation Scenario | iBrus | Pymesh | Trimesh | Vedo |
---|---|---|---|---|
1 grain cut 1 plane/1 grain intersect with 1 box | 10.31 ms | 0.004 ms | 4.49 ms | 1.91 ms |
25 grains cut 1 plane/25 grains difference with 1 box | 0.28 s | 4.09 s | 71 s | Not executable |
- Hardware environment: The above result is produced in a Macbook Pro 2017 edition with 2.3 GHz Dual-Core Intel Core i5 processor, 8 GB 2133 MHz memory.
- First row : In iBrus the grain shape is projected to a plane and the projected area is removed. While in mesh libaries, two mesh volumes are doing
boolean.difference
operaitons. - Second row: The calculation in iBrus is the same as previous scenario. While in mesh libraries, first a
boolean.union
is calculated for all grain meshs, then aboolean.difference
is calculated with the box.
Two scenarios are simulated in profiling the iBrus runtime:
- Multiple numbers of grains pass one plane.
- When a grain passing the workpiece, different number of planes used to represent the workpiece.
To compare the boolean operation speed of different libraries, we designed an experiement, where a sqaure grid of n * n number of grain is generated to intersect with a primitive box that sits just beneath the grid. The size of the box is dependent on the size of the grid. The boolean opeartions taken place are:
- Calculate the union of the grid of grains
- Calculate the difference between the grid and the box.
This test was run on different number of grains(Trimesh test script, Pymesh test script and the runtime scaling effect is plotted in the following 2 plots:
The detailed breakdown of the runtime can be find in Trimesh runtime breakdown and Pymesh runtime breakdown. Those files display in detail which functions consisted the most of runtime.
- Trimesh user suggestions on mesh operations.
- Boolean operation issue on Trimesh suggest boolean is not very fast on trimesh and operation engine is unreliable and slow.
-
Doownload source code and record the repository of pymesh to the environment variable $PYMESH
git clone https://github.com/PyMesh/PyMesh.git cd PyMesh git submodule update --init export PYMESH_PATH=
pwd -
Install the system dependencies: https://pymesh.readthedocs.io/en/latest/installation.html.
-
Navigate to the pymesh folder and build the package with the command
./setup.py build
-
After build, install it using setup. :
./setup.up Install
After this, try import pymesh
in the python console. If it doesn't work:
- Check if you run
setup.py install
- Check if you set the $PYMESH variable correctly.
- Check if system dependencies and python dependencies are all installed.
It takes quite sometime to install all the system dependencies packages made in C++. So be patient
pip install vedo
- Since python-fcl doesn't support fcl 0.6.0 yet, which is the newset version of fcl. You need to install the fcl version 0.5.0 from source code (https://github.com/flexible-collision-library/fcl/releases/tag/0.5.0)
- Make sure you installed all the required dependencies in https://github.com/BerkeleyAutomation/python-fcl and https://github.com/flexible-collision-library/fcl.
pip install trimesh
pip install Rtree
, this is a soft dependencies neeeded.- When you need the boolean engine, you need to install
blender
oropenscad
using your system package manager.