Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions include/eigenpy/quaternion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace eigenpy
typedef typename QuaternionBase::Scalar Scalar;
typedef typename Quaternion::Coefficients Coefficients;
typedef typename QuaternionBase::Vector3 Vector3;
typedef typename Eigen::Matrix<Scalar,4,1> Vector4;
typedef Coefficients Vector4;
typedef typename QuaternionBase::Matrix3 Matrix3;

typedef typename QuaternionBase::AngleAxisType AngleAxis;
Expand All @@ -110,23 +110,25 @@ namespace eigenpy
void visit(PyClass& cl) const
{
cl
.def(bp::init<>(bp::arg("self"),"Default constructor"))
.def(bp::init<>(bp::arg("self"),"Default constructor")[bp::return_value_policy<bp::return_by_value>()])
Copy link
Member

@cmastalli cmastalli May 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to use with_custodian_and_ward, i.e.,

def(bp::init<>(bp::arg("self"),"Default constructor")[bp::with_custodian_and_ward_postcall<0, 1>()]

.def(bp::init<Matrix3>((bp::arg("self"),bp::arg("R")),
"Initialize from rotation matrix.\n"
"\tR : a rotation matrix 3x3."))
.def(bp::init<Vector4>((bp::arg("self"),bp::arg("vec4")),
"Initialize from a vector 4D.\n"
"\tvec4 : a 4D vector representing quaternion coefficients in the order xyzw."))
"\tR : a rotation matrix 3x3.")[bp::return_value_policy<bp::return_by_value>()])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here it should be

  "\tR : a rotation matrix 3x3.")[bp::with_custodian_and_ward_postcall<0, 2>()])

.def(bp::init<AngleAxis>((bp::arg("self"),bp::arg("aa")),
"Initialize from an angle axis.\n"
"\taa: angle axis object."))
.def(bp::init<Quaternion>((bp::arg("self"),bp::arg("quat")),
"Copy constructor.\n"
"\tquat: a quaternion."))
"\tquat: a quaternion.")[bp::return_value_policy<bp::return_by_value>()])
.def("__init__",bp::make_constructor(&QuaternionVisitor::FromTwoVectors,
bp::default_call_policies(),
(bp::arg("u"),bp::arg("v"))),
"Initialize from two vectors u and v")
.def("__init__",bp::make_constructor(&QuaternionVisitor::FromOneVector,
bp::default_call_policies(),
(bp::arg("vec4"))),
"Initialize from a vector 4D.\n"
"\tvec4 : a 4D vector representing quaternion coefficients in the order xyzw.")
.def(bp::init<Scalar,Scalar,Scalar,Scalar>
((bp::arg("self"),bp::arg("w"),bp::arg("x"),bp::arg("y"),bp::arg("z")),
"Initialize from coefficients.\n\n"
Expand Down Expand Up @@ -266,6 +268,12 @@ namespace eigenpy
Quaternion* q(new Quaternion); q->setFromTwoVectors(u,v);
return q;
}

static Quaternion* FromOneVector(const Vector4& v)
{
Quaternion* q(new Quaternion(v));
return q;
}

static bool __eq__(const Quaternion & u, const Quaternion & v)
{
Expand Down