def copy_reg_pickle(): # python 2 and 3 support # first try to import copyreg (python 3) # if the import fail we import copy_reg (python 2) try: import copyreg except ImportError: import copy_reg as copyreg # register sva pickle needed by some rbdyn type import spacevecalg as sva sva.copy_reg_pickle() copyreg.pickle(Body, bodyPickle) copyreg.pickle(Joint, jointPickle) copyreg.pickle(MultiBody, multiBodyPickle)
#! /usr/bin/env python2 import sys import os sys.path.insert(0, os.path.join("@CMAKE_CURRENT_BINARY_DIR@", '../binding/python')) import pickle import eigen3 as e3 import spacevecalg as sva if __name__ == '__main__': # regiter custom pickle function sva.copy_reg_pickle() mv = sva.MotionVecd(e3.Vector6d.Random()) fv = sva.ForceVecd(e3.Vector6d.Random()) pt = sva.PTransformd(e3.Quaterniond(e3.Vector4d.Random().normalized()), e3.Vector3d.Random()) rb = sva.RBInertiad(3., e3.Vector3d.Random(), e3.Matrix3d.Random()) ab = sva.ABInertiad(e3.Matrix3d.Random(), e3.Matrix3d.Random(), e3.Matrix3d.Random()) def test(v): pickled = pickle.dumps(v) v2 = pickle.loads(pickled) assert(v == v2) test(mv) test(fv) test(pt)
# You should have received a copy of the GNU Lesser General Public License # along with SpaceVecAlg. If not, see <http://www.gnu.org/licenses/>. import sys import os sys.path.insert( 0, os.path.join("@CMAKE_CURRENT_BINARY_DIR@", '../binding/python')) import pickle import eigen3 as e3 import spacevecalg as sva if __name__ == '__main__': # regiter custom pickle function sva.copy_reg_pickle() mv = sva.MotionVecd(e3.Vector6d.Random()) fv = sva.ForceVecd(e3.Vector6d.Random()) pt = sva.PTransformd(e3.Quaterniond(e3.Vector4d.Random().normalized()), e3.Vector3d.Random()) rb = sva.RBInertiad(3., e3.Vector3d.Random(), e3.Matrix3d.Random()) ab = sva.ABInertiad(e3.Matrix3d.Random(), e3.Matrix3d.Random(), e3.Matrix3d.Random()) def test(v): pickled = pickle.dumps(v) v2 = pickle.loads(pickled) assert (v == v2) test(mv)