Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ahplTools.hpp
Go to the documentation of this file.
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             // split non-trivial chunks of landmark state
00074             vec3 p0f(subrange(ahplf, 0, 3));
00075             vec3 mf1(subrange(ahplf, 3, 6));
00076             vec3 mf2(subrange(ahplf, 7, 10));
00077 
00078 
00079             // transformed landmark in global frame
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             // split non-trivial chunks of landmark state
00094             vec3 p0f(subrange(ahplf, 0, 3));
00095             vec3 mf1(subrange(ahplf, 3, 6));
00096             vec3 mf2(subrange(ahplf, 7, 10));
00097             // destination chunks
00098             vec3 p0;
00099             vec3 m1;
00100             vec3 m2;
00101             mat JAC_33(3, 3), JAC_37(3, 7);
00102             // Jacobians
00103             AHPL_f.clear();
00104             AHPL_ahplf.clear();
00105             // transform p0
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             // transform m1
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             // transform m2
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             // transform rho1
00121             ahpl(6) = ahplf(6);
00122             AHPL_ahplf(6, 6) = 1;
00123             // transform rho2
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             // split non-trivial chunks of landmark state
00131             vec3 p0(subrange(ahpl, 0, 3));
00132             vec3 m1(subrange(ahpl, 3, 6));
00133             vec3 m2(subrange(ahpl, 7, 10));
00134             // transformed landmark in frame F
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             // split non-trivial chunks of landmark state
00148             vec3 p0(subrange(ahpl, 0, 3));
00149             vec3 m1(subrange(ahpl, 3, 6));
00150             vec3 m2(subrange(ahpl, 7, 10));
00151             // destination chunks
00152             vec3 p0f;
00153             vec3 mf1;
00154             vec3 mf2;
00155             mat JAC_33(3, 3), JAC_37(3, 7);
00156             // Jacobians
00157             AHPLF_f.clear();
00158             AHPLF_ahpl.clear();
00159             // transform p0
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             // transform m1
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             // transform m2
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             // transform rho1
00175             ahplf(6) = ahpl(6);
00176             AHPLF_ahpl(6, 6) = 1;
00177             // transform rho2
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 //          * Reparametrize to Euclidean, with Jacobians.
00199 //          * \param ahp the anchored homogeneous point to be reparametrized.
00200 //          * \param euc the returned Euclidean point.
00201 //          * \param EUC_ahp the Jacobian of the conversion.
00202 //          */
00203 //         template<class VA, class VE, class ME_a>
00204 //         void ahp2euc(const VA & ahp, VE & euc, ME_a & EUC_ahp) {
00205 //            euc.assign(ahp2euc(ahp));
00206 //            // split non-trivial chunks of landmark state
00207 //            vec3 m(subrange(ahp, 3, 6));
00208 //            double rho = ahp(6);
00209 //            identity_mat I(3);
00210 //            subrange(EUC_ahp, 0, 3, 0, 3) = I;
00211 //            subrange(EUC_ahp, 0, 3, 3, 6) = I / rho;
00212 //            column(EUC_ahp, 6) = -m / rho / rho;
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             // value
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; //    before rotation
00315             rotateInv(q, d, v1, V1_q, V1_d1); //  obtain v1
00316             dist1 = norm_2(v1) / rho1; //        obtain non-observable distance
00317             d = m2 - (t - p0) * rho2; //         before rotation
00318             rotateInv(q, d, v2, V2_q, V2_d2); //  obtain v1
00319             dist2 = norm_2(v2) / rho2; //        obtain non-observable distance
00320             // Jacobians
00321             mat33 V1_p0;
00322             mat33 V2_p0;
00323             V1_p0 = V1_d1 * rho1;
00324             V2_p0 = V2_d2 * rho2;
00325             //        mat V_rho(3,1); // This comments only for Jacobian reference...
00326             //        V_m = V_d;
00327             //        V_rho = prod(V_d, (p0 - t));
00328             //        V_t = - V_d * rho;
00329             V1_s.clear();
00330             V1_ahpl.clear();
00331             subrange(V1_s, 0, 3, 0, 3) = -V1_p0; //        dv / dt
00332             subrange(V1_s, 0, 3, 3, 7) = V1_q; //          dv / dq
00333             subrange(V1_ahpl, 0, 3, 0, 3) = V1_p0; //      dv / dp0
00334             subrange(V1_ahpl, 0, 3, 3, 6) = V1_d1; //       dv / dm
00335             column(V1_ahpl, 6) = prod(V1_d1, (p0 - t)); //  dv / drho
00336             V2_s.clear();
00337             V2_ahpl.clear();
00338             subrange(V2_s, 0, 3, 0, 3) = -V2_p0; //        dv / dt
00339             subrange(V2_s, 0, 3, 3, 7) = V2_q; //          dv / dq
00340             subrange(V2_ahpl, 0, 3, 0, 3) = V2_p0; //      dv / dp0
00341             subrange(V2_ahpl, 0, 3, 7, 10) = V2_d2; //       dv / dm
00342             column(V2_ahpl, 10) = prod(V2_d2, (p0 - t)); //  dv / drho
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          template<class VS, class VLS, class VA, class MA_s, class MA_v, class MA_rho>
00394          void fromBearingOnlyFrame(const VS & s, const VLS & v1, const VLS & v2, const double _rho1, const double _rho2,
00395              VA & ahpl, MA_s & AHPL_s, MA_v & AHPL_v1, MA_v & AHPL_v2, MA_rho & AHPL_rho1, MA_rho & AHPL_rho2) {
00396             vec3 t = subrange(s, 0, 3);
00397             vec4 q = subrange(s, 3, 7);
00398             vec3 m1;
00399             vec3 m2;
00400             mat34 M1_q;
00401             mat33 M1_v1;
00402             mat34 M2_q;
00403             mat33 M2_v2;
00404             mat NV1_v1(1, 3);
00405             mat NV2_v2(1, 3);
00406 
00407             rotate(q, v1, m1, M1_q, M1_v1);
00408             rotate(q, v2, m2, M2_q, M2_v2);
00409             double nv1 = norm_2(v1);
00410             double nv2 = norm_2(v2);
00411 
00412             subrange(ahpl, 0, 3) = t; // p0  = t
00413             subrange(ahpl, 3, 6) = m1; // m   = R(q) * v
00414             ahpl(6) = _rho1 * nv1; //              rho = ||v|| * _rho
00415             ublasExtra::norm_2Jac<3>(v1, NV1_v1); // drho / dv = d||v||/dv * _rho
00416             subrange(ahpl, 7, 10) = m2; // m   = R(q) * v
00417             ahpl(10) = _rho2 * nv2; //              rho = ||v|| * _rho
00418             ublasExtra::norm_2Jac<3>(v2, NV2_v2); // drho / dv = d||v||/dv * _rho
00419 
00420             // Jacobians
00421             identity_mat I(3);
00422             AHPL_s.clear();
00423             AHPL_v1.clear();
00424             AHPL_v2.clear();
00425             AHPL_rho1.clear();
00426             AHPL_rho2.clear();
00427             subrange(AHPL_s, 0, 3, 0, 3) = I; //                dp0 / dt
00428             subrange(AHPL_s, 3, 6, 3, 7) = M1_q; //             dm / dq
00429             subrange(AHPL_s, 7, 10, 3, 7) = M2_q; //            dm / dq
00430             subrange(AHPL_v1, 3, 6, 0, 3) = M1_v1; //           dm / dv
00431             subrange(AHPL_v2, 7, 10,0, 3) = M2_v2; //           dm / dv
00432             subrange(AHPL_v1, 6, 7, 0, 3) = _rho1 * NV1_v1; //  drho / dv
00433             subrange(AHPL_v2, 7, 11,0, 3) = _rho2 * NV2_v2; //  drho / dv
00434             AHPL_rho1(6, 0) = nv1; //                           drho / drho
00435             AHPL_rho2(10,0) = nv2; //                           drho / drho
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                vec3 euc = ahp2euc(ahp);
00442 
00443                vec3 hw = euc - subrange(senpose, 0, 3);
00444 
00445                double sigma_rho = sqrt(AHP(6,6));
00446 
00447                double sigma_d   = sigma_rho/(ahp(6)*ahp(6));
00448                double norm_hw   = norm_2(hw);
00449                double norm_m    = norm_2(subrange(ahp, 3, 6));
00450                double cos_a     = inner_prod(subrange(ahp, 3, 6) , hw) / (norm_hw*norm_m);
00451 
00452                double L = 4.0*sigma_d/norm_hw*jmath::abs(cos_a);
00453 
00454 //          std::cout << "rho="<<ahp(6)<<", sr="<<sigma_rho<<", sd="<<sigma_d<<", nh="<<norm_hw<<", nm="<<norm_m<<", cos="<<jmath::abs(cos_a)<<std::endl;
00455 //          std::cout << "linearity score: " << L << std::endl;
00456 
00457                return L; */ return 1.0;// 0.0;
00458          }
00459 
00460       } // namespace landmarkAHPL
00461 
00462 
00463    }
00464 }
00465 
00466 #endif // AHPLTOOLS_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:26 for Jafar by doxygen 1.7.6.1
LAAS-CNRS