OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
wFpsMax.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_THREAD_W_FPS_MAX_HPP
2 #define OPENPOSE_THREAD_W_FPS_MAX_HPP
3 
4 #include <thread>
8 
9 namespace op
10 {
11  template<typename TDatums>
12  class WFpsMax : public Worker<TDatums>
13  {
14  public:
15  explicit WFpsMax(const double fpsMax);
16 
17  virtual ~WFpsMax();
18 
20 
21  void work(TDatums& tDatums);
22 
23  private:
24  const unsigned long long mNanosecondsToSleep;
25 
26  DELETE_COPY(WFpsMax);
27  };
28 }
29 
30 
31 
32 
33 
34 // Implementation
35 namespace op
36 {
37  template<typename TDatums>
38  WFpsMax<TDatums>::WFpsMax(const double fpsMax) :
39  mNanosecondsToSleep{uLongLongRound(1e9/fpsMax)}
40  {
41  }
42 
43  template<typename TDatums>
45  {
46  }
47 
48  template<typename TDatums>
50  {
51  }
52 
53  template<typename TDatums>
54  void WFpsMax<TDatums>::work(TDatums& tDatums)
55  {
56  try
57  {
58  // Debugging log
59  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
60  // Profiling speed
61  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
62  // tDatums not used --> Avoid warning
63  UNUSED(tDatums);
64  // Sleep the desired time
65  std::this_thread::sleep_for(std::chrono::nanoseconds{mNanosecondsToSleep});
66  // Profiling speed
67  Profiler::timerEnd(profilerKey);
68  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
69  // Debugging log
70  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
71  }
72  catch (const std::exception& e)
73  {
74  this->stop();
75  tDatums = nullptr;
76  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
77  }
78  }
79 
81 }
82 
83 #endif // OPENPOSE_THREAD_W_FPS_MAX_HPP
void initializationOnThread()
Definition: wFpsMax.hpp:49
Definition: wFpsMax.hpp:12
void work(TDatums &tDatums)
Definition: wFpsMax.hpp:54
Definition: worker.hpp:9
WFpsMax(const double fpsMax)
Definition: wFpsMax.hpp:38
#define UNUSED(unusedVariable)
Definition: macros.hpp:32
static const std::string timerInit(const int line, const std::string &function, const std::string &file)
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
void dLog(const T &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")
Definition: errorAndLog.hpp:53
virtual ~WFpsMax()
Definition: wFpsMax.hpp:44
static void printAveragedTimeMsOnIterationX(const std::string &key, const int line, const std::string &function, const std::string &file, const unsigned long long x=DEFAULT_X)
COMPILE_TEMPLATE_DATUM(WPoseTriangulation)
unsigned long long uLongLongRound(const T a)
Definition: fastMath.hpp:63
static void timerEnd(const std::string &key)