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 <core/threading/thread.h>
29 #include <core/utils/lockptr.h>
30 #include <aspect/logging.h>
31 #include <aspect/configurable.h>
32 #include <aspect/clock.h>
33 #include <aspect/blackboard.h>
34 #include <aspect/blocked_timing.h>
35 #include <plugins/openni/aspect/openni.h>
36 
37 #include <XnCppWrapper.h>
38 
39 #include <map>
40 
41 namespace fawkes {
42  class HumanSkeletonInterface;
43  class HumanSkeletonProjectionInterface;
44 }
45 namespace firevision {
46  class SharedMemoryImageBuffer;
47 }
48 
50 : public fawkes::Thread,
52  public fawkes::LoggingAspect,
54  public fawkes::ClockAspect,
57 {
58  public:
60  virtual ~OpenNiUserTrackerThread();
61 
62  virtual void init();
63  virtual void loop();
64  virtual void finalize();
65 
66  void new_user(XnUserID id);
67  void lost_user(XnUserID id);
68  void pose_start(XnUserID id, const char *pose_name);
69  void pose_end(XnUserID id, const char *pose_name);
70  void calibration_start(XnUserID id);
71  void calibration_end(XnUserID id, bool success);
72 
73  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
74  protected: virtual void run() { Thread::run(); }
75 
76  private:
77  /** Per user info struct. */
78  typedef struct {
79  bool valid; /**< true if valid */
80  fawkes::HumanSkeletonInterface *skel_if; /**< Skeleton interface */
81  fawkes::HumanSkeletonProjectionInterface *proj_if; /**< Projection interface. */
82  } UserInfo;
83 
84  typedef std::map<XnUserID, UserInfo> UserMap;
85 
86  void update_user(XnUserID id, UserInfo &user);
87  void update_com(XnUserID id, UserInfo &user);
88 
89  private:
90  xn::UserGenerator *__user_gen;
91  xn::DepthGenerator *__depth_gen;
92 
93  xn::SceneMetaData *__scene_md;
94  xn::SkeletonCapability *__skelcap;
95 
96  XnCallbackHandle __user_cb_handle;
97 #if XN_VERSION_GE(1,3,2,0)
98  XnCallbackHandle __pose_start_cb_handle;
99  XnCallbackHandle __pose_end_cb_handle;
100  XnCallbackHandle __calib_start_cb_handle;
101  XnCallbackHandle __calib_complete_cb_handle;
102 #else
103  XnCallbackHandle __pose_cb_handle;
104  XnCallbackHandle __calib_cb_handle;
105 #endif
106 
107  char __calib_pose_name[32];
108  bool __skel_need_calib_pose;
109 
110  UserMap __users;
111 
113  size_t __label_bufsize;
114 };
115 
116 #endif
Thread aspect to access to BlackBoard.
Definition: blackboard.h:34
Thread aspect that allows to obtain the current time from the clock.
Definition: clock.h:36
HumanSkeletonProjectionInterface Fawkes BlackBoard Interface.
virtual ~OpenNiUserTrackerThread()
Destructor.
void new_user(XnUserID id)
Notify of new user.
Fawkes library namespace.
Thread aspect to get access to the OpenNI context.
Definition: openni.h:39
Thread class encapsulation of pthreads.
Definition: thread.h:42
void calibration_end(XnUserID id, bool success)
Notify of calibration end.
void pose_end(XnUserID id, const char *pose_name)
Notify of pose detection end.
virtual void init()
Initialize the thread.
virtual void run()
Stub to see name in backtrace for easier debugging.
Thread aspect to use blocked timing.
virtual void finalize()
Finalize the thread.
OpenNiUserTrackerThread()
Constructor.
Shared memory image buffer.
Definition: shm_image.h:181
Thread aspect to log output.
Definition: logging.h:35
virtual void loop()
Code to execute in the thread.
Thread aspect to access configuration data.
Definition: configurable.h:35
void lost_user(XnUserID id)
Notify of lost user.
OpenNI User Tracker Thread.
HumanSkeletonInterface Fawkes BlackBoard Interface.
void pose_start(XnUserID id, const char *pose_name)
Notify of detected pose.
void calibration_start(XnUserID id)
Notify of calibration start.