00001
00013 #include "jmath/misc.hpp"
00014 #include "rtslam/quatTools.hpp"
00015
00016 #ifndef AHPLTOOLS_HPP
00017 #define AHPLTOOLS_HPP
00018
00019 namespace jafar {
00020 namespace rtslam {
00025 namespace lmkAHPL {
00026 using namespace ublas;
00027 using namespace jblas;
00028 using namespace quaternion;
00029
00030
00039 template<class AHPL, class P0, class M>
00040 void split(const AHPL & ahpl, P0 & p0, M & m1, M & m2, double & rho1, double & rho2) {
00041 p0 = project(ahpl, range(0, 3));
00042 m1 = project(ahpl, range(3, 6));
00043 rho1 = ahpl(6);
00044 m2 = project(ahpl, range(7, 10));
00045 rho2 = ahpl(10);
00046 }
00047
00048
00058 template<class P0, class M>
00059 vec11 compose(const P0 & p0, const M & m1, const M & m2, const double rho1, const double rho2) {
00060 vec11 ahpl;
00061 project(ahpl, range(0, 3)) = p0;
00062 project(ahpl, range(3, 6)) = m1;
00063 ahpl(6) = rho1;
00064 project(ahpl, range(7, 10)) = m2;
00065 ahpl(10) = rho2;
00066 return ahpl;
00067 }
00068
00069 template<class VF, class Vlf>
00070 vec fromFrame(const VF & F, const Vlf & ahplf) {
00071
00072
00073
00074 vec3 p0f(subrange(ahplf, 0, 3));
00075 vec3 mf1(subrange(ahplf, 3, 6));
00076 vec3 mf2(subrange(ahplf, 7, 10));
00077
00078
00079
00080 vec ahpl(11);
00081
00082 subrange(ahpl, 0, 3) = eucFromFrame(F, p0f);
00083 subrange(ahpl, 3, 6) = vecFromFrame(F, mf1);
00084 subrange(ahpl, 7, 10) = vecFromFrame(F, mf2);
00085 ahpl(6) = ahplf(6);
00086 ahpl(10) = ahplf(10);
00087
00088 return ahpl;
00089 }
00090
00091 template<class VF, class Vahplf, class Vahpl, class MAHPL_f, class MAHPL_ahplf>
00092 void fromFrame(const VF & F, const Vahplf & ahplf, Vahpl & ahpl, MAHPL_f & AHPL_f, MAHPL_ahplf & AHPL_ahplf) {
00093
00094 vec3 p0f(subrange(ahplf, 0, 3));
00095 vec3 mf1(subrange(ahplf, 3, 6));
00096 vec3 mf2(subrange(ahplf, 7, 10));
00097
00098 vec3 p0;
00099 vec3 m1;
00100 vec3 m2;
00101 mat JAC_33(3, 3), JAC_37(3, 7);
00102
00103 AHPL_f.clear();
00104 AHPL_ahplf.clear();
00105
00106 eucFromFrame(F, p0f, p0, JAC_37, JAC_33);
00107 subrange(ahpl, 0, 3) = p0;
00108 subrange(AHPL_f, 0, 3, 0, 7) = JAC_37;
00109 subrange(AHPL_ahplf, 0, 3, 0, 3) = JAC_33;
00110
00111 vecFromFrame(F, mf1, m1, JAC_37, JAC_33);
00112 subrange(ahpl, 3, 6) = m1;
00113 subrange(AHPL_f, 3, 6, 0, 7) = JAC_37;
00114 subrange(AHPL_ahplf, 3, 6, 3, 6) = JAC_33;
00115
00116 vecFromFrame(F, mf2, m2, JAC_37, JAC_33);
00117 subrange(ahpl, 7, 10) = m2;
00118 subrange(AHPL_f, 7, 10, 0, 7) = JAC_37;
00119 subrange(AHPL_ahplf, 7, 10, 7, 10) = JAC_33;
00120
00121 ahpl(6) = ahplf(6);
00122 AHPL_ahplf(6, 6) = 1;
00123
00124 ahpl(10) = ahplf(10);
00125 AHPL_ahplf(10, 10) = 1;
00126 }
00127
00128 template<class VF, class Vahpl>
00129 vec toFrame(const VF & F, const Vahpl & ahpl) {
00130
00131 vec3 p0(subrange(ahpl, 0, 3));
00132 vec3 m1(subrange(ahpl, 3, 6));
00133 vec3 m2(subrange(ahpl, 7, 10));
00134
00135 vec ahplf(11);
00136 subrange(ahplf, 0, 3) = eucToFrame(F, p0);
00137 subrange(ahplf, 3, 6) = vecToFrame(F, m1);
00138 ahplf(6) = ahpl(6);
00139 subrange(ahplf, 7, 10) = vecToFrame(F, m2);
00140 ahplf(10) = ahpl(10);
00141
00142 return ahplf;
00143 }
00144
00145 template<class VF, class Vahpl, class Vahplf, class MAHPLF_f, class MAHPLF_ahp>
00146 void toFrame(const VF & F, const Vahpl & ahpl, Vahplf & ahplf, MAHPLF_f & AHPLF_f, MAHPLF_ahp & AHPLF_ahpl) {
00147
00148 vec3 p0(subrange(ahpl, 0, 3));
00149 vec3 m1(subrange(ahpl, 3, 6));
00150 vec3 m2(subrange(ahpl, 7, 10));
00151
00152 vec3 p0f;
00153 vec3 mf1;
00154 vec3 mf2;
00155 mat JAC_33(3, 3), JAC_37(3, 7);
00156
00157 AHPLF_f.clear();
00158 AHPLF_ahpl.clear();
00159
00160 eucToFrame(F, p0, p0f, JAC_37, JAC_33);
00161 subrange(ahplf, 0, 3) = p0f;
00162 subrange(AHPLF_f, 0, 3, 0, 7) = JAC_37;
00163 subrange(AHPLF_ahpl, 0, 3, 0, 3) = JAC_33;
00164
00165 vecToFrame(F, m1, mf1, JAC_37, JAC_33);
00166 subrange(ahplf, 3, 6) = mf1;
00167 subrange(AHPLF_f, 3, 6, 0, 7) = JAC_37;
00168 subrange(AHPLF_ahpl, 3, 6, 3, 6) = JAC_33;
00169
00170 vecToFrame(F, m2, mf2, JAC_37, JAC_33);
00171 subrange(ahplf, 7, 10) = mf2;
00172 subrange(AHPLF_f, 7, 10, 0, 7) = JAC_37;
00173 subrange(AHPLF_ahpl, 7, 10, 7, 10) = JAC_33;
00174
00175 ahplf(6) = ahpl(6);
00176 AHPLF_ahpl(6, 6) = 1;
00177
00178 ahplf(10) = ahpl(10);
00179 AHPLF_ahpl(10, 10) = 1;
00180 }
00181
00182
00188 template<class VA>
00189 vec6 ahpl2euc(const VA & ahpl) {
00190 vec6 ret;
00191 subrange(ret,0,3) = subrange(ahpl, 0, 3) + subrange(ahpl, 3, 6) / ahpl(6);
00192 subrange(ret,3,6) = subrange(ahpl, 0, 3) + subrange(ahpl, 7, 10) / ahpl(10);
00193 return ret;
00194 }
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00232 template<class VS, class VA, class VV>
00233 void toBearingOnlyFrame(const VS & s, const VA & ahpl, VV & v1, VV & v2) {
00234 vec3 p0, m1, m2;
00235 double rho1, rho2;
00236 split(ahpl, p0, m1, m2, rho1, rho2);
00237 vec3 t = subrange(s, 0, 3);
00238 vec4 q = subrange(s, 3, 7);
00239 vec3 d = m1 - (t - p0) * rho1;
00240 v1 = rotateInv(q, d);
00241 d = m2 - (t - p0) * rho2;
00242 v2 = rotateInv(q, d);
00243 }
00244
00245
00265 template<class VS, class VA, class VV>
00266 void toBearingOnlyFrame(const VS & s, const VA & ahpl, VV & v1, VV & v2, double & dist1, double & dist2) {
00267 vec3 p0, m1, m2;
00268 double rho1, rho2;
00269 split(ahpl, p0, m1, m2, rho1, rho2);
00270 vec3 t = subrange(s, 0, 3);
00271 vec4 q = subrange(s, 3, 7);
00272 vec3 d = m1 - (t - p0) * rho1;
00273 v1 = rotateInv(q, d);
00274 dist1 = norm_2(v1) / rho1;
00275 d = m2 - (t - p0) * rho2;
00276 v2 = rotateInv(q, d);
00277 dist2 = norm_2(v2) / rho2;
00278 }
00279
00280
00302 template<class VS, class VA, class VV, class MV_s, class MV_a>
00303 void toBearingOnlyFrame(const VS & s, const VA & ahpl, VV & v1, VV & v2, double & dist1, double & dist2, MV_s & V1_s, MV_a & V1_ahpl, MV_s & V2_s, MV_a & V2_ahpl) {
00304 vec3 p0, m1, m2;
00305 double rho1, rho2;
00306 mat34 V1_q;
00307 mat33 V1_d1;
00308 mat34 V2_q;
00309 mat33 V2_d2;
00310
00311 split(ahpl, p0, m1, m2, rho1, rho2);
00312 vec3 t = subrange(s, 0, 3);
00313 vec4 q = subrange(s, 3, 7);
00314 vec3 d = m1 - (t - p0) * rho1;
00315 rotateInv(q, d, v1, V1_q, V1_d1);
00316 dist1 = norm_2(v1) / rho1;
00317 d = m2 - (t - p0) * rho2;
00318 rotateInv(q, d, v2, V2_q, V2_d2);
00319 dist2 = norm_2(v2) / rho2;
00320
00321 mat33 V1_p0;
00322 mat33 V2_p0;
00323 V1_p0 = V1_d1 * rho1;
00324 V2_p0 = V2_d2 * rho2;
00325
00326
00327
00328
00329 V1_s.clear();
00330 V1_ahpl.clear();
00331 subrange(V1_s, 0, 3, 0, 3) = -V1_p0;
00332 subrange(V1_s, 0, 3, 3, 7) = V1_q;
00333 subrange(V1_ahpl, 0, 3, 0, 3) = V1_p0;
00334 subrange(V1_ahpl, 0, 3, 3, 6) = V1_d1;
00335 column(V1_ahpl, 6) = prod(V1_d1, (p0 - t));
00336 V2_s.clear();
00337 V2_ahpl.clear();
00338 subrange(V2_s, 0, 3, 0, 3) = -V2_p0;
00339 subrange(V2_s, 0, 3, 3, 7) = V2_q;
00340 subrange(V2_ahpl, 0, 3, 0, 3) = V2_p0;
00341 subrange(V2_ahpl, 0, 3, 7, 10) = V2_d2;
00342 column(V2_ahpl, 10) = prod(V2_d2, (p0 - t));
00343 }
00344
00345
00359 template<class VS, class VLS>
00360 vec11 fromBearingOnlyFrame(const VS & s, const VLS & v1, const VLS & v2, const double _rho1, const double _rho2) {
00361 vec3 t = subrange(s, 0, 3);
00362 vec4 q = subrange(s, 3, 7);
00363 vec11 ahpl;
00364
00365 subrange(ahpl, 0, 3) = t;
00366 subrange(ahpl, 3, 6) = rotate(q, v1);
00367 ahpl(6) = _rho1 * norm_2(v1);
00368 subrange(ahpl, 7, 10) = rotate(q, v2);
00369 ahpl(10) = _rho2 * norm_2(v2);
00370 return ahpl;
00371 }
00372
00373
00390 void fromBearingOnlyFrame(const vec7 & s, const vec3 & v1, const vec3 & v2, const double _rho1, const double _rho2,
00391 vec & ahpl, mat & AHPL_s, mat & AHPL_v1, mat & AHPL_v2, mat & AHPL_rho1, mat & AHPL_rho2);
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 template<class VS, class VA, class MA_s>
00439 double linearityScore(const VS & senpose, const VA & ahpl, const MA_s & AHPL){
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 return 1.0;
00458 }
00459
00460 }
00461
00462
00463 }
00464 }
00465
00466 #endif // AHPLTOOLS_HPP