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 #ifndef PCL_TIME_H_
00039 #define PCL_TIME_H_
00040
00041 #include <cmath>
00042 #include <string>
00043 #include <boost/date_time/posix_time/posix_time.hpp>
00044
00052 namespace pcl
00053 {
00054
00058 class StopWatch
00059 {
00060 public:
00062 StopWatch () : start_time_ (boost::posix_time::microsec_clock::local_time ())
00063 {
00064 }
00065
00067 virtual ~StopWatch () {}
00068
00070 inline double
00071 getTime ()
00072 {
00073 boost::posix_time::ptime end_time = boost::posix_time::microsec_clock::local_time ();
00074 return (static_cast<double> (((end_time - start_time_).total_milliseconds ())));
00075 }
00076
00078 inline double
00079 getTimeSeconds ()
00080 {
00081 return (getTime () * 0.001f);
00082 }
00083
00085 inline void
00086 reset ()
00087 {
00088 start_time_ = boost::posix_time::microsec_clock::local_time ();
00089 }
00090
00091 protected:
00092 boost::posix_time::ptime start_time_;
00093 };
00094
00110 class ScopeTime : public StopWatch
00111 {
00112 public:
00113 inline ScopeTime (const char* title) :
00114 title_ (std::string (title))
00115 {
00116 start_time_ = boost::posix_time::microsec_clock::local_time ();
00117 }
00118
00119 inline ScopeTime () :
00120 title_ (std::string (""))
00121 {
00122 start_time_ = boost::posix_time::microsec_clock::local_time ();
00123 }
00124
00125 inline ~ScopeTime ()
00126 {
00127 double val = this->getTime ();
00128 std::cerr << title_ << " took " << val << "ms.\n";
00129 }
00130
00131 private:
00132 std::string title_;
00133 };
00134
00135
00136 #ifndef MEASURE_FUNCTION_TIME
00137 #define MEASURE_FUNCTION_TIME \
00138 ScopeTime scopeTime(__func__)
00139 #endif
00140
00141 inline double
00142 getTime ()
00143 {
00144 boost::posix_time::ptime epoch_time (boost::gregorian::date (1970, 1, 1));
00145 boost::posix_time::ptime current_time = boost::posix_time::microsec_clock::local_time ();
00146 return (static_cast<double>((current_time - epoch_time).total_nanoseconds ()) * 1.0e-9);
00147 }
00148
00150 #ifndef DO_EVERY_TS
00151 #define DO_EVERY_TS(secs, currentTime, code) \
00152 if (1) {\
00153 static double s_lastDone_ = 0.0; \
00154 double s_now_ = (currentTime); \
00155 if (s_lastDone_ > s_now_) \
00156 s_lastDone_ = s_now_; \
00157 if ((s_now_ - s_lastDone_) > (secs)) { \
00158 code; \
00159 s_lastDone_ = s_now_; \
00160 }\
00161 } else \
00162 (void)0
00163 #endif
00164
00166 #ifndef DO_EVERY
00167 #define DO_EVERY(secs, code) \
00168 DO_EVERY_TS(secs, pcl::getTime(), code)
00169 #endif
00170
00171 }
00174 #endif //#ifndef PCL_NORMS_H_