$search
00001 #ifndef WALK_INTERFACE_UTIL_HH 00002 # define WALK_INTERFACE_UTIL_HH 00003 00004 # include <cmath> 00005 00006 # include <walk_interfaces/types.hh> 00007 00008 namespace walk 00009 { 00010 // \brief Convert a 2D \f$SO(2)\f$ matrix transform to a 3D 00011 // \f$SO(3)\f$ matrix transform. 00012 // 00013 // \param src 3x3 \f$SO(2)\f$ matrix transform. 00014 // \param dst 4x4 \f$SO(3)\f$ matrix transform. 00015 template <class U, class V> 00016 void trans2dToTrans3d (U& dst, const V& src) 00017 { 00018 assert (dst.cols () == 4 00019 && "Incorrect columns number for dest matrix, should be 4."); 00020 assert (dst.rows () == 4 00021 && "Incorrect rows number for dest matrix, should be 4."); 00022 assert (src.cols () == 3 00023 && "Wrong columns number for source matrix, should be 3."); 00024 assert (src.rows () == 3 00025 && "Wrong rows number for source matrix, should be 3."); 00026 dst.setIdentity (); 00027 00028 // Fill rotation. 00029 dst(0, 0) = src(0, 0); 00030 dst(0, 1) = src(0, 1); 00031 dst(1, 0) = src(1, 0); 00032 dst(1, 1) = src(1, 1); 00033 00034 // Fill translation. 00035 dst(0, 3) = src(0, 3); 00036 dst(1, 3) = src(1, 3); 00037 } 00038 00039 // \brief Convert a 2D \f$SO(2)\f$ matrix transform to a 3D 00040 // \f$SO(3)\f$ transformation. 00041 // 00042 // \param srcX translation value along x axis. 00043 // \param srcY translation value along y axis. 00044 // \param srcTh rotation angle (radians) around z axis. 00045 // \param dst 4x4 \f$SO(3)\f$ matrix transform. 00046 template <class U> 00047 void trans2dToTrans3d (U& dst, 00048 const double& srcX, 00049 const double& srcY, 00050 const double& srcTh) 00051 { 00052 assert (dst.cols () == 4 00053 && "Incorrect columns number for dest matrix, should be 4."); 00054 assert (dst.rows () == 4 00055 && "Incorrect rows number for dest matrix, should be 4."); 00056 00057 dst.setIdentity (); 00058 00059 // Fill rotation. 00060 dst(0, 0) = std::cos (srcTh); 00061 dst(1, 1) = std::cos (srcTh); 00062 00063 dst(0, 1) = -std::sin (srcTh); 00064 dst(1, 0) = std::sin (srcTh); 00065 00066 // Fill translation. 00067 dst(0, 3) = srcX; 00068 dst(1, 3) = srcY; 00069 } 00070 00074 template <class T> 00075 void convertVector3dToTrans3d (HomogeneousMatrix3d& dst, const T& src) 00076 { 00077 assert (dst.cols () == 4 00078 && "Incorrect columns number for dest matrix, should be 4."); 00079 assert (dst.rows () == 4 00080 && "Incorrect rows number for dest matrix, should be 4."); 00081 00082 dst.setIdentity (); 00083 00084 // Fill translation. 00085 dst(0, 3) = src[0]; 00086 dst(1, 3) = src[1]; 00087 dst(2, 3) = src[2]; 00088 } 00089 00095 template <class T> 00096 void convertToTrans3d (HomogeneousMatrix3d& dst, const T& src) 00097 { 00098 assert (dst.cols () == 4 00099 && "Incorrect columns number for dest matrix, should be 4."); 00100 assert (dst.rows () == 4 00101 && "Incorrect rows number for dest matrix, should be 4."); 00102 00103 dst.setIdentity (); 00104 00105 // Fill matrix. 00106 for (unsigned rowId = 0; rowId < 4; ++rowId) 00107 for (unsigned colId = 0; colId < 4; ++colId) 00108 dst(rowId, colId) = src(rowId, colId); 00109 } 00110 00114 template <class T> 00115 void convertToVector2d (Vector2d& dst, const T& src) 00116 { 00117 assert (dst.size () == 2 00118 && "Incorrect dest vector size mismatch, should be 2."); 00119 00120 dst[0] = src[0]; 00121 dst[1] = src[1]; 00122 } 00123 00127 template <class T> 00128 void convertToVector3d (Vector3d& dst, const T& src) 00129 { 00130 assert (dst.size () == 3 00131 && "Incorrect dest vector size mismatch, should be 3."); 00132 00133 dst[0] = src[0]; 00134 dst[1] = src[1]; 00135 dst[2] = src[2]; 00136 } 00137 00141 template <class T> 00142 void convertToPosture (Posture& dst, const T& src) 00143 { 00144 assert (src.size () == dst.size () 00145 && "Source and dest vectors size mismatch, should be equal."); 00146 assert (src.size () != 0 00147 && "Source vector has a zero size."); 00148 00149 for (unsigned id; id < src.size (); ++id) 00150 dst[id] = src [id]; 00151 } 00152 00153 } // end of namespace walk. 00154 00155 #endif //! WALK_INTERFACE_UTIL_HH