utils.h
Go to the documentation of this file.
00001 /*
00002  * File: utils.h
00003  * Author: Vladislav Tananaev
00004  *
00005  */
00006 
00007 #ifndef MRPT_BRIDGE_UTILS_H
00008 #define MRPT_BRIDGE_UTILS_H
00009 
00010 #include <ros/console.h>
00011 #include <mrpt/system/datetime.h>
00012 #include <mrpt/poses/CPose3D.h>
00013 #include <mrpt/version.h>
00014 #include <log4cxx/logger.h>
00015 
00016 #if MRPT_VERSION>=0x199
00017 #include <mrpt/system/COutputLogger.h>
00018 using namespace mrpt::system;
00019 #else
00020 #include <mrpt/utils/COutputLogger.h>
00021 using namespace mrpt::utils;
00022 #endif
00023 
00024 namespace mrpt_bridge
00025 {
00030 inline VerbosityLevel rosLoggerLvlToMRPTLoggerLvl(log4cxx::LevelPtr lvl)
00031 {
00032         using namespace log4cxx;
00033 
00034         // determine on the corresponding VerbosityLevel
00035         VerbosityLevel mrpt_lvl;
00036 
00037         if (lvl == Level::getFatal() || lvl == Level::getError())
00038         {
00039                 mrpt_lvl = LVL_ERROR;
00040         }
00041         else if (lvl == Level::getWarn())
00042         {
00043                 mrpt_lvl = LVL_WARN;
00044         }
00045         else if (lvl == Level::getInfo())
00046         {
00047                 mrpt_lvl = LVL_INFO;
00048         }
00049         else if (lvl == Level::getDebug())
00050         {
00051                 mrpt_lvl = LVL_DEBUG;
00052         }
00053         else
00054         {
00055                 THROW_EXCEPTION("Unknown log4cxx::Level is given.");
00056         }
00057 
00058         return mrpt_lvl;
00059 
00060 }  // end of rosLoggerLvlToMRPTLoggerLvl
00061 
00069 inline void mrptToROSLoggerCallback(
00070         const std::string& msg, const VerbosityLevel level,
00071         const std::string& loggerName, const mrpt::system::TTimeStamp timestamp)
00072 {
00073         // Remove trailing \n if present
00074         std::string tmsg = msg;
00075         if (!tmsg.empty() &&
00076                 tmsg.compare(tmsg.length() - 1, tmsg.length(), "\n") == 0)
00077         {
00078                 tmsg.erase(tmsg.end() - 1);
00079         }
00080 
00081         if (level == LVL_DEBUG)
00082         {
00083                 ROS_DEBUG("%s", tmsg.c_str());
00084         }
00085         else if (level == LVL_INFO)
00086         {
00087                 ROS_INFO("%s", tmsg.c_str());
00088         }
00089         else if (level == LVL_WARN)
00090         {
00091                 ROS_WARN("%s", tmsg.c_str());
00092         }
00093         else if (level == LVL_ERROR)
00094         {
00095                 ROS_ERROR("%s", tmsg.c_str());
00096         }
00097 }
00098 inline void mrptToROSLoggerCallback_mrpt_15(
00099         const std::string& msg, const VerbosityLevel level,
00100         const std::string& loggerName, const mrpt::system::TTimeStamp timestamp,
00101         void* userParam)
00102 {
00103     mrptToROSLoggerCallback(msg,level,loggerName,timestamp);
00104 }
00105 
00106 inline mrpt::math::TPose3D p2t(const mrpt::poses::CPose3D &p)
00107 {
00108 #if MRPT_VERSION>=0x199
00109         return p.asTPose();
00110 #else
00111         return TPose3D(p);
00112 #endif
00113 }
00114 
00115 }  // namespace mrpt_bridge
00116 
00117 #endif  // MRPT_BRIDGE_UTILS_H


mrpt_bridge
Author(s): Markus Bader , Raphael Zack
autogenerated on Fri Apr 27 2018 05:10:54