Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #ifndef UTILS_H_
00020 #define UTILS_H_
00021 
00022 #include <boost/shared_ptr.hpp>
00023 #include <Eigen/Core>
00024 
00028 #define DESCARTES_CLASS_FORWARD(C)                \
00029     class C;                        \
00030     typedef boost::shared_ptr<C> C##Ptr;        \
00031     typedef boost::shared_ptr<const C> C##ConstPtr;    \
00032 
00033 namespace descartes_core
00034 {
00035 namespace utils
00036 {
00037 
00046 namespace EulerConventions
00047 {
00048   enum EulerConvention
00049   {
00050     XYZ = 0,
00051     ZYX,
00052     ZXZ
00053   };
00054 }
00055 
00056 typedef EulerConventions::EulerConvention EulerConvention;
00057 
00058 static Eigen::Affine3d toFrame(double tx, double ty, double tz, double rx, double ry, double rz,
00059                                int convention = int(EulerConventions::ZYX))
00060 {
00061   Eigen::Affine3d rtn;
00062 
00063   switch(convention)
00064   {
00065     case EulerConventions::XYZ:
00066       rtn = Eigen::Translation3d(tx,ty,tz) *
00067           Eigen::AngleAxisd(rx, Eigen::Vector3d::UnitX()) *
00068           Eigen::AngleAxisd(ry, Eigen::Vector3d::UnitY()) *
00069           Eigen::AngleAxisd(rz, Eigen::Vector3d::UnitZ());
00070       break;
00071 
00072     case EulerConventions::ZYX:
00073       rtn = Eigen::Translation3d(tx,ty,tz) *
00074           Eigen::AngleAxisd(rz, Eigen::Vector3d::UnitZ()) *
00075           Eigen::AngleAxisd(ry, Eigen::Vector3d::UnitY()) *
00076           Eigen::AngleAxisd(rx, Eigen::Vector3d::UnitX());
00077       break;
00078 
00079     case EulerConventions::ZXZ:
00080       rtn = Eigen::Translation3d(tx,ty,tz) *
00081           Eigen::AngleAxisd(rz, Eigen::Vector3d::UnitZ()) *
00082           Eigen::AngleAxisd(rx, Eigen::Vector3d::UnitX()) *
00083           Eigen::AngleAxisd(rz, Eigen::Vector3d::UnitZ());
00084       break;
00085 
00086     default:
00087       logError("Invalid euler convention entry %i",convention);
00088       break;
00089 
00090   }
00091 
00092 
00093   return rtn;
00094 }
00095 
00102 static bool equal(const std::vector<double> &lhs, const std::vector<double> &rhs,
00103                                       const double tol)
00104 {
00105   bool rtn = false;
00106   if( lhs.size() == rhs.size() )
00107   {
00108     rtn = true;
00109     for(size_t ii = 0; ii < lhs.size(); ++ii)
00110     {
00111       if(std::fabs(lhs[ii]-rhs[ii]) > tol)
00112       {
00113         rtn = false;
00114         break;
00115       }
00116     }
00117 
00118   }
00119   else
00120   {
00121     rtn = false;
00122   }
00123   return rtn;
00124 }
00125 
00126 } 
00127 
00128 } 
00129 
00130 
00131 #endif