SLAMflex SE  0.1.0
SLAMflex provides detection and tracking of dominant planes for smartphone devices. This plane can then be used to show AR content relative to the plane orientation. The detection of plane is performed in the field of view of the smartphone camera. In subsequent frames it is tracked. The interface returns the plane position and orientation.
timer.h
Go to the documentation of this file.
1 /*
2  This file is part of the CVD Library.
3 
4  Copyright (C) 2005 The Authors
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
22 //
23 // A timer class designed for dealing with timestamps
24 // CK Nov 2002
25 //
27 
28 #ifndef __CVD_TIMER_H
29 #define __CVD_TIMER_H
30 #include <iostream>
31 #include <string>
32 #include <cassert>
33 #include <deque>
34 struct timeval;
35 
36 namespace CVD {
37 
44 class cvd_timer
45 {
46  public:
48  cvd_timer();
50  double get_time();
51 
55  double conv_ntime(signed long long time);
56 
60  double conv_ntime(const struct timeval& tv);
61 
64  double conv_ntime(const double time) const {
65  return time - startTime * 1.e-6;
66  }
67 
69  double reset();
70 
71 
72  private:
73  unsigned long long startTime;
74 };
75 
78 extern cvd_timer timer;
79 
82 double get_time_of_day();
83 
84 
90 {
91  public:
97  SimpleTimer(const std::string &description, const int &cycles_to_time=1, bool output=true, std::ostream &out=std::cout) : output_info(output), max(0), min(0), average(0), text(description), period(cycles_to_time), increment(0), timings(0), cumulative_time(0), time_at_start_of_timing(0), timing_started(false), sout(out)
98  {
99  assert(period>0);
101  }
102 
105  {
106  delete internal_cvd_timer;
107  }
108 
110  void click()
111  {
112  if (!timing_started)
113  {
114  timing_started=true;
116  }
117  else if (timing_started)
118  {
120  time_buffer.push_back(increment);
121  if((int)time_buffer.size()>period&&period>0)
122  time_buffer.pop_front();
123  timings++;
124  timing_started=false;
125  if (timings%period==0 && output_info)
126  print();
127  }
128  }
129 
132  void print()
133  {
134  if(timings>0)
135  {
136  if((int)time_buffer.size()==1)
137  sout<<text<<" takes: "<<get_average()<<"s over 1 timing"<<std::endl;
138  else
139  sout<<text<<" takes : av "<<get_average()<<"s , max "<<get_max()<<"s, min "<<get_min()<<"s, over "<<time_buffer.size()<<" timings"<<std::endl;
140  }
141  else
142  sout<<text<<" section : error. No timed cycles. Use click() to start and stop timing."<<std::endl;
143  }
144 
146  double get_max(){
147  max=-1;
148  if (time_buffer.size()>0)
149  max=time_buffer[0];
150  if(time_buffer.size()>1)
151  for(int i=0; i<(int)time_buffer.size(); ++i)
152  max=std::max(time_buffer[i], max);
153 
154  return max;
155 
156  }
157 
159  double get_min(){
160  min=-1;
161  if (time_buffer.size()>0)
162  min=time_buffer[0];
163  if(time_buffer.size()>1)
164  for(int i=0; i<(int)time_buffer.size(); ++i)
165  min=std::min(time_buffer[i], min);
166  return min;
167  }
168 
170  double get_average(){
171  average=-1;
172  if(time_buffer.size()>0){
173  cumulative_time=0;
174  for(int i=0; i<(int)time_buffer.size(); ++i)
177  }
178  return average;
179  }
180 
181  private:
183  double max, min, average;
184  std::string text;
185  int period;
186  double increment;
187  int timings;
192  std::ostream& sout;
193  std::deque<double> time_buffer;
194 
195 
196 };
197 
198 }
199 
200 #endif
double conv_ntime(signed long long time)
Definition: cvd_timer.cpp:60
double cumulative_time
Definition: timer.h:188
std::ostream & sout
Definition: timer.h:192
double get_time()
How many seconds have elapsed since the start time?
Definition: cvd_timer.cpp:54
double get_min()
Calculate the min cycle time as double.
Definition: timer.h:159
bool timing_started
Definition: timer.h:190
double average
Definition: timer.h:183
double reset()
Sets the start time to the current time.
Definition: cvd_timer.cpp:46
double get_max()
Calculate the max cycle time as double.
Definition: timer.h:146
cvd_timer timer
Definition: cvd_timer.cpp:82
void print()
Definition: timer.h:132
Definition: abs.h:24
SimpleTimer(const std::string &description, const int &cycles_to_time=1, bool output=true, std::ostream &out=std::cout)
Definition: timer.h:97
~SimpleTimer()
Destructor. Deletes the internal cvd_timer.
Definition: timer.h:104
double get_average()
Calculate the average cycle time as double.
Definition: timer.h:170
double max
Definition: timer.h:183
double time_at_start_of_timing
Definition: timer.h:189
std::string text
Definition: timer.h:184
void click()
Begin or end a timing cycle. Automatically calls print() when cycles_to_time cycles are reached...
Definition: timer.h:110
cvd_timer * internal_cvd_timer
Definition: timer.h:191
std::deque< double > time_buffer
Definition: timer.h:193
cvd_timer()
Create a timer, and set the start time to be now.
Definition: cvd_timer.cpp:41
double min
Definition: timer.h:183
double increment
Definition: timer.h:186
bool output_info
Definition: timer.h:182
double conv_ntime(const double time) const
Definition: timer.h:64
unsigned long long startTime
Definition: timer.h:73
double get_time_of_day()
Definition: cvd_timer.cpp:76
#define cout
Definition: Bundle.cpp:16