00001 #include <iostream> 00002 #include <boost/thread/thread.hpp> 00003 #include <pcl/common/time_trigger.h> 00004 #include <pcl/common/time.h> 00005 00006 using namespace std; 00007 using namespace pcl; 00008 00009 double global_time; 00010 00011 void callback () 00012 { 00013 static double last_time = pcl::getTime (); 00014 double elapsed = pcl::getTime () - last_time; 00015 last_time = pcl::getTime (); 00016 cout << "global fn: " << pcl::getTime () - global_time << " :: " << elapsed << endl; 00017 boost::this_thread::sleep(boost::posix_time::microseconds(1000)); 00018 } 00019 00020 class Dummy 00021 { 00022 public: 00023 void myTimer () 00024 { 00025 static double last_time = pcl::getTime (); 00026 double elapsed = pcl::getTime () - last_time; 00027 last_time = pcl::getTime (); 00028 cout << "member fn: " << pcl::getTime () - global_time << " :: " << elapsed << endl; 00029 } 00030 }; 00031 00032 int main () 00033 { 00034 TimeTrigger trigger (10.0, callback); 00035 Dummy dummy; 00036 global_time = pcl::getTime (); 00037 trigger.start (); 00038 boost::this_thread::sleep(boost::posix_time::seconds(2)); 00039 trigger.registerCallback ( boost::bind(&Dummy::myTimer, dummy)); 00040 boost::this_thread::sleep(boost::posix_time::seconds(3)); 00041 trigger.setInterval (0.2); 00042 boost::this_thread::sleep(boost::posix_time::seconds(2)); 00043 return 0; 00044 }