00001
00002
00003 #ifndef GEOM_T3D_POINT_TOOLS_HPP
00004 #define GEOM_T3D_POINT_TOOLS_HPP
00005
00006 #include "geom/t3dEuler.hpp"
00007 #include "geom/t3dQuaternion.hpp"
00008
00009 namespace jafar {
00010 namespace geom {
00011
00017 namespace t3d {
00018
00023 template<class VecPtB, class VecPtA>
00024 void pointFromFrame(T3D const& aToB, VecPtB const& ptB, VecPtA& ptA) {
00025 JFR_PRECOND(ptB.size() == ptA.size(),
00026 "t3d::from: size of ptA and ptB does not match: " << ptB.size() << "!=" << ptA.size());
00027
00028 switch (ptB.size()) {
00029 case 3:
00030 ptA.assign( ublas::prod(aToB.getR(), ptB) + aToB.getT() );
00031 return;
00032 case 4:
00033 ptA.assign( ublas::prod(aToB.getM(), ptB) );
00034 return;
00035 default:
00036 JFR_PRECOND(ptB.size() == 3 || ptB.size() == 4,
00037 "t3d::from: invalid size for ptB: " << ptB.size());
00038 }
00039 }
00040
00046 template<class VecPtB, class MatJT3D, class MatJPtB>
00047 void pointFromFrameJac(T3D const& aToB, VecPtB const& ptB, MatJT3D& JT3D, MatJPtB& JPtB)
00048 {
00049 JFR_TRACE_BEGIN;
00050 switch (ptB.size()) {
00051 case 3:
00052 switch (aToB.type()) {
00053 case T3D::EULER:
00054 t3d::pointFromFrameJacEuler(aToB.getX(), ptB, JT3D, JPtB);
00055 return;
00056 case T3D::QUATERNION:
00057 t3d::pointFromFrameJacQuaternion(aToB.getX(), ptB, JT3D, JPtB);
00058 return;
00059 default:
00060 JFR_RUN_TIME("t3d::pointFromFrameJac: jacobian computation not yet implemented ("
00061 << aToB.type() << " " << ptB.size() << ")" );
00062 }
00063 case 4:
00064 JFR_RUN_TIME("t3d::pointFromFrameJac: jacobian computation not yet implemented ("
00065 << aToB.type() << " " << ptB.size() << ")" );
00066 default:
00067 JFR_PRECOND(ptB.size() == 3 || ptB.size() == 4,
00068 "t3d::from: invalid size for ptB: " << ptB.size());
00069 }
00070 JFR_TRACE_END("t3d::pointFromFrameJac");
00071 }
00072
00081 template<class VecPtB, class MatJT3D, class MatJPtB>
00082 void pointFromFrameJac(T3D const& aToB, VecPtB const& ptB, VecPtB& ptA, MatJT3D& JT3D, MatJPtB& JPtB)
00083 {
00084 JFR_PRECOND(ptB.size() == ptA.size(),
00085 "ptA and ptB must be of same size");
00086 JFR_TRACE_BEGIN;
00087 switch (ptB.size()) {
00088 case 3:
00089 switch (aToB.type()) {
00090 case T3D::EULER:
00091 t3d::pointFromFrame(aToB, ptB, ptA);
00092 t3d::pointFromFrameJacEuler(aToB.getX(), ptB, JT3D, JPtB);
00093 return;
00094 case T3D::QUATERNION:
00095 t3d::pointFromFrame(aToB, ptB, ptA);
00096 t3d::pointFromFrameJacQuaternion(aToB.getX(), ptB, JT3D, JPtB);
00097 return;
00098 default:
00099 JFR_RUN_TIME("t3d::pointFromFrameJac: jacobian computation not yet implemented ("
00100 << aToB.type() << " " << ptB.size() << ")" );
00101 }
00102 case 4:
00103 JFR_RUN_TIME("t3d::pointFromFrameJac: jacobian computation not yet implemented ("
00104 << aToB.type() << " " << ptB.size() << ")" );
00105 default:
00106 JFR_PRECOND(ptB.size() == 3 || ptB.size() == 4,
00107 "t3d::pointFromFrameJac: invalid size for ptB: " << ptB.size());
00108 }
00109 JFR_TRACE_END("t3d::pointFromFrameJac");
00110 }
00111
00117 template<class VecPtB, class VecPtA>
00118 void pointToFrame(T3D const& aToB, VecPtA const& ptA, VecPtB& ptB)
00119 {
00120 JFR_PRECOND(ptA.size() == ptB.size(),
00121 "t3d::to: size of ptA and ptB does not match: " << ptA.size() << "!=" << ptB.size());
00122
00123 using namespace ublas;
00124 using namespace jblas;
00125
00126 mat33 bToA_R;
00127 vec3 bToA_t;
00128
00129 bToA_R.assign(trans( aToB.getR() ));
00130 bToA_t.assign(-1*prod(bToA_R, aToB.getT()));
00131
00132 switch (ptA.size()) {
00133 case 3:
00134 {
00135 ptB.assign( ublas::prod(bToA_R, ptA) + bToA_t );
00136 return;
00137 }
00138 case 4:
00139 {
00140 mat44 bToA_M;
00141
00142 project(bToA_M, range(0,3), range(0,3)).assign(bToA_R);
00143
00144 bToA_M(0,3) = bToA_t(0);
00145 bToA_M(1,3) = bToA_t(1);
00146 bToA_M(2,3) = bToA_t(2);
00147
00148 bToA_M(3,0) = 0;
00149 bToA_M(3,1) = 0;
00150 bToA_M(3,2) = 0;
00151 bToA_M(3,3) = 1;
00152
00153 ptB.assign( ublas::prod(bToA_M, ptA) );
00154 return;
00155 }
00156 default:
00157 JFR_PRECOND(ptA.size() == 3 || ptA.size() == 4,
00158 "t3d::from: invalid size for ptA: " << ptA.size());
00159 }
00160 }
00161
00167 template<class VecPtB, class MatJT3D, class MatJPtA>
00168 void pointToFrameJac(T3D const& aToB, VecPtB const& ptA, MatJT3D& JT3D, MatJPtA& JPtA)
00169 {
00170 JFR_TRACE_BEGIN;
00171 switch (ptA.size()) {
00172 case 3:
00173 switch (aToB.type()) {
00174 case T3D::EULER:
00175 t3d::pointToFrameJacEuler(aToB.getX(), ptA, JT3D, JPtA);
00176 return;
00177 case T3D::QUATERNION:
00178 t3d::pointToFrameJacQuaternion(aToB.getX(), ptA, JT3D, JPtA);
00179 return;
00180 default:
00181 JFR_RUN_TIME("t3d::pointFromFrameJac: jacobian computation not yet implemented ("
00182 << aToB.type() << " " << ptA.size() << ")" );
00183 }
00184 case 4:
00185 JFR_RUN_TIME("t3d::pointFromFrameJac: jacobian computation not yet implemented ("
00186 << aToB.type() << " " << ptA.size() << ")" );
00187 default:
00188 JFR_PRECOND(ptA.size() == 3 || ptA.size() == 4,
00189 "t3d::from: invalid size for ptB: " << ptA.size());
00190 }
00191 JFR_TRACE_END("t3d::pointFromFrameJac");
00192 }
00193
00202 template<class VecPtB, class MatJT3D, class MatJPtA>
00203 void pointToFrameJac(T3D const& aToB, VecPtB const& ptA, VecPtB& ptB, MatJT3D& JT3D, MatJPtA& JPtA)
00204 {
00205 JFR_PRECOND(ptB.size() == ptA.size(),
00206 "ptA and ptB must be of same size");
00207 JFR_TRACE_BEGIN;
00208 switch (ptA.size()) {
00209 case 3:
00210 switch (aToB.type()) {
00211 case T3D::EULER:
00212 pointToFrame(aToB, ptA, ptB);
00213 t3d::pointToFrameJacEuler(aToB.getX(), ptA, JT3D, JPtA);
00214 return;
00215 case T3D::QUATERNION:
00216 pointToFrame(aToB, ptA, ptB);
00217 t3d::pointToFrameJacQuaternion(aToB.getX(), ptA, JT3D, JPtA);
00218 return;
00219 default:
00220 JFR_RUN_TIME("t3d::pointFromFrameJac: jacobian computation not yet implemented ("
00221 << aToB.type() << " " << ptA.size() << ")" );
00222 }
00223 case 4:
00224 JFR_RUN_TIME("t3d::pointFromFrameJac: jacobian computation not yet implemented ("
00225 << aToB.type() << " " << ptA.size() << ")" );
00226 default:
00227 JFR_PRECOND(ptA.size() == 3 || ptA.size() == 4,
00228 "t3d::from: invalid size for ptB: " << ptA.size());
00229 }
00230 JFR_TRACE_END("t3d::pointFromFrameJac");
00231 }
00232
00233 }
00234
00235 }
00236 }
00237
00238 #endif // GEOM_T3D_POINT_TOOLS_HPP