Nuitrack  1.11.2
3D Skeleton Tracking Middleware
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Events Groups Pages
HandTracker.h
1 #ifndef NUITRACK_HAND_TRACKER_H_
2 #define NUITRACK_HAND_TRACKER_H_
3 
4 #include <functional>
5 
6 #include "nuitrack/modules/HeaderOnlyAPI_Module.h"
7 #include "nuitrack/types/Export.h"
8 #include "nuitrack/types/HandTrackerData.h"
9 #include "nuitrack/capi/HandTracker_CAPI.h"
10 #include "nuitrack/utils/ExceptionTranslator.h"
11 #include "nuitrack/utils/CallbackStruct.h"
12 
13 namespace tdv
14 {
15 namespace nuitrack
16 {
28 class HandTracker : public tdv::nuitrack::HeaderOnlyAPI_Module
29 {
30 public:
35  typedef std::shared_ptr<HandTracker> Ptr;
36 
46  typedef std::function<void (HandTrackerData::Ptr)> OnUpdate;
47 
48  typedef void (*OnUpdateRawFunctionPtr)(HandTrackerData*, HandTracker*);
49 
58  {
59  NuitrackModule* pimpl = NULL;
60  ExceptionType exception_code = nuitrack_CreateHandTracker(&pimpl);
61  ExceptionTranslator::generateExceptionByErrorCode(exception_code);
62  return std::shared_ptr<HandTracker>(new HandTracker(pimpl));
63  }
64 
65  virtual ~HandTracker()
66  {
68  nuitrack_DestroyHandTracker(_pimpl);
69  }
70 
72  HandTracker(NuitrackModule* pimpl)
73  {
74  _pimpl = pimpl;
75 
76  _callbackStruct = new CallbackStruct<HandTrackerData::Ptr>();
77  _callbackWrapper.setHandTracker(this);
78  _callbackWrapper.setFunctionAddress(&onUpdateCallback);
79  nuitrack_registerHandTrackerCallback(_pimpl, &_callbackWrapper);
80  }
81 
89  uint64_t connectOnUpdate(const OnUpdate& callback)
90  {
91  return _callbackStruct->addCallback(callback);
92  }
93 
100  void disconnectOnUpdate(uint64_t handler)
101  {
102  _callbackStruct->deleteCallback(handler);
103  }
104 
108  HandTrackerData::Ptr getData()
109  {
110  HandTrackerDataInner* data = NULL;
111  nuitrack_ReceiveInnerHandTrackerData(_pimpl, &data);
112  HandTrackerData::Ptr newFrame(new HandTrackerData(data));
113  return newFrame;
114  }
115 
119  float getProcessingTime() const
120  {
121  return nuitrack_GetHandTrackerProcessingTime(_pimpl);
122  }
123 
124  bool canUpdate() const
125  {
126  return nuitrack_GetNuitrackModuleCanUpdate(_pimpl);
127  }
128 
135  virtual uint64_t getTimestamp()
136  {
137  return nuitrack_GetNuitrackModuleTimestamp(_pimpl);
138  }
139 
140 protected:
142  static void onUpdateCallback(HandTrackerDataInner* data, HandTracker* tracker)
143  {
144  HandTrackerData::Ptr newFrame(new HandTrackerData(data));
145  tracker->_callbackStruct->executeAllCallbacks(newFrame);
146  }
149  {
150  if(_callbackStruct)
151  delete _callbackStruct;
152  }
154  NuitrackModule* _pimpl;
156  HandTrackerCallbackWrapper _callbackWrapper;
158  CallbackStruct<HandTrackerData::Ptr>* _callbackStruct;
159 };
160 
161 } /* namespace nuitrack */
162 } /* namespace tdv */
163 
164 #endif /* NUITRACK_HAND_TRACKER_H_ */
uint64_t connectOnUpdate(const OnUpdate &callback)
Add a callback for the hand data update request.
Definition: HandTracker.h:89
Represents the interface to the capabilities of the Nuitrack Hand Tracker module. ...
Definition: HandTracker.h:28
HandTrackerCallbackWrapper _callbackWrapper
Definition: HandTracker.h:156
ExceptionType
Possible error codes for Nuitrack internal functions.
Definition: Error.h:20
HandTracker(NuitrackModule *pimpl)
Definition: HandTracker.h:72
float getProcessingTime() const
Returns last hand data processing time in milliseconds.
Definition: HandTracker.h:119
virtual uint64_t getTimestamp()
Returns the last processed data timestamp in microseconds.
Definition: HandTracker.h:135
std::function< void(HandTrackerData::Ptr)> OnUpdate
The callback type of the hand data update request.
Definition: HandTracker.h:46
void destroyHandTracker()
Definition: HandTracker.h:148
std::shared_ptr< HandTracker > Ptr
Smart pointer to access the SkeletonTracker instance.
Definition: HandTracker.h:35
static HandTracker::Ptr create()
Create the HandTracker module object.
Definition: HandTracker.h:57
static void onUpdateCallback(HandTrackerDataInner *data, HandTracker *tracker)
Definition: HandTracker.h:142
void disconnectOnUpdate(uint64_t handler)
Remove a callback of the hand data update request.
Definition: HandTracker.h:100
NuitrackModule * _pimpl
Definition: HandTracker.h:154
HandTrackerData::Ptr getData()
Returns smart pointer to the last avilable HandTrackerData.
Definition: HandTracker.h:108
CallbackStruct< HandTrackerData::Ptr > * _callbackStruct
Definition: HandTracker.h:158
Stores hand tracking results related to a specific point in time.
Definition: HandTrackerData.h:17