├── Mac ├── bundle_template │ ├── InfoPlist.strings │ ├── Localized.r │ └── Info.plist ├── tutorialpluginMac.h ├── projectDef.cmake └── tutorialpluginMac.mm ├── X11 └── projectDef.cmake ├── CMakeLists.txt ├── tutorialpluginAPI.h ├── tutorialplugin.h ├── Factory.cpp ├── PluginConfig.cmake ├── PointDrawer.h ├── Win ├── projectDef.cmake └── WiX │ └── tutorialpluginInstaller.wxs ├── tutorialpluginAPI.cpp ├── tutorialplugin.cpp ├── kinect_main.cpp └── PointDrawer.cpp /Mac/bundle_template/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | CFBundleName = "${PLUGIN_NAME}.plugin"; 4 | NSHumanReadableCopyright = "${FBSTRING_LegalCopyright}"; 5 | -------------------------------------------------------------------------------- /Mac/bundle_template/Localized.r: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | resource 'STR#' (126) 4 | { { 5 | "${FBSTRING_LegalCopyright}", 6 | "${FBSTRING_ProductName}" 7 | } }; 8 | 9 | resource 'STR#' (127) 10 | { { 11 | "", 12 | } }; 13 | 14 | resource 'STR#' (128) 15 | { { 16 | @foreach (FBSTRING_MIMEType CUR_MIMETYPE FBSTRING_FileExtents CUR_EXTENT) 17 | "${CUR_MIMETYPE}", 18 | "${CUR_EXTENT}", 19 | @endforeach 20 | } }; 21 | -------------------------------------------------------------------------------- /X11/projectDef.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # Auto-generated X11 project definition file for the 3 | # tutorial plugin project 4 | #\**********************************************************/ 5 | 6 | # X11 template platform definition CMake file 7 | # Included from ../CMakeLists.txt 8 | 9 | # remember that the current source dir is the project root; this file is in X11/ 10 | file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 11 | X11/[^.]*.cpp 12 | X11/[^.]*.h 13 | X11/[^.]*.cmake 14 | ) 15 | 16 | SOURCE_GROUP(X11 FILES ${PLATFORM}) 17 | 18 | # use this to add preprocessor definitions 19 | add_definitions( 20 | ) 21 | 22 | set (SOURCES 23 | ${SOURCES} 24 | ${PLATFORM} 25 | ) 26 | 27 | add_x11_plugin(${PROJECT_NAME} SOURCES) 28 | 29 | # add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing! 30 | target_link_libraries(${PROJECT_NAME} 31 | ${PLUGIN_INTERNAL_DEPS} 32 | ) 33 | -------------------------------------------------------------------------------- /Mac/tutorialpluginMac.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tutorialpluginMac.h 3 | * FireBreath 4 | * 5 | * Created by Roy Shilkrot on 11/30/11. 6 | * Copyright 2011 MIT. All rights reserved. 7 | * 8 | */ 9 | #pragma once 10 | 11 | #include "PluginEvents/MacEventCarbon.h" 12 | #include "PluginEvents/MacEventCocoa.h" 13 | #include "Mac/PluginWindowMac.h" 14 | 15 | #include "../tutorialplugin.h" 16 | 17 | class tutorialpluginMac : public tutorialplugin { 18 | public: 19 | tutorialpluginMac(); 20 | ~tutorialpluginMac(); 21 | 22 | BEGIN_PLUGIN_EVENT_MAP() 23 | EVENTTYPE_CASE(FB::AttachedEvent, onWindowAttached, FB::PluginWindowMac) 24 | EVENTTYPE_CASE(FB::DetachedEvent, onWindowDetached, FB::PluginWindowMac) 25 | PLUGIN_EVENT_MAP_CASCADE(tutorialplugin) 26 | END_PLUGIN_EVENT_MAP() 27 | 28 | virtual bool onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindowMac*); 29 | virtual bool onWindowDetached(FB::DetachedEvent *evt, FB::PluginWindowMac*); 30 | protected: 31 | 32 | private: 33 | void* m_layer; 34 | 35 | }; 36 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # 3 | # Auto-generated CMakeLists.txt for the tutorial plugin project 4 | # 5 | #\**********************************************************/ 6 | 7 | # Written to work with cmake 2.6 8 | cmake_minimum_required (VERSION 2.6) 9 | set (CMAKE_BACKWARDS_COMPATIBILITY 2.6) 10 | 11 | Project(${PLUGIN_NAME}) 12 | 13 | file (GLOB GENERAL RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 14 | [^.]*.cpp 15 | [^.]*.h 16 | [^.]*.cmake 17 | ) 18 | 19 | include_directories(${PLUGIN_INCLUDE_DIRS}) 20 | 21 | # Generated files are stored in ${GENERATED} by the project configuration 22 | SET_SOURCE_FILES_PROPERTIES( 23 | ${GENERATED} 24 | PROPERTIES 25 | GENERATED 1 26 | ) 27 | 28 | SOURCE_GROUP(Generated FILES 29 | ${GENERATED} 30 | ) 31 | 32 | SET( SOURCES 33 | ${GENERAL} 34 | ${GENERATED} 35 | ) 36 | 37 | find_library(OPENGL OpenGL) 38 | 39 | # This will include Win/projectDef.cmake, X11/projectDef.cmake, Mac/projectDef 40 | # depending on the platform 41 | include_platform() 42 | -------------------------------------------------------------------------------- /Mac/projectDef.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # Auto-generated Mac project definition file for the 3 | # tutorial plugin project 4 | #\**********************************************************/ 5 | 6 | # Mac template platform definition CMake file 7 | # Included from ../CMakeLists.txt 8 | 9 | 10 | SET_TARGET_PROPERTIES( ${TARGET} PROPERTIES XCODE_ATTRIBUTE_ENABLE_OPENMP_SUPPORT YES ) 11 | 12 | # remember that the current source dir is the project root; this file is in Mac/ 13 | file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 14 | Mac/[^.]*.cpp 15 | Mac/[^.]*.h 16 | Mac/[^.]*.cmake 17 | Mac/[^.]*.mm 18 | ) 19 | 20 | # use this to add preprocessor definitions 21 | add_definitions( 22 | 23 | ) 24 | 25 | include_directories("/Users/royshilkrot/Downloads/NITE-Bin-MacOSX-v1.4.1.2/Include") 26 | include_directories("/Users/royshilkrot/Downloads/OpenNI-Bin-MacOSX-v1.3.2.3/Include") 27 | 28 | SOURCE_GROUP(Mac FILES ${PLATFORM}) 29 | 30 | set (SOURCES 31 | ${SOURCES} 32 | ${PLATFORM} 33 | ) 34 | 35 | set(PLIST "Mac/bundle_template/Info.plist") 36 | set(STRINGS "Mac/bundle_template/InfoPlist.strings") 37 | set(LOCALIZED "Mac/bundle_template/Localized.r") 38 | 39 | add_mac_plugin(${PROJECT_NAME} ${PLIST} ${STRINGS} ${LOCALIZED} SOURCES) 40 | 41 | find_library(OPENGL_FRAMEWORK OpenGL) 42 | find_library(QUARTZ_CORE_FRAMEWORK QuartzCore) 43 | 44 | # add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing! 45 | target_link_libraries(${PROJECT_NAME} 46 | ${PLUGIN_INTERNAL_DEPS} 47 | ${OPENGL_FRAMEWORK} 48 | ${QUARTZ_CORE_FRAMEWORK} 49 | /Users/royshilkrot/Downloads/OpenNI-Bin-MacOSX-v1.3.2.3/Lib/libOpenNI.dylib 50 | /Users/royshilkrot/Downloads/NITE-Bin-MacOSX-v1.4.1.2/Bin/libXnVNite_1_4_1.dylib 51 | /Users/royshilkrot/Downloads/NITE-Bin-MacOSX-v1.4.1.2/Bin/libXnVHandGenerator_1_4_1.dylib 52 | ) 53 | -------------------------------------------------------------------------------- /Mac/bundle_template/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${PLUGIN_NAME} 9 | CFBundleGetInfoString 10 | ${PLUGIN_NAME} ${FBSTRING_PLUGIN_VERSION}, ${FBSTRING_LegalCopyright} 11 | CFBundleIdentifier 12 | com.${FBTYPELIB_NAME}.${FBSTRING_PluginName} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundlePackageType 16 | BRPL 17 | CFBundleShortVersionString 18 | ${PLUGIN_NAME} ${FBSTRING_PLUGIN_VERSION} 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${FBSTRING_PLUGIN_VERSION} 23 | CFPlugInDynamicRegisterFunction 24 | 25 | CFPlugInDynamicRegistration 26 | NO 27 | CFPlugInFactories 28 | 29 | 00000000-0000-0000-0000-000000000000 30 | MyFactoryFunction 31 | 32 | CFPlugInTypes 33 | 34 | 00000000-0000-0000-0000-000000000000 35 | 36 | 00000000-0000-0000-0000-000000000000 37 | 38 | 39 | CFPlugInUnloadFunction 40 | 41 | WebPluginName 42 | ${FBSTRING_ProductName} 43 | WebPluginDescription 44 | ${FBSTRING_FileDescription} 45 | WebPluginMIMETypes 46 | 47 | @foreach (FBSTRING_MIMEType CUR_MIMETYPE FBSTRING_FileDescription CUR_DESC) 48 | ${CUR_MIMETYPE} 49 | 50 | WebPluginExtensions 51 | 52 | 53 | 54 | WebPluginTypeDescription 55 | ${CUR_DESC} 56 | 57 | @endforeach 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /tutorialpluginAPI.h: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | 3 | Auto-generated tutorialpluginAPI.h 4 | 5 | \**********************************************************/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include "JSAPIAuto.h" 11 | #include "BrowserHost.h" 12 | #include "tutorialplugin.h" 13 | 14 | #ifndef H_tutorialpluginAPI 15 | #define H_tutorialpluginAPI 16 | 17 | 18 | 19 | class tutorialpluginAPI : public FB::JSAPIAuto 20 | { 21 | public: 22 | tutorialpluginAPI(const tutorialpluginPtr& plugin, const FB::BrowserHostPtr& host):m_plugin(plugin), m_host(host) 23 | { 24 | registerMethod("echo", make_method(this, &tutorialpluginAPI::echo)); 25 | registerMethod("testEvent", make_method(this, &tutorialpluginAPI::testEvent)); 26 | registerMethod("add", make_method(this, &tutorialpluginAPI::add)); 27 | 28 | // Read-write property 29 | registerProperty("testString", 30 | make_property(this, 31 | &tutorialpluginAPI::get_testString, 32 | &tutorialpluginAPI::set_testString)); 33 | 34 | // Read-only property 35 | registerProperty("version", 36 | make_property(this, 37 | &tutorialpluginAPI::get_version)); 38 | } 39 | 40 | 41 | virtual ~tutorialpluginAPI(); 42 | 43 | tutorialpluginPtr getPlugin(); 44 | 45 | // Read/Write property ${PROPERTY.ident} 46 | std::string get_testString(); 47 | void set_testString(const std::string& val); 48 | 49 | // Read-only property ${PROPERTY.ident} 50 | std::string get_version(); 51 | 52 | // Method echo 53 | FB::variant echo(const FB::variant& msg); 54 | 55 | // Event helpers 56 | FB_JSAPI_EVENT(fired, 3, (const FB::variant&, bool, int)); 57 | FB_JSAPI_EVENT(echo, 2, (const FB::variant&, const int)); 58 | FB_JSAPI_EVENT(notify, 0, ()); 59 | 60 | // Method test-event 61 | void testEvent(const FB::variant& s); 62 | 63 | long add(long a, long b, long c); 64 | 65 | private: 66 | tutorialpluginWeakPtr m_plugin; 67 | FB::BrowserHostPtr m_host; 68 | 69 | std::string m_testString; 70 | }; 71 | 72 | #endif // H_tutorialpluginAPI 73 | 74 | -------------------------------------------------------------------------------- /tutorialplugin.h: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | 3 | Auto-generated tutorialplugin.h 4 | 5 | This file contains the auto-generated main plugin object 6 | implementation for the tutorial plugin project 7 | 8 | \**********************************************************/ 9 | #ifndef H_tutorialpluginPLUGIN 10 | #define H_tutorialpluginPLUGIN 11 | 12 | #include "PluginWindow.h" 13 | #include "PluginEvents/MouseEvents.h" 14 | #include "PluginEvents/AttachedEvent.h" 15 | 16 | #include "PluginCore.h" 17 | 18 | FB_FORWARD_PTR(tutorialplugin) 19 | class tutorialplugin : public FB::PluginCore 20 | { 21 | public: 22 | static void StaticInitialize(); 23 | static void StaticDeinitialize(); 24 | 25 | public: 26 | tutorialplugin(); 27 | virtual ~tutorialplugin(); 28 | 29 | public: 30 | void onPluginReady(); 31 | void shutdown(); 32 | virtual FB::JSAPIPtr createJSAPI(); 33 | // If you want your plugin to always be windowless, set this to true 34 | // If you want your plugin to be optionally windowless based on the 35 | // value of the "windowless" param tag, remove this method or return 36 | // FB::PluginCore::isWindowless() 37 | virtual bool isWindowless() { return false; } 38 | 39 | 40 | BEGIN_PLUGIN_EVENT_MAP() 41 | EVENTTYPE_CASE(FB::MouseDownEvent, onMouseDown, FB::PluginWindow) 42 | EVENTTYPE_CASE(FB::MouseUpEvent, onMouseUp, FB::PluginWindow) 43 | EVENTTYPE_CASE(FB::MouseMoveEvent, onMouseMove, FB::PluginWindow) 44 | EVENTTYPE_CASE(FB::MouseMoveEvent, onMouseMove, FB::PluginWindow) 45 | EVENTTYPE_CASE(FB::AttachedEvent, onWindowAttached, FB::PluginWindow) 46 | EVENTTYPE_CASE(FB::DetachedEvent, onWindowDetached, FB::PluginWindow) 47 | END_PLUGIN_EVENT_MAP() 48 | 49 | /** BEGIN EVENTDEF -- DON'T CHANGE THIS LINE **/ 50 | virtual bool onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *); 51 | virtual bool onMouseUp(FB::MouseUpEvent *evt, FB::PluginWindow *); 52 | virtual bool onMouseMove(FB::MouseMoveEvent *evt, FB::PluginWindow *); 53 | virtual bool onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindow *); 54 | virtual bool onWindowDetached(FB::DetachedEvent *evt, FB::PluginWindow *); 55 | /** END EVENTDEF -- DON'T CHANGE THIS LINE **/ 56 | }; 57 | 58 | 59 | #endif 60 | 61 | -------------------------------------------------------------------------------- /Factory.cpp: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | 3 | Auto-generated Factory.cpp 4 | 5 | This file contains the auto-generated factory methods 6 | for the tutorialplugin project 7 | 8 | \**********************************************************/ 9 | 10 | #include "FactoryBase.h" 11 | #if FB_WIN 12 | #include "tutorialplugin.h" 13 | #else 14 | #include "Mac/tutorialpluginMac.h" 15 | #endif 16 | #include 17 | 18 | class PluginFactory : public FB::FactoryBase 19 | { 20 | public: 21 | /////////////////////////////////////////////////////////////////////////////// 22 | /// @fn FB::PluginCorePtr createPlugin(const std::string& mimetype) 23 | /// 24 | /// @brief Creates a plugin object matching the provided mimetype 25 | /// If mimetype is empty, returns the default plugin 26 | /////////////////////////////////////////////////////////////////////////////// 27 | FB::PluginCorePtr createPlugin(const std::string& mimetype) 28 | { 29 | #if FB_WIN 30 | return boost::make_shared(); 31 | #else 32 | return boost::make_shared(); 33 | #endif 34 | } 35 | 36 | /////////////////////////////////////////////////////////////////////////////// 37 | /// @see FB::FactoryBase::globalPluginInitialize 38 | /////////////////////////////////////////////////////////////////////////////// 39 | void globalPluginInitialize() 40 | { 41 | tutorialplugin::StaticInitialize(); 42 | } 43 | 44 | /////////////////////////////////////////////////////////////////////////////// 45 | /// @see FB::FactoryBase::globalPluginDeinitialize 46 | /////////////////////////////////////////////////////////////////////////////// 47 | void globalPluginDeinitialize() 48 | { 49 | tutorialplugin::StaticDeinitialize(); 50 | } 51 | }; 52 | 53 | /////////////////////////////////////////////////////////////////////////////// 54 | /// @fn getFactoryInstance() 55 | /// 56 | /// @brief Returns the factory instance for this plugin module 57 | /////////////////////////////////////////////////////////////////////////////// 58 | FB::FactoryBasePtr getFactoryInstance() 59 | { 60 | static boost::shared_ptr factory = boost::make_shared(); 61 | return factory; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /PluginConfig.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # 3 | # Auto-Generated Plugin Configuration file 4 | # for tutorial plugin 5 | # 6 | #\**********************************************************/ 7 | 8 | set(PLUGIN_NAME "tutorialplugin") 9 | set(PLUGIN_PREFIX "TPL") 10 | set(COMPANY_NAME "somecompany") 11 | 12 | # ActiveX constants: 13 | set(FBTYPELIB_NAME tutorialpluginLib) 14 | set(FBTYPELIB_DESC "tutorialplugin 1.0 Type Library") 15 | set(IFBControl_DESC "tutorialplugin Control Interface") 16 | set(FBControl_DESC "tutorialplugin Control Class") 17 | set(IFBComJavascriptObject_DESC "tutorialplugin IComJavascriptObject Interface") 18 | set(FBComJavascriptObject_DESC "tutorialplugin ComJavascriptObject Class") 19 | set(IFBComEventSource_DESC "tutorialplugin IFBComEventSource Interface") 20 | set(AXVERSION_NUM "1") 21 | 22 | # NOTE: THESE GUIDS *MUST* BE UNIQUE TO YOUR PLUGIN/ACTIVEX CONTROL! YES, ALL OF THEM! 23 | set(FBTYPELIB_GUID 4646191d-6bc3-51cb-97b0-06fa632b56fa) 24 | set(IFBControl_GUID f8af277d-61a2-5f2a-8c68-83946a07670e) 25 | set(FBControl_GUID ef0d769e-d1b0-54b8-9992-ffe9cb26600d) 26 | set(IFBComJavascriptObject_GUID cb6d19ac-7722-54ba-ad40-b8b8bc43a97f) 27 | set(FBComJavascriptObject_GUID 9b371295-4b8f-5bb8-86df-341b88315bda) 28 | set(IFBComEventSource_GUID b07de59b-bebc-5fcd-aaab-229b48e53f42) 29 | 30 | # these are the pieces that are relevant to using it from Javascript 31 | set(ACTIVEX_PROGID "somecompany.tutorialplugin") 32 | set(MOZILLA_PLUGINID "somecompany.com/tutorialplugin") 33 | 34 | # strings 35 | set(FBSTRING_CompanyName "some company") 36 | set(FBSTRING_FileDescription "tutorial plugin") 37 | set(FBSTRING_PLUGIN_VERSION "1.0.0.0") 38 | set(FBSTRING_LegalCopyright "Copyright 2011 some company") 39 | set(FBSTRING_PluginFileName "np${PLUGIN_NAME}.dll") 40 | set(FBSTRING_ProductName "tutorial plugin") 41 | set(FBSTRING_FileExtents "") 42 | set(FBSTRING_PluginName "tutorial plugin") 43 | set(FBSTRING_MIMEType "application/x-tutorialplugin") 44 | 45 | # Uncomment this next line if you're not planning on your plugin doing 46 | # any drawing: 47 | 48 | #set (FB_GUI_DISABLED 1) 49 | 50 | # Mac plugin settings. If your plugin does not draw, set these all to 0 51 | set(FBMAC_USE_QUICKDRAW 0) 52 | set(FBMAC_USE_CARBON 0) 53 | set(FBMAC_USE_COCOA 1) 54 | set(FBMAC_USE_COREGRAPHICS 0) 55 | set(FBMAC_USE_COREANIMATION 1) 56 | set(FBMAC_USE_INVALIDATINGCOREANIMATION 1) 57 | 58 | # If you want to register per-machine on Windows, uncomment this line 59 | #set (FB_ATLREG_MACHINEWIDE 1) 60 | -------------------------------------------------------------------------------- /PointDrawer.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * * 3 | * PrimeSense NITE 1.3 - Point Viewer Sample * 4 | * Copyright (C) 2010 PrimeSense Ltd. * 5 | * * 6 | *******************************************************************************/ 7 | 8 | #ifndef XNV_POINT_DRAWER_H_ 9 | #define XNV_POINT_DRAWER_H_ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | typedef enum 17 | { 18 | IN_SESSION, 19 | NOT_IN_SESSION, 20 | QUICK_REFOCUS 21 | } SessionState; 22 | 23 | void PrintSessionState(SessionState eState); 24 | /** 25 | * This is a point control, which stores the history of every point 26 | * It can draw all the points as well as the depth map. 27 | */ 28 | class XnVPointDrawer : public XnVPointControl 29 | { 30 | public: 31 | XnVPointDrawer(XnUInt32 nHistorySize, xn::DepthGenerator depthGenerator); 32 | virtual ~XnVPointDrawer(); 33 | 34 | /** 35 | * Handle a new message. 36 | * Calls other callbacks for each point, then draw the depth map (if needed) and the points 37 | */ 38 | void Update(XnVMessage* pMessage); 39 | 40 | /** 41 | * Handle creation of a new point 42 | */ 43 | void OnPointCreate(const XnVHandPointContext* cxt); 44 | /** 45 | * Handle new position of an existing point 46 | */ 47 | void OnPointUpdate(const XnVHandPointContext* cxt); 48 | /** 49 | * Handle destruction of an existing point 50 | */ 51 | void OnPointDestroy(XnUInt32 nID); 52 | 53 | /** 54 | * Draw the points, each with its own color. 55 | */ 56 | void Draw() const; 57 | 58 | /** 59 | * Change mode - should draw the depth map? 60 | */ 61 | void SetDepthMap(XnBool bDrawDM); 62 | /** 63 | * Change mode - print out the frame id 64 | */ 65 | void SetFrameID(XnBool bFrameID); 66 | 67 | void SetTouchingFOVEdge(XnUInt32 nID); 68 | protected: 69 | XnBool IsTouching(XnUInt32 nID) const; 70 | // Number of previous position to store for each hand 71 | XnUInt32 m_nHistorySize; 72 | // previous positions per hand 73 | std::map > m_History; 74 | std::list m_TouchingFOVEdge; 75 | // Source of the depth map 76 | xn::DepthGenerator m_DepthGenerator; 77 | XnFloat* m_pfPositionBuffer; 78 | 79 | XnBool m_bDrawDM; 80 | XnBool m_bFrameID; 81 | }; 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /Mac/tutorialpluginMac.mm: -------------------------------------------------------------------------------- 1 | /* 2 | * tutorialpluginMac.mm 3 | * FireBreath 4 | * 5 | * Created by Roy Shilkrot on 11/30/11. 6 | * Copyright 2011 MIT. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "tutorialpluginMac.h" 11 | 12 | #import 13 | 14 | #include "Mac/PluginWindowMac.h" 15 | #include "Mac/PluginWindowMacQD.h" 16 | #include "Mac/PluginWindowMacCG.h" 17 | #include "Mac/PluginWindowMacCA.h" 18 | #include "Mac/PluginWindowMacICA.h" 19 | 20 | #include 21 | using namespace std; 22 | 23 | #include "tutorialpluginMac.h" 24 | 25 | void glutDisplay (void); 26 | 27 | @interface MyCAOpenGLLayer : CAOpenGLLayer { 28 | GLfloat m_angle; 29 | } 30 | @end 31 | 32 | @implementation MyCAOpenGLLayer 33 | 34 | - (id) init { 35 | if ([super init]) { 36 | m_angle = 0; 37 | } 38 | return self; 39 | } 40 | 41 | - (void)drawInCGLContext:(CGLContextObj)ctx pixelFormat:(CGLPixelFormatObj)pf forLayerTime:(CFTimeInterval)t displayTime:(const CVTimeStamp *)ts { 42 | //m_angle += 1; 43 | GLsizei width = CGRectGetWidth([self bounds]), height = CGRectGetHeight([self bounds]); 44 | GLfloat halfWidth = width / 2, halfHeight = height / 2; 45 | 46 | glViewport(0, 0, width, height); 47 | 48 | glutDisplay(); //let NITE draw it's stuff 49 | 50 | [super drawInCGLContext:ctx pixelFormat:pf forLayerTime:t displayTime:ts]; 51 | } 52 | 53 | @end 54 | 55 | tutorialpluginMac::tutorialpluginMac() : m_layer(NULL) {} 56 | 57 | tutorialpluginMac::~tutorialpluginMac() 58 | { 59 | if (m_layer) { 60 | [(CALayer*)m_layer removeFromSuperlayer]; 61 | [(CALayer*)m_layer release]; 62 | m_layer = NULL; 63 | } 64 | } 65 | 66 | bool tutorialpluginMac::onWindowAttached(FB::AttachedEvent* evt, FB::PluginWindowMac* wnd) 67 | { 68 | cout << "tutorialpluginMac::onWindowAttached" << endl; 69 | if (FB::PluginWindowMac::DrawingModelCoreAnimation == wnd->getDrawingModel() || 70 | FB::PluginWindowMac::DrawingModelInvalidatingCoreAnimation == wnd->getDrawingModel()) 71 | { 72 | cout << " Setup CAOpenGL drawing. "<getDrawingModel()) ? NO : YES; 75 | layer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable; 76 | layer.needsDisplayOnBoundsChange = YES; 77 | m_layer = layer; 78 | if (FB::PluginWindowMac::DrawingModelInvalidatingCoreAnimation == wnd->getDrawingModel()) 79 | wnd->StartAutoInvalidate(1.0/30.0); 80 | [(CALayer*) wnd->getDrawingPrimitive() addSublayer:layer]; 81 | } 82 | return tutorialplugin::onWindowAttached(evt,wnd); 83 | } 84 | 85 | bool tutorialpluginMac::onWindowDetached(FB::DetachedEvent* evt, FB::PluginWindowMac* wnd) 86 | { 87 | return tutorialplugin::onWindowDetached(evt,wnd); 88 | } 89 | -------------------------------------------------------------------------------- /Win/projectDef.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # Auto-generated Windows project definition file for the 3 | # tutorial plugin project 4 | #\**********************************************************/ 5 | 6 | # Windows template platform definition CMake file 7 | # Included from ../CMakeLists.txt 8 | 9 | # remember that the current source dir is the project root; this file is in Win/ 10 | file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 11 | Win/[^.]*.cpp 12 | Win/[^.]*.h 13 | Win/[^.]*.cmake 14 | ) 15 | 16 | # use this to add preprocessor definitions 17 | add_definitions( 18 | /D "_ATL_STATIC_REGISTRY" 19 | ) 20 | 21 | SOURCE_GROUP(Win FILES ${PLATFORM}) 22 | 23 | set (SOURCES 24 | ${SOURCES} 25 | ${PLATFORM} 26 | ) 27 | 28 | add_windows_plugin(${PROJECT_NAME} SOURCES) 29 | 30 | # This is an example of how to add a build step to sign the plugin DLL before 31 | # the WiX installer builds. The first filename (certificate.pfx) should be 32 | # the path to your pfx file. If it requires a passphrase, the passphrase 33 | # should be located inside the second file. If you don't need a passphrase 34 | # then set the second filename to "". If you don't want signtool to timestamp 35 | # your DLL then make the last parameter "". 36 | # 37 | # Note that this will not attempt to sign if the certificate isn't there -- 38 | # that's so that you can have development machines without the cert and it'll 39 | # still work. Your cert should only be on the build machine and shouldn't be in 40 | # source control! 41 | # -- uncomment lines below this to enable signing -- 42 | #firebreath_sign_plugin(${PROJECT_NAME} 43 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/certificate.pfx" 44 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/passphrase.txt" 45 | # "http://timestamp.verisign.com/scripts/timestamp.dll") 46 | 47 | # add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing! 48 | target_link_libraries(${PROJECT_NAME} 49 | ${PLUGIN_INTERNAL_DEPS} 50 | ) 51 | 52 | set(WIX_HEAT_FLAGS 53 | -gg # Generate GUIDs 54 | -srd # Suppress Root Dir 55 | -cg PluginDLLGroup # Set the Component group name 56 | -dr INSTALLDIR # Set the directory ID to put the files in 57 | ) 58 | 59 | add_wix_installer( ${PLUGIN_NAME} 60 | ${CMAKE_CURRENT_SOURCE_DIR}/Win/WiX/tutorialpluginInstaller.wxs 61 | PluginDLLGroup 62 | ${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/ 63 | ${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/${FBSTRING_PluginFileName}.dll 64 | ${PROJECT_NAME} 65 | ) 66 | 67 | # This is an example of how to add a build step to sign the WiX installer 68 | # -- uncomment lines below this to enable signing -- 69 | #firebreath_sign_file("${PLUGIN_NAME}_WiXInstall" 70 | # "${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/${PLUGIN_NAME}.msi" 71 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/certificate.pfx" 72 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/passphrase.txt" 73 | # "http://timestamp.verisign.com/scripts/timestamp.dll") 74 | -------------------------------------------------------------------------------- /tutorialpluginAPI.cpp: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | 3 | Auto-generated tutorialpluginAPI.cpp 4 | 5 | \**********************************************************/ 6 | 7 | #include "JSObject.h" 8 | #include "variant_list.h" 9 | #include "DOM/Document.h" 10 | #include "global/config.h" 11 | 12 | #include "tutorialpluginAPI.h" 13 | 14 | /////////////////////////////////////////////////////////////////////////////// 15 | /// @fn tutorialpluginAPI::tutorialpluginAPI(const tutorialpluginPtr& plugin, const FB::BrowserHostPtr host) 16 | /// 17 | /// @brief Constructor for your JSAPI object. You should register your methods, properties, and events 18 | /// that should be accessible to Javascript from here. 19 | /// 20 | /// @see FB::JSAPIAuto::registerMethod 21 | /// @see FB::JSAPIAuto::registerProperty 22 | /// @see FB::JSAPIAuto::registerEvent 23 | /////////////////////////////////////////////////////////////////////////////// 24 | //tutorialpluginAPI::tutorialpluginAPI(const tutorialpluginPtr& plugin, const FB::BrowserHostPtr& host) : m_plugin(plugin), m_host(host) 25 | 26 | 27 | /////////////////////////////////////////////////////////////////////////////// 28 | /// @fn tutorialpluginAPI::~tutorialpluginAPI() 29 | /// 30 | /// @brief Destructor. Remember that this object will not be released until 31 | /// the browser is done with it; this will almost definitely be after 32 | /// the plugin is released. 33 | /////////////////////////////////////////////////////////////////////////////// 34 | tutorialpluginAPI::~tutorialpluginAPI() 35 | { 36 | } 37 | 38 | /////////////////////////////////////////////////////////////////////////////// 39 | /// @fn tutorialpluginPtr tutorialpluginAPI::getPlugin() 40 | /// 41 | /// @brief Gets a reference to the plugin that was passed in when the object 42 | /// was created. If the plugin has already been released then this 43 | /// will throw a FB::script_error that will be translated into a 44 | /// javascript exception in the page. 45 | /////////////////////////////////////////////////////////////////////////////// 46 | tutorialpluginPtr tutorialpluginAPI::getPlugin() 47 | { 48 | tutorialpluginPtr plugin(m_plugin.lock()); 49 | if (!plugin) { 50 | throw FB::script_error("The plugin is invalid"); 51 | } 52 | return plugin; 53 | } 54 | 55 | 56 | 57 | // Read/Write property testString 58 | std::string tutorialpluginAPI::get_testString() 59 | { 60 | return m_testString; 61 | } 62 | void tutorialpluginAPI::set_testString(const std::string& val) 63 | { 64 | m_testString = val; 65 | } 66 | 67 | // Read-only property version 68 | std::string tutorialpluginAPI::get_version() 69 | { 70 | return FBSTRING_PLUGIN_VERSION; 71 | } 72 | 73 | // Method echo 74 | FB::variant tutorialpluginAPI::echo(const FB::variant& msg) 75 | { 76 | static int n(0); 77 | fire_echo(msg, n++); 78 | return msg; 79 | } 80 | 81 | void tutorialpluginAPI::testEvent(const FB::variant& var) 82 | { 83 | fire_fired(var, true, 1); 84 | } 85 | 86 | long tutorialpluginAPI::add(long a, long b, long c) { return a+b+c;} -------------------------------------------------------------------------------- /Win/WiX/tutorialpluginInstaller.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 32 | 33 | 34 | 35 | 36 | 43 | 44 | 45 | 46 | 47 | 54 | 55 | 56 | 57 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /tutorialplugin.cpp: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | 3 | Auto-generated tutorialplugin.cpp 4 | 5 | This file contains the auto-generated main plugin object 6 | implementation for the tutorial plugin project 7 | 8 | \**********************************************************/ 9 | 10 | #include "tutorialpluginAPI.h" 11 | 12 | #include "tutorialplugin.h" 13 | 14 | #include 15 | using namespace std; 16 | 17 | int head_extractor_main(int argc, char** argv); 18 | 19 | /////////////////////////////////////////////////////////////////////////////// 20 | /// @fn tutorialplugin::StaticInitialize() 21 | /// 22 | /// @brief Called from PluginFactory::globalPluginInitialize() 23 | /// 24 | /// @see FB::FactoryBase::globalPluginInitialize 25 | /////////////////////////////////////////////////////////////////////////////// 26 | void tutorialplugin::StaticInitialize() 27 | { 28 | // Place one-time initialization stuff here; As of FireBreath 1.4 this should only 29 | // be called once per process 30 | } 31 | 32 | /////////////////////////////////////////////////////////////////////////////// 33 | /// @fn tutorialplugin::StaticInitialize() 34 | /// 35 | /// @brief Called from PluginFactory::globalPluginDeinitialize() 36 | /// 37 | /// @see FB::FactoryBase::globalPluginDeinitialize 38 | /////////////////////////////////////////////////////////////////////////////// 39 | void tutorialplugin::StaticDeinitialize() 40 | { 41 | // Place one-time deinitialization stuff here. As of FireBreath 1.4 this should 42 | // always be called just before the plugin library is unloaded 43 | } 44 | 45 | /////////////////////////////////////////////////////////////////////////////// 46 | /// @brief tutorialplugin constructor. Note that your API is not available 47 | /// at this point, nor the window. For best results wait to use 48 | /// the JSAPI object until the onPluginReady method is called 49 | /////////////////////////////////////////////////////////////////////////////// 50 | tutorialplugin::tutorialplugin() 51 | { 52 | } 53 | 54 | /////////////////////////////////////////////////////////////////////////////// 55 | /// @brief tutorialplugin destructor. 56 | /////////////////////////////////////////////////////////////////////////////// 57 | tutorialplugin::~tutorialplugin() 58 | { 59 | // This is optional, but if you reset m_api (the shared_ptr to your JSAPI 60 | // root object) and tell the host to free the retained JSAPI objects then 61 | // unless you are holding another shared_ptr reference to your JSAPI object 62 | // they will be released here. 63 | releaseRootJSAPI(); 64 | m_host->freeRetainedObjects(); 65 | } 66 | 67 | void tutorialplugin::onPluginReady() 68 | { 69 | // When this is called, the BrowserHost is attached, the JSAPI object is 70 | // created, and we are ready to interact with the page and such. The 71 | // PluginWindow may or may not have already fire the AttachedEvent at 72 | // this point. 73 | } 74 | 75 | void tutorialplugin::shutdown() 76 | { 77 | // This will be called when it is time for the plugin to shut down; 78 | // any threads or anything else that may hold a shared_ptr to this 79 | // object should be released here so that this object can be safely 80 | // destroyed. This is the last point that shared_from_this and weak_ptr 81 | // references to this object will be valid 82 | } 83 | 84 | /////////////////////////////////////////////////////////////////////////////// 85 | /// @brief Creates an instance of the JSAPI object that provides your main 86 | /// Javascript interface. 87 | /// 88 | /// Note that m_host is your BrowserHost and shared_ptr returns a 89 | /// FB::PluginCorePtr, which can be used to provide a 90 | /// boost::weak_ptr for your JSAPI class. 91 | /// 92 | /// Be very careful where you hold a shared_ptr to your plugin class from, 93 | /// as it could prevent your plugin class from getting destroyed properly. 94 | /////////////////////////////////////////////////////////////////////////////// 95 | FB::JSAPIPtr tutorialplugin::createJSAPI() 96 | { 97 | // m_host is the BrowserHost 98 | return boost::make_shared(FB::ptr_cast(shared_from_this()), m_host); 99 | } 100 | 101 | bool tutorialplugin::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *) 102 | { 103 | printf("Mouse down at: %d, %d\n", evt->m_x, evt->m_y); 104 | return false; 105 | } 106 | 107 | bool tutorialplugin::onMouseUp(FB::MouseUpEvent *evt, FB::PluginWindow *) 108 | { 109 | // printf("Mouse up at: %d, %d\n", evt->m_x, evt->m_y); 110 | return false; 111 | } 112 | 113 | bool tutorialplugin::onMouseMove(FB::MouseMoveEvent *evt, FB::PluginWindow *) 114 | { 115 | // printf("Mouse move at: %d, %d\n", evt->m_x, evt->m_y); 116 | return false; 117 | } 118 | 119 | int kinect_main(int argc, char ** argv); 120 | bool tutorialplugin::onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindow *) 121 | { 122 | // The window is attached; act appropriately 123 | kinect_main(0, 0); 124 | cout << "tutorialplugin::onWindowAttached" << endl; 125 | return true; 126 | } 127 | 128 | bool tutorialplugin::onWindowDetached(FB::DetachedEvent *evt, FB::PluginWindow *) 129 | { 130 | // The window is about to be detached; act appropriately 131 | return true; 132 | } 133 | 134 | -------------------------------------------------------------------------------- /kinect_main.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * * 3 | * PrimeSense NITE 1.3 - Point Viewer Sample * 4 | * Copyright (C) 2010 PrimeSense Ltd. * 5 | * * 6 | *******************************************************************************/ 7 | 8 | // Headers for OpenNI 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | // Header for NITE 15 | #include "XnVNite.h" 16 | // local header 17 | #include "PointDrawer.h" 18 | 19 | #define CHECK_RC(rc, what) \ 20 | if (rc != XN_STATUS_OK) \ 21 | { \ 22 | printf("%s failed: %s\n", what, xnGetStatusString(rc)); \ 23 | return rc; \ 24 | } 25 | 26 | #define CHECK_ERRORS(rc, errors, what) \ 27 | if (rc == XN_STATUS_NO_NODE_PRESENT) \ 28 | { \ 29 | XnChar strError[1024]; \ 30 | errors.ToString(strError, 1024); \ 31 | printf("%s\n", strError); \ 32 | return (rc); \ 33 | } 34 | 35 | #if defined(__APPLE__) 36 | # include 37 | #elif defined(__linux__) 38 | # include 39 | #else 40 | # include 41 | #endif 42 | 43 | #undef USE_GLUT 44 | 45 | 46 | //#ifdef USE_GLUT 47 | // #if (XN_PLATFORM == XN_PLATFORM_MACOSX) 48 | // #include 49 | // #else 50 | // #include 51 | // #endif 52 | //#elif defined(USE_GLES) 53 | // #include "opengles.h" 54 | // #include "kbhit.h" 55 | //#endif 56 | //#include "signal_catch.h" 57 | 58 | //#ifdef USE_GLES 59 | //static EGLDisplay display = EGL_NO_DISPLAY; 60 | //static EGLSurface surface = EGL_NO_SURFACE; 61 | //static EGLContext context = EGL_NO_CONTEXT; 62 | //#endif 63 | 64 | // OpenNI objects 65 | xn::Context g_Context; 66 | xn::ScriptNode g_ScriptNode; 67 | xn::DepthGenerator g_DepthGenerator; 68 | xn::HandsGenerator g_HandsGenerator; 69 | xn::GestureGenerator g_GestureGenerator; 70 | 71 | // NITE objects 72 | XnVSessionManager* g_pSessionManager; 73 | XnVFlowRouter* g_pFlowRouter; 74 | 75 | // the drawer 76 | XnVPointDrawer* g_pDrawer; 77 | 78 | #define GL_WIN_SIZE_X 720 79 | #define GL_WIN_SIZE_Y 480 80 | 81 | // Draw the depth map? 82 | XnBool g_bDrawDepthMap = true; 83 | XnBool g_bPrintFrameID = false; 84 | // Use smoothing? 85 | XnFloat g_fSmoothing = 0.0f; 86 | XnBool g_bPause = false; 87 | XnBool g_bQuit = false; 88 | 89 | SessionState g_SessionState = NOT_IN_SESSION; 90 | 91 | void CleanupExit() 92 | { 93 | exit (1); 94 | } 95 | 96 | // Callback for when the focus is in progress 97 | void XN_CALLBACK_TYPE FocusProgress(const XnChar* strFocus, const XnPoint3D& ptPosition, XnFloat fProgress, void* UserCxt) 98 | { 99 | // printf("Focus progress: %s @(%f,%f,%f): %f\n", strFocus, ptPosition.X, ptPosition.Y, ptPosition.Z, fProgress); 100 | } 101 | // callback for session start 102 | void XN_CALLBACK_TYPE SessionStarting(const XnPoint3D& ptPosition, void* UserCxt) 103 | { 104 | printf("Session start: (%f,%f,%f)\n", ptPosition.X, ptPosition.Y, ptPosition.Z); 105 | g_SessionState = IN_SESSION; 106 | } 107 | // Callback for session end 108 | void XN_CALLBACK_TYPE SessionEnding(void* UserCxt) 109 | { 110 | printf("Session end\n"); 111 | g_SessionState = NOT_IN_SESSION; 112 | } 113 | void XN_CALLBACK_TYPE NoHands(void* UserCxt) 114 | { 115 | if (g_SessionState != NOT_IN_SESSION) 116 | { 117 | printf("Quick refocus\n"); 118 | g_SessionState = QUICK_REFOCUS; 119 | } 120 | } 121 | 122 | void XN_CALLBACK_TYPE TouchingCallback(xn::HandTouchingFOVEdgeCapability& generator, XnUserID id, const XnPoint3D* pPosition, XnFloat fTime, XnDirection eDir, void* pCookie) 123 | { 124 | g_pDrawer->SetTouchingFOVEdge(id); 125 | } 126 | /* 127 | void XN_CALLBACK_TYPE MyGestureInProgress(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie) 128 | { 129 | printf("Gesture %s in progress\n", strGesture); 130 | } 131 | void XN_CALLBACK_TYPE MyGestureReady(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie) 132 | { 133 | printf("Gesture %s ready for next stage\n", strGesture); 134 | } 135 | */ 136 | 137 | // this function is called each frame 138 | void glutDisplay (void) 139 | { 140 | 141 | glDisable(GL_DEPTH_TEST); 142 | glEnable(GL_TEXTURE_2D); 143 | 144 | glEnableClientState(GL_VERTEX_ARRAY); 145 | glDisableClientState(GL_COLOR_ARRAY); 146 | 147 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 148 | 149 | // Setup the OpenGL viewpoint 150 | glMatrixMode(GL_PROJECTION); 151 | glPushMatrix(); 152 | glLoadIdentity(); 153 | 154 | XnMapOutputMode mode; 155 | g_DepthGenerator.GetMapOutputMode(mode); 156 | //#ifdef USE_GLUT 157 | glOrtho(0, mode.nXRes, mode.nYRes, 0, -1.0, 1.0); 158 | #if defined(USE_GLES) 159 | glOrthof(0, mode.nXRes, mode.nYRes, 0, -1.0, 1.0); 160 | #endif 161 | 162 | glDisable(GL_TEXTURE_2D); 163 | 164 | if (!g_bPause) 165 | { 166 | // Read next available data 167 | g_Context.WaitOneUpdateAll(g_DepthGenerator); 168 | // Update NITE tree 169 | g_pSessionManager->Update(&g_Context); 170 | #ifdef USE_GLUT 171 | PrintSessionState(g_SessionState); 172 | #endif 173 | } 174 | 175 | #ifdef USE_GLUT 176 | glutSwapBuffers(); 177 | #endif 178 | } 179 | 180 | #ifdef USE_GLUT 181 | void glutIdle (void) 182 | { 183 | if (g_bQuit) { 184 | CleanupExit(); 185 | } 186 | 187 | // Display the frame 188 | glutPostRedisplay(); 189 | } 190 | 191 | void glutKeyboard (unsigned char key, int x, int y) 192 | { 193 | switch (key) 194 | { 195 | case 27: 196 | // Exit 197 | CleanupExit(); 198 | case'p': 199 | // Toggle pause 200 | g_bPause = !g_bPause; 201 | break; 202 | case 'd': 203 | // Toggle drawing of the depth map 204 | g_bDrawDepthMap = !g_bDrawDepthMap; 205 | g_pDrawer->SetDepthMap(g_bDrawDepthMap); 206 | break; 207 | case 'f': 208 | g_bPrintFrameID = !g_bPrintFrameID; 209 | g_pDrawer->SetFrameID(g_bPrintFrameID); 210 | break; 211 | case 's': 212 | // Toggle smoothing 213 | if (g_fSmoothing == 0) 214 | g_fSmoothing = 0.1; 215 | else 216 | g_fSmoothing = 0; 217 | g_HandsGenerator.SetSmoothing(g_fSmoothing); 218 | break; 219 | case 'e': 220 | // end current session 221 | g_pSessionManager->EndSession(); 222 | break; 223 | } 224 | } 225 | void glInit (int * pargc, char ** argv) 226 | { 227 | glutInit(pargc, argv); 228 | glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); 229 | glutInitWindowSize(GL_WIN_SIZE_X, GL_WIN_SIZE_Y); 230 | glutCreateWindow ("PrimeSense Nite Point Viewer"); 231 | //glutFullScreen(); 232 | glutSetCursor(GLUT_CURSOR_NONE); 233 | 234 | glutKeyboardFunc(glutKeyboard); 235 | glutDisplayFunc(glutDisplay); 236 | glutIdleFunc(glutIdle); 237 | 238 | glDisable(GL_DEPTH_TEST); 239 | glEnable(GL_TEXTURE_2D); 240 | 241 | glEnableClientState(GL_VERTEX_ARRAY); 242 | glDisableClientState(GL_COLOR_ARRAY); 243 | } 244 | #endif 245 | 246 | void XN_CALLBACK_TYPE GestureIntermediateStageCompletedHandler(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie) 247 | { 248 | printf("Gesture %s: Intermediate stage complete (%f,%f,%f)\n", strGesture, pPosition->X, pPosition->Y, pPosition->Z); 249 | } 250 | void XN_CALLBACK_TYPE GestureReadyForNextIntermediateStageHandler(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie) 251 | { 252 | printf("Gesture %s: Ready for next intermediate stage (%f,%f,%f)\n", strGesture, pPosition->X, pPosition->Y, pPosition->Z); 253 | } 254 | void XN_CALLBACK_TYPE GestureProgressHandler(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, XnFloat fProgress, void* pCookie) 255 | { 256 | printf("Gesture %s progress: %f (%f,%f,%f)\n", strGesture, fProgress, pPosition->X, pPosition->Y, pPosition->Z); 257 | } 258 | 259 | 260 | // xml to initialize OpenNI 261 | #define SAMPLE_XML_PATH "/Users/royshilkrot/Downloads/NITE-Bin-MacOSX-v1.4.1.2/Data/Sample-Tracking.xml" 262 | 263 | int kinect_main(int argc, char ** argv) 264 | { 265 | XnStatus rc = XN_STATUS_OK; 266 | xn::EnumerationErrors errors; 267 | 268 | // Initialize OpenNI 269 | rc = g_Context.InitFromXmlFile(SAMPLE_XML_PATH, g_ScriptNode, &errors); 270 | CHECK_ERRORS(rc, errors, "InitFromXmlFile"); 271 | CHECK_RC(rc, "InitFromXmlFile"); 272 | 273 | rc = g_Context.FindExistingNode(XN_NODE_TYPE_DEPTH, g_DepthGenerator); 274 | CHECK_RC(rc, "Find depth generator"); 275 | rc = g_Context.FindExistingNode(XN_NODE_TYPE_HANDS, g_HandsGenerator); 276 | CHECK_RC(rc, "Find hands generator"); 277 | rc = g_Context.FindExistingNode(XN_NODE_TYPE_GESTURE, g_GestureGenerator); 278 | CHECK_RC(rc, "Find gesture generator"); 279 | 280 | XnCallbackHandle h; 281 | if (g_HandsGenerator.IsCapabilitySupported(XN_CAPABILITY_HAND_TOUCHING_FOV_EDGE)) 282 | { 283 | g_HandsGenerator.GetHandTouchingFOVEdgeCap().RegisterToHandTouchingFOVEdge(TouchingCallback, NULL, h); 284 | } 285 | 286 | XnCallbackHandle hGestureIntermediateStageCompleted, hGestureProgress, hGestureReadyForNextIntermediateStage; 287 | g_GestureGenerator.RegisterToGestureIntermediateStageCompleted(GestureIntermediateStageCompletedHandler, NULL, hGestureIntermediateStageCompleted); 288 | g_GestureGenerator.RegisterToGestureReadyForNextIntermediateStage(GestureReadyForNextIntermediateStageHandler, NULL, hGestureReadyForNextIntermediateStage); 289 | g_GestureGenerator.RegisterGestureCallbacks(NULL, GestureProgressHandler, NULL, hGestureProgress); 290 | 291 | 292 | // Create NITE objects 293 | g_pSessionManager = new XnVSessionManager; 294 | rc = g_pSessionManager->Initialize(&g_Context, "Click,Wave", "RaiseHand,Click"); 295 | CHECK_RC(rc, "SessionManager::Initialize"); 296 | 297 | g_pSessionManager->RegisterSession(NULL, SessionStarting, SessionEnding, FocusProgress); 298 | 299 | g_pDrawer = new XnVPointDrawer(20, g_DepthGenerator); 300 | g_pFlowRouter = new XnVFlowRouter; 301 | g_pFlowRouter->SetActive(g_pDrawer); 302 | 303 | g_pSessionManager->AddListener(g_pFlowRouter); 304 | 305 | g_pDrawer->RegisterNoPoints(NULL, NoHands); 306 | g_pDrawer->SetDepthMap(g_bDrawDepthMap); 307 | 308 | // Initialization done. Start generating 309 | rc = g_Context.StartGeneratingAll(); 310 | CHECK_RC(rc, "StartGenerating"); 311 | 312 | // Mainloop 313 | #ifdef USE_GLUT 314 | 315 | glInit(&argc, argv); 316 | glutMainLoop(); 317 | 318 | #elif defined(USE_GLES) 319 | if (!opengles_init(GL_WIN_SIZE_X, GL_WIN_SIZE_Y, &display, &surface, &context)) 320 | { 321 | printf("Error initializing opengles\n"); 322 | CleanupExit(); 323 | } 324 | glDisable(GL_DEPTH_TEST); 325 | glEnable(GL_TEXTURE_2D); 326 | glEnableClientState(GL_VERTEX_ARRAY); 327 | glDisableClientState(GL_COLOR_ARRAY); 328 | 329 | while ((!_kbhit()) && (!g_bQuit)) 330 | { 331 | glutDisplay(); 332 | eglSwapBuffers(display, surface); 333 | } 334 | opengles_shutdown(display, surface, context); 335 | 336 | CleanupExit(); 337 | #endif 338 | } 339 | -------------------------------------------------------------------------------- /PointDrawer.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * * 3 | * PrimeSense NITE 1.3 - Point Viewer Sample * 4 | * Copyright (C) 2010 PrimeSense Ltd. * 5 | * * 6 | *******************************************************************************/ 7 | 8 | #include "PointDrawer.h" 9 | #include "XnVDepthMessage.h" 10 | #include 11 | 12 | //#ifdef USE_GLUT 13 | // #if (XN_PLATFORM == XN_PLATFORM_MACOSX) 14 | // #include 15 | // #else 16 | // #include 17 | // #endif 18 | //#elif defined(USE_GLES) 19 | // #include "opengles.h" 20 | //#endif 21 | 22 | #if defined(__APPLE__) 23 | # include 24 | #elif defined(__linux__) 25 | # include 26 | #else 27 | # include 28 | #endif 29 | 30 | // Constructor. Receives the number of previous positions to store per hand, 31 | // and a source for depth map 32 | XnVPointDrawer::XnVPointDrawer(XnUInt32 nHistory, xn::DepthGenerator depthGenerator) : 33 | XnVPointControl("XnVPointDrawer"), 34 | m_nHistorySize(nHistory), m_DepthGenerator(depthGenerator), m_bDrawDM(false), m_bFrameID(false) 35 | { 36 | m_pfPositionBuffer = new XnFloat[nHistory*3]; 37 | } 38 | 39 | // Destructor. Clear all data structures 40 | XnVPointDrawer::~XnVPointDrawer() 41 | { 42 | std::map >::iterator iter; 43 | for (iter = m_History.begin(); iter != m_History.end(); ++iter) 44 | { 45 | iter->second.clear(); 46 | } 47 | m_History.clear(); 48 | 49 | delete []m_pfPositionBuffer; 50 | } 51 | 52 | // Change whether or not to draw the depth map 53 | void XnVPointDrawer::SetDepthMap(XnBool bDrawDM) 54 | { 55 | m_bDrawDM = bDrawDM; 56 | } 57 | // Change whether or not to print the frame ID 58 | void XnVPointDrawer::SetFrameID(XnBool bFrameID) 59 | { 60 | m_bFrameID = bFrameID; 61 | } 62 | 63 | // Handle creation of a new hand 64 | static XnBool bShouldPrint = false; 65 | void XnVPointDrawer::OnPointCreate(const XnVHandPointContext* cxt) 66 | { 67 | printf("** %d\n", cxt->nID); 68 | // Create entry for the hand 69 | m_History[cxt->nID].clear(); 70 | bShouldPrint = true; 71 | OnPointUpdate(cxt); 72 | bShouldPrint = true; 73 | } 74 | // Handle new position of an existing hand 75 | void XnVPointDrawer::OnPointUpdate(const XnVHandPointContext* cxt) 76 | { 77 | // positions are kept in projective coordinates, since they are only used for drawing 78 | XnPoint3D ptProjective(cxt->ptPosition); 79 | 80 | if (bShouldPrint)printf("Point (%f,%f,%f)", ptProjective.X, ptProjective.Y, ptProjective.Z); 81 | m_DepthGenerator.ConvertRealWorldToProjective(1, &ptProjective, &ptProjective); 82 | if (bShouldPrint)printf(" -> (%f,%f,%f)\n", ptProjective.X, ptProjective.Y, ptProjective.Z); 83 | 84 | // Add new position to the history buffer 85 | m_History[cxt->nID].push_front(ptProjective); 86 | // Keep size of history buffer 87 | if (m_History[cxt->nID].size() > m_nHistorySize) 88 | m_History[cxt->nID].pop_back(); 89 | bShouldPrint = false; 90 | } 91 | 92 | // Handle destruction of an existing hand 93 | void XnVPointDrawer::OnPointDestroy(XnUInt32 nID) 94 | { 95 | // No need for the history buffer 96 | m_History.erase(nID); 97 | } 98 | 99 | #define MAX_DEPTH 10000 100 | float g_pDepthHist[MAX_DEPTH]; 101 | unsigned int getClosestPowerOfTwo(unsigned int n) 102 | { 103 | unsigned int m = 2; 104 | while(m < n) m<<=1; 105 | 106 | return m; 107 | } 108 | GLuint initTexture(void** buf, int& width, int& height) 109 | { 110 | GLuint texID = 0; 111 | glGenTextures(1,&texID); 112 | 113 | width = getClosestPowerOfTwo(width); 114 | height = getClosestPowerOfTwo(height); 115 | *buf = new unsigned char[width*height*4]; 116 | glBindTexture(GL_TEXTURE_2D,texID); 117 | 118 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 119 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 120 | 121 | return texID; 122 | } 123 | 124 | GLfloat texcoords[8]; 125 | void DrawRectangle(float topLeftX, float topLeftY, float bottomRightX, float bottomRightY) 126 | { 127 | GLfloat verts[8] = { topLeftX, topLeftY, 128 | topLeftX, bottomRightY, 129 | bottomRightX, bottomRightY, 130 | bottomRightX, topLeftY 131 | }; 132 | glVertexPointer(2, GL_FLOAT, 0, verts); 133 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 134 | 135 | glFlush(); 136 | } 137 | void DrawTexture(float topLeftX, float topLeftY, float bottomRightX, float bottomRightY) 138 | { 139 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); 140 | glTexCoordPointer(2, GL_FLOAT, 0, texcoords); 141 | 142 | DrawRectangle(topLeftX, topLeftY, bottomRightX, bottomRightY); 143 | 144 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); 145 | } 146 | 147 | void DrawDepthMap(const xn::DepthMetaData& dm) 148 | { 149 | static bool bInitialized = false; 150 | static GLuint depthTexID; 151 | static unsigned char* pDepthTexBuf; 152 | static int texWidth, texHeight; 153 | 154 | float topLeftX; 155 | float topLeftY; 156 | float bottomRightY; 157 | float bottomRightX; 158 | float texXpos; 159 | float texYpos; 160 | 161 | if(!bInitialized) 162 | { 163 | XnUInt16 nXRes = dm.XRes(); 164 | XnUInt16 nYRes = dm.YRes(); 165 | texWidth = getClosestPowerOfTwo(nXRes); 166 | texHeight = getClosestPowerOfTwo(nYRes); 167 | 168 | depthTexID = initTexture((void**)&pDepthTexBuf,texWidth, texHeight) ; 169 | 170 | bInitialized = true; 171 | 172 | topLeftX = nXRes; 173 | topLeftY = 0; 174 | bottomRightY = nYRes; 175 | bottomRightX = 0; 176 | texXpos =(float)nXRes/texWidth; 177 | texYpos =(float)nYRes/texHeight; 178 | 179 | memset(texcoords, 0, 8*sizeof(float)); 180 | texcoords[0] = texXpos, texcoords[1] = texYpos, texcoords[2] = texXpos, texcoords[7] = texYpos; 181 | 182 | } 183 | unsigned int nValue = 0; 184 | unsigned int nHistValue = 0; 185 | unsigned int nIndex = 0; 186 | unsigned int nX = 0; 187 | unsigned int nY = 0; 188 | unsigned int nNumberOfPoints = 0; 189 | XnUInt16 g_nXRes = dm.XRes(); 190 | XnUInt16 g_nYRes = dm.YRes(); 191 | 192 | unsigned char* pDestImage = pDepthTexBuf; 193 | 194 | const XnUInt16* pDepth = dm.Data(); 195 | 196 | // Calculate the accumulative histogram 197 | memset(g_pDepthHist, 0, MAX_DEPTH*sizeof(float)); 198 | for (nY=0; nY::const_iterator iter = m_TouchingFOVEdge.begin(); iter != m_TouchingFOVEdge.end(); ++iter) 304 | { 305 | if (*iter == id) 306 | return TRUE; 307 | } 308 | return FALSE; 309 | } 310 | 311 | void XnVPointDrawer::Draw() const 312 | { 313 | std::map >::const_iterator PointIterator; 314 | 315 | // Go over each existing hand 316 | for (PointIterator = m_History.begin(); 317 | PointIterator != m_History.end(); 318 | ++PointIterator) 319 | { 320 | // Clear buffer 321 | XnUInt32 nPoints = 0; 322 | XnUInt32 i = 0; 323 | XnUInt32 Id = PointIterator->first; 324 | 325 | // Go over all previous positions of current hand 326 | std::list::const_iterator PositionIterator; 327 | for (PositionIterator = PointIterator->second.begin(); 328 | PositionIterator != PointIterator->second.end(); 329 | ++PositionIterator, ++i) 330 | { 331 | // Add position to buffer 332 | XnPoint3D pt(*PositionIterator); 333 | m_pfPositionBuffer[3*i] = pt.X; 334 | m_pfPositionBuffer[3*i + 1] = pt.Y; 335 | m_pfPositionBuffer[3*i + 2] = 0;//pt.Z(); 336 | } 337 | 338 | // Set color 339 | XnUInt32 nColor = Id % nColors; 340 | XnUInt32 nSingle = GetPrimaryID(); 341 | if (Id == GetPrimaryID()) 342 | nColor = 6; 343 | // Draw buffer: 344 | glColor4f(Colors[nColor][0], 345 | Colors[nColor][1], 346 | Colors[nColor][2], 347 | 1.0f); 348 | glPointSize(2); 349 | glVertexPointer(3, GL_FLOAT, 0, m_pfPositionBuffer); 350 | glDrawArrays(GL_LINE_STRIP, 0, i); 351 | 352 | 353 | if (IsTouching(Id)) 354 | { 355 | glColor4f(1.0f, 0.0f, 0.0f, 1.0f); 356 | } 357 | glPointSize(8); 358 | glDrawArrays(GL_POINTS, 0, 1); 359 | glFlush(); 360 | } 361 | } 362 | void XnVPointDrawer::SetTouchingFOVEdge(XnUInt32 nID) 363 | { 364 | m_TouchingFOVEdge.push_front(nID); 365 | } 366 | 367 | // Handle a new Message 368 | void XnVPointDrawer::Update(XnVMessage* pMessage) 369 | { 370 | // PointControl's Update calls all callbacks for each hand 371 | XnVPointControl::Update(pMessage); 372 | 373 | if (m_bDrawDM) 374 | { 375 | // Draw depth map 376 | xn::DepthMetaData depthMD; 377 | m_DepthGenerator.GetMetaData(depthMD); 378 | DrawDepthMap(depthMD); 379 | } 380 | #ifdef USE_GLUT 381 | if (m_bFrameID) 382 | { 383 | // Print out frame ID 384 | xn::DepthMetaData depthMD; 385 | m_DepthGenerator.GetMetaData(depthMD); 386 | DrawFrameID(depthMD.FrameID()); 387 | } 388 | #endif 389 | // Draw hands 390 | Draw(); 391 | m_TouchingFOVEdge.clear(); 392 | } 393 | #ifdef USE_GLUT 394 | void PrintSessionState(SessionState eState) 395 | { 396 | glColor4f(1,0,1,1); 397 | glRasterPos2i(20, 20); 398 | XnChar strLabel[200]; 399 | 400 | switch (eState) 401 | { 402 | case IN_SESSION: 403 | sprintf(strLabel, "Tracking hands"); break; 404 | case NOT_IN_SESSION: 405 | sprintf(strLabel, "Perform click or wave gestures to track hand"); break; 406 | case QUICK_REFOCUS: 407 | sprintf(strLabel, "Raise your hand for it to be identified, or perform click or wave gestures"); break; 408 | } 409 | 410 | glPrintString(GLUT_BITMAP_HELVETICA_18, strLabel); 411 | } 412 | #endif 413 | --------------------------------------------------------------------------------