27 #ifndef OPENCV_CORE_DUALQUATERNION_INL_HPP
28 #define OPENCV_CORE_DUALQUATERNION_INL_HPP
30 #ifndef OPENCV_CORE_DUALQUATERNION_HPP
31 #error This is not a standalone header. Include dualquaternion.hpp instead.
43 w(vw),
x(vx),
y(vy), z(vz), w_(_w), x_(_x), y_(_y), z_(_z){}
47 w_(q[4]), x_(q[5]), y_(q[6]), z_(q[7]){}
67 Quat<T> t{0, trans[0], trans[1], trans[2]};
68 return createFromQuat(
r, t *
r *
T(0.5));
75 if (_R.size() !=
Size(4, 4))
81 Quat<T> trans(0,
R.at<
T>(0, 3),
R.at<
T>(1, 3),
R.at<
T>(2, 3));
82 return createFromQuat(
r, trans *
r *
T(0.5));
88 return createFromMat(
R.matrix);
94 T half_angle =
angle *
T(0.5), half_d = d *
T(0.5);
97 qmoment -= qaxis * axis.
dot(moment);
99 half_d *
std::cos(half_angle) * qaxis;
103 template <
typename T>
106 return (
abs(w - q.
w) < CV_DUAL_QUAT_EPS &&
abs(
x - q.
x) < CV_DUAL_QUAT_EPS &&
107 abs(
y - q.
y) < CV_DUAL_QUAT_EPS &&
abs(z - q.
z) < CV_DUAL_QUAT_EPS &&
108 abs(w_ - q.
w_) < CV_DUAL_QUAT_EPS &&
abs(x_ - q.
x_) < CV_DUAL_QUAT_EPS &&
109 abs(y_ - q.
y_) < CV_DUAL_QUAT_EPS &&
abs(z_ - q.
z_) < CV_DUAL_QUAT_EPS);
112 template <
typename T>
118 template <
typename T>
121 return Quat<T>(w_, x_, y_, z_);
124 template <
typename T>
130 template <
typename T>
136 template <
typename T>
140 T realNorm = real.
norm();
142 if (realNorm < CV_DUAL_QUAT_EPS){
145 return DualQuat<T>(realNorm, 0, 0, 0, real.
dot(dual) / realNorm, 0, 0, 0);
148 template <
typename T>
153 return getRealPart();
155 return getRealPart().normalize();
158 template <
typename T>
161 Quat<T> trans =
T(2.0) * (getDualPart() * getRealPart().inv(assumeUnit));
162 return Vec<T, 3>{trans[1], trans[2], trans[3]};
165 template <
typename T>
171 if (p_norm < CV_DUAL_QUAT_EPS)
177 return createFromQuat(p_nr, q_nr - p_nr * p_nr.
dot(q_nr));
180 template <
typename T>
183 return q.
w * w + q.
x *
x + q.
y *
y + q.
z * z + q.
w_ * w_ + q.
x_ * x_ + q.
y_ * y_ + q.
z_ * z_;
186 template <
typename T>
189 return dq.
inv(assumeUnit);
192 template <
typename T>
197 return createFromQuat(real.
inv(assumeUnit), -real.
inv(assumeUnit) * dual * real.
inv(assumeUnit));
200 template <
typename T>
206 template <
typename T>
212 template <
typename T>
218 template <
typename T>
225 template <
typename T>
235 template <
typename T>
242 template <
typename T>
248 template <
typename T>
254 template <
typename T>
260 template <
typename T>
267 template <
typename T>
273 template <
typename T>
279 template <
typename T>
285 template <
typename T>
288 return DualQuat<T>(w / a,
x / a,
y / a, z / a, w_ / a, x_ / a, y_ / a, z_ / a);
291 template <
typename T>
294 return *
this * q.inv();
297 template <
typename T>
304 template <
typename T>
311 template <
typename T>
319 template <
typename _Tp>
326 std::cos(nv), -sinc_nv * q.
x, -sinc_nv * q.
y, -sinc_nv * q.
z,
327 sinc_nv * q.
x, csiii_nv * q.
x * q.
x + sinc_nv, csiii_nv * q.
x * q.
y, csiii_nv * q.
x * q.
z,
328 sinc_nv * q.
y, csiii_nv * q.
y * q.
x, csiii_nv * q.
y * q.
y + sinc_nv, csiii_nv * q.
y * q.
z,
329 sinc_nv * q.
z, csiii_nv * q.
z * q.
x, csiii_nv * q.
z * q.
y, csiii_nv * q.
z * q.
z + sinc_nv
336 template <
typename T>
343 template <
typename T>
346 return dq.
log(assumeUnit);
349 template <
typename T>
354 return createFromQuat(plog,
Quat<T>(jacob.
inv() * getDualPart().toVec()));
357 template <
typename T>
360 return dq.
power(t, assumeUnit);
363 template <
typename T>
366 return (t *
log(assumeUnit)).exp();
369 template <
typename T>
372 return p.
power(q, assumeUnit);
375 template <
typename T>
378 return (q *
log(assumeUnit)).exp();
381 template <
typename T>
387 template <
typename T>
390 return Affine3<T>(toMat(assumeUnit));
393 template <
typename T>
397 Vec<T, 3> translation = getTranslation(assumeUnit);
398 rot44(0, 3) = translation[0];
399 rot44(1, 3) = translation[1];
400 rot44(2, 3) = translation[2];
404 template <
typename T>
413 Quat<T> v0Real = v0.getRealPart();
415 if (directChange && v1Real.
dot(v0Real) < 0)
423 template <
typename T>
432 if (v1.getRotation(assumeUnit).dot(v2.
getRotation(assumeUnit)) < 0)
434 return ((1 - t) * v1 - t * v2).normalize();
436 return ((1 - t) * v1 + t * v2).normalize();
439 template <
typename T>
444 Size dq_s = _dualquat.size();
445 if (dq_s != _weight.size() || (dq_s.
height != 1 && dq_s.
width != 1))
447 CV_Error(
Error::StsBadArg,
"The size of weight must be the same as dualquat, both of them should be (1, n) or (n, 1)");
449 Mat dualquat = _dualquat.getMat(), weight = _weight.getMat();
453 for (
int i = 0; i < cn; ++i)
460 for (
int i = 1; i < cn; ++i)
463 dq_blend = dq_blend + dualquat.
at<
Vec<T, 8>>(i) *
k * weight.at<
T>(i);
468 template <
typename T>
478 for (
int i = 0; i < cn ; ++i)
480 dualquat_mat.
at<
Vec<T, 8>>(i) = dualquat[i].toVec();
482 return gdqblend(dualquat_mat, _weight, assumeUnit);
Definition: dualquaternion.hpp:146
_Tp y_
Definition: dualquaternion.hpp:165
Vec< _Tp, 3 > getTranslation(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
return the translation vector. The rotation in this dual quaternion is applied before translation ....
Definition: dualquaternion.inl.hpp:159
static DualQuat< _Tp > createFromAffine3(const Affine3< _Tp > &R)
create dual quaternion from an affine matrix. The definition of affine matrix can refer to createFrom...
Definition: dualquaternion.inl.hpp:86
_Tp y
Definition: dualquaternion.hpp:165
friend DualQuat< T > log(const DualQuat< T > &dq, QuatAssumeType assumeUnit)
return the value of logarithm function value
Definition: dualquaternion.inl.hpp:344
Quat< _Tp > getRealPart() const
return a quaternion which represent the real part of dual quaternion. The definition of real part is ...
Definition: dualquaternion.inl.hpp:113
static DualQuat< _Tp > gdqblend(const Vec< DualQuat< _Tp >, cn > &dualquat, InputArray weights, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
The generalized Dual Quaternion linear Blending works for more than two rigid transformations....
static DualQuat< _Tp > createFromAngleAxisTrans(const _Tp angle, const Vec< _Tp, 3 > &axis, const Vec< _Tp, 3 > &translation)
create a dual quaternion from a rotation angle , a rotation axis and a translation ....
Definition: dualquaternion.inl.hpp:64
_Tp w_
Definition: dualquaternion.hpp:165
DualQuat< _Tp > operator-() const
Return opposite dual quaternion which satisfies .
Definition: dualquaternion.inl.hpp:207
DualQuat< _Tp > & operator/=(const DualQuat< _Tp > &)
Division assignment operator of two dual quaternions p and q; It divides left operand with the right ...
DualQuat< _Tp > operator/(const _Tp s) const
Division operator of a dual quaternions and a scalar. It divides left operand with the right operand ...
_Tp z_
Definition: dualquaternion.hpp:165
Affine3< _Tp > toAffine3(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
Transform this dual quaternion to a instance of Affine3.
Definition: dualquaternion.inl.hpp:388
friend DualQuat< T > power(const DualQuat< T > &dq, const T t, QuatAssumeType assumeUnit)
return the value of where p is a dual quaternion. This could be calculated as:
Definition: dualquaternion.inl.hpp:358
Vec< _Tp, 8 > toVec() const
Transform this dual quaternion to a vector.
Definition: dualquaternion.inl.hpp:382
DualQuat< _Tp > & operator+=(const DualQuat< _Tp > &)
Addition assignment operator of two dual quaternions p and q. It adds right operand to the left opera...
Definition: dualquaternion.inl.hpp:219
_Tp x_
Definition: dualquaternion.hpp:165
Quat< _Tp > getDualPart() const
return a quaternion which represent the dual part of dual quaternion. The definition of dual part is ...
Definition: dualquaternion.inl.hpp:119
_Tp dot(DualQuat< _Tp > p) const
return the dot product of two dual quaternion.
Definition: dualquaternion.inl.hpp:181
static DualQuat< _Tp > createFromMat(InputArray _R)
Transform this dual quaternion to an affine transformation matrix . Dual quaternion consists of a rot...
Definition: dualquaternion.inl.hpp:72
DualQuat< _Tp > exp() const
return the value of exponential function value
Definition: dualquaternion.inl.hpp:337
static DualQuat< _Tp > dqblend(const DualQuat< _Tp > &q1, const DualQuat< _Tp > &q2, const _Tp t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
The method of Dual Quaternion linear Blending(DQB) is to compute a transformation between dual quater...
Definition: dualquaternion.inl.hpp:424
DualQuat< _Tp > & operator*=(const DualQuat< _Tp > &)
Multiplication assignment operator of two quaternions. It multiplies right operand with the left oper...
friend DualQuat< T > exp(const DualQuat< T > &dq)
return the value of exponential function value
Definition: dualquaternion.inl.hpp:312
bool operator==(const DualQuat< _Tp > &) const
return true if two dual quaternions p and q are nearly equal, i.e. when the absolute value of each a...
Definition: dualquaternion.inl.hpp:104
friend DualQuat< T > conjugate(const DualQuat< T > &dq)
return the conjugate of a dual quaternion.
Definition: dualquaternion.inl.hpp:125
_Tp x
Definition: dualquaternion.hpp:165
DualQuat< _Tp > & operator-=(const DualQuat< _Tp > &)
Subtraction assignment operator of two dual quaternions p and q. It subtracts right operand from the ...
Definition: dualquaternion.inl.hpp:261
friend DualQuat< T > inv(const DualQuat< T > &dq, QuatAssumeType assumeUnit)
if is a dual quaternion, p is not zero, the inverse dual quaternion is
Definition: dualquaternion.inl.hpp:187
static DualQuat< _Tp > createFromPitch(const _Tp angle, const _Tp d, const Vec< _Tp, 3 > &axis, const Vec< _Tp, 3 > &moment)
A dual quaternion is a vector in form of.
Definition: dualquaternion.inl.hpp:92
DualQuat< _Tp > operator+(const DualQuat< _Tp > &) const
Addition operator of two dual quaternions p and q. It returns a new dual quaternion that each value i...
Definition: dualquaternion.inl.hpp:213
DualQuat< _Tp > conjugate() const
return the conjugate of a dual quaternion.
Definition: dualquaternion.inl.hpp:131
static DualQuat< _Tp > sclerp(const DualQuat< _Tp > &q1, const DualQuat< _Tp > &q2, const _Tp t, bool directChange=true, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
The screw linear interpolation(ScLERP) is an extension of spherical linear interpolation of dual quat...
Definition: dualquaternion.inl.hpp:405
Matx< _Tp, 4, 4 > toMat(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
Transform this dual quaternion to a affine transformation matrix the form of matrix,...
Definition: dualquaternion.inl.hpp:394
DualQuat< _Tp > norm() const
return the norm of dual quaternion .
Definition: dualquaternion.inl.hpp:137
_Tp z
Definition: dualquaternion.hpp:165
Quat< _Tp > getRotation(QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT) const
return the rotation in quaternion form.
Definition: dualquaternion.inl.hpp:149
DualQuat< _Tp > normalize() const
return a normalized dual quaternion. A dual quaternion can be expressed as
Definition: dualquaternion.inl.hpp:166
DualQuat< _Tp > operator*(const DualQuat< _Tp > &) const
Multiplication operator of two dual quaternions q and p. Multiplies values on either side of the oper...
Definition: dualquaternion.inl.hpp:226
_Tp w
Definition: dualquaternion.hpp:165
DualQuat()
Definition: dualquaternion.inl.hpp:39
static DualQuat< _Tp > createFromQuat(const Quat< _Tp > &realPart, const Quat< _Tp > &dualPart)
create Dual Quaternion from two same type quaternions p and q. A Dual Quaternion has the form:
Definition: dualquaternion.inl.hpp:50
n-dimensional dense array class
Definition: mat.hpp:812
_Tp & at(int i0=0)
Returns a reference to the specified array element.
Template class for small matrices whose type and size are known at compilation time.
Definition: matx.hpp:100
Matx< _Tp, n, m > inv(int method=DECOMP_LU, bool *p_is_ok=NULL) const
invert the matrix
_Tp dot(const Matx< _Tp, m, n > &v) const
dot product computed with the default precision
Definition: matx.inl.hpp:328
Definition: quaternion.hpp:211
_Tp dot(Quat< _Tp > q) const
return the dot between quaternion and this quaternion.
static Quat< _Tp > createFromRotMat(InputArray R)
from a 3x3 rotation matrix.
_Tp z
Definition: quaternion.hpp:1618
_Tp y
Definition: quaternion.hpp:1618
Quat< _Tp > normalize() const
return a normalized .
friend Quat< T > exp(const Quat< T > &q)
return the value of exponential value.
friend Quat< T > inv(const Quat< T > &q, QuatAssumeType assumeUnit)
return which is an inverse of which satisfies .
_Tp x
Definition: quaternion.hpp:1618
static Quat< _Tp > createFromAngleAxis(const _Tp angle, const Vec< _Tp, 3 > &axis)
from an angle, axis. Axis will be normalized in this function. And it generates
friend Quat< T > log(const Quat< T > &q, QuatAssumeType assumeUnit)
return the value of logarithm function.
_Tp norm() const
return the norm of quaternion.
_Tp w
Definition: quaternion.hpp:1618
Template class for specifying the size of an image or rectangle.
Definition: types.hpp:335
_Tp height
the height
Definition: types.hpp:363
_Tp width
the width
Definition: types.hpp:362
Template class for short numerical vectors, a partial case of Matx.
Definition: matx.hpp:369
InputArrayOfArrays InputArrayOfArrays InputOutputArray InputOutputArray InputOutputArray InputOutputArray Size InputOutputArray InputOutputArray T
Definition: calib3d.hpp:1867
InputArrayOfArrays InputArrayOfArrays InputOutputArray InputOutputArray InputOutputArray InputOutputArray Size InputOutputArray R
Definition: calib3d.hpp:1867
CV__DEBUG_NS_END typedef const _InputArray & InputArray
Definition: mat.hpp:442
const CvArr * angle
Definition: core_c.h:1194
const CvArr const CvArr const CvArr * B
Definition: core_c.h:1341
const CvArr CvArr * x
Definition: core_c.h:1195
const CvArr * y
Definition: core_c.h:1187
#define CV_MAT_DEPTH(flags)
Definition: interface.h:83
#define CV_64FC(n)
Definition: interface.h:128
#define CV_MAKETYPE(depth, cn)
Definition: interface.h:85
#define CV_Error(code, msg)
Call the error handler.
Definition: base.hpp:320
QuatAssumeType
Unit quaternion flag.
Definition: quaternion.hpp:39
std::ostream & operator<<(std::ostream &, const DualQuat< _Tp > &)
@ QUAT_ASSUME_NOT_UNIT
Definition: quaternion.hpp:46
@ QUAT_ASSUME_UNIT
Definition: quaternion.hpp:52
CvRect r
Definition: imgproc_c.h:984
CV_EXPORTS OutputArray int double double InputArray OutputArray int int bool double k
Definition: imgproc.hpp:2133
@ StsBadArg
function arg/param is bad
Definition: base.hpp:74
Matx< _Tp, 4, 4 > jacob_exp(const Quat< _Tp > &q)
Definition: dualquaternion.inl.hpp:320
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441
DualQuat< T > operator+(const T a, const DualQuat< T > &q)
Definition: dualquaternion.inl.hpp:243
DualQuat< T > power(const DualQuat< T > &dq, const T t, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
Definition: dualquaternion.inl.hpp:358
DualQuat< T > inv(const DualQuat< T > &dq, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
Definition: dualquaternion.inl.hpp:187
DualQuat< T > operator*(const T a, const DualQuat< T > &q)
Definition: dualquaternion.inl.hpp:274
DualQuat< T > log(const DualQuat< T > &dq, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
Definition: dualquaternion.inl.hpp:344
DualQuat< T > operator-(const DualQuat< T > &q, const T a)
Definition: dualquaternion.inl.hpp:255
DualQuat< T > conjugate(const DualQuat< T > &dq)
Definition: dualquaternion.inl.hpp:125
DualQuat< T > exp(const DualQuat< T > &dq)
Definition: dualquaternion.inl.hpp:312
static uchar abs(uchar a)
Definition: cvstd.hpp:66
Definition: traits.hpp:386