utils.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (Apache License)
00003  *
00004  * Copyright (c) 2014, Southwest Research Institute
00005  *
00006  * Licensed under the Apache License, Version 2.0 (the "License");
00007  * you may not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  * http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS,
00014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
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 {
00045 namespace EulerConventions
00046 {
00047 enum EulerConvention
00048 {
00049   XYZ = 0,
00050   ZYX,
00051   ZXZ
00052 };
00053 }
00054 
00055 typedef EulerConventions::EulerConvention EulerConvention;
00056 
00057 // Use a function declaration so that we can add the 'unused' attribute, which prevents compiler warnings
00058 static Eigen::Affine3d toFrame(double tx, double ty, double tz, double rx, double ry, double rz,
00059                                int convention = int(EulerConventions::ZYX)) __attribute__((unused));
00060 
00061 static Eigen::Affine3d toFrame(double tx, double ty, double tz, double rx, double ry, double rz, int convention)
00062 {
00063   Eigen::Affine3d rtn;
00064 
00065   switch (convention)
00066   {
00067     case EulerConventions::XYZ:
00068       rtn = Eigen::Translation3d(tx, ty, tz) * Eigen::AngleAxisd(rx, Eigen::Vector3d::UnitX()) *
00069             Eigen::AngleAxisd(ry, Eigen::Vector3d::UnitY()) * Eigen::AngleAxisd(rz, Eigen::Vector3d::UnitZ());
00070       break;
00071 
00072     case EulerConventions::ZYX:
00073       rtn = Eigen::Translation3d(tx, ty, tz) * Eigen::AngleAxisd(rz, Eigen::Vector3d::UnitZ()) *
00074             Eigen::AngleAxisd(ry, Eigen::Vector3d::UnitY()) * Eigen::AngleAxisd(rx, Eigen::Vector3d::UnitX());
00075       break;
00076 
00077     case EulerConventions::ZXZ:
00078       rtn = Eigen::Translation3d(tx, ty, tz) * Eigen::AngleAxisd(rz, Eigen::Vector3d::UnitZ()) *
00079             Eigen::AngleAxisd(rx, Eigen::Vector3d::UnitX()) * Eigen::AngleAxisd(rz, Eigen::Vector3d::UnitZ());
00080       break;
00081 
00082     default:
00083       logError("Invalid euler convention entry %i", convention);
00084       break;
00085   }
00086 
00087   return rtn;
00088 }
00089 
00097 // Use a function declaration so that we can add the 'unused' attribute, which prevents compiler warnings
00098 static bool equal(const std::vector<double> &lhs, const std::vector<double> &rhs, const double tol)
00099     __attribute__((unused));
00100 
00101 static bool equal(const std::vector<double> &lhs, const std::vector<double> &rhs, const double tol)
00102 {
00103   bool rtn = false;
00104   if (lhs.size() == rhs.size())
00105   {
00106     rtn = true;
00107     for (size_t ii = 0; ii < lhs.size(); ++ii)
00108     {
00109       if (std::fabs(lhs[ii] - rhs[ii]) > tol)
00110       {
00111         rtn = false;
00112         break;
00113       }
00114     }
00115   }
00116   else
00117   {
00118     rtn = false;
00119   }
00120   return rtn;
00121 }
00122 
00123 }  // utils
00124 
00125 }  // descartes_core
00126 
00127 #endif /* UTILS_H_ */


descartes_core
Author(s): Dan Solomon
autogenerated on Thu Jun 6 2019 21:35:59