@@ -110,12 +110,16 @@ namespace eigenpy
110110 void visit (PyClass& cl) const
111111 {
112112 cl
113- .def (bp::init<Matrix3>((bp::arg (" self" ),bp::arg (" R" )),
114- " Initialize from rotation matrix.\n "
115- " \t R : a rotation matrix 3x3." )[bp::return_value_policy<bp::return_by_value>()])
116- .def (bp::init<AngleAxis>((bp::arg (" self" ),bp::arg (" aa" )),
117- " Initialize from an angle axis.\n "
118- " \t aa: angle axis object." ))
113+ .def (" __init__" ,bp::make_constructor (&QuaternionVisitor::FromRotationMatrix,
114+ bp::default_call_policies (),
115+ (bp::arg (" R" ))),
116+ " Initialize from rotation matrix.\n "
117+ " \t R : a rotation matrix 3x3." )
118+ .def (" __init__" ,bp::make_constructor (&QuaternionVisitor::FromAngleAxis,
119+ bp::default_call_policies (),
120+ (bp::arg (" aa" ))),
121+ " Initialize from an angle axis.\n "
122+ " \t aa: angle axis object." )
119123 .def (bp::init<Quaternion>((bp::arg (" self" ),bp::arg (" quat" )),
120124 " Copy constructor.\n "
121125 " \t quat: a quaternion." )[bp::return_value_policy<bp::return_by_value>()])
@@ -130,11 +134,12 @@ namespace eigenpy
130134 " \t vec4 : a 4D vector representing quaternion coefficients in the order xyzw." )
131135 .def (" __init__" ,bp::make_constructor (&QuaternionVisitor::DefaultConstructor),
132136 " Default constructor" )
133- .def (bp::init<Scalar,Scalar,Scalar,Scalar>
134- ((bp::arg (" self" ),bp::arg (" w" ),bp::arg (" x" ),bp::arg (" y" ),bp::arg (" z" )),
137+ .def (" __init__" ,bp::make_constructor (&QuaternionVisitor::FromCoefficients,
138+ bp::default_call_policies (),
139+ (bp::arg (" w" ),bp::arg (" x" ),bp::arg (" y" ),bp::arg (" z" ))),
135140 " Initialize from coefficients.\n\n "
136141 " ... note:: The order of coefficients is *w*, *x*, *y*, *z*. "
137- " The [] operator numbers them differently, 0...4 for *x* *y* *z* *w*!" ))
142+ " The [] operator numbers them differently, 0...4 for *x* *y* *z* *w*!" )
138143
139144 .add_property (" x" ,
140145 &QuaternionVisitor::getCoeff<0 >,
@@ -244,16 +249,16 @@ namespace eigenpy
244249 ;
245250 }
246251 private:
247-
252+
248253 template <int i>
249254 static void setCoeff (Quaternion & self, Scalar value) { self.coeffs ()[i] = value; }
250-
255+
251256 template <int i>
252257 static Scalar getCoeff (Quaternion & self) { return self.coeffs ()[i]; }
253-
258+
254259 static Quaternion & setFromTwoVectors (Quaternion & self, const Vector3 & a, const Vector3 & b)
255260 { return self.setFromTwoVectors (a,b); }
256-
261+
257262 template <typename OtherQuat>
258263 static Quaternion & assign (Quaternion & self, const OtherQuat & quat)
259264 { return self = quat; }
@@ -263,24 +268,42 @@ namespace eigenpy
263268 Quaternion* q (new Quaternion); q->setIdentity ();
264269 return q;
265270 }
266-
267- static Quaternion* FromTwoVectors (const Vector3& u, const Vector3& v)
271+
272+ static Quaternion* FromCoefficients (Scalar w, Scalar x, Scalar y, Scalar z)
273+ {
274+ Quaternion* q (new Quaternion (w, x, y, z));
275+ return q;
276+ }
277+
278+ static Quaternion* FromAngleAxis (const AngleAxis& aa)
279+ {
280+ Quaternion* q (new Quaternion (aa));
281+ return q;
282+ }
283+
284+ static Quaternion* FromTwoVectors (const Eigen::Ref<Vector3> u, const Eigen::Ref<Vector3> v)
268285 {
269286 Quaternion* q (new Quaternion); q->setFromTwoVectors (u,v);
270287 return q;
271288 }
272-
289+
273290 static Quaternion* DefaultConstructor ()
274291 {
275292 return new Quaternion;
276293 }
277-
294+
278295 static Quaternion* FromOneVector (const Eigen::Ref<Vector4> v)
279296 {
280297 Quaternion* q (new Quaternion (v[3 ],v[0 ],v[1 ],v[2 ]));
281298 return q;
282299 }
283-
300+
301+ static Quaternion* FromRotationMatrix (const Eigen::Ref<Matrix3> R)
302+ {
303+ Quaternion* q (new Quaternion (R));
304+ return q;
305+ }
306+
284307 static bool __eq__ (const Quaternion & u, const Quaternion & v)
285308 {
286309 return u.coeffs () == v.coeffs ();
0 commit comments