00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 */ 00035 00036 #ifndef PCL_TIME_H_ 00037 #define PCL_TIME_H_ 00038 00039 #include <cmath> 00040 #include "pcl/win32_macros.h" 00041 00042 #ifdef _WIN32 00043 00044 # include <time.h> 00045 # include <windows.h> 00046 00047 #else 00048 00049 # include <sys/time.h> 00050 00051 #endif 00052 00053 namespace pcl 00054 { 00061 class ScopeTime 00062 { 00063 public: 00064 inline ScopeTime (const char* title); 00065 inline ~ScopeTime (); 00066 private: 00067 std::string title_; 00068 #ifdef _WIN32 00069 LARGE_INTEGER start_time_, frequency_; 00070 #else 00071 timeval start_time_; 00072 #endif 00073 }; 00074 00075 #ifndef MEASURE_FUNCTION_TIME 00076 #define MEASURE_FUNCTION_TIME \ 00077 ScopeTime scopeTime(__func__) 00078 #endif 00079 00080 inline double getTime (); 00081 00083 #ifndef DO_EVERY_TS 00084 #define DO_EVERY_TS(secs, currentTime, code) \ 00085 if (1) {\ 00086 static double s_lastDone_ = 0.0; \ 00087 double s_now_ = (currentTime); \ 00088 if (s_lastDone_ > s_now_) \ 00089 s_lastDone_ = s_now_; \ 00090 if (s_now_ - s_lastDone_ > (secs)) { \ 00091 code; \ 00092 s_lastDone_ = s_now_; \ 00093 }\ 00094 } else \ 00095 (void)0 00096 #endif 00097 00099 #ifndef DO_EVERY 00100 #define DO_EVERY(secs, code) \ 00101 DO_EVERY_TS(secs, pcl::getTime(), code) 00102 #endif 00103 00104 } // end namespace 00105 00106 #include "pcl/common/time.hpp" 00107 00108 #endif //#ifndef PCL_NORMS_H_