This package provides Python bindings for specific algorithms of CGAL. The bindings are generated with PyBind11 and data is exchanged using NumPy arrays.
More information is available in the docs: https://compas.dev/compas_cgal/
compas_cgal
is available via conda-forge
for Windows, OSX, and Linux,
and can be installed using conda
.
conda create -n cgal -c conda-forge compas compas_cgal --yes
Create a development environment with the required dependencies using conda
and compile and install an editable version of compas_cgal
using setuptools
.
Windows:
conda create -n cgal-dev python=3.8 mpir mpfr boost-cpp eigen=3.3 cgal-cpp=5.2 pybind11 compas compas_view2 --yes
conda activate cgal-dev
git clone https://github.com/compas-dev/compas_cgal
cd compas_cgal
pip install -e .
Mac:
conda create -n cgal-dev python=3.8 gmp mpfr boost-cpp eigen=3.3 cgal-cpp=5.2 pybind11 compas compas_view2 --yes
conda activate cgal-dev
git clone https://github.com/compas-dev/compas_cgal
cd compas_cgal
pip install -e .
Note that the version of eigen is important and should be
3.3
.
To add a new c++ module to the Python wrapper, or to exclude some of the existing modules during development
you can modify the list of extension modules in setup.py
.
ext_modules = [
Extension(
'compas_cgal._cgal',
sorted([
'src/compas_cgal.cpp',
'src/compas.cpp',
'src/meshing.cpp',
'src/booleans.cpp',
'src/slicer.cpp',
'src/intersections.cpp',
'src/measure.cpp',
]),
include_dirs=[
'./include',
get_eigen_include(),
get_pybind_include()
],
library_dirs=[
get_library_dirs(),
],
libraries=['mpfr', 'gmp'],
language='c++'
),
]
This section provides a step-to-step guide on how to setup a new module and function, replicating the measure.volume
function in a new dummy module and submodule called measuring.voluming
to illustrate the steps involved.
Duplicate the files measure.cpp
and measure.h
as measuring.cpp
and measuring.h
- Open
measuring.cpp
. Replacepmp_volume
andinit_measure
as respectivelypmp_voluming
andinit_measuring
. These respectively define the replicated module and submodule.
- Under
init_measuring
, the name contained inm.def_submodule(measure)
register the name of the submodule whereas the name contained insubmodule.def(volume)
register the name of the submodule method. In the two places, replacemeasure
andvolume
asmeasuring
andvoluming
. Furthermore, replacepmp_volume
aspmp_voluming
to reference the newly replicated submodule function. Finally, replace#include "measure.h"
as#include "measuring.h"
- Repeat the steps in
measuring.h
, the header file
-
To register the module, open
compas_cgal.cpp
. Insertvoid init_measuring(py::module&);
andinit_measuring
in the two corresponding areas with similar declarations belownamespace py = pybind11;
and within the clausePYBIND11_MODULE(_cgal, m){}
. -
To add the module for compilation. Open
setup.py
and insertsrc/measuring.cpp
underext_modules
. -
(Optional) Replicate the files
measure.py
andmeasure.pyi
-
To recompile, simply rerun
pip install -e.
The compiling process may be sped up by commenting out modules that are not required insetup.py
underext_modules
, and commenting out their corresponding references incompas_cgal.cpp
The provided functionality can be used directly from the compas_cgal
package
or from compas.geometry
through the plugin mechanism in COMPAS.
For examples, see https://compas.dev/compas_cgal/latest/examples.html.
compas_cgal
is released under the LGPL 3.0 to be compatible with the license of CGAL.