FPSCounter.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package VisionX::Tools
19  * @author Kai Welke (kai dot welke at kit dot edu)
20  * @date 2011
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 namespace visionx
28 {
30  // definition of class FPSCounter
32 
36  class FPSCounter
37  {
38  public:
45  FPSCounter(int nDelayFrames = 10);
46 
48  // control
50 
53  void reset();
54 
61  void update();
62 
66  void recalculate();
67 
77  void assureFPS(float fFrameRate);
78 
80  // getter
82 
88  bool getValid();
89 
95  float getFPS();
96 
102  int getUpdates();
103 
109  float getMeanCycleTimeMS();
110 
116  float getMinCycleTimeMS();
117 
123  float getMaxCycleTimeMS();
124 
125  private:
126  // private methods
127  void updateMembers(int nCycleTime);
128  void recalculateFPS(int nCycleTime);
129  void recalculateStats(int nCycleTime);
130 
131  int calculateTimeDiff(long& nSec, long& nUSec, bool bSetTime = false);
132 
133  // settings
134  int m_nDelayFrames;
135 
136  // times
137  long m_nCycleSec;
138  long m_nCycleUSec;
139  int m_nIntervalTime;
140 
141  // results
142  int m_nUpdates;
143  float m_fFPS;
144  float m_fMinCycleTimeMS;
145  float m_fMaxCycleTimeMS;
146  float m_fLastCycleTimesMS[10];
147  };
148 }
149 
visionx::FPSCounter::getMinCycleTimeMS
float getMinCycleTimeMS()
Get minimum cycle time since start.
Definition: FPSCounter.cpp:154
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::FPSCounter::getFPS
float getFPS()
Get frames per second.
Definition: FPSCounter.cpp:127
visionx::FPSCounter::FPSCounter
FPSCounter(int nDelayFrames=10)
Constructs a new FPS counter.
Definition: FPSCounter.cpp:38
visionx::FPSCounter::getMeanCycleTimeMS
float getMeanCycleTimeMS()
Get mean cycle time over last 10 frames.
Definition: FPSCounter.cpp:137
visionx::FPSCounter::update
void update()
Updates the FPS counter.
Definition: FPSCounter.cpp:60
visionx::FPSCounter::getUpdates
int getUpdates()
Get number of updates.
Definition: FPSCounter.cpp:122
visionx::FPSCounter::reset
void reset()
Resets the FPS counter to its initial state.
Definition: FPSCounter.cpp:49
visionx::FPSCounter::getValid
bool getValid()
Get if calculated values are valid.
Definition: FPSCounter.cpp:117
visionx::FPSCounter::getMaxCycleTimeMS
float getMaxCycleTimeMS()
Get maximum cycle time since start.
Definition: FPSCounter.cpp:164
visionx::FPSCounter::assureFPS
void assureFPS(float fFrameRate)
Synchronize to FPS.
Definition: FPSCounter.cpp:82
visionx::FPSCounter
The FPSCounter class provides methods for calculating the frames per second (FPS) count in periodic t...
Definition: FPSCounter.h:36
visionx::FPSCounter::recalculate
void recalculate()
recalculates the FPS statistics
Definition: FPSCounter.cpp:72