Commit 92031d0d authored by jcarpent's avatar jcarpent
Browse files

[Python] Add copyable method to create a raw copy of Spatial classes

parent 6228f196
...@@ -63,6 +63,7 @@ SET(${PYWRAP}_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/${PYTHON_SITELIB}/${PROJECT_NA ...@@ -63,6 +63,7 @@ SET(${PYWRAP}_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/${PYTHON_SITELIB}/${PROJECT_NA
SET(${PROJECT_NAME}_PYTHON_HEADERS SET(${PROJECT_NAME}_PYTHON_HEADERS
utils/eigen_container.hpp utils/eigen_container.hpp
utils/handler.hpp utils/handler.hpp
utils/copyable.hpp
python.hpp python.hpp
spatial/se3.hpp spatial/se3.hpp
spatial/force.hpp spatial/force.hpp
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "pinocchio/multibody/frame.hpp" #include "pinocchio/multibody/frame.hpp"
#include "pinocchio/multibody/model.hpp" #include "pinocchio/multibody/model.hpp"
#include "pinocchio/container/aligned-vector.hpp" #include "pinocchio/container/aligned-vector.hpp"
#include "pinocchio/bindings/python/utils/copyable.hpp"
namespace se3 namespace se3
{ {
...@@ -81,8 +82,9 @@ namespace se3 ...@@ -81,8 +82,9 @@ namespace se3
"A Plucker coordinate frame related to a parent joint inside a kinematic tree.\n\n", "A Plucker coordinate frame related to a parent joint inside a kinematic tree.\n\n",
bp::no_init bp::no_init
) )
.def(FramePythonVisitor()) .def(FramePythonVisitor())
; .def(CopyableVisitor<Frame>())
;
bp::class_< std::vector<Frame> >("StdVec_Frame") bp::class_< std::vector<Frame> >("StdVec_Frame")
.def(bp::vector_indexing_suite< container::aligned_vector<Frame> >()); .def(bp::vector_indexing_suite< container::aligned_vector<Frame> >());
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <eigenpy/memory.hpp> #include <eigenpy/memory.hpp>
#include "pinocchio/spatial/force.hpp" #include "pinocchio/spatial/force.hpp"
#include "pinocchio/bindings/python/utils/copyable.hpp"
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(se3::Force) EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(se3::Force)
...@@ -98,6 +99,7 @@ namespace se3 ...@@ -98,6 +99,7 @@ namespace se3
"Supported operations ...", "Supported operations ...",
bp::init<>()) bp::init<>())
.def(ForcePythonVisitor<Force>()) .def(ForcePythonVisitor<Force>())
.def(CopyableVisitor<Force>())
; ;
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <eigenpy/memory.hpp> #include <eigenpy/memory.hpp>
#include "pinocchio/spatial/inertia.hpp" #include "pinocchio/spatial/inertia.hpp"
#include "pinocchio/bindings/python/utils/copyable.hpp"
namespace se3 namespace se3
{ {
...@@ -124,6 +125,7 @@ namespace se3 ...@@ -124,6 +125,7 @@ namespace se3
"Supported operations ...", "Supported operations ...",
bp::init<>()) bp::init<>())
.def(InertiaPythonVisitor<Inertia>()) .def(InertiaPythonVisitor<Inertia>())
.def(CopyableVisitor<Inertia>())
; ;
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "pinocchio/spatial/motion.hpp" #include "pinocchio/spatial/motion.hpp"
#include "pinocchio/spatial/force.hpp" #include "pinocchio/spatial/force.hpp"
#include "pinocchio/bindings/python/utils/copyable.hpp"
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(se3::Motion) EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(se3::Motion)
...@@ -106,6 +107,7 @@ namespace se3 ...@@ -106,6 +107,7 @@ namespace se3
"Supported operations ...", "Supported operations ...",
bp::init<>()) bp::init<>())
.def(MotionPythonVisitor<Motion>()) .def(MotionPythonVisitor<Motion>())
.def(CopyableVisitor<Motion>())
; ;
} }
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <eigenpy/memory.hpp> #include <eigenpy/memory.hpp>
#include "pinocchio/spatial/se3.hpp" #include "pinocchio/spatial/se3.hpp"
#include "pinocchio/bindings/python/utils/copyable.hpp"
EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(se3::SE3) EIGENPY_DEFINE_STRUCT_ALLOCATOR_SPECIALIZATION(se3::SE3)
...@@ -110,6 +111,7 @@ namespace se3 ...@@ -110,6 +111,7 @@ namespace se3
"Supported operations ...", "Supported operations ...",
bp::init<>()) bp::init<>())
.def(SE3PythonVisitor<SE3>()) .def(SE3PythonVisitor<SE3>())
.def(CopyableVisitor<SE3>())
; ;
} }
......
//
// Copyright (c) 2016 CNRS
//
// This file is part of Pinocchio
// Pinocchio is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either version
// 3 of the License, or (at your option) any later version.
//
// Pinocchio is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// Pinocchio If not, see
// <http://www.gnu.org/licenses/>.
#ifndef __se3_python_utils_copyable_hpp__
#define __se3_python_utils_copyable_hpp__
#include <boost/python.hpp>
namespace se3
{
namespace python
{
namespace bp = boost::python;
///
/// \brief Add the Python method copy to allow a copy of this by calling the copy constructor.
///
template<class C>
struct CopyableVisitor : public bp::def_visitor< CopyableVisitor<C> >
{
template<class PyClass>
void visit(PyClass & cl) const
{ cl.def("copy",&copy,"Returns a copy of *this."); }
private:
static C copy(const C & self) { return C(self); }
};
} // namespace python
} // namespace se3
#endif // ifndef __se3_python_utils_copyable_hpp__
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment