From 0877b17a5de8dd58a37d1e9edc0e2ea4e8313163 Mon Sep 17 00:00:00 2001 From: rakeshs Date: Wed, 20 Mar 2019 17:23:20 -0700 Subject: [PATCH 1/4] expose the raw data (quaternion) of SO3 --- sophus.pyx | 6 +++++- sophus_defs.pxd | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sophus.pyx b/sophus.pyx index 2faed62..983c37e 100644 --- a/sophus.pyx +++ b/sophus.pyx @@ -41,7 +41,11 @@ cdef class SO3: def log(self): return ndarray(self.thisptr.log()) - + + def data(self): + ptr = self.thisptr.data() + return (ptr[0], ptr[1], ptr[2], ptr[3]) + def inverse(self): res = SO3() res.thisptr = new _SO3d(self.thisptr.inverse()) diff --git a/sophus_defs.pxd b/sophus_defs.pxd index 540be98..f98056d 100644 --- a/sophus_defs.pxd +++ b/sophus_defs.pxd @@ -13,6 +13,7 @@ cdef extern from "" namespace "Sophus": Matrix3d& matrix() Vector3d log() + Scalar* data() SO3 inverse() void normalize() From a141fdb1c15801cb210339a4d69c96cdbe44c34b Mon Sep 17 00:00:00 2001 From: rakeshshrestha31 Date: Fri, 22 Mar 2019 13:47:36 -0700 Subject: [PATCH 2/4] update README: instructions for cython, install instead of build_ext for install to dist-packages --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a469633..94ffcbd 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,18 @@ If you require any functionality that is not currently in the wrapper, feel free How to install -------------- +Install `cython` if you don't have already -First, setup `eigency` +``` +pip install cython +``` + +Then, setup `eigency` ``` git clone https://github.com/wouterboomsma/eigency.git cd eigency -python setup.py build_ext --inplace +python setup.py # put in your bashrc export PYTHONPATH="$PYTHONPATH:" ``` @@ -56,6 +61,8 @@ git submodule update python setup.py build_ext --inplace # put in your bashrc export PYTHONPATH="$PYTHONPATH:" +# alternately, install it to your default dist-packages +python setup.py install ``` Usage From 87f362a4f255b64a6a1141227b775fb8f932aad5 Mon Sep 17 00:00:00 2001 From: rakeshshrestha31 Date: Fri, 22 Mar 2019 15:00:29 -0700 Subject: [PATCH 3/4] set_data method for SO3 to set rotation as quaternion directly --- sophus.pyx | 11 ++++++++++- sophus_defs.pxd | 2 -- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/sophus.pyx b/sophus.pyx index 983c37e..8c4873b 100644 --- a/sophus.pyx +++ b/sophus.pyx @@ -45,7 +45,16 @@ cdef class SO3: def data(self): ptr = self.thisptr.data() return (ptr[0], ptr[1], ptr[2], ptr[3]) - + + def setData(self, np.ndarray data): + data = data.reshape((4,)) + ptr = self.thisptr.data() + ptr[0] = data[0] + ptr[1] = data[1] + ptr[2] = data[2] + ptr[3] = data[3] + self.normalize() + def inverse(self): res = SO3() res.thisptr = new _SO3d(self.thisptr.inverse()) diff --git a/sophus_defs.pxd b/sophus_defs.pxd index f98056d..8f00e22 100644 --- a/sophus_defs.pxd +++ b/sophus_defs.pxd @@ -1,8 +1,6 @@ # -*- coding: utf-8 -*- from eigency.core cimport * - - cdef extern from "" namespace "Sophus": cdef cppclass SO3[Scalar]: SO3() except + From 7844ec64266d6aa593110009a763c4e056409e74 Mon Sep 17 00:00:00 2001 From: rakeshshrestha31 Date: Fri, 22 Mar 2019 15:39:53 -0700 Subject: [PATCH 4/4] setQuaternion method for SE3 and data method returning numpy array instead of tuple --- sophus.pyx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sophus.pyx b/sophus.pyx index 8c4873b..045763b 100644 --- a/sophus.pyx +++ b/sophus.pyx @@ -44,7 +44,7 @@ cdef class SO3: def data(self): ptr = self.thisptr.data() - return (ptr[0], ptr[1], ptr[2], ptr[3]) + return numpy.array((ptr[0], ptr[1], ptr[2], ptr[3])) def setData(self, np.ndarray data): data = data.reshape((4,)) @@ -152,7 +152,7 @@ cdef class SE3: Returns the SO3 part (rotation) """ return SO3(ndarray(self.thisptr.so3().matrix())) - + def log(self): return ndarray(self.thisptr.log()) @@ -170,6 +170,14 @@ cdef class SE3: def setRotationMatrix(self, np.ndarray matrix): self.thisptr.setRotationMatrix(Map[Matrix3d](matrix)) + def setQuaternion(self, np.ndarray quaternion): + quaternion = quaternion.reshape((4,)) + ptr = self.thisptr.so3().data() + ptr[0] = quaternion[0] + ptr[1] = quaternion[1] + ptr[2] = quaternion[2] + ptr[3] = quaternion[3] + def __mul__(SE3 x, SE3 y): """ Group multiplication operator