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 
17  virtual ~WIdGenerator();
18 
20 
21  void work(TDatums& tDatums);
22 
23  private:
24  unsigned long long mGlobalCounter;
25 
26  DELETE_COPY(WIdGenerator);
27  };
28 }
29 
30 
31 
32 
33 
34 // Implementation
36 namespace op
37 {
38  template<typename TDatums>
40  mGlobalCounter{0ull}
41  {
42  }
43 
44  template<typename TDatums>
46  {
47  }
48 
49  template<typename TDatums>
51  {
52  }
53 
54  template<typename TDatums>
55  void WIdGenerator<TDatums>::work(TDatums& tDatums)
56  {
57  try
58  {
59  if (checkNoNullNorEmpty(tDatums))
60  {
61  // Debugging log
62  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
63  // Profiling speed
64  const auto profilerKey = Profiler::timerInit(__LINE__, __FUNCTION__, __FILE__);
65  // Add ID
66  for (auto& tDatum : *tDatums)
67  // To avoid overwritting ID if e.g., custom input has already filled it
68  if (tDatum.id == std::numeric_limits<unsigned long long>::max())
69  tDatum.id = mGlobalCounter;
70  // Increase ID
71  const auto& tDatum = (*tDatums)[0];
72  if (tDatum.subId == tDatum.subIdMax)
73  mGlobalCounter++;
74  // Profiling speed
75  Profiler::timerEnd(profilerKey);
76  Profiler::printAveragedTimeMsOnIterationX(profilerKey, __LINE__, __FUNCTION__, __FILE__);
77  // Debugging log
78  dLog("", Priority::Low, __LINE__, __FUNCTION__, __FILE__);
79  }
80  }
81  catch (const std::exception& e)
82  {
83  this->stop();
84  tDatums = nullptr;
85  error(e.what(), __LINE__, __FUNCTION__, __FILE__);
86  }
87  }
88 
90 }
91 
92 #endif // OPENPOSE_THREAD_W_ID_GENERATOR_HPP
void initializationOnThread()
Definition: wIdGenerator.hpp:50
Definition: worker.hpp:9
Definition: wIdGenerator.hpp:12
WIdGenerator()
Definition: wIdGenerator.hpp:39
void work(TDatums &tDatums)
Definition: wIdGenerator.hpp:55
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="")
virtual ~WIdGenerator()
Definition: wIdGenerator.hpp:45
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)