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 <aspect/blackboard.h>
27 #include <aspect/blocked_timing.h>
28 #include <aspect/clock.h>
29 #include <aspect/configurable.h>
30 #include <aspect/logging.h>
31 #include <core/threading/thread.h>
32 #include <core/utils/lockptr.h>
33 #include <plugins/openni/aspect/openni.h>
34 
35 #include <XnCppWrapper.h>
36 #include <map>
37 
38 namespace fawkes {
39 class ObjectPositionInterface;
40 }
43  public fawkes::LoggingAspect,
45  public fawkes::ClockAspect,
48 {
49 public:
51  virtual ~OpenNiHandTrackerThread();
52 
53  virtual void init();
54  virtual void loop();
55  virtual void finalize();
56 
57  void hand_create(XnUserID &user, const XnPoint3D *position, XnFloat &time);
58  void hand_destroy(XnUserID &user, XnFloat &time);
59  void hand_update(XnUserID &user, const XnPoint3D *position, XnFloat &time);
60 
61  void gesture_recognized(const XnChar * gesture_name,
62  const XnPoint3D *position,
63  const XnPoint3D *end_position);
64  void gesture_progress(const XnChar *gesture_name, const XnPoint3D *position, XnFloat progress);
65 
66  /** Stub to see name in backtrace for easier debugging. @see Thread::run() */
67 protected:
68  virtual void
69  run()
70  {
71  Thread::run();
72  }
73 
74 private:
75  void update_hand(XnUserID &user, const XnPoint3D *position);
76 
77 private:
78  typedef std::map<XnUserID, fawkes::ObjectPositionInterface *> HandMap;
79 
80 private:
81  xn::HandsGenerator * hand_gen_;
82  xn::DepthGenerator * depth_gen_;
83  xn::GestureGenerator *gesture_gen_;
84 
85  XnCallbackHandle hand_cb_handle_;
86  XnCallbackHandle gesture_cb_handle_;
87 
88  std::map<std::string, bool> enabled_gesture_;
89 
90  std::map<XnUserID, bool> needs_write_;
91  HandMap hands_;
92 
93  unsigned int width_;
94  unsigned int height_;
95 };
96 
97 #endif
OpenNiHandTrackerThread::hand_create
void hand_create(XnUserID &user, const XnPoint3D *position, XnFloat &time)
Notify of new hand.
Definition: handtracker_thread.cpp:258
OpenNiHandTrackerThread
Definition: handtracker_thread.h:41
fawkes::BlockedTimingAspect
Definition: blocked_timing.h:56
OpenNiHandTrackerThread::OpenNiHandTrackerThread
OpenNiHandTrackerThread()
Constructor.
Definition: handtracker_thread.cpp:44
OpenNiHandTrackerThread::~OpenNiHandTrackerThread
virtual ~OpenNiHandTrackerThread()
Destructor.
Definition: handtracker_thread.cpp:51
OpenNiHandTrackerThread::gesture_recognized
void gesture_recognized(const XnChar *gesture_name, const XnPoint3D *position, const XnPoint3D *end_position)
Notify of recognized gesture.
Definition: handtracker_thread.cpp:341
OpenNiHandTrackerThread::hand_destroy
void hand_destroy(XnUserID &user, XnFloat &time)
Notify of disappeared hand.
Definition: handtracker_thread.cpp:307
fawkes::OpenNiAspect
Definition: openni.h:38
fawkes::BlackBoardAspect
Definition: blackboard.h:38
fawkes
fawkes::LoggingAspect
Definition: logging.h:38
OpenNiHandTrackerThread::gesture_progress
void gesture_progress(const XnChar *gesture_name, const XnPoint3D *position, XnFloat progress)
Notify of gesture progress.
Definition: handtracker_thread.cpp:364
OpenNiHandTrackerThread::run
virtual void run()
Stub to see name in backtrace for easier debugging.
Definition: handtracker_thread.h:69
fawkes::Thread
Definition: thread.h:45
OpenNiHandTrackerThread::hand_update
void hand_update(XnUserID &user, const XnPoint3D *position, XnFloat &time)
Notify of hand update.
Definition: handtracker_thread.cpp:291
fawkes::ConfigurableAspect
Definition: configurable.h:38
OpenNiHandTrackerThread::finalize
virtual void finalize()
Finalize the thread.
Definition: handtracker_thread.cpp:190
OpenNiHandTrackerThread::init
virtual void init()
Initialize the thread.
Definition: handtracker_thread.cpp:107
OpenNiHandTrackerThread::loop
virtual void loop()
Code to execute in the thread.
Definition: handtracker_thread.cpp:215
fawkes::ClockAspect
Definition: clock.h:40