44 #ifndef OPENCV_CORE_AFFINE3_HPP
45 #define OPENCV_CORE_AFFINE3_HPP
49 #include <opencv2/core.hpp>
129 typedef T float_type;
130 typedef Matx<float_type, 3, 3> Mat3;
131 typedef Matx<float_type, 4, 4> Mat4;
132 typedef Vec<float_type, 3> Vec3;
138 Affine3(
const Mat4& affine);
153 Affine3(
const Mat3&
R,
const Vec3& t = Vec3::all(0));
164 Affine3(
const Vec3& rvec,
const Vec3& t = Vec3::all(0));
179 explicit Affine3(
const Mat&
data,
const Vec3& t = Vec3::all(0));
182 explicit Affine3(
const float_type* vals);
185 static Affine3 Identity();
196 void rotation(
const Mat3&
R);
206 void rotation(
const Vec3& rvec);
218 void rotation(
const Mat&
data);
227 void linear(
const Mat3& L);
236 void translation(
const Vec3& t);
239 Mat3 rotation()
const;
245 Vec3 translation()
const;
258 Affine3
rotate(
const Mat3&
R)
const;
261 Affine3
rotate(
const Vec3& rvec)
const;
264 Affine3 translate(
const Vec3& t)
const;
267 Affine3 concatenate(
const Affine3& affine)
const;
269 template <
typename Y>
operator Affine3<Y>()
const;
271 template <
typename Y> Affine3<Y> cast()
const;
275 #if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H
276 Affine3(
const Eigen::Transform<
T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine);
277 Affine3(
const Eigen::Transform<T, 3, Eigen::Affine>& affine);
278 operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>()
const;
279 operator Eigen::Transform<T, 3, Eigen::Affine>()
const;
283 template<
typename T>
static
284 Affine3<T>
operator*(
const Affine3<T>& affine1,
const Affine3<T>& affine2);
287 template<
typename T,
typename V>
static
288 V operator*(
const Affine3<T>& affine,
const V& vector);
290 typedef Affine3<float> Affine3f;
291 typedef Affine3<double> Affine3d;
296 template<
typename _Tp>
class DataType< Affine3<_Tp> >
299 typedef Affine3<_Tp> value_type;
300 typedef Affine3<typename DataType<_Tp>::work_type> work_type;
301 typedef _Tp channel_type;
303 enum { generic_type = 0,
305 fmt = traits::SafeFmt<channel_type>::fmt + ((
channels - 1) << 8)
306 #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
312 typedef Vec<channel_type, channels> vec_type;
316 template<
typename _Tp>
318 template<
typename _Tp>
331 template<
typename T>
inline
332 cv::Affine3<T>::Affine3()
333 : matrix(Mat4::eye())
336 template<
typename T>
inline
337 cv::Affine3<T>::Affine3(
const Mat4& affine)
341 template<
typename T>
inline
342 cv::Affine3<T>::Affine3(
const Mat3&
R,
const Vec3& t)
346 matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
350 template<
typename T>
inline
351 cv::Affine3<T>::Affine3(
const Vec3& _rvec,
const Vec3& t)
355 matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
359 template<
typename T>
inline
360 cv::Affine3<T>::Affine3(
const cv::Mat&
data,
const Vec3& t)
365 if (
data.cols == 4 &&
data.rows == 4)
370 else if (
data.cols == 4 &&
data.rows == 3)
373 translation(
data(
Rect(3, 0, 1, 3)));
381 matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
385 template<
typename T>
inline
386 cv::Affine3<T>::Affine3(
const float_type* vals) : matrix(vals)
389 template<
typename T>
inline
390 cv::Affine3<T> cv::Affine3<T>::Identity()
392 return Affine3<T>(cv::Affine3<T>::Mat4::eye());
395 template<
typename T>
inline
396 void cv::Affine3<T>::rotation(
const Mat3&
R)
401 template<
typename T>
inline
402 void cv::Affine3<T>::rotation(
const Vec3& _rvec)
406 if (
theta < DBL_EPSILON)
407 rotation(Mat3::eye());
415 Point3_<T>
r = _rvec*itheta;
418 Mat3 r_x( 0, -
r.z,
r.
y,
r.z, 0, -
r.
x, -
r.
y,
r.
x, 0 );
422 Mat3
R = c*Mat3::eye() + c1*rrt + s*r_x;
429 template<
typename T>
inline
435 if (
data.cols == 3 &&
data.rows == 3)
441 else if ((
data.cols == 3 &&
data.rows == 1) || (
data.cols == 1 &&
data.rows == 3))
444 data.reshape(1, 3).copyTo(_rvec);
448 CV_Error(Error::StsError,
"Input matrix can only be 3x3, 1x3 or 3x1");
451 template<
typename T>
inline
452 void cv::Affine3<T>::linear(
const Mat3& L)
454 matrix.val[0] = L.val[0]; matrix.val[1] = L.val[1]; matrix.val[ 2] = L.val[2];
455 matrix.val[4] = L.val[3]; matrix.val[5] = L.val[4]; matrix.val[ 6] = L.val[5];
456 matrix.val[8] = L.val[6]; matrix.val[9] = L.val[7]; matrix.val[10] = L.val[8];
459 template<
typename T>
inline
460 void cv::Affine3<T>::translation(
const Vec3& t)
462 matrix.val[3] = t[0]; matrix.val[7] = t[1]; matrix.val[11] = t[2];
465 template<
typename T>
inline
466 typename cv::Affine3<T>::Mat3 cv::Affine3<T>::rotation()
const
471 template<
typename T>
inline
472 typename cv::Affine3<T>::Mat3 cv::Affine3<T>::linear()
const
474 typename cv::Affine3<T>::Mat3
R;
475 R.val[0] = matrix.val[0];
R.val[1] = matrix.val[1];
R.val[2] = matrix.val[ 2];
476 R.val[3] = matrix.val[4];
R.val[4] = matrix.val[5];
R.val[5] = matrix.val[ 6];
477 R.val[6] = matrix.val[8];
R.val[7] = matrix.val[9];
R.val[8] = matrix.val[10];
481 template<
typename T>
inline
482 typename cv::Affine3<T>::Vec3 cv::Affine3<T>::translation()
const
484 return Vec3(matrix.val[3], matrix.val[7], matrix.val[11]);
487 template<
typename T>
inline
488 typename cv::Affine3<T>::Vec3 cv::Affine3<T>::rvec()
const
495 double rx =
R.val[7] -
R.val[5];
496 double ry =
R.val[2] -
R.val[6];
497 double rz =
R.val[3] -
R.val[1];
499 double s =
std::sqrt((rx*rx + ry*ry + rz*rz)*0.25);
500 double c = (
R.val[0] +
R.val[4] +
R.val[8] - 1) * 0.5;
501 c = c > 1.0 ? 1.0 : c < -1.0 ? -1.0 : c;
511 t = (
R.val[0] + 1) * 0.5;
513 t = (
R.val[4] + 1) * 0.5;
515 t = (
R.val[8] + 1) * 0.5;
518 if(
fabs(rx) <
fabs(ry) &&
fabs(rx) <
fabs(rz) && (
R.val[5] > 0) != (ry*rz > 0) )
528 double vth = 1/(2*s);
530 rx *= vth; ry *= vth; rz *= vth;
536 template<
typename T>
inline
539 return matrix.inv(
method);
542 template<
typename T>
inline
546 Vec3 tc = translation();
551 for(
int j = 0; j < 3; ++j)
553 for(
int i = 0; i < 3; ++i)
555 float_type
value = 0;
556 for(
int k = 0;
k < 3; ++
k)
561 result(j, 3) =
R.row(j).dot(tc.t());
566 template<
typename T>
inline
569 return rotate(Affine3f(_rvec).rotation());
572 template<
typename T>
inline
573 cv::Affine3<T> cv::Affine3<T>::translate(
const Vec3& t)
const
582 template<
typename T>
inline
583 cv::Affine3<T> cv::Affine3<T>::concatenate(
const Affine3<T>& affine)
const
585 return (*this).rotate(affine.rotation()).translate(affine.translation());
588 template<
typename T>
template <
typename Y>
inline
589 cv::Affine3<T>::operator Affine3<Y>()
const
591 return Affine3<Y>(matrix);
594 template<
typename T>
template <
typename Y>
inline
595 cv::Affine3<Y> cv::Affine3<T>::cast()
const
597 return Affine3<Y>(matrix);
600 template<
typename T>
inline
601 cv::Affine3<T>
cv::operator*(
const cv::Affine3<T>& affine1,
const cv::Affine3<T>& affine2)
603 return affine2.concatenate(affine1);
606 template<
typename T,
typename V>
inline
609 const typename Affine3<T>::Mat4& m = affine.matrix;
612 r.
x = m.val[0] * v.x + m.val[1] * v.y + m.val[ 2] * v.z + m.val[ 3];
613 r.
y = m.val[4] * v.x + m.val[5] * v.y + m.val[ 6] * v.z + m.val[ 7];
614 r.z = m.val[8] * v.
x + m.val[9] * v.y + m.val[10] * v.z + m.val[11];
623 r.val[0] = m.
val[0] * v[0] + m.
val[1] * v[1] + m.
val[ 2] * v[2] + m.
val[ 3];
624 r.val[1] = m.
val[4] * v[0] + m.
val[5] * v[1] + m.
val[ 6] * v[2] + m.
val[ 7];
625 r.val[2] = m.
val[8] * v[0] + m.
val[9] * v[1] + m.
val[10] * v[2] + m.
val[11];
634 r.val[0] = m.
val[0] * v[0] + m.
val[1] * v[1] + m.
val[ 2] * v[2] + m.
val[ 3];
635 r.val[1] = m.
val[4] * v[0] + m.
val[5] * v[1] + m.
val[ 6] * v[2] + m.
val[ 7];
636 r.val[2] = m.
val[8] * v[0] + m.
val[9] * v[1] + m.
val[10] * v[2] + m.
val[11];
642 #if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H
644 template<
typename T>
inline
645 cv::Affine3<T>::Affine3(
const Eigen::Transform<
T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine)
650 template<
typename T>
inline
651 cv::Affine3<T>::Affine3(
const Eigen::Transform<T, 3, Eigen::Affine>& affine)
653 Eigen::Transform<
T, 3, Eigen::Affine, (Eigen::RowMajor)> a = affine;
657 template<
typename T>
inline
658 cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>()
const
660 Eigen::Transform<
T, 3, Eigen::Affine, (Eigen::RowMajor)>
r;
666 template<
typename T>
inline
667 cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine>()
const
669 return this->
operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>();
n-dimensional dense array class
Definition: mat.hpp:812
void copyTo(OutputArray m) const
Copies the matrix to another one.
Template class for small matrices whose type and size are known at compilation time.
Definition: matx.hpp:100
_Tp val[m *n]
matrix elements
Definition: matx.hpp:218
@ FULL_UV
Definition: core.hpp:2762
@ MODIFY_A
Definition: core.hpp:2755
static void compute(InputArray src, OutputArray w, OutputArray u, OutputArray vt, int flags=0)
decomposes matrix and stores the results to user-provided matrices
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_EXPORTS_W void rotate(InputArray src, OutputArray dst, int rotateCode)
Rotates a 2D array in multiples of 90 degrees. The function cv::rotate rotates the array in one of th...
@ DECOMP_SVD
Definition: base.hpp:138
Rect2i Rect
Definition: types.hpp:489
Vec< double, 3 > Vec3d
Definition: matx.hpp:464
static double norm(const Matx< _Tp, m, n > &M)
Vec< float, 3 > Vec3f
Definition: matx.hpp:459
int CvScalar value
Definition: core_c.h:720
int int channels
Definition: core_c.h:100
int int type
Definition: core_c.h:221
int depth
Definition: core_c.h:100
void * data
Definition: core_c.h:427
const CvArr const CvArr * V
Definition: core_c.h:1341
const CvArr const CvArr CvArr * result
Definition: core_c.h:1423
#define CV_MAKETYPE(depth, cn)
Definition: interface.h:85
#define CV_Error(code, msg)
Call the error handler.
Definition: base.hpp:320
#define CV_Assert(expr)
Checks a condition at runtime and throws exception if it fails.
Definition: base.hpp:342
Quat< T > inv(const Quat< T > &q, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
CvRect r
Definition: imgproc_c.h:984
void int double double theta
Definition: imgproc_c.h:926
const CvArr CvArr int method
Definition: imgproc_c.h:384
CV_EXPORTS OutputArray int double double InputArray OutputArray int int bool double k
Definition: imgproc.hpp:2133
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441
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
int y
Definition: types_c.h:834
int x
Definition: types_c.h:833
@ value
Definition: traits.hpp:382
Definition: traits.hpp:386
@ value
Definition: traits.hpp:386