Fawkes API Fawkes Development Version
usertracker_thread.h
1
2/***************************************************************************
3 * usertracker_thread.h - OpenNI user tracker thread
4 *
5 * Created: Sun Feb 27 17:52:26 2011
6 * Copyright 2006-2011 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL file in the doc directory.
21 */
22
23#ifndef _PLUGINS_OPENNI_USERTRACKER_THREAD_H_
24#define _PLUGINS_OPENNI_USERTRACKER_THREAD_H_
25
26#include "utils/version.h"
27
28#include <aspect/blackboard.h>
29#include <aspect/blocked_timing.h>
30#include <aspect/clock.h>
31#include <aspect/configurable.h>
32#include <aspect/logging.h>
33#include <core/threading/thread.h>
34#include <core/utils/lockptr.h>
35#include <plugins/openni/aspect/openni.h>
36
37#include <XnCppWrapper.h>
38#include <map>
39
40namespace fawkes {
41class HumanSkeletonInterface;
42class HumanSkeletonProjectionInterface;
43} // namespace fawkes
44namespace firevision {
45class SharedMemoryImageBuffer;
46}
47
55{
56public:
59
60 virtual void init();
61 virtual void loop();
62 virtual void finalize();
63
64 void new_user(XnUserID id);
65 void lost_user(XnUserID id);
66 void pose_start(XnUserID id, const char *pose_name);
67 void pose_end(XnUserID id, const char *pose_name);
68 void calibration_start(XnUserID id);
69 void calibration_end(XnUserID id, bool success);
70
71 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
72protected:
73 virtual void
75 {
76 Thread::run();
77 }
78
79private:
80 /** Per user info struct. */
81 typedef struct
82 {
83 bool valid; /**< true if valid */
84 fawkes::HumanSkeletonInterface * skel_if; /**< Skeleton interface */
85 fawkes::HumanSkeletonProjectionInterface *proj_if; /**< Projection interface. */
86 } UserInfo;
87
88 typedef std::map<XnUserID, UserInfo> UserMap;
89
90 void update_user(XnUserID id, UserInfo &user);
91 void update_com(XnUserID id, UserInfo &user);
92
93private:
94 xn::UserGenerator * user_gen_;
95 xn::DepthGenerator *depth_gen_;
96
97 xn::SceneMetaData * scene_md_;
98 xn::SkeletonCapability *skelcap_;
99
100 XnCallbackHandle user_cb_handle_;
101#if XN_VERSION_GE(1, 3, 2, 0)
102 XnCallbackHandle pose_start_cb_handle_;
103 XnCallbackHandle pose_end_cb_handle_;
104 XnCallbackHandle calib_start_cb_handle_;
105 XnCallbackHandle calib_complete_cb_handle_;
106#else
107 XnCallbackHandle pose_cb_handle_;
108 XnCallbackHandle calib_cb_handle_;
109#endif
110
111 char calib_pose_name_[32];
112 bool skel_need_calib_pose_;
113
114 UserMap users_;
115
117 size_t label_bufsize_;
118};
119
120#endif
OpenNI User Tracker Thread.
void calibration_end(XnUserID id, bool success)
Notify of calibration end.
virtual void init()
Initialize the thread.
void new_user(XnUserID id)
Notify of new user.
virtual ~OpenNiUserTrackerThread()
Destructor.
virtual void loop()
Code to execute in the thread.
void pose_end(XnUserID id, const char *pose_name)
Notify of pose detection end.
OpenNiUserTrackerThread()
Constructor.
void pose_start(XnUserID id, const char *pose_name)
Notify of detected pose.
virtual void run()
Stub to see name in backtrace for easier debugging.
void calibration_start(XnUserID id)
Notify of calibration start.
void lost_user(XnUserID id)
Notify of lost user.
virtual void finalize()
Finalize the thread.
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect to use blocked timing.
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:34
Thread aspect to access configuration data.
Definition: configurable.h:33
HumanSkeletonInterface Fawkes BlackBoard Interface.
HumanSkeletonProjectionInterface Fawkes BlackBoard Interface.
Thread aspect to log output.
Definition: logging.h:33
Thread aspect to get access to the OpenNI context.
Definition: openni.h:39
Thread class encapsulation of pthreads.
Definition: thread.h:46
Shared memory image buffer.
Definition: shm_image.h:184
Fawkes library namespace.