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
wIdGenerator.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_THREAD_W_ID_GENERATOR_HPP
2 #define OPENPOSE_THREAD_W_ID_GENERATOR_HPP
3 
4 #include <queue> // std::priority_queue
8 
9 namespace op
10 {
11  template<typename TDatums>
12  class WIdGenerator : public Worker<TDatums>
13  {
14  public:
15  explicit WIdGenerator();
16 
18 
19  void work(TDatums& tDatums);
20 
21  private:
22  unsigned long long mGlobalCounter;
23 
24  DELETE_COPY(WIdGenerator);
25  };
26 }
27 
28 
29 
30 
31 
32 // Implementation
34 namespace op
35 {
36  template<typename TDatums>
38  mGlobalCounter{0ull}
39  {
40  }
41 
42  template<typename TDatums>
44  {
45  }
46 
47  template<typename TDatums>
48  void WIdGenerator<TDatums>::work(TDatums& tDatums)
49  {
50  try
51  {
52  if (checkNoNullNorEmpty(tDatums))
53  {
54  // Debugging log
55  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
56  // Profiling speed
57  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
58  // Add ID
59  for (auto& tDatum : *tDatums)
60  // To avoid overwritting ID if e.g., custom input has already filled it
61  if (tDatum.id == std::numeric_limits<unsigned long long>::max())
62  tDatum.id = mGlobalCounter;
63  // Increase ID
64  const auto& tDatum = (*tDatums)[0];
65  if (tDatum.subId == tDatum.subIdMax)
66  mGlobalCounter++;
67  // Profiling speed
68  Profiler::timerEnd(profilerKey);
69  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
70  // Debugging log
71  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
72  }
73  }
74  catch (const std::exception& e)
75  {
76  this->stop();
77  tDatums = nullptr;
78  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
79  }
80  }
81 
83 }
84 
85 #endif // OPENPOSE_THREAD_W_ID_GENERATOR_HPP
void initializationOnThread()
Definition: wIdGenerator.hpp:43
Definition: worker.hpp:9
Definition: wIdGenerator.hpp:12
WIdGenerator()
Definition: wIdGenerator.hpp:37
void work(TDatums &tDatums)
Definition: wIdGenerator.hpp:48
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
bool checkNoNullNorEmpty(const TPointerContainer &tPointerContainer)
Definition: pointerContainer.hpp:7
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)
static void timerEnd(const std::string &key)