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
38namespace fawkes {
39class ObjectPositionInterface;
40}
48{
49public:
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() */
67protected:
68 virtual void
70 {
71 Thread::run();
72 }
73
74private:
75 void update_hand(XnUserID &user, const XnPoint3D *position);
76
77private:
78 typedef std::map<XnUserID, fawkes::ObjectPositionInterface *> HandMap;
79
80private:
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
OpenNI Hand Tracker Thread.
void hand_create(XnUserID &user, const XnPoint3D *position, XnFloat &time)
Notify of new hand.
virtual void init()
Initialize the thread.
void hand_update(XnUserID &user, const XnPoint3D *position, XnFloat &time)
Notify of hand update.
void hand_destroy(XnUserID &user, XnFloat &time)
Notify of disappeared hand.
virtual void finalize()
Finalize the thread.
void gesture_recognized(const XnChar *gesture_name, const XnPoint3D *position, const XnPoint3D *end_position)
Notify of recognized gesture.
virtual ~OpenNiHandTrackerThread()
Destructor.
virtual void run()
Stub to see name in backtrace for easier debugging.
void gesture_progress(const XnChar *gesture_name, const XnPoint3D *position, XnFloat progress)
Notify of gesture progress.
OpenNiHandTrackerThread()
Constructor.
virtual void loop()
Code to execute in 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
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
Fawkes library namespace.