Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * handtracker_thread.h - OpenNI hand tracker thread 00004 * 00005 * Created: Sun Feb 27 17:52:26 2011 00006 * Copyright 2006-2011 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Library General Public License for more details. 00019 * 00020 * Read the full text in the LICENSE.GPL file in the doc directory. 00021 */ 00022 00023 #ifndef __PLUGINS_OPENNI_HANDTRACKER_THREAD_H_ 00024 #define __PLUGINS_OPENNI_HANDTRACKER_THREAD_H_ 00025 00026 #include <core/threading/thread.h> 00027 #include <core/utils/lockptr.h> 00028 #include <aspect/logging.h> 00029 #include <aspect/configurable.h> 00030 #include <aspect/clock.h> 00031 #include <aspect/blackboard.h> 00032 #include <aspect/blocked_timing.h> 00033 #include <plugins/openni/aspect/openni.h> 00034 00035 #include <XnCppWrapper.h> 00036 00037 #include <map> 00038 00039 namespace fawkes { 00040 class ObjectPositionInterface; 00041 } 00042 class OpenNiHandTrackerThread 00043 : public fawkes::Thread, 00044 public fawkes::BlockedTimingAspect, 00045 public fawkes::LoggingAspect, 00046 public fawkes::ConfigurableAspect, 00047 public fawkes::ClockAspect, 00048 public fawkes::BlackBoardAspect, 00049 public fawkes::OpenNiAspect 00050 { 00051 public: 00052 OpenNiHandTrackerThread(); 00053 virtual ~OpenNiHandTrackerThread(); 00054 00055 virtual void init(); 00056 virtual void loop(); 00057 virtual void finalize(); 00058 00059 void hand_create(XnUserID &user, const XnPoint3D *position, XnFloat &time); 00060 void hand_destroy(XnUserID &user, XnFloat &time); 00061 void hand_update(XnUserID &user, const XnPoint3D *position, XnFloat &time); 00062 00063 void gesture_recognized(const XnChar *gesture_name, const XnPoint3D *position, 00064 const XnPoint3D *end_position); 00065 void gesture_progress(const XnChar *gesture_name, const XnPoint3D *position, 00066 XnFloat progress); 00067 00068 /** Stub to see name in backtrace for easier debugging. @see Thread::run() */ 00069 protected: virtual void run() { Thread::run(); } 00070 00071 private: 00072 void update_hand(XnUserID &user, const XnPoint3D *position); 00073 00074 00075 private: 00076 typedef std::map<XnUserID, fawkes::ObjectPositionInterface *> HandMap; 00077 00078 private: 00079 xn::HandsGenerator *__hand_gen; 00080 xn::DepthGenerator *__depth_gen; 00081 xn::GestureGenerator *__gesture_gen; 00082 00083 XnCallbackHandle __hand_cb_handle; 00084 XnCallbackHandle __gesture_cb_handle; 00085 00086 std::map<std::string, bool> __enabled_gesture; 00087 00088 std::map<XnUserID, bool> __needs_write; 00089 HandMap __hands; 00090 00091 unsigned int __width; 00092 unsigned int __height; 00093 }; 00094 00095 #endif