I am interested in implementing some geometric algorithms and making them interactive. I have used the Matplotlib library in Python for some simple animations and I find it sooo simple and easy to visually test my ideas with. (Thanks Jake VanderPlas!)

However, the biggest and robust geometric algorithms library on the planet is CGAL. I want to make heavy use of the large number of packages in it.

I have played around with CGAL's Qt visualization package, and I did not like it very much. There are not too many examples to play around with and it looks like I will have to spend a wasteful investment in time and effort for a task that seems (at least on the face of it) simple.

My use case would be something like this: When the code starts, a matplotlib window opens, the user clicks in some points, or places and moves certain objects like disks with his mouse. He presses a button which then animates the progress of the algorithm.

My codes will be written in C++ (the language of CGAL) but the code that takes care of the interactivity and visualization will be done in Python. Muscle in C++ and the eyes in Python so-to-speak.

Is this possible? I heard of a library called ZeroMQ which allows to send messages between two live processes but I don't know if this would be appropriate for my problem

1 Answer 1


You can embed python and its libraries in a C/C++ program and you can embed C/C++ code into python programs as well - either would take care of your use case.

To embed python inside of a C++ program there are useful examples in the documentation for both Python 2 and Python 3 but the simplest example in C would be:

#include <Python.h>

main(int argc, char *argv[])
    wchar_t *program = Py_DecodeLocale(argv[0], NULL);
    if (program == NULL) {
        fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
    Py_SetProgramName(program);  /* optional but recommended */
    PyRun_SimpleString("from time import time,ctime\n"
                       "print('Today is', ctime(time()))\n");
    return 0;

Your C/C++ code and python code can call each other as required. It is also worth looking at extending python with C/C++.

There is a huge list of programs that combine C/C++ and python including: GIMP & Blender

Finally there is a python package for interfacing directly to CGAL called cgal-bindings this provides wrappers for the following CGAL packages as at version 0.7:

  • Few Kernel primitives
  • 2D Triangulations
  • 3D Triangulations
  • 2D Alpha Shapes
  • 2D Convex Hulls and Extreme Points
  • dD Spatial Searching (only for 2D and 3D cases)
  • 3D Fast Intersection and Distance Computation (AABB Tree)
  • 3D Polyhedral Surfaces
  • 2D Conforming Triangulations and Meshes
  • 3D Surface Mesh Generation
  • 3D Mesh Generation
  • 2D and Surface Function Interpolation
  • 2D Voronoi Diagram Adaptor
  • Halfedge Data Structures
  • Point Set Processing
  • Intersecting Sequences of dD Iso-oriented Boxes
  • Polygon Mesh Processing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.