Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

firebreath plugin push

  • Loading branch information...
commit 33c3fc799abc13c43c47f9cd76a758a0dcbf247a 1 parent 4db4bfe
Roy Shilkrot royshil authored
Showing with 1,484 additions and 1 deletion.
  1. +0 −1  firebreath-plugin
  2. +40 −0 firebreath-plugin/CMakeLists.txt
  3. +58 −0 firebreath-plugin/Debug/depthjsplugin.plugin/Contents/Info.plist
  4. BIN  firebreath-plugin/Debug/depthjsplugin.plugin/Contents/MacOS/depthjsplugin
  5. +4 −0 firebreath-plugin/Debug/depthjsplugin.plugin/Contents/Resources/English.lproj/InfoPlist.strings
  6. BIN  firebreath-plugin/Debug/depthjsplugin.plugin/Contents/Resources/English.lproj/Localized.rsrc
  7. +23 −0 firebreath-plugin/Debug/depthjsplugin.plugin/Contents/Resources/Sample-Tracking.xml
  8. +55 −0 firebreath-plugin/Factory.cpp
  9. +11 −0 firebreath-plugin/HandMessageListener.cpp
  10. +156 −0 firebreath-plugin/HandMessageListener.h
  11. +12 −0 firebreath-plugin/Mac/ResourceRecovery.mm
  12. +60 −0 firebreath-plugin/Mac/bundle_template/Info.plist
  13. +4 −0 firebreath-plugin/Mac/bundle_template/InfoPlist.strings
  14. +20 −0 firebreath-plugin/Mac/bundle_template/Localized.r
  15. +61 −0 firebreath-plugin/Mac/projectDef.cmake
  16. +59 −0 firebreath-plugin/PluginConfig.cmake
  17. +1 −0  firebreath-plugin/ResourceRecovery.h
  18. +76 −0 firebreath-plugin/Win/WiX/depthjspluginInstaller.wxs
  19. +73 −0 firebreath-plugin/Win/projectDef.cmake
  20. +32 −0 firebreath-plugin/X11/projectDef.cmake
  21. +142 −0 firebreath-plugin/depthjsplugin.cpp
  22. +63 −0 firebreath-plugin/depthjsplugin.h
  23. +177 −0 firebreath-plugin/depthjspluginAPI.cpp
  24. +63 −0 firebreath-plugin/depthjspluginAPI.h
  25. +273 −0 firebreath-plugin/openni_backend.cpp
  26. +21 −0 firebreath-plugin/openni_backend.hpp
1  firebreath-plugin
View
40 firebreath-plugin/CMakeLists.txt
View
@@ -0,0 +1,40 @@
+#/**********************************************************\
+#
+# Auto-generated CMakeLists.txt for the DepthJS Plugin project
+#
+#\**********************************************************/
+
+# Written to work with cmake 2.6
+cmake_minimum_required (VERSION 2.6)
+set (CMAKE_BACKWARDS_COMPATIBILITY 2.6)
+
+Project(${PLUGIN_NAME})
+
+file (GLOB GENERAL RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ [^.]*.cpp
+ [^.]*.h
+ [^.]*.hpp
+ [^.]*.cmake
+ )
+
+include_directories(${PLUGIN_INCLUDE_DIRS})
+
+# Generated files are stored in ${GENERATED} by the project configuration
+SET_SOURCE_FILES_PROPERTIES(
+ ${GENERATED}
+ PROPERTIES
+ GENERATED 1
+ )
+
+SOURCE_GROUP(Generated FILES
+ ${GENERATED}
+ )
+
+SET( SOURCES
+ ${GENERAL}
+ ${GENERATED}
+ )
+
+# This will include Win/projectDef.cmake, X11/projectDef.cmake, Mac/projectDef
+# depending on the platform
+include_platform()
58 firebreath-plugin/Debug/depthjsplugin.plugin/Contents/Info.plist
View
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>depthjsplugin</string>
+ <key>CFBundleGetInfoString</key>
+ <string>depthjsplugin 1.0.0.0, Copyright 2012 MIT Media Lab</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.depthjspluginLib.DepthJS Plugin</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>BRPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>depthjsplugin 1.0.0.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0.0.0</string>
+ <key>CFPlugInDynamicRegisterFunction</key>
+ <string></string>
+ <key>CFPlugInDynamicRegistration</key>
+ <string>NO</string>
+ <key>CFPlugInFactories</key>
+ <dict>
+ <key>00000000-0000-0000-0000-000000000000</key>
+ <string>MyFactoryFunction</string>
+ </dict>
+ <key>CFPlugInTypes</key>
+ <dict>
+ <key>00000000-0000-0000-0000-000000000000</key>
+ <array>
+ <string>00000000-0000-0000-0000-000000000000</string>
+ </array>
+ </dict>
+ <key>CFPlugInUnloadFunction</key>
+ <string></string>
+ <key>WebPluginDescription</key>
+ <string>The native plugin part of the DepthJS project</string>
+ <key>WebPluginMIMETypes</key>
+ <dict>
+ <key>application/x-depthjsplugin</key>
+ <dict>
+ <key>WebPluginExtensions</key>
+ <array>
+ <string></string>
+ </array>
+ <key>WebPluginTypeDescription</key>
+ <string>The native plugin part of the DepthJS project</string>
+ </dict>
+ </dict>
+ <key>WebPluginName</key>
+ <string>DepthJS Plugin</string>
+</dict>
+</plist>
BIN  firebreath-plugin/Debug/depthjsplugin.plugin/Contents/MacOS/depthjsplugin
View
Binary file not shown
4 firebreath-plugin/Debug/depthjsplugin.plugin/Contents/Resources/English.lproj/InfoPlist.strings
View
@@ -0,0 +1,4 @@
+/* Localized versions of Info.plist keys */
+
+CFBundleName = "depthjsplugin.plugin";
+NSHumanReadableCopyright = "Copyright 2012 MIT Media Lab";
BIN  firebreath-plugin/Debug/depthjsplugin.plugin/Contents/Resources/English.lproj/Localized.rsrc
View
Binary file not shown
23 firebreath-plugin/Debug/depthjsplugin.plugin/Contents/Resources/Sample-Tracking.xml
View
@@ -0,0 +1,23 @@
+<OpenNI>
+ <Licenses>
+ <License vendor="PrimeSense" key="insert key here"/>
+ </Licenses>
+ <Log writeToConsole="true" writeToFile="false">
+ <!-- 0 - Verbose, 1 - Info, 2 - Warning, 3 - Error (default) -->
+ <LogLevel value="3"/>
+ <Masks>
+ <Mask name="ALL" on="false"/>
+ </Masks>
+ <Dumps>
+ </Dumps>
+ </Log>
+ <ProductionNodes>
+ <Node type="Depth">
+ <Configuration>
+ <Mirror on="true"/>
+ </Configuration>
+ </Node>
+ <Node type="Gesture" />
+ <Node type="Hands" />
+ </ProductionNodes>
+</OpenNI>
55 firebreath-plugin/Factory.cpp
View
@@ -0,0 +1,55 @@
+/**********************************************************\
+
+ Auto-generated Factory.cpp
+
+ This file contains the auto-generated factory methods
+ for the depthjsplugin project
+
+\**********************************************************/
+
+#include "FactoryBase.h"
+#include "depthjsplugin.h"
+#include <boost/make_shared.hpp>
+
+class PluginFactory : public FB::FactoryBase
+{
+public:
+ ///////////////////////////////////////////////////////////////////////////////
+ /// @fn FB::PluginCorePtr createPlugin(const std::string& mimetype)
+ ///
+ /// @brief Creates a plugin object matching the provided mimetype
+ /// If mimetype is empty, returns the default plugin
+ ///////////////////////////////////////////////////////////////////////////////
+ FB::PluginCorePtr createPlugin(const std::string& mimetype)
+ {
+ return boost::make_shared<depthjsplugin>();
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ /// @see FB::FactoryBase::globalPluginInitialize
+ ///////////////////////////////////////////////////////////////////////////////
+ void globalPluginInitialize()
+ {
+ depthjsplugin::StaticInitialize();
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////
+ /// @see FB::FactoryBase::globalPluginDeinitialize
+ ///////////////////////////////////////////////////////////////////////////////
+ void globalPluginDeinitialize()
+ {
+ depthjsplugin::StaticDeinitialize();
+ }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+/// @fn getFactoryInstance()
+///
+/// @brief Returns the factory instance for this plugin module
+///////////////////////////////////////////////////////////////////////////////
+FB::FactoryBasePtr getFactoryInstance()
+{
+ static boost::shared_ptr<PluginFactory> factory = boost::make_shared<PluginFactory>();
+ return factory;
+}
+
11 firebreath-plugin/HandMessageListener.cpp
View
@@ -0,0 +1,11 @@
+/*
+ * HandMessageListener.cpp
+ * OpenniTry
+ *
+ * Created by Roy Shilkrot on 9/30/11.
+ * Copyright 2011 MIT. All rights reserved.
+ *
+ */
+
+#include "HandMessageListener.h"
+
156 firebreath-plugin/HandMessageListener.h
View
@@ -0,0 +1,156 @@
+/*
+ * HandMessageListener.h
+ * OpenniTry
+ *
+ * Created by Roy Shilkrot on 9/30/11.
+ * Copyright 2011 MIT. All rights reserved.
+ *
+ */
+
+#ifndef _HANDMESSAGELISTENER_H
+#define _HANDMESSAGELISTENER_H
+
+#include <XnCppWrapper.h>
+#include <XnVPointControl.h>
+#include <XnVFlowRouter.h>
+#include <XnVSwipeDetector.h>
+#include <XnVSelectableSlider1D.h>
+#include <XnVSteadyDetector.h>
+#include <XnVBroadcaster.h>
+#include <XnVPushDetector.h>
+#include <XnVWaveDetector.h>
+#include <XnVSessionManager.h>
+#include <XnVCircleDetector.h>
+
+#include <sstream>
+using namespace std;
+
+void send_event(const string& etype, const string& edata);
+void send_log(const std::string& s);
+
+class HandPointControl : public XnVPointControl {
+public:
+ HandPointControl(xn::DepthGenerator depthGenerator, XnVSessionManager* sessionManager):m_DepthGenerator(depthGenerator),m_SessionManager(sessionManager) {
+// m_pInnerFlowRouter = new XnVFlowRouter;
+ m_pPushDetector = new XnVPushDetector;
+ m_pSwipeDetector = new XnVSwipeDetector;
+ m_pSwipeDetector->SetMotionSpeedThreshold(0.8); //swipes should be faster then regular movement
+// m_pSteadyDetector = new XnVSteadyDetector;
+// m_pWaveDetector = new XnVWaveDetector;
+ m_pCircleDetector = new XnVCircleDetector;
+ m_pCircleDetector->SetMinRadius(80); //circles should be big enough to prevent confusion with random movement
+
+// m_pInnerFlowRouter->SetActive(m_pPushDetector);
+
+ // Add the push detector and flow manager to the broadcaster
+// m_Broadcaster.AddListener(m_pInnerFlowRouter);
+// m_Broadcaster.AddListener(m_pPushDetector);
+
+ // Push
+ m_pPushDetector->RegisterPush(this, &Push_Pushed);
+ m_pCircleDetector->RegisterCircle(this, &ACircle);
+ //m_pWaveDetector->RegisterWave(this, &Wave_Waved);
+ m_pSwipeDetector->RegisterSwipeLeft(this, &Swipe_Left);
+ m_pSwipeDetector->RegisterSwipeRight(this, &Swipe_Right);
+ m_pSwipeDetector->RegisterSwipeUp(this, &Swipe_Up);
+ m_pSwipeDetector->RegisterSwipeDown(this, &Swipe_Down);
+
+ send_log("HandPointControl() DONE");
+ }
+
+ void Update(XnVMessage* pMessage)
+ {
+ XnVPointControl::Update(pMessage);
+ //m_Broadcaster.Update(pMessage);
+ m_pPushDetector->Update(pMessage);
+// m_pWaveDetector->Update(pMessage);
+ m_pCircleDetector->Update(pMessage);
+ m_pSwipeDetector->Update(pMessage);
+ }
+
+ static void XN_CALLBACK_TYPE Swipe_Left(XnFloat fVelocity, XnFloat fAngle, void* pUserCxt) {
+ send_event("SwipeLeft", "");
+ }
+ static void XN_CALLBACK_TYPE Swipe_Right(XnFloat fVelocity, XnFloat fAngle, void* pUserCxt) {
+ send_event("SwipeRight", "");
+ }
+ static void XN_CALLBACK_TYPE Swipe_Up(XnFloat fVelocity, XnFloat fAngle, void* pUserCxt) {
+ send_event("SwipeUp", "");
+ }
+ static void XN_CALLBACK_TYPE Swipe_Down(XnFloat fVelocity, XnFloat fAngle, void* pUserCxt) {
+ send_event("SwipeDown", "");
+ }
+
+ // Push detector
+ static void XN_CALLBACK_TYPE Push_Pushed(XnFloat fVelocity, XnFloat fAngle, void* cxt)
+ {
+ printf("Push!\n");
+ send_event("Push", "");
+ }
+
+ static void XN_CALLBACK_TYPE ACircle(XnFloat fTimes, XnBool bConfident, const XnVCircle* pCircle, void* cxt) {
+ if(bConfident) {
+ printf("Bye Bye!\n");
+ ((HandPointControl*)cxt)->KillSession();
+ }
+ }
+
+ // Wave detector
+ static void XN_CALLBACK_TYPE Wave_Waved(void* cxt)
+ {
+ printf("Bye Bye!\n");
+ ((HandPointControl*)cxt)->KillSession();
+ }
+
+ void KillSession() { m_SessionManager->EndSession(); }
+
+ /**
+ * Handle creation of a new point
+ */
+ void OnPointCreate(const XnVHandPointContext* cxt) {
+ printf("** %d\n", cxt->nID);
+ send_event("Register", "");
+ }
+
+ /**
+ * Handle new position of an existing point
+ */
+ void OnPointUpdate(const XnVHandPointContext* cxt) {
+ // positions are kept in projective coordinates, since they are only used for drawing
+ XnPoint3D ptProjective(cxt->ptPosition);
+
+// printf("Point (%f,%f,%f)", ptProjective.X, ptProjective.Y, ptProjective.Z);
+ m_DepthGenerator.ConvertRealWorldToProjective(1, &ptProjective, &ptProjective);
+// printf(" -> (%f,%f,%f)\n", ptProjective.X, ptProjective.Y, ptProjective.Z);
+
+ //move to [0->100,0->100,0->2048]
+ stringstream ss;
+ ss << "\"x\":" << (int)(100.0*ptProjective.X/640.0)
+ << ",\"y\":" << (int)(100.0*ptProjective.Y/480.0)
+ << ",\"z\":" << (int)ptProjective.Z;
+ //cout << "move: " << ss.str() << endl;
+ send_event("Move", ss.str());
+ }
+
+ /**
+ * Handle destruction of an existing point
+ */
+ void OnPointDestroy(XnUInt32 nID) {
+ printf("OnPointDestroy\n");
+ send_event("Unregister", "");
+ }
+private:
+ xn::DepthGenerator m_DepthGenerator;
+ XnVSessionManager* m_SessionManager;
+
+// XnVBroadcaster m_Broadcaster;
+ XnVPushDetector* m_pPushDetector;
+ XnVSwipeDetector* m_pSwipeDetector;
+// XnVSteadyDetector* m_pSteadyDetector;
+// XnVFlowRouter* m_pInnerFlowRouter;
+//
+// XnVWaveDetector* m_pWaveDetector;
+ XnVCircleDetector* m_pCircleDetector;
+};
+
+#endif
12 firebreath-plugin/Mac/ResourceRecovery.mm
View
@@ -0,0 +1,12 @@
+#include <CoreFoundation/CoreFoundation.h>
+#include "../gen/global/config.h"
+#include <string>
+
+std::string getResourcesDirectory() {
+ // Get the XML file for OpenNI from the resources directory of the plugin bundle
+ CFBundleRef bundleRef = CFBundleGetBundleWithIdentifier(CFSTR("com.depthjspluginLib.DepthJS Plugin"));
+ CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(bundleRef);
+ UInt8 cbuf[1024] = {0};
+ CFURLGetFileSystemRepresentation(resourcesURL,true,cbuf,1024);
+ return std::string((char*)cbuf);
+}
60 firebreath-plugin/Mac/bundle_template/Info.plist
View
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${PLUGIN_NAME}</string>
+ <key>CFBundleGetInfoString</key>
+ <string>${PLUGIN_NAME} ${FBSTRING_PLUGIN_VERSION}, ${FBSTRING_LegalCopyright}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.${FBTYPELIB_NAME}.${FBSTRING_PluginName}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>BRPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>${PLUGIN_NAME} ${FBSTRING_PLUGIN_VERSION}</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>${FBSTRING_PLUGIN_VERSION}</string>
+ <key>CFPlugInDynamicRegisterFunction</key>
+ <string></string>
+ <key>CFPlugInDynamicRegistration</key>
+ <string>NO</string>
+ <key>CFPlugInFactories</key>
+ <dict>
+ <key>00000000-0000-0000-0000-000000000000</key>
+ <string>MyFactoryFunction</string>
+ </dict>
+ <key>CFPlugInTypes</key>
+ <dict>
+ <key>00000000-0000-0000-0000-000000000000</key>
+ <array>
+ <string>00000000-0000-0000-0000-000000000000</string>
+ </array>
+ </dict>
+ <key>CFPlugInUnloadFunction</key>
+ <string></string>
+ <key>WebPluginName</key>
+ <string>${FBSTRING_ProductName}</string>
+ <key>WebPluginDescription</key>
+ <string>${FBSTRING_FileDescription}</string>
+ <key>WebPluginMIMETypes</key>
+ <dict>
+@foreach (FBSTRING_MIMEType CUR_MIMETYPE FBSTRING_FileDescription CUR_DESC)
+ <key>${CUR_MIMETYPE}</key>
+ <dict>
+ <key>WebPluginExtensions</key>
+ <array>
+ <string></string>
+ </array>
+ <key>WebPluginTypeDescription</key>
+ <string>${CUR_DESC}</string>
+ </dict>
+@endforeach
+ </dict>
+</dict>
+</plist>
4 firebreath-plugin/Mac/bundle_template/InfoPlist.strings
View
@@ -0,0 +1,4 @@
+/* Localized versions of Info.plist keys */
+
+CFBundleName = "${PLUGIN_NAME}.plugin";
+NSHumanReadableCopyright = "${FBSTRING_LegalCopyright}";
20 firebreath-plugin/Mac/bundle_template/Localized.r
View
@@ -0,0 +1,20 @@
+#include <CoreServices/CoreServices.r>
+
+resource 'STR#' (126)
+{ {
+ "${FBSTRING_LegalCopyright}",
+ "${FBSTRING_ProductName}"
+} };
+
+resource 'STR#' (127)
+{ {
+ "",
+} };
+
+resource 'STR#' (128)
+{ {
+@foreach (FBSTRING_MIMEType CUR_MIMETYPE FBSTRING_FileExtents CUR_EXTENT)
+ "${CUR_MIMETYPE}",
+ "${CUR_EXTENT}",
+@endforeach
+} };
61 firebreath-plugin/Mac/projectDef.cmake
View
@@ -0,0 +1,61 @@
+#/**********************************************************\
+# Auto-generated Mac project definition file for the
+# DepthJS Plugin project
+#\**********************************************************/
+
+# Mac template platform definition CMake file
+# Included from ../CMakeLists.txt
+
+# remember that the current source dir is the project root; this file is in Mac/
+file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ Mac/[^.]*.cpp
+ Mac/[^.]*.h
+ Mac/[^.]*.cmake
+ Mac/[^.]*.mm
+ )
+
+# use this to add preprocessor definitions
+add_definitions(
+
+)
+
+find_library(OPENGL_FRAMEWORK OpenGL)
+find_library(QUARTZ_CORE_FRAMEWORK QuartzCore)
+find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation)
+
+include_directories(${CORE_FOUNDATION_FRAMEWORK})
+include_directories("/Users/royshilkrot/Downloads/NITE-Bin-MacOSX-v1.4.1.2/Include")
+include_directories("/Users/royshilkrot/Downloads/OpenNI-Bin-MacOSX-v1.3.2.3/Include")
+
+set(OPENNI_XML_FILE "/Users/royshilkrot/Downloads/NITE-Bin-MacOSX-v1.4.1.2/Data/Sample-Tracking.xml")
+set_source_files_properties(
+ ${OPENNI_XML_FILE}
+ PROPERTIES
+ MACOSX_PACKAGE_LOCATION "Resources"
+)
+
+SOURCE_GROUP(Mac FILES ${PLATFORM})
+
+set (SOURCES
+ ${SOURCES}
+ ${PLATFORM}
+ ${OPENNI_XML_FILE}
+ )
+
+set(PLIST "Mac/bundle_template/Info.plist")
+set(STRINGS "Mac/bundle_template/InfoPlist.strings")
+set(LOCALIZED "Mac/bundle_template/Localized.r")
+
+add_mac_plugin(${PROJECT_NAME} ${PLIST} ${STRINGS} ${LOCALIZED} SOURCES)
+
+
+# add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing!
+target_link_libraries(${PROJECT_NAME}
+ ${PLUGIN_INTERNAL_DEPS}
+ ${OPENGL_FRAMEWORK}
+ ${QUARTZ_CORE_FRAMEWORK}
+ ${CORE_FOUNDATION_FRAMEWORK}
+ /Users/royshilkrot/Downloads/OpenNI-Bin-MacOSX-v1.3.2.3/Lib/libOpenNI.dylib
+ /Users/royshilkrot/Downloads/NITE-Bin-MacOSX-v1.4.1.2/Bin/libXnVNite_1_4_1.dylib
+ /Users/royshilkrot/Downloads/NITE-Bin-MacOSX-v1.4.1.2/Bin/libXnVHandGenerator_1_4_1.dylib
+ )
59 firebreath-plugin/PluginConfig.cmake
View
@@ -0,0 +1,59 @@
+#/**********************************************************\
+#
+# Auto-Generated Plugin Configuration file
+# for DepthJS Plugin
+#
+#\**********************************************************/
+
+set(PLUGIN_NAME "depthjsplugin")
+set(PLUGIN_PREFIX "DJP")
+set(COMPANY_NAME "mitmedialab")
+
+# ActiveX constants:
+set(FBTYPELIB_NAME depthjspluginLib)
+set(FBTYPELIB_DESC "depthjsplugin 1.0 Type Library")
+set(IFBControl_DESC "depthjsplugin Control Interface")
+set(FBControl_DESC "depthjsplugin Control Class")
+set(IFBComJavascriptObject_DESC "depthjsplugin IComJavascriptObject Interface")
+set(FBComJavascriptObject_DESC "depthjsplugin ComJavascriptObject Class")
+set(IFBComEventSource_DESC "depthjsplugin IFBComEventSource Interface")
+set(AXVERSION_NUM "1")
+
+# NOTE: THESE GUIDS *MUST* BE UNIQUE TO YOUR PLUGIN/ACTIVEX CONTROL! YES, ALL OF THEM!
+set(FBTYPELIB_GUID a2420d9e-3906-547c-b726-b2dad0aefee9)
+set(IFBControl_GUID df2aaf09-8562-53b9-90eb-9b1bc920d6e9)
+set(FBControl_GUID d76e88da-5167-551c-9608-ace40abf22d4)
+set(IFBComJavascriptObject_GUID 5ff9b773-f7e9-50e3-b62a-e39c2933d46e)
+set(FBComJavascriptObject_GUID be9a7083-405b-5562-8a69-b166312230bf)
+set(IFBComEventSource_GUID 0344798c-8962-508e-9331-f9285d69a83d)
+
+# these are the pieces that are relevant to using it from Javascript
+set(ACTIVEX_PROGID "mitmedialab.depthjsplugin")
+set(MOZILLA_PLUGINID "depthjs.media.mit.edu/depthjsplugin")
+
+# strings
+set(FBSTRING_CompanyName "MIT Media Lab")
+set(FBSTRING_FileDescription "The native plugin part of the DepthJS project")
+set(FBSTRING_PLUGIN_VERSION "1.0.0.0")
+set(FBSTRING_LegalCopyright "Copyright 2012 MIT Media Lab")
+set(FBSTRING_PluginFileName "np${PLUGIN_NAME}.dll")
+set(FBSTRING_ProductName "DepthJS Plugin")
+set(FBSTRING_FileExtents "")
+set(FBSTRING_PluginName "DepthJS Plugin")
+set(FBSTRING_MIMEType "application/x-depthjsplugin")
+
+# Uncomment this next line if you're not planning on your plugin doing
+# any drawing:
+
+#set (FB_GUI_DISABLED 1)
+
+# Mac plugin settings. If your plugin does not draw, set these all to 0
+set(FBMAC_USE_QUICKDRAW 0)
+set(FBMAC_USE_CARBON 1)
+set(FBMAC_USE_COCOA 1)
+set(FBMAC_USE_COREGRAPHICS 1)
+set(FBMAC_USE_COREANIMATION 0)
+set(FBMAC_USE_INVALIDATINGCOREANIMATION 0)
+
+# If you want to register per-machine on Windows, uncomment this line
+#set (FB_ATLREG_MACHINEWIDE 1)
1  firebreath-plugin/ResourceRecovery.h
View
@@ -0,0 +1 @@
+std::string getResourcesDirectory();
76 firebreath-plugin/Win/WiX/depthjspluginInstaller.wxs
View
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
+ <Product Id="*" Name="${FBSTRING_PluginName}" Language="1033" Version="${FBSTRING_PLUGIN_VERSION}" Manufacturer="${FBSTRING_CompanyName}" UpgradeCode="{9f5516bd-8108-5341-ba9d-49d28a08ab5f}">
+ <Package InstallerVersion="200" Compressed="yes" Description="Installer for the ${PLUGIN_NAME} plugin" InstallScope="perUser" />
+ <Upgrade Id="{9f5516bd-8108-5341-ba9d-49d28a08ab5f}">
+ <UpgradeVersion
+ Property="OLD_VERSION_FOUND"
+ Minimum="0.0.1" IncludeMinimum="yes"
+ Maximum="${FBSTRING_PLUGIN_VERSION}" IncludeMaximum="yes"
+ OnlyDetect="no" IgnoreRemoveFailure="yes"
+ MigrateFeatures="yes" />
+ </Upgrade>
+ <Property Id="MSIRESTARTMANAGERCONTROL" Value="Disable" />
+ <InstallExecuteSequence>
+ <RemoveExistingProducts After="InstallInitialize" />
+ <InstallExecute After="RemoveExistingProducts" />
+ </InstallExecuteSequence>
+ <Media Id="1" Cabinet="${PLUGIN_NAME}.cab" EmbedCab="yes" />
+
+ <Directory Id="TARGETDIR" Name="SourceDir">
+ <Directory Id="${FB_WIX_INSTALL_LOCATION}">
+ <Directory Id="CompanyDir" Name="${COMPANY_NAME}">
+ <Component Id="CompanyDirComp" Guid="*">
+ <RemoveFolder Id="RemoveCompanyDir" On="uninstall" />
+ <RegistryValue
+ Root="HKCU"
+ Key="SOFTWARE\${COMPANY_NAME}"
+ Name="Uninstall"
+ Type="string"
+ Value="${FBSTRING_PLUGIN_VERSION}"
+ KeyPath="yes" />
+ </Component>
+ <Directory Id="PluginNameDir" Name="${PLUGIN_NAME}">
+ <Component Id="PluginNameDirComp" Guid="*">
+ <RemoveFolder Id="RemovePluginNameDir" On="uninstall" />
+ <RegistryValue
+ Root="HKCU"
+ Key="SOFTWARE\${COMPANY_NAME}\${PLUGIN_NAME}"
+ Name="Uninstall"
+ Type="string"
+ Value="${FBSTRING_PLUGIN_VERSION}"
+ KeyPath="yes" />
+ </Component>
+ <Directory Id="INSTALLDIR" Name="${FBSTRING_PLUGIN_VERSION}">
+ <Component Id="InstallDirComp" Guid="*">
+ <RemoveFolder Id="RemoveInstallDir" On="uninstall" />
+ <RegistryValue
+ Root="HKCU"
+ Key="SOFTWARE\${COMPANY_NAME}\${PLUGIN_NAME}\${FBSTRING_PLUGIN_VERSION}"
+ Name="Uninstall"
+ Type="string"
+ Value="${FBSTRING_PLUGIN_VERSION}"
+ KeyPath="yes" />
+ </Component>
+
+ <!-- Put Additional files here: -->
+ <!-- example:
+ <Component Id="UniqueComponentId" Guid="*">
+ <File Id="uniqueFileId" KeyPath="yes" Source="SourceDir\filename.ext" />
+ </Component>
+ /example -->
+ <!-- -->
+ </Directory>
+ </Directory>
+ </Directory>
+ </Directory>
+ </Directory>
+
+ <Feature Id="MainPluginFeature" Title="${FBSTRING_ProductName}" Level="1">
+ <ComponentRef Id="InstallDirComp"/>
+ <ComponentRef Id="PluginNameDirComp"/>
+ <ComponentRef Id="CompanyDirComp"/>
+ <ComponentGroupRef Id="PluginDLLGroup"/>
+ </Feature>
+ </Product>
+</Wix>
73 firebreath-plugin/Win/projectDef.cmake
View
@@ -0,0 +1,73 @@
+#/**********************************************************\
+# Auto-generated Windows project definition file for the
+# DepthJS Plugin project
+#\**********************************************************/
+
+# Windows template platform definition CMake file
+# Included from ../CMakeLists.txt
+
+# remember that the current source dir is the project root; this file is in Win/
+file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ Win/[^.]*.cpp
+ Win/[^.]*.h
+ Win/[^.]*.cmake
+ )
+
+# use this to add preprocessor definitions
+add_definitions(
+ /D "_ATL_STATIC_REGISTRY"
+)
+
+SOURCE_GROUP(Win FILES ${PLATFORM})
+
+set (SOURCES
+ ${SOURCES}
+ ${PLATFORM}
+ )
+
+add_windows_plugin(${PROJECT_NAME} SOURCES)
+
+# This is an example of how to add a build step to sign the plugin DLL before
+# the WiX installer builds. The first filename (certificate.pfx) should be
+# the path to your pfx file. If it requires a passphrase, the passphrase
+# should be located inside the second file. If you don't need a passphrase
+# then set the second filename to "". If you don't want signtool to timestamp
+# your DLL then make the last parameter "".
+#
+# Note that this will not attempt to sign if the certificate isn't there --
+# that's so that you can have development machines without the cert and it'll
+# still work. Your cert should only be on the build machine and shouldn't be in
+# source control!
+# -- uncomment lines below this to enable signing --
+#firebreath_sign_plugin(${PROJECT_NAME}
+# "${CMAKE_CURRENT_SOURCE_DIR}/sign/certificate.pfx"
+# "${CMAKE_CURRENT_SOURCE_DIR}/sign/passphrase.txt"
+# "http://timestamp.verisign.com/scripts/timestamp.dll")
+
+# add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing!
+target_link_libraries(${PROJECT_NAME}
+ ${PLUGIN_INTERNAL_DEPS}
+ )
+
+set(WIX_HEAT_FLAGS
+ -gg # Generate GUIDs
+ -srd # Suppress Root Dir
+ -cg PluginDLLGroup # Set the Component group name
+ -dr INSTALLDIR # Set the directory ID to put the files in
+ )
+
+add_wix_installer( ${PLUGIN_NAME}
+ ${CMAKE_CURRENT_SOURCE_DIR}/Win/WiX/depthjspluginInstaller.wxs
+ PluginDLLGroup
+ ${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/
+ ${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/${FBSTRING_PluginFileName}.dll
+ ${PROJECT_NAME}
+ )
+
+# This is an example of how to add a build step to sign the WiX installer
+# -- uncomment lines below this to enable signing --
+#firebreath_sign_file("${PLUGIN_NAME}_WiXInstall"
+# "${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/${PLUGIN_NAME}.msi"
+# "${CMAKE_CURRENT_SOURCE_DIR}/sign/certificate.pfx"
+# "${CMAKE_CURRENT_SOURCE_DIR}/sign/passphrase.txt"
+# "http://timestamp.verisign.com/scripts/timestamp.dll")
32 firebreath-plugin/X11/projectDef.cmake
View
@@ -0,0 +1,32 @@
+#/**********************************************************\
+# Auto-generated X11 project definition file for the
+# DepthJS Plugin project
+#\**********************************************************/
+
+# X11 template platform definition CMake file
+# Included from ../CMakeLists.txt
+
+# remember that the current source dir is the project root; this file is in X11/
+file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ X11/[^.]*.cpp
+ X11/[^.]*.h
+ X11/[^.]*.cmake
+ )
+
+SOURCE_GROUP(X11 FILES ${PLATFORM})
+
+# use this to add preprocessor definitions
+add_definitions(
+)
+
+set (SOURCES
+ ${SOURCES}
+ ${PLATFORM}
+ )
+
+add_x11_plugin(${PROJECT_NAME} SOURCES)
+
+# add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing!
+target_link_libraries(${PROJECT_NAME}
+ ${PLUGIN_INTERNAL_DEPS}
+ )
142 firebreath-plugin/depthjsplugin.cpp
View
@@ -0,0 +1,142 @@
+/**********************************************************\
+
+ Auto-generated depthjsplugin.cpp
+
+ This file contains the auto-generated main plugin object
+ implementation for the DepthJS Plugin project
+
+\**********************************************************/
+
+#include "depthjspluginAPI.h"
+
+#include "depthjsplugin.h"
+
+#include "openni_backend.hpp"
+
+///////////////////////////////////////////////////////////////////////////////
+/// @fn depthjsplugin::StaticInitialize()
+///
+/// @brief Called from PluginFactory::globalPluginInitialize()
+///
+/// @see FB::FactoryBase::globalPluginInitialize
+///////////////////////////////////////////////////////////////////////////////
+void depthjsplugin::StaticInitialize()
+{
+ // Place one-time initialization stuff here; As of FireBreath 1.4 this should only
+ // be called once per process
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// @fn depthjsplugin::StaticInitialize()
+///
+/// @brief Called from PluginFactory::globalPluginDeinitialize()
+///
+/// @see FB::FactoryBase::globalPluginDeinitialize
+///////////////////////////////////////////////////////////////////////////////
+void depthjsplugin::StaticDeinitialize()
+{
+ // Place one-time deinitialization stuff here. As of FireBreath 1.4 this should
+ // always be called just before the plugin library is unloaded
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief depthjsplugin constructor. Note that your API is not available
+/// at this point, nor the window. For best results wait to use
+/// the JSAPI object until the onPluginReady method is called
+///////////////////////////////////////////////////////////////////////////////
+depthjsplugin::depthjsplugin()
+{
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief depthjsplugin destructor.
+///////////////////////////////////////////////////////////////////////////////
+depthjsplugin::~depthjsplugin()
+{
+ // This is optional, but if you reset m_api (the shared_ptr to your JSAPI
+ // root object) and tell the host to free the retained JSAPI objects then
+ // unless you are holding another shared_ptr reference to your JSAPI object
+ // they will be released here.
+ releaseRootJSAPI();
+ m_host->freeRetainedObjects();
+}
+
+void depthjsplugin::onPluginReady()
+{
+ // When this is called, the BrowserHost is attached, the JSAPI object is
+ // created, and we are ready to interact with the page and such. The
+ // PluginWindow may or may not have already fire the AttachedEvent at
+ // this point.
+ boost::shared_ptr<depthjspluginAPI> djs_jsapi = FB::ptr_cast<depthjspluginAPI>(createJSAPI());
+ djs_jsapi->DepthJSLog("depthjsplugin::onPluginReady");
+ kinect_status = init_openni_backend(djs_jsapi);
+}
+
+void depthjsplugin::shutdown()
+{
+ // This will be called when it is time for the plugin to shut down;
+ // any threads or anything else that may hold a shared_ptr to this
+ // object should be released here so that this object can be safely
+ // destroyed. This is the last point that shared_from_this and weak_ptr
+ // references to this object will be valid
+ kill_openni_backend();
+}
+
+bool depthjsplugin::RunDepthJS() {
+ if(!kinect_status) return false; //initialization failed.
+
+ boost::shared_ptr<depthjspluginAPI> djs_jsapi = FB::ptr_cast<depthjspluginAPI>(createJSAPI());
+ djs_jsapi->DepthJSLog("depthjsplugin::RunDepthJS");
+
+ boost::thread thrd(boost::bind(openni_backend,(void*)0));
+
+ djs_jsapi->DepthJSLog("depthjsplugin::RunDepthJS - thread running?");
+ return thrd.joinable();
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// @brief Creates an instance of the JSAPI object that provides your main
+/// Javascript interface.
+///
+/// Note that m_host is your BrowserHost and shared_ptr returns a
+/// FB::PluginCorePtr, which can be used to provide a
+/// boost::weak_ptr<depthjsplugin> for your JSAPI class.
+///
+/// Be very careful where you hold a shared_ptr to your plugin class from,
+/// as it could prevent your plugin class from getting destroyed properly.
+///////////////////////////////////////////////////////////////////////////////
+FB::JSAPIPtr depthjsplugin::createJSAPI()
+{
+ // m_host is the BrowserHost
+ return boost::make_shared<depthjspluginAPI>(FB::ptr_cast<depthjsplugin>(shared_from_this()), m_host);
+}
+
+bool depthjsplugin::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *)
+{
+ //printf("Mouse down at: %d, %d\n", evt->m_x, evt->m_y);
+ return false;
+}
+
+bool depthjsplugin::onMouseUp(FB::MouseUpEvent *evt, FB::PluginWindow *)
+{
+ //printf("Mouse up at: %d, %d\n", evt->m_x, evt->m_y);
+ return false;
+}
+
+bool depthjsplugin::onMouseMove(FB::MouseMoveEvent *evt, FB::PluginWindow *)
+{
+ //printf("Mouse move at: %d, %d\n", evt->m_x, evt->m_y);
+ return false;
+}
+bool depthjsplugin::onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindow *)
+{
+ // The window is attached; act appropriately
+ return false;
+}
+
+bool depthjsplugin::onWindowDetached(FB::DetachedEvent *evt, FB::PluginWindow *)
+{
+ // The window is about to be detached; act appropriately
+ return false;
+}
+
63 firebreath-plugin/depthjsplugin.h
View
@@ -0,0 +1,63 @@
+/**********************************************************\
+
+ Auto-generated depthjsplugin.h
+
+ This file contains the auto-generated main plugin object
+ implementation for the DepthJS Plugin project
+
+\**********************************************************/
+#ifndef H_depthjspluginPLUGIN
+#define H_depthjspluginPLUGIN
+
+#include "PluginWindow.h"
+#include "PluginEvents/MouseEvents.h"
+#include "PluginEvents/AttachedEvent.h"
+
+#include "PluginCore.h"
+
+
+FB_FORWARD_PTR(depthjsplugin)
+class depthjsplugin : public FB::PluginCore
+{
+public:
+ static void StaticInitialize();
+ static void StaticDeinitialize();
+
+public:
+ depthjsplugin();
+ virtual ~depthjsplugin();
+
+public:
+ void onPluginReady();
+ void shutdown();
+ virtual FB::JSAPIPtr createJSAPI();
+ // If you want your plugin to always be windowless, set this to true
+ // If you want your plugin to be optionally windowless based on the
+ // value of the "windowless" param tag, remove this method or return
+ // FB::PluginCore::isWindowless()
+ virtual bool isWindowless() { return true; }
+
+ int kinect_status;
+ bool RunDepthJS();
+
+ BEGIN_PLUGIN_EVENT_MAP()
+ EVENTTYPE_CASE(FB::MouseDownEvent, onMouseDown, FB::PluginWindow)
+ EVENTTYPE_CASE(FB::MouseUpEvent, onMouseUp, FB::PluginWindow)
+ EVENTTYPE_CASE(FB::MouseMoveEvent, onMouseMove, FB::PluginWindow)
+ EVENTTYPE_CASE(FB::MouseMoveEvent, onMouseMove, FB::PluginWindow)
+ EVENTTYPE_CASE(FB::AttachedEvent, onWindowAttached, FB::PluginWindow)
+ EVENTTYPE_CASE(FB::DetachedEvent, onWindowDetached, FB::PluginWindow)
+ END_PLUGIN_EVENT_MAP()
+
+ /** BEGIN EVENTDEF -- DON'T CHANGE THIS LINE **/
+ virtual bool onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *);
+ virtual bool onMouseUp(FB::MouseUpEvent *evt, FB::PluginWindow *);
+ virtual bool onMouseMove(FB::MouseMoveEvent *evt, FB::PluginWindow *);
+ virtual bool onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindow *);
+ virtual bool onWindowDetached(FB::DetachedEvent *evt, FB::PluginWindow *);
+ /** END EVENTDEF -- DON'T CHANGE THIS LINE **/
+};
+
+
+#endif
+
177 firebreath-plugin/depthjspluginAPI.cpp
View
@@ -0,0 +1,177 @@
+/**********************************************************\
+
+ Auto-generated depthjspluginAPI.cpp
+
+\**********************************************************/
+
+#include "JSObject.h"
+#include "variant_list.h"
+#include "DOM/Document.h"
+#include "global/config.h"
+
+#include "depthjspluginAPI.h"
+
+#include "openni_backend.hpp"
+
+///////////////////////////////////////////////////////////////////////////////
+/// @fn depthjspluginAPI::depthjspluginAPI(const depthjspluginPtr& plugin, const FB::BrowserHostPtr host)
+///
+/// @brief Constructor for your JSAPI object. You should register your methods, properties, and events
+/// that should be accessible to Javascript from here.
+///
+/// @see FB::JSAPIAuto::registerMethod
+/// @see FB::JSAPIAuto::registerProperty
+/// @see FB::JSAPIAuto::registerEvent
+///////////////////////////////////////////////////////////////////////////////
+depthjspluginAPI::depthjspluginAPI(const depthjspluginPtr& plugin, const FB::BrowserHostPtr& host) :
+ m_plugin(plugin),
+ m_host(host)
+{
+ registerMethod("echo", make_method(this, &depthjspluginAPI::echo));
+ registerMethod("testEvent", make_method(this, &depthjspluginAPI::testEvent));
+ registerMethod("InitDepthJS", make_method(this, &depthjspluginAPI::InitDepthJS));
+ registerMethod("ShutdownDepthJS", make_method(this, &depthjspluginAPI::ShutdownDepthJS));
+ registerMethod("CallbackTest", make_method(this, &depthjspluginAPI::CallbackTest));
+
+ // Read-write property
+ registerProperty("testString",
+ make_property(this,
+ &depthjspluginAPI::get_testString,
+ &depthjspluginAPI::set_testString));
+
+ // Read-only property
+ registerProperty("version",
+ make_property(this,
+ &depthjspluginAPI::get_version));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// @fn depthjspluginAPI::~depthjspluginAPI()
+///
+/// @brief Destructor. Remember that this object will not be released until
+/// the browser is done with it; this will almost definitely be after
+/// the plugin is released.
+///////////////////////////////////////////////////////////////////////////////
+depthjspluginAPI::~depthjspluginAPI()
+{
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// @fn depthjspluginPtr depthjspluginAPI::getPlugin()
+///
+/// @brief Gets a reference to the plugin that was passed in when the object
+/// was created. If the plugin has already been released then this
+/// will throw a FB::script_error that will be translated into a
+/// javascript exception in the page.
+///////////////////////////////////////////////////////////////////////////////
+depthjspluginPtr depthjspluginAPI::getPlugin()
+{
+ depthjspluginPtr plugin(m_plugin.lock());
+ if (!plugin) {
+ throw FB::script_error("The plugin is invalid");
+ }
+ return plugin;
+}
+
+
+
+// Read/Write property testString
+std::string depthjspluginAPI::get_testString()
+{
+ return m_testString;
+}
+void depthjspluginAPI::set_testString(const std::string& val)
+{
+ m_testString = val;
+}
+
+// Read-only property version
+std::string depthjspluginAPI::get_version()
+{
+ return FBSTRING_PLUGIN_VERSION;
+}
+
+// Method echo
+FB::variant depthjspluginAPI::echo(const FB::variant& msg)
+{
+ static int n(0);
+ fire_echo(msg, n++);
+ return msg;
+}
+
+void depthjspluginAPI::testEvent(const FB::variant& var)
+{
+ fire_fired(var, true, 1);
+}
+
+void depthjspluginAPI::DepthJSLog(const std::string& s){
+ // Retrieve a reference to the DOM Window
+ FB::DOM::WindowPtr window = m_host->getDOMWindow();
+
+ // Check if the DOM Window has an the property console
+ if (window && window->getJSObject()->HasProperty("console")) {
+ // Create a reference to the browswer console object
+ FB::JSObjectPtr obj = window->getProperty<FB::JSObjectPtr>("console");
+
+ // Invoke the "log" method on the console object
+ obj->Invoke("log", FB::variant_list_of(s));
+ }
+}
+
+bool depthjspluginAPI::InitDepthJS() {
+ DepthJSLog("depthjspluginAPI: start DepthJS");
+ return getPlugin()->RunDepthJS();
+}
+
+void depthjspluginAPI::ShutdownDepthJS() {
+ DepthJSLog("depthjspluginAPI: shutdown DepthJS");
+ kill_openni_backend();
+}
+
+void depthjspluginAPI::CallbackTest() {
+ // Retrieve a reference to the DOM Window
+ FB::DOM::WindowPtr window = m_host->getDOMWindow();
+
+ // Check if the DOM Window has an the property console
+ if (window && window->getJSObject()->HasProperty("DepthJS")) {
+ // Create a reference to the browswer console object
+ FB::JSObjectPtr obj = window->getProperty<FB::JSObjectPtr>("DepthJS");
+
+ // Invoke the "log" method on the console object
+ obj->Invoke("k", FB::variant_list_of("test"));
+ }
+}
+
+void depthjspluginAPI::DepthJSEvent(const std::string& etype, const std::string& edata) {
+ std::stringstream ss; ss<<"new message: "<<etype<<" - "<<edata;
+// DepthJSLog(ss.str());
+ try {
+ m_host->CallOnMainThread(boost::bind(&depthjspluginAPI::DepthJSEvent_internal,this,etype,edata));
+ }
+ catch (const FB::script_error&) {
+ DepthJSLog("Can't CallOnMainThread");
+ }
+}
+
+void depthjspluginAPI::DepthJSEvent_internal(const std::string& etype, const std::string& edata) {
+ //TODO: why is this "caching" mechanism not working??
+ if(!npBackendObj) { //first time init...
+ FB::DOM::WindowPtr window = m_host->getDOMWindow();
+
+ if (window && window->getJSObject()->HasProperty("DepthJS")) {
+ FB::JSObjectPtr obj = window->getProperty<FB::JSObjectPtr>("DepthJS");
+
+ if(obj && obj->HasProperty("npBackend")) {
+ npBackendObj = obj->GetProperty("npBackend").cast<FB::JSObjectPtr>();
+ if(!npBackendObj) { DepthJSLog("can't aqcuire npBackend obj"); return; }
+ if(!npBackendObj->HasMethod("receiveEvent")) { npBackendObj.reset(); DepthJSLog("npBackend obj has no 'recieveEvent' method"); return; }
+ DepthJSLog("Got the backend object");
+ }
+ }
+ }
+ if(npBackendObj) {
+ std::stringstream ss;
+ ss << "{\"type\":\"" << etype << "\",\"data\":{" << edata << "}}";
+ npBackendObj->InvokeAsync("receiveEvent", FB::variant_list_of(ss.str()));
+ }
+}
63 firebreath-plugin/depthjspluginAPI.h
View
@@ -0,0 +1,63 @@
+/**********************************************************\
+
+ Auto-generated depthjspluginAPI.h
+
+\**********************************************************/
+
+#include <string>
+#include <sstream>
+#include <boost/weak_ptr.hpp>
+#include "JSAPIAuto.h"
+#include "BrowserHost.h"
+#include "depthjsplugin.h"
+#include "DOM/Window.h"
+
+#ifndef H_depthjspluginAPI
+#define H_depthjspluginAPI
+
+class depthjspluginAPI : public FB::JSAPIAuto
+{
+public:
+ depthjspluginAPI(const depthjspluginPtr& plugin, const FB::BrowserHostPtr& host);
+ virtual ~depthjspluginAPI();
+
+ depthjspluginPtr getPlugin();
+
+ // Read/Write property ${PROPERTY.ident}
+ std::string get_testString();
+ void set_testString(const std::string& val);
+
+ // Read-only property ${PROPERTY.ident}
+ std::string get_version();
+
+ // Method echo
+ FB::variant echo(const FB::variant& msg);
+
+ // Event helpers
+ FB_JSAPI_EVENT(fired, 3, (const FB::variant&, bool, int));
+ FB_JSAPI_EVENT(echo, 2, (const FB::variant&, const int));
+ FB_JSAPI_EVENT(notify, 0, ());
+
+ // Method test-event
+ void testEvent(const FB::variant& s);
+
+
+ bool InitDepthJS();
+ void ShutdownDepthJS();
+ void CallbackTest();
+
+ void DepthJSLog(const std::string& s);
+
+ void DepthJSEvent(const std::string& etype, const std::string& emessage);
+private:
+ void DepthJSEvent_internal(const std::string& etype, const std::string& emessage);
+ FB::JSObjectPtr npBackendObj; //DepthJS backend link
+
+ depthjspluginWeakPtr m_plugin;
+ FB::BrowserHostPtr m_host;
+
+ std::string m_testString;
+};
+
+#endif // H_depthjspluginAPI
+
273 firebreath-plugin/openni_backend.cpp
View
@@ -0,0 +1,273 @@
+/*
+ * openni_backend.cpp
+ * webkit-plugin-mac
+ *
+ * Created by Roy Shilkrot on 9/30/11.
+ * Copyright 2011 MIT. All rights reserved.
+ *
+ */
+
+#include "openni_backend.hpp"
+
+// Headers for OpenNI
+#include <XnOpenNI.h>
+#include <XnCppWrapper.h>
+#include <XnHash.h>
+#include <XnLog.h>
+#include <XnUSB.h>
+
+#define VID_MICROSOFT 0x45e
+#define PID_NUI_MOTOR 0x02b0
+
+// Header for NITE
+#include "XnVNite.h"
+
+#include <iostream>
+
+#include "ResourceRecovery.h"
+
+boost::shared_ptr<depthjspluginAPI> openni_plugin_jsapi_ptr;
+void send_event(const std::string& etype, const std::string& edata) {
+// openni_plugin_jsapi_ptr->DepthJSLog(etype);
+ openni_plugin_jsapi_ptr->DepthJSEvent(etype,edata);
+}
+void send_log(const std::string& s) {
+ openni_plugin_jsapi_ptr->DepthJSLog(s);
+}
+
+#define CHECK_RC(rc, what) \
+ if (rc != XN_STATUS_OK) \
+ { \
+ printf("%s failed: %s\n", what, xnGetStatusString(rc)); \
+ std::stringstream ss; ss << what << " failed: " << xnGetStatusString(rc); \
+ send_log(ss.str()); \
+ return rc; \
+ }
+
+#define CHECK_ERRORS(rc, errors, what) \
+ if (rc == XN_STATUS_NO_NODE_PRESENT) \
+ { \
+ XnChar strError[1024]; \
+ errors.ToString(strError, 1024); \
+ printf("%s\n", strError); \
+ send_log(std::string(what) + std::string(strError));\
+ return (rc); \
+ }
+
+#include "HandMessageListener.h"
+
+#define GESTURE_TO_USE "Wave"
+
+using namespace xn;
+using namespace std;
+
+typedef enum
+{
+ IN_SESSION,
+ NOT_IN_SESSION,
+ QUICK_REFOCUS
+} SessionState;
+
+// Callback for when the focus is in progress
+void XN_CALLBACK_TYPE FocusProgress(const XnChar* strFocus, const XnPoint3D& ptPosition, XnFloat fProgress, void* UserCxt)
+{
+ send_log("OpenNIBackend: FocusProgress");
+ printf("Focus progress: %s @(%f,%f,%f): %f\n", strFocus, ptPosition.X, ptPosition.Y, ptPosition.Z, fProgress);
+}
+
+void XN_CALLBACK_TYPE GestureIntermediateStageCompletedHandler(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie)
+{
+ send_log("OpenNIBackend: GestureIntermediateStageCompletedHandler");
+ printf("Gesture %s: Intermediate stage complete (%f,%f,%f)\n", strGesture, pPosition->X, pPosition->Y, pPosition->Z);
+}
+void XN_CALLBACK_TYPE GestureReadyForNextIntermediateStageHandler(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie)
+{
+ send_log("OpenNIBackend: GestureReadyForNextIntermediateStageHandler");
+ printf("Gesture %s: Ready for next intermediate stage (%f,%f,%f)\n", strGesture, pPosition->X, pPosition->Y, pPosition->Z);
+}
+void XN_CALLBACK_TYPE GestureProgressHandler(xn::GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, XnFloat fProgress, void* pCookie)
+{
+ send_log("OpenNIBackend: GestureProgressHandler");
+ printf("Gesture %s progress: %f (%f,%f,%f)\n", strGesture, fProgress, pPosition->X, pPosition->Y, pPosition->Z);
+}
+
+void XN_CALLBACK_TYPE SessionStarting(const XnPoint3D& ptPosition, void* UserCxt);
+void XN_CALLBACK_TYPE SessionEnding(void* UserCxt);
+void XN_CALLBACK_TYPE NoHands(void* UserCxt);
+
+
+// xml to initialize OpenNI
+#define SAMPLE_XML_PATH "/Sample-Tracking.xml"
+
+XnMapOutputMode QVGAMode = { 320, 240, 30 };
+XnMapOutputMode VGAMode = { 640, 480, 30 };
+
+class OpenNIBackend {
+public:
+ OpenNIBackend():g_SessionState(NOT_IN_SESSION),running(true),terminated(false) {}
+
+ void run() {
+ send_log("OpenNIBackend: start openni backend thread");
+ printf("start openni backend thread\n");
+ terminated = false;
+ while (running) {
+// XnMapOutputMode mode;
+// g_DepthGenerator.GetMapOutputMode(mode);
+ // Read next available data
+ g_Context.WaitOneUpdateAll(g_DepthGenerator);
+ // Update NITE tree
+ g_pSessionManager->Update(&g_Context);
+ }
+ terminated = true;
+ printf("end openni backend thread\n");
+ send_log("OpenNIBackend: end openni backend thread");
+ }
+ void stop() { printf("stopping openni backend...\n"); running = false;}
+ bool isDead() { return terminated; }
+
+ int setKinectAngle() {
+ XN_USB_DEV_HANDLE dev;
+
+ int angle = 20;
+
+ XnStatus rc = XN_STATUS_OK;
+
+ rc = xnUSBInit();
+ CHECK_RC(rc,"init usb device");
+
+ rc = xnUSBOpenDevice(VID_MICROSOFT, PID_NUI_MOTOR, NULL, NULL, &dev);
+ CHECK_RC(rc,"open usb device");
+
+ uint8_t empty[0x1];
+ angle = angle * 2;
+
+ rc = xnUSBSendControl(dev,
+ XN_USB_CONTROL_TYPE_VENDOR,
+ 0x31,
+ (XnUInt16)angle,
+ 0x0,
+ empty,
+ 0x0, 0);
+ CHECK_RC(rc,"send usb command");
+
+ rc = xnUSBCloseDevice(dev);
+ CHECK_RC(rc,"close usb device");
+
+ return rc;
+ }
+
+ int init() {
+ send_log("OpenNIBackend: init()");
+
+ running = true;
+ terminated = false;
+ setKinectAngle();
+
+ XnStatus rc = XN_STATUS_OK;
+ xn::EnumerationErrors errors;
+
+ // Initialize OpenNI
+ send_log("OpenNIBackend: getResourcesDirectory");
+ std::string xml_file_path = getResourcesDirectory();
+ send_log("XML in: "+xml_file_path);
+
+ rc = g_Context.InitFromXmlFile((xml_file_path + SAMPLE_XML_PATH).c_str(), g_ScriptNode, &errors);
+ CHECK_ERRORS(rc, errors, "InitFromXmlFile");
+ CHECK_RC(rc, "InitFromXmlFile");
+
+ rc = g_Context.FindExistingNode(XN_NODE_TYPE_DEPTH, g_DepthGenerator);
+ CHECK_RC(rc, "Find depth generator");
+// rc = g_DepthGenerator.SetMapOutputMode(QVGAMode);
+// CHECK_RC(rc, "Set Mode");
+ rc = g_Context.FindExistingNode(XN_NODE_TYPE_HANDS, g_HandsGenerator);
+ CHECK_RC(rc, "Find hands generator");
+ rc = g_Context.FindExistingNode(XN_NODE_TYPE_GESTURE, g_GestureGenerator);
+ CHECK_RC(rc, "Find gesture generator");
+
+ // XnCallbackHandle h;
+ // if (g_HandsGenerator.IsCapabilitySupported(XN_CAPABILITY_HAND_TOUCHING_FOV_EDGE))
+ // {
+ // g_HandsGenerator.GetHandTouchingFOVEdgeCap().RegisterToHandTouchingFOVEdge(TouchingCallback, NULL, h);
+ // }
+
+ XnCallbackHandle hGestureIntermediateStageCompleted, hGestureProgress, hGestureReadyForNextIntermediateStage;
+ g_GestureGenerator.RegisterToGestureIntermediateStageCompleted(GestureIntermediateStageCompletedHandler, NULL, hGestureIntermediateStageCompleted);
+ g_GestureGenerator.RegisterToGestureReadyForNextIntermediateStage(GestureReadyForNextIntermediateStageHandler, NULL, hGestureReadyForNextIntermediateStage);
+ g_GestureGenerator.RegisterGestureCallbacks(NULL, GestureProgressHandler, NULL, hGestureProgress);
+
+ g_HandsGenerator.SetSmoothing(0.1);
+
+ // Create NITE objects
+ g_pSessionManager = new XnVSessionManager;
+ rc = g_pSessionManager->Initialize(&g_Context, "Click,Wave", "RaiseHand");
+ CHECK_RC(rc, "SessionManager::Initialize");
+
+ g_pSessionManager->RegisterSession(this, SessionStarting, SessionEnding, FocusProgress);
+
+ g_pHandListener = new HandPointControl(g_DepthGenerator,g_pSessionManager);
+ g_pFlowRouter = new XnVFlowRouter;
+ g_pFlowRouter->SetActive(g_pHandListener);
+
+ g_pSessionManager->AddListener(g_pFlowRouter);
+
+ g_pHandListener->RegisterNoPoints(this, NoHands);
+
+ // Initialization done. Start generating
+ rc = g_Context.StartGeneratingAll();
+ CHECK_RC(rc, "StartGenerating");
+
+ stringstream ss; ss<<"openni_backend: kinect inited? " << (rc == XN_STATUS_OK);
+ send_log(ss.str());
+
+ return rc == XN_STATUS_OK;
+ }
+
+ SessionState g_SessionState;
+private:
+ bool running,terminated;
+
+ // OpenNI objects
+ xn::Context g_Context;
+ xn::ScriptNode g_ScriptNode;
+ xn::DepthGenerator g_DepthGenerator;
+ xn::HandsGenerator g_HandsGenerator;
+ xn::GestureGenerator g_GestureGenerator;
+
+ // NITE objects
+ XnVSessionManager* g_pSessionManager;
+ XnVFlowRouter* g_pFlowRouter;
+
+ HandPointControl* g_pHandListener;
+};
+
+// callback for session start
+void XN_CALLBACK_TYPE SessionStarting(const XnPoint3D& ptPosition, void* UserCxt)
+{
+ send_log("OpenNIBackend: SessionStarting");
+ printf("Session start: (%f,%f,%f)\n", ptPosition.X, ptPosition.Y, ptPosition.Z);
+ ((OpenNIBackend*)UserCxt)->g_SessionState = IN_SESSION;
+}
+// Callback for session end
+void XN_CALLBACK_TYPE SessionEnding(void* UserCxt)
+{
+ send_log("OpenNIBackend: SessionEnding");
+ printf("Session end\n");
+ ((OpenNIBackend*)UserCxt)->g_SessionState = NOT_IN_SESSION;
+}
+void XN_CALLBACK_TYPE NoHands(void* UserCxt)
+{
+ if (((OpenNIBackend*)UserCxt)->g_SessionState != NOT_IN_SESSION)
+ {
+ send_log("OpenNIBackend: NoHands");
+ printf("Quick refocus\n");
+ ((OpenNIBackend*)UserCxt)->g_SessionState = QUICK_REFOCUS;
+ }
+}
+
+
+OpenNIBackend onib;
+
+int openni_backend(void* _arg) { onib.run(); return 0; }
+void kill_openni_backend() { onib.stop(); }
+bool is_openni_backend_dead() { return onib.isDead(); }
+int init_openni_backend(const boost::shared_ptr<depthjspluginAPI>& _plugin_jspai) { openni_plugin_jsapi_ptr = _plugin_jspai; return onib.init(); }
21 firebreath-plugin/openni_backend.hpp
View
@@ -0,0 +1,21 @@
+/*
+ * openni_backend.h
+ * webkit-plugin-mac
+ *
+ * Created by Roy Shilkrot on 9/30/11.
+ * Copyright 2011 MIT. All rights reserved.
+ *
+ */
+
+#ifndef _OPENNI_BACKEND_HPP
+#define _OPENNI_BACKEND_HPP
+
+#include <boost/shared_ptr.hpp>
+#include "depthjspluginAPI.h"
+
+int openni_backend(void* _arg);
+void kill_openni_backend();
+bool is_openni_backend_dead();
+int init_openni_backend(const boost::shared_ptr<depthjspluginAPI>&);
+
+#endif
Please sign in to comment.
Something went wrong with that request. Please try again.