strasdat / Sophus

C++ implementation of Lie Groups using Eigen.
Other
2.07k stars 599 forks source link

Sophus python binding #522

Closed chpeng-fb closed 1 year ago

chpeng-fb commented 1 year ago

This pull request implement python binding for sophus that provides access to SO3, SE3, interpolate and iterativeMean features.

Feature list

Python module (pysophus) installation step

cd Sophus
pip install .

Vectorization detail

In python, we choose to export our Sophus::SO3 as a vector of SO3 objects by binding the cpp object SO3Group defined below. This is because numerical code in python tends to work with array of values to get efficient program. This approach is inspired by scipy.spatial.transform.Rotation.

class SO3Group : public std::vector<Sophus::SO3<Scalar>> 
class SE3Group : public std::vector<Sophus::SE3<Scalar>> 

Passing a single SO3/SE3 object to c++ code in python binding

To allow other python binding c++ code to take in a single SO3/SE3 object, we also build a caster so that, even if we wrap SO3Group/SE3Group in python, those can be implicitly converted to the c++ Sophus::SO3/SE3 object at boundaries between languages. This is so we can pass python SO3/SE3 object to c++ function as if they were regular 1-element Sophus::SO3/SE3 object. This simplifies binding the rest of c++ code. The implicit cast fails if the python object is not a 1-element object.

strasdat commented 1 year ago

@chpeng-fb - thank you for the contribution. That looks great!