1 #ifndef NUITRACK_USERTRACKER_H_
2 #define NUITRACK_USERTRACKER_H_
6 #include "nuitrack/modules/HeaderOnlyAPI_Module.h"
7 #include "nuitrack/types/Export.h"
8 #include "nuitrack/types/UserFrame.h"
9 #include "nuitrack/capi/UserTracker_CAPI.h"
10 #include "nuitrack/capi/Nuitrack_CAPI.h"
11 #include "nuitrack/utils/ExceptionTranslator.h"
12 #include "nuitrack/utils/CallbackStruct.h"
33 class UserTracker :
public tdv::nuitrack::HeaderOnlyAPI_Module
40 typedef std::shared_ptr<UserTracker>
Ptr;
49 typedef std::function<void (UserFrame::Ptr)>
OnUpdate;
62 typedef void (*OnNewUserRawFunctionPtr)(int,
UserTracker*);
73 typedef void (*OnLostUserRawFunctionPtr)(int,
UserTracker*);
84 NuitrackModule* pimpl = NULL;
85 ExceptionType exception_code = nuitrack_CreateUserTracker(&pimpl);
86 ExceptionTranslator::generateExceptionByErrorCode(exception_code);;
87 return std::shared_ptr<UserTracker>(
new UserTracker(pimpl));
95 _onUpdateCallbackStruct =
new CallbackStruct<UserFrame::Ptr>();
96 _onNewUserCallbackStruct =
new CallbackStruct<int>();
97 _onLostUserCallbackStruct =
new CallbackStruct<int>();
99 _callbackWrapper.setUserTracker(
this);
100 _callbackWrapper.setOnUpdateAddress(&onUpdateCallback);
101 _callbackWrapper.setOnNewUserAddress(&onNewUserCallback);
102 _callbackWrapper.setOnLostUserAddress(&onLostUserCallback);
104 nuitrack_registerUserTrackerCallback(_pimpl, &_callbackWrapper);
109 nuitrack_DestroyUserTracker(_pimpl);
110 destroyUserTracker();
122 return _onUpdateCallbackStruct->addCallback(callback);
133 _onUpdateCallbackStruct->deleteCallback(handler);
146 return _onNewUserCallbackStruct->addCallback(callback);
157 _onNewUserCallbackStruct->deleteCallback(handler);
170 return _onLostUserCallbackStruct->addCallback(callback);
181 _onLostUserCallbackStruct->deleteCallback(handler);
189 UserTrackerDataPtr data = nuitrack_GetUserTrackerData(_pimpl);
190 UserFrame::Ptr newFrame(
new UserFrame(data));
199 return nuitrack_GetUserTrackerProcessingTime(_pimpl);
202 bool canUpdate()
const
204 return nuitrack_GetNuitrackModuleCanUpdate(_pimpl);
216 return nuitrack_GetNuitrackModuleTimestamp(_pimpl);
221 static void onUpdateCallback(UserTrackerData* userFrameImpl,
UserTracker* tracker)
223 UserFrame::Ptr newFrame(
new UserFrame(userFrameImpl));
224 tracker->_onUpdateCallbackStruct->executeAllCallbacks(newFrame);
227 static void onNewUserCallback(
int usedID,
UserTracker* tracker)
229 tracker->_onNewUserCallbackStruct->executeAllCallbacks(usedID);
231 static void onLostUserCallback(
int usedID,
UserTracker* tracker)
233 tracker->_onLostUserCallbackStruct->executeAllCallbacks(usedID);
236 void destroyUserTracker()
238 if(_onUpdateCallbackStruct)
239 delete _onUpdateCallbackStruct;
240 if(_onNewUserCallbackStruct)
241 delete _onNewUserCallbackStruct;
242 if(_onLostUserCallbackStruct)
243 delete _onLostUserCallbackStruct;
246 NuitrackModule* _pimpl;
248 UserTrackerCallbackWrapper _callbackWrapper;
250 CallbackStruct<UserFrame::Ptr>* _onUpdateCallbackStruct;
251 CallbackStruct<int>* _onNewUserCallbackStruct;
252 CallbackStruct<int>* _onLostUserCallbackStruct;
float getProcessingTime() const
Returns last frame processing time in milliseconds.
Definition: UserTracker.h:197
ExceptionType
Possible error codes for Nuitrack internal functions.
Definition: Error.h:20
Represents a user map with information about the floor.
Definition: UserFrame.h:27
void disconnectOnNewUser(uint64_t handler)
Remove a callback of the new user appearance event.
Definition: UserTracker.h:155
static UserTracker::Ptr create()
Create the UserTracker module object.
Definition: UserTracker.h:82
UserFrame::Ptr getUserFrame()
Returns smart pointer to the last avilable UserFrame.
Definition: UserTracker.h:187
std::function< void(UserFrame::Ptr)> OnUpdate
The callback type of the user frame update request.
Definition: UserTracker.h:49
uint64_t connectOnLostUser(const OnLostUser &callback)
Add a callback for the user disappearance event.
Definition: UserTracker.h:168
std::function< void(int)> OnLostUser
The callback type of the user disapearance event.
Definition: UserTracker.h:71
void disconnectOnUpdate(uint64_t handler)
Remove a callback of the user frame update request.
Definition: UserTracker.h:131
virtual uint64_t getTimestamp()
Returns the last processed data timestamp in microseconds.
Definition: UserTracker.h:214
std::function< void(int)> OnNewUser
The callback type of the new user apearance event.
Definition: UserTracker.h:60
void disconnectOnLostUser(uint64_t handler)
Remove a callback of the user disappearance event.
Definition: UserTracker.h:179
uint64_t connectOnNewUser(const OnNewUser &callback)
Add a callback for the new user appearance event.
Definition: UserTracker.h:144
Represents the interface to the capabilities of the Nuitrack User Tracker module. ...
Definition: UserTracker.h:33
uint64_t connectOnUpdate(const OnUpdate &callback)
Add a callback for the user frame update request.
Definition: UserTracker.h:120
UserTracker(NuitrackModule *pimpl)
Definition: UserTracker.h:91
std::shared_ptr< UserTracker > Ptr
Smart pointer to access the UserTracker instance.
Definition: UserTracker.h:40