Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpHomogeneousMatrix.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Homogeneous matrix.
32 */
33
39
40#include <visp3/core/vpException.h>
41#include <visp3/core/vpHomogeneousMatrix.h>
42#include <visp3/core/vpMatrix.h>
43#include <visp3/core/vpPoint.h>
44#include <visp3/core/vpQuaternionVector.h>
45
47const unsigned int vpHomogeneousMatrix::constr_value_4 = 4;
53 : vpArray2D<double>(constr_value_4, constr_value_4)
54{
55 const unsigned int index_3 = 3;
56 buildFrom(t, q);
57 (*this)[index_3][index_3] = 1.;
58}
59
63vpHomogeneousMatrix::vpHomogeneousMatrix() : vpArray2D<double>(constr_value_4, constr_value_4), m_index(0) { eye(); }
64
69vpHomogeneousMatrix::vpHomogeneousMatrix(const vpHomogeneousMatrix &M) : vpArray2D<double>(constr_value_4, constr_value_4), m_index(0)
70{
71 *this = M;
72}
73
79 : vpArray2D<double>(constr_value_4, constr_value_4), m_index(0)
80{
81 const unsigned int index_3 = 3;
82 buildFrom(t, tu);
83 (*this)[index_3][index_3] = 1.;
84}
85
91 : vpArray2D<double>(constr_value_4, constr_value_4), m_index(0)
92{
93 const unsigned int index_3 = 3;
94 insert(R);
95 insert(t);
96 (*this)[index_3][index_3] = 1.;
97}
98
102vpHomogeneousMatrix::vpHomogeneousMatrix(const vpPoseVector &p) : vpArray2D<double>(constr_value_4, constr_value_4), m_index(0)
103{
104 const unsigned int index_0 = 0;
105 const unsigned int index_1 = 1;
106 const unsigned int index_2 = 2;
107 const unsigned int index_3 = 3;
108 const unsigned int index_4 = 4;
109 const unsigned int index_5 = 5;
110 buildFrom(p[index_0], p[index_1], p[index_2], p[index_3], p[index_4], p[index_5]);
111 (*this)[index_3][index_3] = 1.;
112}
113
157vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector<float> &v) : vpArray2D<double>(constr_value_4, constr_value_4), m_index(0)
158{
159 const unsigned int index_3 = 3;
160 buildFrom(v);
161 (*this)[index_3][index_3] = 1.;
162}
163
164#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
205vpHomogeneousMatrix::vpHomogeneousMatrix(const std::initializer_list<double> &list)
206 : vpArray2D<double>(4, 4), m_index(0)
207{
208 if (list.size() == 12) {
209 std::copy(list.begin(), list.end(), data);
210 data[12] = 0.;
211 data[13] = 0.;
212 data[14] = 0.;
213 data[15] = 1.;
214 }
215 else if (list.size() == 16) {
216 std::copy(list.begin(), list.end(), data);
217 for (size_t i = 12; i < 15; ++i) {
218 if (std::fabs(data[i]) > std::numeric_limits<double>::epsilon()) {
219 throw(vpException(vpException::fatalError,
220 "Cannot initialize homogeneous matrix. "
221 "List element %d (%f) should be 0.",
222 i, data[i]));
223 }
224 }
225 if (std::fabs(data[15] - 1.) > std::numeric_limits<double>::epsilon()) {
227 "Cannot initialize homogeneous matrix. "
228 "List element 15 (%f) should be 1.",
229 data[15]));
230 }
231 }
232 else {
234 "Cannot initialize homogeneous matrix from a list (%d elements) that has not 12 or 16 elements",
235 list.size()));
236 }
237
238 if (!isAnHomogeneousMatrix()) {
239 if (isAnHomogeneousMatrix(1e-3)) {
240 // re-orthogonalize rotation matrix since the input is close to a valid rotation matrix
241 orthogonalizeRotation();
242 }
243 else {
244 throw(vpException(
246 "Homogeneous matrix initialization fails since its elements are not valid (rotation part or last row)"));
247 }
248 }
249}
250#endif
251
295vpHomogeneousMatrix::vpHomogeneousMatrix(const std::vector<double> &v) : vpArray2D<double>(constr_value_4, constr_value_4), m_index(0)
296{
297 const unsigned int index_3 = 3;
298 buildFrom(v);
299 (*this)[index_3][index_3] = 1.;
300}
301
307vpHomogeneousMatrix::vpHomogeneousMatrix(double tx, double ty, double tz, double tux, double tuy, double tuz)
308 : vpArray2D<double>(constr_value_4, constr_value_4), m_index(0)
309{
310 const unsigned int index_3 = 3;
311 buildFrom(tx, ty, tz, tux, tuy, tuz);
312 (*this)[index_3][index_3] = 1.;
313}
314
320{
321 insert(tu);
322 insert(t);
323 return *this;
324}
325
331{
332 insert(R);
333 insert(t);
334 return *this;
335}
336
341{
342 const unsigned int index_0 = 0;
343 const unsigned int index_1 = 1;
344 const unsigned int index_2 = 2;
345 const unsigned int index_3 = 3;
346 const unsigned int index_4 = 4;
347 const unsigned int index_5 = 5;
348 vpTranslationVector tv(p[index_0], p[index_1], p[index_2]);
349 vpThetaUVector tu(p[index_3], p[index_4], p[index_5]);
350
351 insert(tu);
352 insert(tv);
353 return *this;
354}
355
366
372vpHomogeneousMatrix &vpHomogeneousMatrix::buildFrom(const double &tx, const double &ty, const double &tz, const double &tux, const double &tuy, const double &tuz)
373{
374 vpRotationMatrix R(tux, tuy, tuz);
375 vpTranslationVector t(tx, ty, tz);
376
377 insert(R);
378 insert(t);
379 return *this;
380}
381
427{
428 const std::size_t val_12 = 12;
429 const std::size_t val_16 = 16;
430 const unsigned int val_12ui = 12, val_16ui = 16;
431 if ((v.size() != val_12) && (v.size() != val_16)) {
432 throw(vpException(vpException::dimensionError, "Cannot convert std::vector<float> to vpHomogeneousMatrix"));
433 }
434
435 for (unsigned int i = 0; i < val_12ui; ++i) {
436 this->data[i] = static_cast<double>(v[i]);
437 }
438
439 if (v.size() == val_12) {
440 data[12] = 0.;
441 data[13] = 0.;
442 data[14] = 0.;
443 data[15] = 1.;
444 }
445 else {
446 for (unsigned int i = val_12ui; i < val_16ui; ++i) {
447 this->data[i] = static_cast<double>(v[i]);
448 }
449 }
450
451 if (!isAnHomogeneousMatrix()) {
452 if (isAnHomogeneousMatrix(1e-3)) {
453 // re-orthogonalize rotation matrix since the input is close to a valid rotation matrix
455 }
456 else {
457 throw(vpException(
459 "Homogeneous matrix initialization failed since its elements are not valid (rotation part or last row)"));
460 }
461 }
462 return *this;
463}
464
510{
511 const std::size_t val_12 = 12;
512 const std::size_t val_16 = 16;
513 const unsigned int val_12ui = 12, val_16ui = 16;
514
515
516 if ((v.size() != val_12) && (v.size() != val_16)) {
517 throw(vpException(vpException::dimensionError, "Cannot convert std::vector<double> to vpHomogeneousMatrix"));
518 }
519
520 for (unsigned int i = 0; i < val_12ui; ++i) {
521 this->data[i] = static_cast<double>(v[i]);
522 }
523
524 if (v.size() == val_12) {
525 data[12] = 0.;
526 data[13] = 0.;
527 data[14] = 0.;
528 data[15] = 1.;
529 }
530 else {
531 for (unsigned int i = val_12ui; i < val_16ui; ++i) {
532 this->data[i] = static_cast<double>(v[i]);
533 }
534 }
535
536 if (!isAnHomogeneousMatrix()) {
537 if (isAnHomogeneousMatrix(1e-3)) {
538 // re-orthogonalize rotation matrix since the input is close to a valid rotation matrix
540 }
541 else {
542 throw(vpException(
544 "Homogeneous matrix initialization fails since its elements are not valid (rotation part or last row)"));
545 }
546 }
547
548 return *this;
549}
550
557{
558 const int val_4 = 4;
559 for (int i = 0; i < val_4; ++i) {
560 for (int j = 0; j < val_4; ++j) {
561 rowPtrs[i][j] = M.rowPtrs[i][j];
562 }
563 }
564 return *this;
565}
566
589{
591
592 vpRotationMatrix R1, R2, R;
593 vpTranslationVector T1, T2, T;
594
595 extract(T1);
596 M.extract(T2);
597
598 extract(R1);
599 M.extract(R2);
600
601 R = R1 * R2;
602
603 T = (R1 * T2) + T1;
604
605 p.insert(T);
606 p.insert(R);
607
608 return p;
609}
610
633{
634 (*this) = (*this) * M;
635 return (*this);
636}
637
646{
647 const unsigned int val_4 = 4;
648 if (v.getRows() != val_4) {
650 "Cannot multiply a (4x4) homogeneous matrix by a "
651 "(%dx1) column vector",
652 v.getRows()));
653 }
655
656 p = 0.0;
657
658 for (unsigned int j = 0; j < val_4; ++j) {
659 for (unsigned int i = 0; i < val_4; ++i) {
660 p[i] += rowPtrs[i][j] * v[j];
661 }
662 }
663
664 return p;
665}
666
679{
680 vpPoint aP;
681
682 vpColVector v(4), v1(4);
683
684 const unsigned int index_0 = 0;
685 const unsigned int index_1 = 1;
686 const unsigned int index_2 = 2;
687 const unsigned int index_3 = 3;
688
689 v[index_0] = bP.get_X();
690 v[index_1] = bP.get_Y();
691 v[index_2] = bP.get_Z();
692 v[index_3] = bP.get_W();
693
694 v1[index_0] = ((*this)[index_0][index_0] * v[index_0]) + ((*this)[index_0][index_1] * v[index_1]) + ((*this)[index_0][index_2] * v[index_2]) + ((*this)[index_0][index_3] * v[index_3]);
695 v1[index_1] = ((*this)[index_1][index_0] * v[index_0]) + ((*this)[index_1][index_1] * v[index_1]) + ((*this)[index_1][index_2] * v[index_2]) + ((*this)[index_1][index_3] * v[index_3]);
696 v1[index_2] = ((*this)[index_2][index_0] * v[index_0]) + ((*this)[index_2][index_1] * v[index_1]) + ((*this)[index_2][index_2] * v[index_2]) + ((*this)[index_2][index_3] * v[index_3]);
697 v1[index_3] = ((*this)[index_3][index_0] * v[index_0]) + ((*this)[index_3][index_1] * v[index_1]) + ((*this)[index_3][index_2] * v[index_2]) + ((*this)[index_3][index_3] * v[index_3]);
698
699 v1 /= v1[index_3];
700
701 // --comment: v1 equals M multiplied by v
702 aP.set_X(v1[index_0]);
703 aP.set_Y(v1[index_1]);
704 aP.set_Z(v1[index_2]);
705 aP.set_W(v1[index_3]);
706
707 aP.set_oX(v1[index_0]);
708 aP.set_oY(v1[index_1]);
709 aP.set_oZ(v1[index_2]);
710 aP.set_oW(v1[index_3]);
711
712 return aP;
713}
714
726{
728 const unsigned int index_0 = 0;
729 const unsigned int index_1 = 1;
730 const unsigned int index_2 = 2;
731 const unsigned int index_3 = 3;
732 t_out[index_0] = (((*this)[index_0][0] * t[0]) + ((*this)[index_0][1] * t[1]) + ((*this)[index_0][index_2] * t[index_2])) + (*this)[index_0][index_3];
733 t_out[index_1] = (((*this)[index_1][0] * t[0]) + ((*this)[index_1][1] * t[1]) + ((*this)[index_1][index_2] * t[index_2])) + (*this)[index_1][index_3];
734 t_out[index_2] = (((*this)[index_2][0] * t[0]) + ((*this)[index_2][1] * t[1]) + ((*this)[index_2][index_2] * t[index_2])) + (*this)[index_2][index_3];
735
736 return t_out;
737}
738
754{
755 return (vpHomogeneousMatrix((*this).getTranslationVector(), (*this).getRotationMatrix() * R));
756}
757
805{
806 m_index = 0;
807 data[m_index] = val;
808 return *this;
809}
810
858{
859 ++m_index;
860 if (m_index >= size()) {
862 "Cannot set homogenous matrix out of bounds. It has only %d elements while you try to initialize "
863 "with %d elements",
864 size(), m_index + 1));
865 }
866 data[m_index] = val;
867 return *this;
868}
869
870/*********************************************************************/
871
879{
881 extract(R);
882
883 const unsigned int index_0 = 0;
884 const unsigned int index_1 = 1;
885 const unsigned int index_2 = 2;
886 const unsigned int index_3 = 3;
887 const double epsilon = std::numeric_limits<double>::epsilon();
888 bool isLastRowOK = vpMath::nul((*this)[index_3][index_0], epsilon) && vpMath::nul((*this)[index_3][index_1], epsilon) &&
889 vpMath::nul((*this)[index_3][index_2], epsilon);
890 return R.isARotationMatrix(threshold) && isLastRowOK && vpMath::equal((*this)[index_3][index_3], 1.0, epsilon);
891}
892
898{
899 unsigned int l_size = size();
900 for (unsigned int i = 0; i < l_size; ++i) {
901 if (vpMath::isNaN(data[i])) {
902 return false;
903 }
904 }
905 return true;
906}
907
913{
914 const unsigned int val_3 = 3;
915 for (unsigned int i = 0; i < val_3; ++i) {
916 for (unsigned int j = 0; j < val_3; ++j) {
917 R[i][j] = (*this)[i][j];
918 }
919 }
920}
921
926{
927 const unsigned int index_0 = 0;
928 const unsigned int index_1 = 1;
929 const unsigned int index_2 = 2;
930 const unsigned int index_3 = 3;
931 t[index_0] = (*this)[index_0][index_3];
932 t[index_1] = (*this)[index_1][index_3];
933 t[index_2] = (*this)[index_2][index_3];
934}
935
939{
941 (*this).extract(R);
942 tu.buildFrom(R);
943}
944
949{
951 (*this).extract(R);
952 q.buildFrom(R);
953}
954
959{
960 const unsigned int val_3 = 3;
961 for (unsigned int i = 0; i < val_3; ++i) {
962 for (unsigned int j = 0; j < val_3; ++j) {
963 (*this)[i][j] = R[i][j];
964 }
965 }
966}
967
975{
976 vpRotationMatrix R(tu);
977 insert(R);
978}
979
984{
985 const unsigned int index_0 = 0;
986 const unsigned int index_1 = 1;
987 const unsigned int index_2 = 2;
988 const unsigned int index_3 = 3;
989 (*this)[index_0][index_3] = t[index_0];
990 (*this)[index_1][index_3] = t[index_1];
991 (*this)[index_2][index_3] = t[index_2];
992}
993
1001
1017{
1019
1021 extract(R);
1023 extract(T);
1024
1026 RtT = -(R.t() * T);
1027
1028 Mi.insert(R.t());
1029 Mi.insert(RtT);
1030
1031 return Mi;
1032}
1033
1038{
1039 const unsigned int index_0 = 0;
1040 const unsigned int index_1 = 1;
1041 const unsigned int index_2 = 2;
1042 const unsigned int index_3 = 3;
1043 (*this)[index_0][index_0] = 1;
1044 (*this)[index_1][index_1] = 1;
1045 (*this)[index_2][index_2] = 1;
1046 (*this)[index_3][index_3] = 1;
1047
1048 (*this)[index_0][index_1] = 0;
1049 (*this)[index_0][index_2] = 0;
1050 (*this)[index_0][index_3] = 0;
1051 (*this)[index_1][index_0] = 0;
1052 (*this)[index_1][index_2] = 0;
1053 (*this)[index_1][index_3] = 0;
1054 (*this)[index_2][index_0] = 0;
1055 (*this)[index_2][index_1] = 0;
1056 (*this)[index_2][index_3] = 0;
1057 (*this)[index_3][index_0] = 0;
1058 (*this)[index_3][index_1] = 0;
1059 (*this)[index_3][index_2] = 0;
1060}
1061
1077
1078void vpHomogeneousMatrix::save(std::ofstream &f) const
1079{
1080 if (!f.fail()) {
1081 f << *this;
1082 }
1083 else {
1084 throw(vpException(vpException::ioError, "Cannot save homogeneous matrix: ostream not open"));
1085 }
1086}
1087
1088void vpHomogeneousMatrix::save(const std::string &filename) const
1089{
1090 std::ofstream f;
1091 f.open(filename.c_str());
1092 save(f);
1093 f.close();
1094}
1095
1096void vpHomogeneousMatrix::load(std::ifstream &f)
1097{
1098 if (!f.fail()) {
1099 const unsigned int val_4 = 4;
1100 for (unsigned int i = 0; i < val_4; ++i) {
1101 for (unsigned int j = 0; j < val_4; ++j) {
1102 f >> (*this)[i][j];
1103 }
1104 }
1105 }
1106 else {
1107 throw(vpException(vpException::ioError, "Cannot load homogeneous matrix: ifstream not open"));
1108 }
1109}
1110
1111void vpHomogeneousMatrix::load(const std::string &filename)
1112{
1113 std::ifstream f;
1114 f.open(filename.c_str());
1115 load(f);
1116 f.close();
1117}
1118
1123{
1124 vpRotationMatrix R(*this);
1125 R.orthogonalize();
1126 insert(R);
1127}
1128
1131{
1132 vpPoseVector r(*this);
1133 std::cout << r.t();
1134}
1135
1140void vpHomogeneousMatrix::convert(std::vector<float> &M)
1141{
1142 const std::size_t val_12 = 12;
1143 const unsigned int val_12ui = 12;
1144 M.resize(val_12);
1145 for (unsigned int i = 0; i < val_12ui; ++i) {
1146 M[i] = static_cast<float>(this->data[i]);
1147 }
1148}
1149
1154void vpHomogeneousMatrix::convert(std::vector<double> &M)
1155{
1156 const std::size_t val_12 = 12;
1157 const unsigned int val_12ui = 12;
1158 M.resize(val_12);
1159 for (unsigned int i = 0; i < val_12ui; ++i) {
1160 M[i] = this->data[i];
1161 }
1162}
1163
1168{
1170 this->extract(tr);
1171 return tr;
1172}
1173
1178{
1180 this->extract(R);
1181 return R;
1182}
1183
1189{
1190 vpThetaUVector tu;
1191 this->extract(tu);
1192 return tu;
1193}
1194
1228{
1229 if (j >= getCols()) {
1230 throw(vpException(vpException::dimensionError, "Unable to extract a column vector from the homogeneous matrix"));
1231 }
1232 unsigned int nb_rows = getRows();
1233 vpColVector c(nb_rows);
1234 for (unsigned int i = 0; i < nb_rows; ++i) {
1235 c[i] = (*this)[i][j];
1236 }
1237 return c;
1238}
1239
1246vpHomogeneousMatrix vpHomogeneousMatrix::compute3d3dTransformation(const std::vector<vpPoint> &p, const std::vector<vpPoint> &q)
1247{
1248 const double N = static_cast<double>(p.size());
1249
1250 vpColVector p_bar(3, 0.0);
1251 vpColVector q_bar(3, 0.0);
1252 size_t p_size = p.size();
1253 const unsigned int val_3 = 3;
1254 for (size_t i = 0; i < p_size; ++i) {
1255 for (unsigned int j = 0; j < val_3; ++j) {
1256 p_bar[j] += p.at(i).oP[j];
1257 q_bar[j] += q.at(i).oP[j];
1258 }
1259 }
1260
1261 for (unsigned int j = 0; j < val_3; ++j) {
1262 p_bar[j] /= N;
1263 q_bar[j] /= N;
1264 }
1265
1266 vpMatrix pc(static_cast<unsigned int>(p.size()), 3);
1267 vpMatrix qc(static_cast<unsigned int>(q.size()), 3);
1268
1269 for (unsigned int i = 0; i < static_cast<unsigned int>(p_size); ++i) {
1270 for (unsigned int j = 0; j < val_3; ++j) {
1271 pc[i][j] = p.at(i).oP[j] - p_bar[j];
1272 qc[i][j] = q.at(i).oP[j] - q_bar[j];
1273 }
1274 }
1275
1276 const vpMatrix pct_qc = pc.t() * qc;
1277 vpMatrix U = pct_qc, V;
1278 vpColVector W;
1279 U.svd(W, V);
1280
1281 vpMatrix Vt = V.t();
1282 vpMatrix R = U * Vt;
1283 if (R.det() < 0) {
1284 const unsigned int index_0 = 0;
1285 const unsigned int index_1 = 1;
1286 const unsigned int index_2 = 2;
1287 Vt[index_2][index_0] *= -1.;
1288 Vt[index_2][index_1] *= -1.;
1289 Vt[index_2][index_2] *= -1.;
1290
1291 R = U * Vt;
1292 }
1293
1294 const vpColVector t = p_bar - (R * q_bar);
1295
1297}
1298
1308vpHomogeneousMatrix vpHomogeneousMatrix::mean(const std::vector<vpHomogeneousMatrix> &vec_M)
1309{
1310 vpMatrix meanR(3, 3);
1311 vpColVector meanT(3);
1313 const unsigned int index_0 = 0;
1314 const unsigned int index_1 = 1;
1315 const unsigned int index_2 = 2;
1316 size_t vec_m_size = vec_M.size();
1317 for (size_t i = 0; i < vec_m_size; ++i) {
1318 R = vec_M[i].getRotationMatrix();
1319 meanR += static_cast<vpMatrix>(R);
1320 meanT += static_cast<vpColVector>(vec_M[i].getTranslationVector());
1321 }
1322 meanR /= static_cast<double>(vec_M.size());
1323 meanT /= static_cast<double>(vec_M.size());
1324
1325 // Euclidean mean of the rotation matrix following Moakher's method (SIAM 2002)
1326 vpMatrix M, U, V;
1327 vpColVector sv;
1328 meanR.pseudoInverse(M, sv, 1e-6, U, V);
1329 double det = sv[index_0] * sv[index_1] * sv[index_2];
1330 if (det > 0) {
1331 meanR = U * V.t();
1332 }
1333 else {
1334 vpMatrix D(3, 3);
1335 D = 0.0;
1336 D[index_0][index_0] = 1.0;
1337 D[index_1][index_1] = 1.0;
1338 D[index_2][index_2] = -1.;
1339 meanR = U * D * V.t();
1340 }
1341
1342 R = meanR;
1343
1344 vpTranslationVector t(meanT);
1346 return mean;
1347}
1348
1349#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1350
1358
1359#endif //#if defined(VISP_BUILD_DEPRECATED_FUNCTIONS)
1360
1361#ifdef VISP_HAVE_NLOHMANN_JSON
1362VP_ATTRIBUTE_NO_DESTROY const std::string vpHomogeneousMatrix::jsonTypeName = "vpHomogeneousMatrix";
1363#include <visp3/core/vpJsonParsing.h>
1364void vpHomogeneousMatrix::convert_to_json(nlohmann::json &j) const
1365{
1366 const vpArray2D<double> *asArray = (vpArray2D<double>*) this;
1367 to_json(j, *asArray);
1369}
1370
1371void vpHomogeneousMatrix::parse_json(const nlohmann::json &j)
1372{
1373#ifdef ENABLE_VISP_NAMESPACE
1374 using namespace VISP_NAMESPACE_NAME;
1375#endif
1376 vpArray2D<double> *asArray = (vpArray2D<double>*) this;
1377 if (j.is_object() && j.contains("type")) { // Specific conversions
1378 const bool converted = convertFromTypeAndBuildFrom<vpHomogeneousMatrix, vpPoseVector>(j, *this);
1379 if (!converted) {
1380 from_json(j, *asArray);
1381 }
1382 }
1383 else { // Generic 2D array conversion
1384 from_json(j, *asArray);
1385 }
1386
1387 if ((getCols() != 4) && (getRows() != 4)) {
1388 throw vpException(vpException::badValue, "From JSON, tried to read something that is not a 4x4 matrix");
1389 }
1390 if (!isAnHomogeneousMatrix()) {
1391 throw vpException(vpException::badValue, "From JSON read a non homogeneous matrix into a vpHomogeneousMatrix");
1392 }
1393}
1394#endif
1395END_VISP_NAMESPACE
Implementation of a generic 2D array used as base class for matrices and vectors.
Definition vpArray2D.h:146
unsigned int getCols() const
Definition vpArray2D.h:423
unsigned int rowNum
Definition vpArray2D.h:1201
unsigned int size() const
Definition vpArray2D.h:435
vpArray2D< double > t() const
Definition vpArray2D.h:1273
unsigned int getRows() const
Definition vpArray2D.h:433
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
Definition vpException.h:60
@ ioError
I/O error.
Definition vpException.h:67
@ badValue
Used to indicate that a value is not in the allowed range.
Definition vpException.h:73
@ dimensionError
Bad dimension.
Definition vpException.h:71
@ fatalError
Fatal error.
Definition vpException.h:72
vpThetaUVector getThetaUVector() const
void load(std::ifstream &f)
friend void from_json(const nlohmann::json &j, vpHomogeneousMatrix &T)
VP_DEPRECATED void setIdentity()
void print() const
Print the matrix as a pose vector .
vpRotationMatrix getRotationMatrix() const
bool isAnHomogeneousMatrix(double threshold=1e-6) const
static vpHomogeneousMatrix compute3d3dTransformation(const std::vector< vpPoint > &p, const std::vector< vpPoint > &q)
vpHomogeneousMatrix & operator*=(const vpHomogeneousMatrix &M)
vpHomogeneousMatrix & buildFrom(const vpTranslationVector &t, const vpRotationMatrix &R)
vpHomogeneousMatrix inverse() const
static vpHomogeneousMatrix mean(const std::vector< vpHomogeneousMatrix > &vec_M)
vpTranslationVector getTranslationVector() const
void convert(std::vector< float > &M)
void extract(vpRotationMatrix &R) const
vpColVector getCol(unsigned int j) const
vpHomogeneousMatrix & operator<<(double val)
void insert(const vpRotationMatrix &R)
vpHomogeneousMatrix operator*(const vpHomogeneousMatrix &M) const
void save(std::ofstream &f) const
vpHomogeneousMatrix & operator=(const vpHomogeneousMatrix &M)
friend void to_json(nlohmann::json &j, const vpHomogeneousMatrix &T)
static const std::string jsonTypeName
vpHomogeneousMatrix & operator,(double val)
static bool isNaN(double value)
Definition vpMath.cpp:101
static bool equal(double x, double y, double threshold=0.001)
Definition vpMath.h:470
static bool nul(double x, double threshold=0.001)
Definition vpMath.h:453
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
void svd(vpColVector &w, vpMatrix &V)
vpMatrix pseudoInverse(double svThreshold=1e-6) const
vpMatrix t() const
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:79
void set_W(double cW)
Set the point cW coordinate in the camera frame.
Definition vpPoint.cpp:459
void set_oW(double oW)
Set the point oW coordinate in the object frame.
Definition vpPoint.cpp:468
double get_Y() const
Get the point cY coordinate in the camera frame.
Definition vpPoint.cpp:411
void set_oY(double oY)
Set the point oY coordinate in the object frame.
Definition vpPoint.cpp:464
void set_X(double cX)
Set the point cX coordinate in the camera frame.
Definition vpPoint.cpp:453
double get_W() const
Get the point cW coordinate in the camera frame.
Definition vpPoint.cpp:415
void set_Y(double cY)
Set the point cY coordinate in the camera frame.
Definition vpPoint.cpp:455
double get_Z() const
Get the point cZ coordinate in the camera frame.
Definition vpPoint.cpp:413
void set_oZ(double oZ)
Set the point oZ coordinate in the object frame.
Definition vpPoint.cpp:466
void set_Z(double cZ)
Set the point cZ coordinate in the camera frame.
Definition vpPoint.cpp:457
void set_oX(double oX)
Set the point oX coordinate in the object frame.
Definition vpPoint.cpp:462
double get_X() const
Get the point cX coordinate in the camera frame.
Definition vpPoint.cpp:409
Implementation of a pose vector and operations on poses.
Implementation of a rotation vector as quaternion angle minimal representation.
vpQuaternionVector & buildFrom(const double &qx, const double &qy, const double &qz, const double &qw)
Implementation of a rotation matrix and operations on such kind of matrices.
Implementation of a rotation vector as axis-angle minimal representation.
Class that consider the case of a translation vector.