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
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef PCL_TIME_H_
00040 #define PCL_TIME_H_
00041
00042 #ifdef __GNUC__
00043 #pragma GCC system_header
00044 #endif
00045
00046 #include <cmath>
00047 #include <string>
00048 #include <boost/date_time/posix_time/posix_time.hpp>
00049
00057 namespace pcl
00058 {
00062 class StopWatch
00063 {
00064 public:
00066 StopWatch () : start_time_ (boost::posix_time::microsec_clock::local_time ())
00067 {
00068 }
00069
00071 virtual ~StopWatch () {}
00072
00074 inline double
00075 getTime ()
00076 {
00077 boost::posix_time::ptime end_time = boost::posix_time::microsec_clock::local_time ();
00078 return (static_cast<double> (((end_time - start_time_).total_milliseconds ())));
00079 }
00080
00082 inline double
00083 getTimeSeconds ()
00084 {
00085 return (getTime () * 0.001f);
00086 }
00087
00089 inline void
00090 reset ()
00091 {
00092 start_time_ = boost::posix_time::microsec_clock::local_time ();
00093 }
00094
00095 protected:
00096 boost::posix_time::ptime start_time_;
00097 };
00098
00114 class ScopeTime : public StopWatch
00115 {
00116 public:
00117 inline ScopeTime (const char* title) :
00118 title_ (std::string (title))
00119 {
00120 start_time_ = boost::posix_time::microsec_clock::local_time ();
00121 }
00122
00123 inline ScopeTime () :
00124 title_ (std::string (""))
00125 {
00126 start_time_ = boost::posix_time::microsec_clock::local_time ();
00127 }
00128
00129 inline ~ScopeTime ()
00130 {
00131 double val = this->getTime ();
00132 std::cerr << title_ << " took " << val << "ms.\n";
00133 }
00134
00135 private:
00136 std::string title_;
00137 };
00138
00139
00140 #ifndef MEASURE_FUNCTION_TIME
00141 #define MEASURE_FUNCTION_TIME \
00142 ScopeTime scopeTime(__func__)
00143 #endif
00144
00145 inline double
00146 getTime ()
00147 {
00148 boost::posix_time::ptime epoch_time (boost::gregorian::date (1970, 1, 1));
00149 boost::posix_time::ptime current_time = boost::posix_time::microsec_clock::local_time ();
00150 return (static_cast<double>((current_time - epoch_time).total_nanoseconds ()) * 1.0e-9);
00151 }
00152
00154 #ifndef DO_EVERY_TS
00155 #define DO_EVERY_TS(secs, currentTime, code) \
00156 if (1) {\
00157 static double s_lastDone_ = 0.0; \
00158 double s_now_ = (currentTime); \
00159 if (s_lastDone_ > s_now_) \
00160 s_lastDone_ = s_now_; \
00161 if ((s_now_ - s_lastDone_) > (secs)) { \
00162 code; \
00163 s_lastDone_ = s_now_; \
00164 }\
00165 } else \
00166 (void)0
00167 #endif
00168
00170 #ifndef DO_EVERY
00171 #define DO_EVERY(secs, code) \
00172 DO_EVERY_TS(secs, pcl::getTime(), code)
00173 #endif
00174
00175 }
00178 #endif //#ifndef PCL_NORMS_H_