Fawkes API  Fawkes Development Version
handtracker_thread.h
1 
2 /***************************************************************************
3  * handtracker_thread.h - OpenNI hand 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_HANDTRACKER_THREAD_H_
24 #define __PLUGINS_OPENNI_HANDTRACKER_THREAD_H_
25 
26 #include <core/threading/thread.h>
27 #include <core/utils/lockptr.h>
28 #include <aspect/logging.h>
29 #include <aspect/configurable.h>
30 #include <aspect/clock.h>
31 #include <aspect/blackboard.h>
32 #include <aspect/blocked_timing.h>
33 #include <plugins/openni/aspect/openni.h>
34 
35 #include <XnCppWrapper.h>
36 
37 #include <map>
38 
39 namespace fawkes {
40  class ObjectPositionInterface;
41 }
43 : public fawkes::Thread,
45  public fawkes::LoggingAspect,
47  public fawkes::ClockAspect,
50 {
51  public:
53  virtual ~OpenNiHandTrackerThread();
54 
55  virtual void init();
56  virtual void loop();
57  virtual void finalize();
58 
59  void hand_create(XnUserID &user, const XnPoint3D *position, XnFloat &time);
60  void hand_destroy(XnUserID &user, XnFloat &time);
61  void hand_update(XnUserID &user, const XnPoint3D *position, XnFloat &time);
62 
63  void gesture_recognized(const XnChar *gesture_name, const XnPoint3D *position,
64  const XnPoint3D *end_position);
65  void gesture_progress(const XnChar *gesture_name, const XnPoint3D *position,
66  XnFloat progress);
67 
68  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
69  protected: virtual void run() { Thread::run(); }
70 
71  private:
72  void update_hand(XnUserID &user, const XnPoint3D *position);
73 
74 
75  private:
76  typedef std::map<XnUserID, fawkes::ObjectPositionInterface *> HandMap;
77 
78  private:
79  xn::HandsGenerator *__hand_gen;
80  xn::DepthGenerator *__depth_gen;
81  xn::GestureGenerator *__gesture_gen;
82 
83  XnCallbackHandle __hand_cb_handle;
84  XnCallbackHandle __gesture_cb_handle;
85 
86  std::map<std::string, bool> __enabled_gesture;
87 
88  std::map<XnUserID, bool> __needs_write;
89  HandMap __hands;
90 
91  unsigned int __width;
92  unsigned int __height;
93 };
94 
95 #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
Fawkes library namespace.
virtual void run()
Code to execute in the thread.
Definition: thread.cpp:939
Thread aspect to get access to the OpenNI context.
Definition: openni.h:39
OpenNI Hand Tracker Thread.
Thread class encapsulation of pthreads.
Definition: thread.h:42
virtual void run()
Stub to see name in backtrace for easier debugging.
Thread aspect to use blocked timing.
Thread aspect to log output.
Definition: logging.h:35
Thread aspect to access configuration data.
Definition: configurable.h:35