├── README ├── Win ├── ResourceRecovery.cpp ├── kinectathomeWin.h ├── Factory.cpp ├── projectDef.cmake ├── kinectathomeWin.cpp └── WiX │ └── kinectathomeInstaller.wxs ├── ResourceRecovery.h ├── Mac ├── bundle_template │ ├── InfoPlist.strings │ ├── Localized.r │ └── Info.plist ├── ResourceRecovery.mm ├── kinectathomeMac.h ├── projectDef.cmake ├── Factory.cpp └── kinectathomeMac.mm ├── Logging.h ├── Logging.cpp ├── PointDrawer.h ├── Compressor.h ├── X11 └── projectDef.cmake ├── kinectathomeAPI.h ├── CMakeLists.txt ├── cmake └── Modules │ ├── FindOpenNI.cmake │ ├── Findx264.cmake │ ├── LibFindMacros.cmake │ └── FindFFmpeg.cmake ├── Compressor.cpp ├── kinectathome.h ├── PluginConfig.cmake ├── kinect_main.cpp ├── kinect_common.h ├── kinectathomeAPI.cpp ├── kinectathome.cpp └── PointDrawer.cpp /README: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Win/ResourceRecovery.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::string getResourcesDirectory() { 4 | return "./"; 5 | } -------------------------------------------------------------------------------- /ResourceRecovery.h: -------------------------------------------------------------------------------- 1 | /* Each OS should implement this (directory where to find resources) */ 2 | std::string getResourcesDirectory(); -------------------------------------------------------------------------------- /Mac/bundle_template/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | CFBundleName = "${PLUGIN_NAME}.plugin"; 4 | NSHumanReadableCopyright = "${FBSTRING_LegalCopyright}"; 5 | -------------------------------------------------------------------------------- /Logging.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Logging.h 3 | * FireBreath 4 | * 5 | * Created by Roy Shilkrot on 1/30/12. 6 | * Copyright 2012 MIT. All rights reserved. 7 | * 8 | */ 9 | 10 | #include 11 | #include 12 | #include "kinectathomeAPI.h" 13 | 14 | void send_event(const std::string& etype, const std::string& edata); 15 | void send_log(const std::string& s); 16 | void init_logging(const boost::shared_ptr& ); -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Mac/ResourceRecovery.mm: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../gen/global/config.h" 3 | #include 4 | 5 | std::string getResourcesDirectory() { 6 | // Get the XML file for OpenNI from the resources directory of the plugin bundle 7 | CFBundleRef bundleRef = CFBundleGetBundleWithIdentifier(CFSTR("com.kinectathomeLib.Kinect@Home Plugin")); 8 | CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(bundleRef); 9 | UInt8 cbuf[1024] = {0}; 10 | CFURLGetFileSystemRepresentation(resourcesURL,true,cbuf,1024); 11 | return std::string((char*)cbuf); 12 | } -------------------------------------------------------------------------------- /Logging.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Logging.cpp 3 | * FireBreath 4 | * 5 | * Created by Roy Shilkrot on 1/30/12. 6 | * Copyright 2012 MIT. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "Logging.h" 11 | 12 | boost::shared_ptr plugin_jsapi_ptr; 13 | void send_event(const std::string& etype, const std::string& edata) { 14 | // if(plugin_jsapi_ptr) 15 | // plugin_jsapi_ptr->Event(etype,edata); 16 | //TODO: TBD 17 | } 18 | void send_log(const std::string& s) { 19 | if (plugin_jsapi_ptr) 20 | plugin_jsapi_ptr->Log(s); 21 | } 22 | void init_logging(const boost::shared_ptr& _plugin_jsapi_ptr) { 23 | plugin_jsapi_ptr = _plugin_jsapi_ptr; 24 | } -------------------------------------------------------------------------------- /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 | 15 | void DrawDepthMap(const xn::DepthMetaData& dm); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Compressor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Compressor.h 3 | * FireBreath 4 | * 5 | * Created by Roy Shilkrot on 1/26/12. 6 | * Copyright 2012 MIT. All rights reserved. 7 | * 8 | */ 9 | 10 | #define UINT64_C(val) val##ui64 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #include 15 | #include 16 | } 17 | #endif 18 | 19 | #include 20 | 21 | class Compressor { 22 | public: 23 | Compressor(xn::Context& context, xn::DepthGenerator& depthGenerator, xn::ImageGenerator& imageGenerator); 24 | 25 | void Update(const xn::DepthGenerator& depthGenerator, const xn::ImageGenerator& imageGenerator); 26 | private: 27 | xn::Context& m_context; 28 | xn::DepthGenerator& m_depthGenerator; 29 | xn::ImageGenerator& m_imageGenerator; 30 | 31 | struct SwsContext* convertCtx; 32 | x264_picture_t pic_in, pic_out; 33 | x264_t* encoder; 34 | int width; 35 | int height; 36 | }; -------------------------------------------------------------------------------- /X11/projectDef.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # Auto-generated X11 project definition file for the 3 | # Kinect@Home 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/kinectathomeMac.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 "../kinectathome.h" 16 | 17 | class kinectathomeMac : public kinectathome { 18 | public: 19 | kinectathomeMac(); 20 | ~kinectathomeMac(); 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(kinectathome) 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 | -------------------------------------------------------------------------------- /kinectathomeAPI.h: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | 3 | Auto-generated kinectathomeAPI.h 4 | 5 | \**********************************************************/ 6 | 7 | #include 8 | #include 9 | #include 10 | #include "JSAPIAuto.h" 11 | #include "BrowserHost.h" 12 | #include "kinectathome.h" 13 | 14 | #ifndef H_kinectathomeAPI 15 | #define H_kinectathomeAPI 16 | 17 | class kinectathomeAPI : public FB::JSAPIAuto 18 | { 19 | public: 20 | kinectathomeAPI(const kinectathomePtr& plugin, const FB::BrowserHostPtr& host); 21 | virtual ~kinectathomeAPI(); 22 | 23 | kinectathomePtr getPlugin(); 24 | 25 | // Read/Write property ${PROPERTY.ident} 26 | std::string get_testString(); 27 | void set_testString(const std::string& val); 28 | 29 | // Read-only property ${PROPERTY.ident} 30 | std::string get_version(); 31 | 32 | // Method echo 33 | FB::variant echo(const FB::variant& msg); 34 | 35 | // Event helpers 36 | FB_JSAPI_EVENT(fired, 3, (const FB::variant&, bool, int)); 37 | FB_JSAPI_EVENT(echo, 2, (const FB::variant&, const int)); 38 | FB_JSAPI_EVENT(notify, 0, ()); 39 | 40 | // Method test-event 41 | void testEvent(const FB::variant& s); 42 | 43 | void Log(const std::string& s); 44 | 45 | private: 46 | kinectathomeWeakPtr m_plugin; 47 | FB::BrowserHostPtr m_host; 48 | 49 | std::string m_testString; 50 | }; 51 | 52 | #endif // H_kinectathomeAPI 53 | 54 | -------------------------------------------------------------------------------- /Win/kinectathomeWin.h: -------------------------------------------------------------------------------- 1 | #include "../kinectathome.h" 2 | #include "../kinectathomeAPI.h" 3 | 4 | #ifdef FB_WIN 5 | #include "PluginWindowWin.h" 6 | #include "PluginWindowlessWin.h" 7 | #include "PluginEvents/WindowsEvent.h" 8 | #ifdef HAS_LEAKFINDER 9 | #define XML_LEAK_FINDER 10 | #include "LeakFinder/LeakFinder.h" 11 | #endif 12 | #endif 13 | 14 | #ifdef HAS_LEAKFINDER 15 | boost::scoped_ptr FBTestPlugin::pOut; 16 | #endif 17 | 18 | //openGL stuff 19 | //opengl thread stuff 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include "../kinectathome.h" 27 | #include "../Logging.h" 28 | 29 | class kinectathomeWin : public kinectathome { 30 | private: 31 | void EnableOpenGL(HWND handleWnd, HDC * hdc, HGLRC * hRC); 32 | void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC); 33 | 34 | 35 | HANDLE openGLThreadHandle; 36 | DWORD dwThreadID; 37 | 38 | HWND hWnd; 39 | HDC hDC; 40 | HGLRC hRC; 41 | bool run; 42 | 43 | FB::PluginWindowWin* pluginWindowWin; 44 | FB::PluginWindow* pluginWindow; 45 | 46 | public: 47 | VOID drawThreaded(); 48 | 49 | BEGIN_PLUGIN_EVENT_MAP() 50 | EVENTTYPE_CASE(FB::AttachedEvent, onWindowAttached, FB::PluginWindowWin) 51 | EVENTTYPE_CASE(FB::DetachedEvent, onWindowDetached, FB::PluginWindowWin) 52 | PLUGIN_EVENT_MAP_CASCADE(kinectathome) 53 | END_PLUGIN_EVENT_MAP() 54 | 55 | kinectathomeWin(); 56 | ~kinectathomeWin(); 57 | 58 | virtual bool onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindowWin *); 59 | virtual bool onWindowDetached(FB::DetachedEvent *evt, FB::PluginWindowWin *); 60 | 61 | }; 62 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # 3 | # Auto-generated CMakeLists.txt for the Kinect@Home 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 | cmake/Modules/*.cmake 18 | ) 19 | 20 | include_directories(${PLUGIN_INCLUDE_DIRS}) 21 | 22 | # Generated files are stored in ${GENERATED} by the project configuration 23 | SET_SOURCE_FILES_PROPERTIES( 24 | ${GENERATED} 25 | PROPERTIES 26 | GENERATED 1 27 | ) 28 | 29 | SOURCE_GROUP(Generated FILES 30 | ${GENERATED} 31 | ) 32 | 33 | SET( SOURCES 34 | ${GENERAL} 35 | ${GENERATED} 36 | ) 37 | 38 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") 39 | 40 | find_library(OpenGL REQUIRED) 41 | 42 | find_package(FFmpeg) 43 | if(${FFMPEG_LIBSWSCALE_FOUND}) 44 | message(STATUS "found swscale at ${FFMPEG_LIBSWSCALE_INCLUDE_DIRS} and ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS}") 45 | include_directories(${FFMPEG_LIBSWSCALE_INCLUDE_DIRS}) 46 | include_directories(${FFMPEG_LIBAVUTIL_INCLUDE_DIRS}) 47 | else(${FFMPEG_LIBSWSCALE_FOUND}) 48 | message(STATUS "can't find SWSCALE!!") 49 | endif(${FFMPEG_LIBSWSCALE_FOUND}) 50 | 51 | find_package(x264) 52 | if(${X264_FOUND}) 53 | include_directories(${X264_INCLUDE_DIRS}) 54 | endif() 55 | 56 | # This will include Win/projectDef.cmake, X11/projectDef.cmake, Mac/projectDef 57 | # depending on the platform 58 | include_platform() 59 | -------------------------------------------------------------------------------- /cmake/Modules/FindOpenNI.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find OpenNI 2 | # Once done, this will define 3 | # 4 | # OpenNI_FOUND - system has OpenNI 5 | # OpenNI_INCLUDE_DIRS - the OpenNI include directories 6 | # OpenNI_LIBRARIES - link these to use OpenNI 7 | 8 | #include(LibFindMacros) 9 | 10 | # Dependencies 11 | 12 | # Use pkg-config to get hints about paths 13 | find_package(PkgConfig) 14 | pkg_check_modules(OpenNI_PKGCONF OpenNI) 15 | 16 | # Include dir 17 | find_path(OpenNI_INCLUDE_DIR 18 | NAMES XnOpenNI.h 19 | HINTS ${OpenNI_PKGCONF_INCLUDE_DIRS} 20 | PATH_SUFFIXES "ni" 21 | ) 22 | 23 | if(OpenNI_INCLUDE_DIR STREQUAL "OpenNI_INCLUDE_DIR-NOTFOUND") 24 | message(STATUS "Looking for OpenNI in default dirs") 25 | find_path(OpenNI_INCLUDE_DIR NAMES XnOpenNI.h 26 | PATH_SUFFIXES "ni" 27 | ) 28 | endif() 29 | 30 | # Finally the library itself 31 | find_library(OpenNI_LIBRARY 32 | NAMES OpenNI 33 | PATHS ${OpenNI_PKGCONF_LIBRARY_DIRS} 34 | ) 35 | 36 | # Set the include dir variables and the libraries and let libfind_process do the rest. 37 | # NOTE: Singular variables for this library, plural for libraries this this lib depends on. 38 | #set(OpenNI_PROCESS_INCLUDES OpenNI_INCLUDE_DIR OpenNI_INCLUDE_DIRS) 39 | #set(OpenNI_PROCESS_LIBS OpenNI_LIBRARY OpenNI_LIBRARIES) 40 | #libfind_process(OpenNI) 41 | 42 | set(OpenNI_LIBRARIES ${OpenNI_LIBRARY} ) 43 | set(OpenNI_LIBS ${OpenNI_LIBRARY} ) 44 | set(OpenNI_INCLUDE_DIRS ${OpenNI_INCLUDE_DIR} ) 45 | 46 | include(FindPackageHandleStandardArgs) 47 | # handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE 48 | # if all listed variables are TRUE 49 | find_package_handle_standard_args(OpenNI DEFAULT_MSG 50 | OpenNI_LIBRARY OpenNI_INCLUDE_DIR) 51 | 52 | mark_as_advanced(OpenNI_INCLUDE_DIR OpenNI_LIBRARY ) 53 | -------------------------------------------------------------------------------- /Mac/projectDef.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # Auto-generated Mac project definition file for the 3 | # Kinect@Home Plugin project 4 | #\**********************************************************/ 5 | 6 | # Mac 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 Mac/ 10 | file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} 11 | Mac/[^.]*.cpp 12 | Mac/[^.]*.h 13 | Mac/[^.]*.cmake 14 | Mac/[^.]*.mm 15 | ) 16 | 17 | # use this to add preprocessor definitions 18 | add_definitions( 19 | 20 | ) 21 | 22 | find_library(OPENGL_FRAMEWORK OpenGL) 23 | find_library(QUARTZ_CORE_FRAMEWORK QuartzCore) 24 | find_library(CORE_FOUNDATION_FRAMEWORK CoreFoundation) 25 | find_package(OpenNI) 26 | 27 | if(NOT OPENNI_FOUND) 28 | message(STATUS "Can't find OpenNI!") 29 | else() 30 | message(STATUS "OpenNI found in ${OpenNI_INCLUDE_DIRS}") 31 | endif() 32 | 33 | include_directories(${CORE_FOUNDATION_FRAMEWORK}) 34 | include_directories(${OpenNI_INCLUDE_DIRS}) 35 | 36 | set(OPENNI_XML_FILE "/Users/royshilkrot/Downloads/NITE-Bin-MacOSX-v1.4.1.2/Data/Sample-Tracking.xml") 37 | set_source_files_properties( 38 | ${OPENNI_XML_FILE} 39 | PROPERTIES 40 | MACOSX_PACKAGE_LOCATION "Resources" 41 | ) 42 | 43 | 44 | SOURCE_GROUP(Mac FILES ${PLATFORM}) 45 | 46 | set (SOURCES 47 | ${SOURCES} 48 | ${PLATFORM} 49 | ${OPENNI_XML_FILE} 50 | ) 51 | 52 | set(PLIST "Mac/bundle_template/Info.plist") 53 | set(STRINGS "Mac/bundle_template/InfoPlist.strings") 54 | set(LOCALIZED "Mac/bundle_template/Localized.r") 55 | 56 | add_mac_plugin(${PROJECT_NAME} ${PLIST} ${STRINGS} ${LOCALIZED} SOURCES) 57 | 58 | 59 | # add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing! 60 | target_link_libraries(${PROJECT_NAME} 61 | ${PLUGIN_INTERNAL_DEPS} 62 | ${OPENGL_FRAMEWORK} 63 | ${QUARTZ_CORE_FRAMEWORK} 64 | ${FFMPEG_LIBSWSCALE_LIBS} 65 | ${FFMPEG_LIBAVUTIL_LIBS} 66 | ${X264_LIBS} 67 | ${OpenNI_LIBRARIES} 68 | ) 69 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Win/Factory.cpp: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | 3 | Auto-generated Factory.cpp 4 | 5 | This file contains the auto-generated factory methods 6 | for the kinectathome project 7 | 8 | \**********************************************************/ 9 | 10 | #include "FactoryBase.h" 11 | #include "kinectathomeWin.h" 12 | #include 13 | 14 | class PluginFactory : public FB::FactoryBase 15 | { 16 | public: 17 | /////////////////////////////////////////////////////////////////////////////// 18 | /// @fn FB::PluginCorePtr createPlugin(const std::string& mimetype) 19 | /// 20 | /// @brief Creates a plugin object matching the provided mimetype 21 | /// If mimetype is empty, returns the default plugin 22 | /////////////////////////////////////////////////////////////////////////////// 23 | FB::PluginCorePtr createPlugin(const std::string& mimetype) 24 | { 25 | return boost::make_shared(); 26 | } 27 | 28 | /////////////////////////////////////////////////////////////////////////////// 29 | /// @see FB::FactoryBase::globalPluginInitialize 30 | /////////////////////////////////////////////////////////////////////////////// 31 | void globalPluginInitialize() 32 | { 33 | kinectathome::StaticInitialize(); 34 | } 35 | 36 | /////////////////////////////////////////////////////////////////////////////// 37 | /// @see FB::FactoryBase::globalPluginDeinitialize 38 | /////////////////////////////////////////////////////////////////////////////// 39 | void globalPluginDeinitialize() 40 | { 41 | kinectathome::StaticDeinitialize(); 42 | } 43 | }; 44 | 45 | /////////////////////////////////////////////////////////////////////////////// 46 | /// @fn getFactoryInstance() 47 | /// 48 | /// @brief Returns the factory instance for this plugin module 49 | /////////////////////////////////////////////////////////////////////////////// 50 | FB::FactoryBasePtr getFactoryInstance() 51 | { 52 | static boost::shared_ptr factory = boost::make_shared(); 53 | return factory; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /Mac/Factory.cpp: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | 3 | Auto-generated Factory.cpp 4 | 5 | This file contains the auto-generated factory methods 6 | for the kinectathome project 7 | 8 | \**********************************************************/ 9 | 10 | #include "FactoryBase.h" 11 | #include "kinectathomeMac.h" 12 | #include 13 | 14 | class PluginFactory : public FB::FactoryBase 15 | { 16 | public: 17 | /////////////////////////////////////////////////////////////////////////////// 18 | /// @fn FB::PluginCorePtr createPlugin(const std::string& mimetype) 19 | /// 20 | /// @brief Creates a plugin object matching the provided mimetype 21 | /// If mimetype is empty, returns the default plugin 22 | /////////////////////////////////////////////////////////////////////////////// 23 | FB::PluginCorePtr createPlugin(const std::string& mimetype) 24 | { 25 | return boost::make_shared(); 26 | } 27 | 28 | /////////////////////////////////////////////////////////////////////////////// 29 | /// @see FB::FactoryBase::globalPluginInitialize 30 | /////////////////////////////////////////////////////////////////////////////// 31 | void globalPluginInitialize() 32 | { 33 | kinectathomeMac::StaticInitialize(); 34 | } 35 | 36 | /////////////////////////////////////////////////////////////////////////////// 37 | /// @see FB::FactoryBase::globalPluginDeinitialize 38 | /////////////////////////////////////////////////////////////////////////////// 39 | void globalPluginDeinitialize() 40 | { 41 | kinectathomeMac::StaticDeinitialize(); 42 | } 43 | }; 44 | 45 | /////////////////////////////////////////////////////////////////////////////// 46 | /// @fn getFactoryInstance() 47 | /// 48 | /// @brief Returns the factory instance for this plugin module 49 | /////////////////////////////////////////////////////////////////////////////// 50 | FB::FactoryBasePtr getFactoryInstance() 51 | { 52 | static boost::shared_ptr factory = boost::make_shared(); 53 | return factory; 54 | } 55 | 56 | -------------------------------------------------------------------------------- /Compressor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Compressor.cpp 3 | * FireBreath 4 | * 5 | * Created by Roy Shilkrot on 1/26/12. 6 | * Copyright 2012 MIT. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "Compressor.h" 11 | 12 | Compressor::Compressor(xn::Context& context, 13 | xn::DepthGenerator& depthGenerator, 14 | xn::ImageGenerator& imageGenerator): 15 | m_context(context), 16 | m_depthGenerator(depthGenerator), 17 | m_imageGenerator(imageGenerator) 18 | { 19 | xn::ImageMetaData imd; 20 | imageGenerator.GetMetaData(imd); 21 | width = imd.XRes(); 22 | height = imd.YRes(); 23 | 24 | //init pix format converter 25 | //TODO: release in d'tor 26 | convertCtx = sws_getCachedContext(convertCtx, width, height, PIX_FMT_RGB24, width, height, PIX_FMT_YUV420P, SWS_FAST_BILINEAR, NULL, NULL, NULL); 27 | 28 | //TODO: init x264 compressor 29 | x264_param_t param; 30 | x264_param_default_preset(¶m, "veryfast", "zerolatency"); 31 | param.i_threads = 1; 32 | param.i_width = width; 33 | param.i_height = height; 34 | param.i_fps_num = 10; 35 | param.i_fps_den = 1; 36 | // Intra refres: 37 | param.i_keyint_max = 10; 38 | param.b_intra_refresh = 1; 39 | //Rate control: 40 | param.rc.i_rc_method = X264_RC_CRF; 41 | param.rc.f_rf_constant = 25; 42 | param.rc.f_rf_constant_max = 35; 43 | //For streaming: 44 | param.b_repeat_headers = 1; 45 | param.b_annexb = 1; 46 | x264_param_apply_profile(¶m, "baseline"); 47 | 48 | encoder = x264_encoder_open(¶m); 49 | x264_picture_alloc(&pic_in, X264_CSP_I420, width, height); 50 | } 51 | 52 | void Compressor::Update(const xn::DepthGenerator& depthGenerator, 53 | const xn::ImageGenerator& imageGenerator) { 54 | //get RGB image buffer from generator 55 | xn::ImageMetaData imd; 56 | imageGenerator.GetMetaData(imd); 57 | const XnUInt8* data = imd.Data(); 58 | 59 | //convert pix-fmt 60 | int srcstride = width*3; //RGB stride is just 3*width 61 | sws_scale(convertCtx, &data, &srcstride, 0, height, pic_in.img.plane, pic_in.img.i_stride); 62 | 63 | //send to x264 compression 64 | x264_nal_t* nals; 65 | int i_nals; 66 | int frame_size = x264_encoder_encode(encoder, &nals, &i_nals, &pic_in, &pic_out); 67 | if (frame_size >= 0) 68 | { 69 | // OK 70 | } 71 | } -------------------------------------------------------------------------------- /cmake/Modules/Findx264.cmake: -------------------------------------------------------------------------------- 1 | FIND_PACKAGE(PkgConfig) 2 | 3 | PKG_CHECK_MODULES(PC_X264 x264) 4 | FIND_PATH(X264_INCLUDE_DIR x264.h 5 | HINTS ${PC_X264_INCLUDEDIR} ${PC_X264_INCLUDE_DIRS} 6 | NO_DEFAULT_PATH 7 | ) 8 | 9 | IF(${X264_INCLUDE_DIR} STREQUAL X264_INCLUDE_DIR-NOTFOUND) 10 | FIND_PATH(X264_INCLUDE_DIR x264.h) #try to use default dirs... 11 | ENDIF() 12 | 13 | IF(${X264_INCLUDE_DIR} STREQUAL X264_INCLUDE_DIR-NOTFOUND) 14 | FILE(GLOB_RECURSE X264_INCLUDE_DIR "/x264*/x264.h") #last resort! , besides the directory name may be different... it's very bad anyway 15 | IF(NOT ${X264_INCLUDE_DIR} STREQUAL X264_INCLUDE_DIR-NOTFOUND) 16 | GET_FILENAME_COMPONENT(X264_INCLUDE_DIR ${X264_INCLUDE_DIR} PATH) 17 | ENDIF() 18 | ENDIF() 19 | 20 | IF(${X264_INCLUDE_DIR} STREQUAL X264_INCLUDE_DIR-NOTFOUND) 21 | PKG_CHECK_MODULES(PC_X264 libx264) 22 | FIND_PATH(X264_INCLUDE_DIR x264.h 23 | HINTS ${PC_X264_INCLUDEDIR} ${PC_X264_INCLUDE_DIRS} 24 | NO_DEFAULT_PATH) 25 | ENDIF() 26 | 27 | IF(${X264_INCLUDE_DIR} STREQUAL X264_INCLUDE_DIR-NOTFOUND) 28 | MESSAGE(STATUS "Can't find x264!") 29 | ELSE() 30 | MESSAGE(STATUS "Found x264: ${X264_INCLUDE_DIR}") 31 | 32 | #GET_FILENAME_COMPONENT(X264_PARENT ${X264_INCLUDE_DIR} PATH) 33 | SET(X264_PARENT ${X264_INCLUDE_DIR}) 34 | MESSAGE(STATUS "Using x264 dir parent as hint: ${X264_PARENT}") 35 | 36 | IF(NOT WIN32) 37 | FIND_LIBRARY(X264_LIBRARIES x264 38 | HINTS ${PC_X264_LIBDIR} ${PC_X264_LIBRARY_DIR} ${X264_PARENT} 39 | NO_DEFAULT_PATH) 40 | IF(${X264_LIBRARIES} STREQUAL X264_LIBRARIES-NOTFOUND) 41 | FIND_LIBRARY(X264_LIBRARIES libx264 42 | HINTS ${PC_X264_LIBDIR} ${PC_X264_LIBRARY_DIR} ${X264_PARENT} 43 | NO_DEFAULT_PATH) 44 | ENDIF() 45 | ELSE() 46 | FIND_FILE(X264_LIBRARIES NAMES libx264.lib HINTS ${X264_PARENT}) 47 | # SET(X264_LIBRARIES "${X264_LIBRARIES}/libx264.lib") 48 | ENDIF() 49 | 50 | IF(NOT ${X264_INCLUDE_DIR} STREQUAL X264_INCLUDE_DIR-NOTFOUND 51 | AND NOT ${X264_LIBRARIES} STREQUAL X264_LIBRARIES-NOTFOUND) 52 | 53 | SET(X264_FOUND 1) 54 | SET(X264_INCLUDE_DIRS ${X264_INCLUDE_DIR}) 55 | SET(X264_LIBS ${X264_LIBRARIES}) 56 | 57 | MESSAGE(STATUS "x264 include: ${X264_INCLUDE_DIRS}") 58 | MESSAGE(STATUS "x264 lib: ${X264_LIBS}") 59 | ELSE() 60 | MESSAGE(STATUS "Can't find x264") 61 | ENDIF() 62 | ENDIF() 63 | -------------------------------------------------------------------------------- /kinectathome.h: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | 3 | Auto-generated kinectathome.h 4 | 5 | This file contains the auto-generated main plugin object 6 | implementation for the Kinect@Home Plugin project 7 | 8 | \**********************************************************/ 9 | #ifndef H_kinectathomePLUGIN 10 | #define H_kinectathomePLUGIN 11 | 12 | #include "PluginWindow.h" 13 | #include "PluginEvents/MouseEvents.h" 14 | #include "PluginEvents/AttachedEvent.h" 15 | 16 | #include "PluginCore.h" 17 | 18 | 19 | FB_FORWARD_PTR(kinectathome) 20 | class kinectathome : public FB::PluginCore 21 | { 22 | public: 23 | static void StaticInitialize(); 24 | static void StaticDeinitialize(); 25 | 26 | public: 27 | kinectathome(); 28 | virtual ~kinectathome(); 29 | 30 | public: 31 | void onPluginReady(); 32 | void shutdown(); 33 | virtual FB::JSAPIPtr createJSAPI(); 34 | // If you want your plugin to always be windowless, set this to true 35 | // If you want your plugin to be optionally windowless based on the 36 | // value of the "windowless" param tag, remove this method or return 37 | // FB::PluginCore::isWindowless() 38 | virtual bool isWindowless() { return false; } 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 | -------------------------------------------------------------------------------- /PluginConfig.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # 3 | # Auto-Generated Plugin Configuration file 4 | # for Kinect@Home Plugin 5 | # 6 | #\**********************************************************/ 7 | 8 | set(PLUGIN_NAME "kinectathome") 9 | set(PLUGIN_PREFIX "KPL") 10 | set(COMPANY_NAME "mitmedialab") 11 | 12 | # ActiveX constants: 13 | set(FBTYPELIB_NAME kinectathomeLib) 14 | set(FBTYPELIB_DESC "kinectathome 1.0 Type Library") 15 | set(IFBControl_DESC "kinectathome Control Interface") 16 | set(FBControl_DESC "kinectathome Control Class") 17 | set(IFBComJavascriptObject_DESC "kinectathome IComJavascriptObject Interface") 18 | set(FBComJavascriptObject_DESC "kinectathome ComJavascriptObject Class") 19 | set(IFBComEventSource_DESC "kinectathome 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 75c50098-61a4-5cc8-b9f6-651426a6605d) 24 | set(IFBControl_GUID 139b8c40-9913-5e04-aef1-02ed3393d665) 25 | set(FBControl_GUID 33192714-ad31-58bf-ba4d-f2c23bf1cc4b) 26 | set(IFBComJavascriptObject_GUID 1c533c2e-2b04-5c86-8452-61017e1fff9e) 27 | set(FBComJavascriptObject_GUID b2bdcb3f-0eb9-51f1-a71d-935c4bc01a33) 28 | set(IFBComEventSource_GUID 375c25a1-6217-5bb5-a482-b20eca5f83d2) 29 | 30 | # these are the pieces that are relevant to using it from Javascript 31 | set(ACTIVEX_PROGID "mitmedialab.kinectathome") 32 | set(MOZILLA_PLUGINID "kinectathome.media.mit.edu/kinectathome") 33 | 34 | # strings 35 | set(FBSTRING_CompanyName "MIT Media Lab") 36 | set(FBSTRING_FileDescription "Native plugin for Kinect@Home project") 37 | set(FBSTRING_PLUGIN_VERSION "1.0.0.0") 38 | set(FBSTRING_LegalCopyright "Copyright 2012 MIT Media Lab") 39 | set(FBSTRING_PluginFileName "np${PLUGIN_NAME}.dll") 40 | set(FBSTRING_ProductName "Kinect@Home Plugin") 41 | set(FBSTRING_FileExtents "") 42 | set(FBSTRING_PluginName "Kinect@Home Plugin") 43 | set(FBSTRING_MIMEType "application/x-kinectathome") 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 1) 53 | set(FBMAC_USE_COCOA 1) 54 | set(FBMAC_USE_COREGRAPHICS 1) 55 | set(FBMAC_USE_COREANIMATION 0) 56 | set(FBMAC_USE_INVALIDATINGCOREANIMATION 0) 57 | 58 | # If you want to register per-machine on Windows, uncomment this line 59 | #set (FB_ATLREG_MACHINEWIDE 1) 60 | -------------------------------------------------------------------------------- /Mac/kinectathomeMac.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 | 11 | #import 12 | 13 | #include "Mac/PluginWindowMac.h" 14 | #include "Mac/PluginWindowMacQD.h" 15 | #include "Mac/PluginWindowMacCG.h" 16 | #include "Mac/PluginWindowMacCA.h" 17 | #include "Mac/PluginWindowMacICA.h" 18 | 19 | #include 20 | using namespace std; 21 | 22 | #include "kinectathomeMac.h" 23 | 24 | void glutDisplay (void); 25 | 26 | @interface MyCAOpenGLLayer : CAOpenGLLayer { 27 | GLfloat m_angle; 28 | } 29 | @end 30 | 31 | @implementation MyCAOpenGLLayer 32 | 33 | - (id) init { 34 | if ([super init]) { 35 | m_angle = 0; 36 | } 37 | return self; 38 | } 39 | 40 | //This is the main loop of the plugin 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 | kinectathomeMac::kinectathomeMac() : m_layer(NULL) {} 56 | 57 | kinectathomeMac::~kinectathomeMac() 58 | { 59 | if (m_layer) { 60 | [(CALayer*)m_layer removeFromSuperlayer]; 61 | [(CALayer*)m_layer release]; 62 | m_layer = NULL; 63 | } 64 | } 65 | 66 | bool kinectathomeMac::onWindowAttached(FB::AttachedEvent* evt, FB::PluginWindowMac* wnd) 67 | { 68 | cout << "kinectathomeMac::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 kinectathome::onWindowAttached(evt,wnd); 83 | } 84 | 85 | bool kinectathomeMac::onWindowDetached(FB::DetachedEvent* evt, FB::PluginWindowMac* wnd) 86 | { 87 | return kinectathome::onWindowDetached(evt,wnd); 88 | } 89 | -------------------------------------------------------------------------------- /kinect_main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include "kinect_common.h" 5 | 6 | // local header 7 | #include "PointDrawer.h" 8 | 9 | #if defined(__APPLE__) 10 | # include 11 | #elif defined(__linux__) 12 | # include 13 | #else 14 | # include 15 | #endif 16 | 17 | // OpenNI objects 18 | xn::Context g_Context; 19 | xn::ScriptNode g_ScriptNode; 20 | xn::DepthGenerator g_DepthGenerator; 21 | xn::ImageGenerator g_ImageGenerator; 22 | 23 | #define GL_WIN_SIZE_X 720 24 | #define GL_WIN_SIZE_Y 480 25 | 26 | XnBool g_bPause = false; 27 | XnBool g_bRecord = false; 28 | bool kinect_initialized = false; 29 | 30 | void kinect_setRecord(bool is_record) { g_bRecord = is_record; } 31 | 32 | // this function is called each frame 33 | void glutDisplay (void) 34 | { 35 | if(!kinect_initialized) return; 36 | 37 | glDisable(GL_DEPTH_TEST); 38 | glEnable(GL_TEXTURE_2D); 39 | 40 | glEnableClientState(GL_VERTEX_ARRAY); 41 | glDisableClientState(GL_COLOR_ARRAY); 42 | 43 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 44 | 45 | // Setup the OpenGL viewpoint 46 | glMatrixMode(GL_PROJECTION); 47 | glPushMatrix(); 48 | glLoadIdentity(); 49 | 50 | XnMapOutputMode mode; 51 | g_DepthGenerator.GetMapOutputMode(mode); 52 | glOrtho(0, mode.nXRes, mode.nYRes, 0, -1.0, 1.0); 53 | 54 | glDisable(GL_TEXTURE_2D); 55 | 56 | if (!g_bPause) 57 | { 58 | // Read next available data 59 | g_Context.WaitOneUpdateAll(g_DepthGenerator); 60 | 61 | // Draw depth map 62 | xn::DepthMetaData depthMD; 63 | g_DepthGenerator.GetMetaData(depthMD); //in case we need to know the actual image format... 64 | DrawDepthMap(depthMD); 65 | 66 | if(g_bRecord) { 67 | // TODO: Save data 68 | } 69 | } 70 | } 71 | 72 | // xml to initialize OpenNI 73 | #define SAMPLE_XML_PATH "/Sample-Tracking.xml" 74 | 75 | void kinect_stop() { 76 | g_Context.StopGeneratingAll(); 77 | } 78 | 79 | int kinect_main(int argc, char ** argv) 80 | { 81 | XnStatus rc = XN_STATUS_OK; 82 | xn::EnumerationErrors errors; 83 | 84 | if(kinect_initialized) { 85 | g_Context.StartGeneratingAll(); 86 | return XN_STATUS_OK; 87 | } 88 | 89 | // Initialize OpenNI 90 | std::string xml_file_path = getResourcesDirectory(); 91 | rc = g_Context.InitFromXmlFile((xml_file_path + SAMPLE_XML_PATH).c_str(), g_ScriptNode, &errors); 92 | CHECK_ERRORS(rc, errors, "InitFromXmlFile"); 93 | CHECK_RC(rc, "InitFromXmlFile"); 94 | 95 | rc = g_Context.FindExistingNode(XN_NODE_TYPE_DEPTH, g_DepthGenerator); 96 | CHECK_RC(rc, "Find depth generator"); 97 | rc = g_Context.CreateAnyProductionTree(XN_NODE_TYPE_IMAGE, NULL, g_ImageGenerator, &errors); 98 | CHECK_ERRORS(rc, errors, "Create Image"); 99 | 100 | /************ Recorder code **************/ 101 | RecConfiguration config; 102 | //set up image formats / resolution 103 | rc = ConfigureGenerators(config, g_Context, g_DepthGenerator, g_ImageGenerator); 104 | CHECK_RC(rc, "Config generators"); 105 | 106 | //TODO: add the Kinect@Home recorder / streamer 107 | /*****************************************/ 108 | 109 | 110 | // Initialization done. Start generating 111 | rc = g_Context.StartGeneratingAll(); 112 | CHECK_RC(rc, "StartGenerating"); 113 | 114 | kinect_initialized = true; 115 | 116 | return rc; 117 | } 118 | -------------------------------------------------------------------------------- /Win/projectDef.cmake: -------------------------------------------------------------------------------- 1 | #/**********************************************************\ 2 | # Auto-generated Windows project definition file for the 3 | # Kinect@Home 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 | include_directories("D:\\Program Files\\OpenNI\\Include") 22 | include_directories("D:\\Program Files\\NITE\\Include") 23 | 24 | SOURCE_GROUP(Win FILES ${PLATFORM}) 25 | 26 | set (SOURCES 27 | ${SOURCES} 28 | ${PLATFORM} 29 | ) 30 | 31 | add_windows_plugin(${PROJECT_NAME} SOURCES) 32 | 33 | # This is an example of how to add a build step to sign the plugin DLL before 34 | # the WiX installer builds. The first filename (certificate.pfx) should be 35 | # the path to your pfx file. If it requires a passphrase, the passphrase 36 | # should be located inside the second file. If you don't need a passphrase 37 | # then set the second filename to "". If you don't want signtool to timestamp 38 | # your DLL then make the last parameter "". 39 | # 40 | # Note that this will not attempt to sign if the certificate isn't there -- 41 | # that's so that you can have development machines without the cert and it'll 42 | # still work. Your cert should only be on the build machine and shouldn't be in 43 | # source control! 44 | # -- uncomment lines below this to enable signing -- 45 | #firebreath_sign_plugin(${PROJECT_NAME} 46 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/certificate.pfx" 47 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/passphrase.txt" 48 | # "http://timestamp.verisign.com/scripts/timestamp.dll") 49 | 50 | # add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing! 51 | target_link_libraries(${PROJECT_NAME} 52 | ${PLUGIN_INTERNAL_DEPS} 53 | ${FFMPEG_LIBSWSCALE_LIBS} 54 | ${FFMPEG_LIBAVUTIL_LIBS} 55 | ${X264_LIBS} 56 | ${OPENGL_LIBS} ${OPENGL_LIBRARY} ${OPENGL_LIBRARIES} OPENGL32.LIB #OMG I HATE COMPILING FOR WIN32 57 | "D:\\Program Files\\NITE\\Lib\\XnVNITE_1_5_2.lib" 58 | "D:\\Program Files\\NITE\\Lib\\XnVHandGenerator_1_5_2.lib" 59 | "D:\\Program Files\\OpenNI\\Lib\\openNI.lib" 60 | ) 61 | 62 | set(WIX_HEAT_FLAGS 63 | -gg # Generate GUIDs 64 | -srd # Suppress Root Dir 65 | -cg PluginDLLGroup # Set the Component group name 66 | -dr INSTALLDIR # Set the directory ID to put the files in 67 | ) 68 | 69 | add_wix_installer( ${PLUGIN_NAME} 70 | ${CMAKE_CURRENT_SOURCE_DIR}/Win/WiX/kinectathomeInstaller.wxs 71 | PluginDLLGroup 72 | ${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/ 73 | ${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/${FBSTRING_PluginFileName}.dll 74 | ${PROJECT_NAME} 75 | ) 76 | 77 | # This is an example of how to add a build step to sign the WiX installer 78 | # -- uncomment lines below this to enable signing -- 79 | #firebreath_sign_file("${PLUGIN_NAME}_WiXInstall" 80 | # "${FB_BIN_DIR}/${PLUGIN_NAME}/${CMAKE_CFG_INTDIR}/${PLUGIN_NAME}.msi" 81 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/certificate.pfx" 82 | # "${CMAKE_CURRENT_SOURCE_DIR}/sign/passphrase.txt" 83 | # "http://timestamp.verisign.com/scripts/timestamp.dll") 84 | -------------------------------------------------------------------------------- /Win/kinectathomeWin.cpp: -------------------------------------------------------------------------------- 1 | #include "kinectathomeWin.h" 2 | 3 | void glutDisplay (void); 4 | 5 | kinectathomeWin::kinectathomeWin() { } //c'tor 6 | kinectathomeWin::~kinectathomeWin() { } //d'tor 7 | 8 | // OpenGL thread 9 | void kinectathomeWin::drawThreaded() 10 | { 11 | send_log("kinectathomeWin::drawThreaded"); 12 | EnableOpenGL( pluginWindowWin->getHWND(), &hDC, &hRC ); 13 | SetFocus(pluginWindowWin->getHWND()); 14 | //FB:: 15 | FBLOG_INFO("BrowserHost", "Logging to HTML: " << "Bla!"); 16 | static int fps = 1; 17 | static double start = 0, diff, wait; 18 | wait = 1 / fps; 19 | 20 | //return 0; 21 | run = true; 22 | 23 | while(run) 24 | { 25 | try 26 | { 27 | FB::Rect pos = pluginWindow->getWindowPosition(); 28 | #if FB_WIN 29 | //HDC hDC; 30 | //FB::PluginWindowlessWin *wndLess = dynamic_cast(pluginWindow); 31 | //FB::PluginWindowWin *wnd = dynamic_cast(pluginWindow); 32 | PAINTSTRUCT ps; 33 | /*if (wndLess) { 34 | hDC = wndLess->getHDC(); 35 | } else if (wnd) {*/ 36 | if(pluginWindowWin){ 37 | 38 | //if(!hDC) 39 | hDC = BeginPaint(pluginWindowWin->getHWND(), &ps); 40 | 41 | pos.right -= pos.left; 42 | pos.left = 0; 43 | pos.bottom -= pos.top; 44 | pos.top = 0; 45 | 46 | 47 | glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); 48 | glClear( GL_COLOR_BUFFER_BIT ); 49 | 50 | glutDisplay(); 51 | 52 | SwapBuffers( hDC ); 53 | 54 | } 55 | ::SetTextAlign(hDC, TA_CENTER|TA_BASELINE); 56 | LPCTSTR pszText = _T("FireBreath Plugin!\n:-)"); 57 | 58 | ::TextOut(hDC, pos.left + (pos.right - pos.left) / 2, pos.top + (pos.bottom - pos.top) / 2, pszText, lstrlen(pszText)); 59 | 60 | if (pluginWindowWin) { 61 | // Release the device context 62 | EndPaint(pluginWindowWin->getHWND(), &ps); 63 | } 64 | #endif 65 | //return true; 66 | }catch(...) 67 | { 68 | return; 69 | } 70 | 71 | 72 | //doesnt work 73 | /* 74 | diff = GetTickCount() - start; 75 | if (diff < wait) { 76 | Sleep(wait - diff); 77 | } 78 | start = GetTickCount();*/ 79 | Sleep(10); 80 | 81 | 82 | }//end of while run 83 | } 84 | 85 | 86 | void kinectathomeWin::EnableOpenGL(HWND handleWnd, HDC * hdc, HGLRC * hRC) 87 | { 88 | 89 | PIXELFORMATDESCRIPTOR pfd; 90 | int format; 91 | 92 | // get the device context (DC) 93 | *hdc = GetDC( handleWnd ); 94 | 95 | // set the pixel format for the DC 96 | ZeroMemory( &pfd, sizeof( pfd ) ); 97 | pfd.nSize = sizeof( pfd ); 98 | pfd.nVersion = 1; 99 | pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; 100 | pfd.iPixelType = PFD_TYPE_RGBA; 101 | pfd.cColorBits = 24; 102 | pfd.cDepthBits = 16; 103 | pfd.iLayerType = PFD_MAIN_PLANE; 104 | format = ChoosePixelFormat( *hdc, &pfd ); 105 | SetPixelFormat( *hdc, format, &pfd ); 106 | 107 | // create and enable the render context (RC) 108 | *hRC = wglCreateContext( *hdc ); 109 | wglMakeCurrent( *hdc, *hRC ); 110 | 111 | hDC = *hdc; 112 | } 113 | // Disable OpenGL 114 | 115 | void kinectathomeWin::DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC) 116 | { 117 | wglMakeCurrent( NULL, NULL ); 118 | wglDeleteContext( hRC ); 119 | ReleaseDC( hWnd, hDC ); 120 | } 121 | 122 | bool kinectathomeWin::onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindowWin* window) 123 | { 124 | send_log("kinectathomeWin::onWindowAttached"); 125 | pluginWindow = window; 126 | FB::PluginWindowlessWin *wndLess = dynamic_cast(window); 127 | pluginWindowWin = dynamic_cast(window); 128 | 129 | boost::thread t(boost::bind(&kinectathomeWin::drawThreaded, this)); 130 | return kinectathome::onWindowAttached(evt,window); 131 | } 132 | 133 | bool kinectathomeWin::onWindowDetached(FB::DetachedEvent *evt, FB::PluginWindowWin* window) 134 | { 135 | send_log("kinectathomeWin::onWindowDetached"); 136 | // The window is about to be detached; act appropriately 137 | 138 | return kinectathome::onWindowDetached(evt,window); 139 | } 140 | -------------------------------------------------------------------------------- /kinect_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * kinect_common.h 3 | * FireBreath 4 | * 5 | * Created by Roy Shilkrot on 1/18/12. 6 | * 7 | */ 8 | 9 | #pragma once 10 | 11 | // Headers for OpenNI 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "Logging.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 | send_log(std::string(what) + " failed " + std::string(xnGetStatusString(rc))); \ 24 | return rc; \ 25 | } 26 | 27 | #define CHECK_ERRORS(rc, errors, what) \ 28 | if (rc == XN_STATUS_NO_NODE_PRESENT) \ 29 | { \ 30 | XnChar strError[1024]; \ 31 | errors.ToString(strError, 1024); \ 32 | printf("%s\n", strError); \ 33 | send_log(strError); \ 34 | return (rc); \ 35 | } 36 | 37 | #include "ResourceRecovery.h" 38 | 39 | 40 | 41 | XnMapOutputMode QVGAMode = { 320, 240, 30 }; 42 | XnMapOutputMode VGAMode = { 640, 480, 30 }; 43 | 44 | // Configuration 45 | // Taken from CyclicBuffer example 46 | struct RecConfiguration 47 | { 48 | RecConfiguration() 49 | { 50 | pDepthMode = &QVGAMode; 51 | pImageMode = &QVGAMode; 52 | bRecordDepth = TRUE; 53 | bRecordImage = TRUE; 54 | 55 | bMirrorIndicated = FALSE; 56 | bMirror = FALSE; 57 | 58 | bRegister = FALSE; 59 | bFrameSync = FALSE; 60 | bVerbose = FALSE; 61 | 62 | nDumpTime = 1; 63 | sprintf(strDirName, "."); 64 | } 65 | XnMapOutputMode* pDepthMode; 66 | XnMapOutputMode* pImageMode; 67 | XnBool bRecordDepth; 68 | XnBool bRecordImage; 69 | 70 | XnBool bMirrorIndicated; 71 | XnBool bMirror; 72 | XnBool bRegister; 73 | XnBool bFrameSync; 74 | XnBool bVerbose; 75 | 76 | XnUInt32 nDumpTime; 77 | XnChar strDirName[XN_FILE_MAX_PATH]; 78 | }; 79 | 80 | XnStatus ConfigureGenerators(const RecConfiguration& config, xn::Context& context, xn::DepthGenerator& depthGenerator, xn::ImageGenerator& imageGenerator) 81 | { 82 | XnStatus nRetVal = XN_STATUS_OK; 83 | xn::EnumerationErrors errors; 84 | 85 | // Configure the depth, if needed 86 | if (config.bRecordDepth) 87 | { 88 | nRetVal = context.CreateAnyProductionTree(XN_NODE_TYPE_DEPTH, NULL, depthGenerator, &errors); 89 | CHECK_ERRORS(nRetVal, errors, "Create Depth"); 90 | nRetVal = depthGenerator.SetMapOutputMode(*config.pDepthMode); 91 | CHECK_RC(nRetVal, "Set Mode"); 92 | if (config.bMirrorIndicated && depthGenerator.IsCapabilitySupported(XN_CAPABILITY_MIRROR)) 93 | { 94 | depthGenerator.GetMirrorCap().SetMirror(config.bMirror); 95 | } 96 | 97 | // Set Hole Filter 98 | depthGenerator.SetIntProperty("HoleFilter", TRUE); 99 | } 100 | // Configure the image, if needed 101 | if (config.bRecordImage) 102 | { 103 | nRetVal = context.CreateAnyProductionTree(XN_NODE_TYPE_IMAGE, NULL, imageGenerator, &errors); 104 | CHECK_ERRORS(nRetVal, errors, "Create Image"); 105 | nRetVal = imageGenerator.SetMapOutputMode(*config.pImageMode); 106 | CHECK_RC(nRetVal, "Set Mode"); 107 | 108 | if (config.bMirrorIndicated && imageGenerator.IsCapabilitySupported(XN_CAPABILITY_MIRROR)) 109 | { 110 | imageGenerator.GetMirrorCap().SetMirror(config.bMirror); 111 | } 112 | } 113 | 114 | // Configuration for when there are both streams 115 | if (config.bRecordDepth && config.bRecordImage) 116 | { 117 | // Registration 118 | if (config.bRegister && depthGenerator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT)) 119 | { 120 | nRetVal = depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator); 121 | CHECK_RC(nRetVal, "Registration"); 122 | } 123 | // Frame Sync 124 | if (config.bFrameSync && depthGenerator.IsCapabilitySupported(XN_CAPABILITY_FRAME_SYNC)) 125 | { 126 | if (depthGenerator.GetFrameSyncCap().CanFrameSyncWith(imageGenerator)) 127 | { 128 | nRetVal = depthGenerator.GetFrameSyncCap().FrameSyncWith(imageGenerator); 129 | CHECK_RC(nRetVal, "Frame sync"); 130 | } 131 | } 132 | } 133 | 134 | return XN_STATUS_OK; 135 | } 136 | -------------------------------------------------------------------------------- /kinectathomeAPI.cpp: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | 3 | Auto-generated kinectathomeAPI.cpp 4 | 5 | \**********************************************************/ 6 | 7 | #include "JSObject.h" 8 | #include "variant_list.h" 9 | #include "DOM/Document.h" 10 | #include "global/config.h" 11 | #include "DOM/Window.h" 12 | 13 | #include "kinectathomeAPI.h" 14 | 15 | /////////////////////////////////////////////////////////////////////////////// 16 | /// @fn kinectathomeAPI::kinectathomeAPI(const kinectathomePtr& plugin, const FB::BrowserHostPtr host) 17 | /// 18 | /// @brief Constructor for your JSAPI object. You should register your methods, properties, and events 19 | /// that should be accessible to Javascript from here. 20 | /// 21 | /// @see FB::JSAPIAuto::registerMethod 22 | /// @see FB::JSAPIAuto::registerProperty 23 | /// @see FB::JSAPIAuto::registerEvent 24 | /////////////////////////////////////////////////////////////////////////////// 25 | kinectathomeAPI::kinectathomeAPI(const kinectathomePtr& plugin, const FB::BrowserHostPtr& host) : m_plugin(plugin), m_host(host) 26 | { 27 | registerMethod("echo", make_method(this, &kinectathomeAPI::echo)); 28 | registerMethod("testEvent", make_method(this, &kinectathomeAPI::testEvent)); 29 | 30 | // Read-write property 31 | registerProperty("testString", 32 | make_property(this, 33 | &kinectathomeAPI::get_testString, 34 | &kinectathomeAPI::set_testString)); 35 | 36 | // Read-only property 37 | registerProperty("version", 38 | make_property(this, 39 | &kinectathomeAPI::get_version)); 40 | } 41 | 42 | /////////////////////////////////////////////////////////////////////////////// 43 | /// @fn kinectathomeAPI::~kinectathomeAPI() 44 | /// 45 | /// @brief Destructor. Remember that this object will not be released until 46 | /// the browser is done with it; this will almost definitely be after 47 | /// the plugin is released. 48 | /////////////////////////////////////////////////////////////////////////////// 49 | kinectathomeAPI::~kinectathomeAPI() 50 | { 51 | } 52 | 53 | /////////////////////////////////////////////////////////////////////////////// 54 | /// @fn kinectathomePtr kinectathomeAPI::getPlugin() 55 | /// 56 | /// @brief Gets a reference to the plugin that was passed in when the object 57 | /// was created. If the plugin has already been released then this 58 | /// will throw a FB::script_error that will be translated into a 59 | /// javascript exception in the page. 60 | /////////////////////////////////////////////////////////////////////////////// 61 | kinectathomePtr kinectathomeAPI::getPlugin() 62 | { 63 | kinectathomePtr plugin(m_plugin.lock()); 64 | if (!plugin) { 65 | throw FB::script_error("The plugin is invalid"); 66 | } 67 | return plugin; 68 | } 69 | 70 | 71 | 72 | // Read/Write property testString 73 | std::string kinectathomeAPI::get_testString() 74 | { 75 | return m_testString; 76 | } 77 | void kinectathomeAPI::set_testString(const std::string& val) 78 | { 79 | m_testString = val; 80 | } 81 | 82 | // Read-only property version 83 | std::string kinectathomeAPI::get_version() 84 | { 85 | return FBSTRING_PLUGIN_VERSION; 86 | } 87 | 88 | // Method echo 89 | FB::variant kinectathomeAPI::echo(const FB::variant& msg) 90 | { 91 | static int n(0); 92 | fire_echo(msg, n++); 93 | return msg; 94 | } 95 | 96 | void kinectathomeAPI::testEvent(const FB::variant& var) 97 | { 98 | fire_fired(var, true, 1); 99 | } 100 | 101 | void kinectathomeAPI::Log(const std::string& s){ 102 | // Retrieve a reference to the DOM Window 103 | FB::DOM::WindowPtr window = m_host->getDOMWindow(); 104 | 105 | // Check if the DOM Window has an the property console 106 | if (window && window->getJSObject()->HasProperty("console")) { 107 | // Create a reference to the browswer console object 108 | FB::JSObjectPtr obj = window->getProperty("console"); 109 | 110 | // Invoke the "log" method on the console object 111 | obj->Invoke("log", FB::variant_list_of(s)); 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /Win/WiX/kinectathomeInstaller.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 | -------------------------------------------------------------------------------- /cmake/Modules/LibFindMacros.cmake: -------------------------------------------------------------------------------- 1 | # Works the same as find_package, but forwards the "REQUIRED" and "QUIET" arguments 2 | # used for the current package. For this to work, the first parameter must be the 3 | # prefix of the current package, then the prefix of the new package etc, which are 4 | # passed to find_package. 5 | macro (libfind_package PREFIX) 6 | set (LIBFIND_PACKAGE_ARGS ${ARGN}) 7 | if (${PREFIX}_FIND_QUIETLY) 8 | set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} QUIET) 9 | endif (${PREFIX}_FIND_QUIETLY) 10 | if (${PREFIX}_FIND_REQUIRED) 11 | set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED) 12 | endif (${PREFIX}_FIND_REQUIRED) 13 | find_package(${LIBFIND_PACKAGE_ARGS}) 14 | endmacro (libfind_package) 15 | 16 | # CMake developers made the UsePkgConfig system deprecated in the same release (2.6) 17 | # where they added pkg_check_modules. Consequently I need to support both in my scripts 18 | # to avoid those deprecated warnings. Here's a helper that does just that. 19 | # Works identically to pkg_check_modules, except that no checks are needed prior to use. 20 | macro (libfind_pkg_check_modules PREFIX PKGNAME) 21 | if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 22 | include(UsePkgConfig) 23 | pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS) 24 | else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 25 | find_package(PkgConfig) 26 | if (PKG_CONFIG_FOUND) 27 | pkg_check_modules(${PREFIX} ${PKGNAME}) 28 | endif (PKG_CONFIG_FOUND) 29 | endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 30 | endmacro (libfind_pkg_check_modules) 31 | 32 | # Do the final processing once the paths have been detected. 33 | # If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain 34 | # all the variables, each of which contain one include directory. 35 | # Ditto for ${PREFIX}_PROCESS_LIBS and library files. 36 | # Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES. 37 | # Also handles errors in case library detection was required, etc. 38 | macro (libfind_process PREFIX) 39 | # Skip processing if already processed during this run 40 | if (NOT ${PREFIX}_FOUND) 41 | # Start with the assumption that the library was found 42 | set (${PREFIX}_FOUND TRUE) 43 | 44 | # Process all includes and set _FOUND to false if any are missing 45 | foreach (i ${${PREFIX}_PROCESS_INCLUDES}) 46 | if (${i}) 47 | set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}}) 48 | mark_as_advanced(${i}) 49 | else (${i}) 50 | set (${PREFIX}_FOUND FALSE) 51 | endif (${i}) 52 | endforeach (i) 53 | 54 | # Process all libraries and set _FOUND to false if any are missing 55 | foreach (i ${${PREFIX}_PROCESS_LIBS}) 56 | if (${i}) 57 | set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}}) 58 | mark_as_advanced(${i}) 59 | else (${i}) 60 | set (${PREFIX}_FOUND FALSE) 61 | endif (${i}) 62 | endforeach (i) 63 | 64 | # Print message and/or exit on fatal error 65 | if (${PREFIX}_FOUND) 66 | if (NOT ${PREFIX}_FIND_QUIETLY) 67 | message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}") 68 | endif (NOT ${PREFIX}_FIND_QUIETLY) 69 | else (${PREFIX}_FOUND) 70 | if (${PREFIX}_FIND_REQUIRED) 71 | foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS}) 72 | message("${i}=${${i}}") 73 | endforeach (i) 74 | message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.") 75 | endif (${PREFIX}_FIND_REQUIRED) 76 | endif (${PREFIX}_FOUND) 77 | endif (NOT ${PREFIX}_FOUND) 78 | endmacro (libfind_process) 79 | 80 | macro(libfind_library PREFIX basename) 81 | set(TMP "") 82 | if(MSVC80) 83 | set(TMP -vc80) 84 | endif(MSVC80) 85 | if(MSVC90) 86 | set(TMP -vc90) 87 | endif(MSVC90) 88 | set(${PREFIX}_LIBNAMES ${basename}${TMP}) 89 | if(${ARGC} GREATER 2) 90 | set(${PREFIX}_LIBNAMES ${basename}${TMP}-${ARGV2}) 91 | string(REGEX REPLACE "\\." "_" TMP ${${PREFIX}_LIBNAMES}) 92 | set(${PREFIX}_LIBNAMES ${${PREFIX}_LIBNAMES} ${TMP}) 93 | endif(${ARGC} GREATER 2) 94 | find_library(${PREFIX}_LIBRARY 95 | NAMES ${${PREFIX}_LIBNAMES} 96 | PATHS ${${PREFIX}_PKGCONF_LIBRARY_DIRS} 97 | ) 98 | endmacro(libfind_library) 99 | 100 | -------------------------------------------------------------------------------- /cmake/Modules/FindFFmpeg.cmake: -------------------------------------------------------------------------------- 1 | find_package(PkgConfig) 2 | 3 | 4 | MACRO(FFMPEG_FIND varname shortname headername) 5 | 6 | IF(NOT WIN32) 7 | PKG_CHECK_MODULES(PC_${varname} ${shortname}) 8 | 9 | FIND_PATH(${varname}_INCLUDE_DIR "${shortname}/${headername}" 10 | HINTS ${PC_${varname}_INCLUDEDIR} ${PC_${varname}_INCLUDE_DIRS} 11 | NO_DEFAULT_PATH 12 | ) 13 | ELSE() 14 | FIND_PATH(${varname}_INCLUDE_DIR "${shortname}/${headername}") 15 | ENDIF() 16 | 17 | IF(${varname}_INCLUDE_DIR STREQUAL "${varname}_INCLUDE_DIR-NOTFOUND") 18 | message(STATUS "look for newer strcture") 19 | IF(NOT WIN32) 20 | PKG_CHECK_MODULES(PC_${varname} "lib${shortname}") 21 | 22 | FIND_PATH(${varname}_INCLUDE_DIR "lib${shortname}/${headername}" 23 | HINTS ${PC_${varname}_INCLUDEDIR} ${PC_${varname}_INCLUDE_DIRS} 24 | NO_DEFAULT_PATH 25 | ) 26 | ELSE() 27 | FIND_PATH(${varname}_INCLUDE_DIR "lib${shortname}/${headername}") 28 | IF(${${varname}_INCLUDE_DIR} STREQUAL "${varname}_INCLUDE_DIR-NOTFOUND") 29 | #Desperate times call for desperate measures 30 | MESSAGE(STATUS "globbing...") 31 | FILE(GLOB_RECURSE ${varname}_INCLUDE_DIR "/ffmpeg*/${headername}") 32 | MESSAGE(STATUS "found: ${${varname}_INCLUDE_DIR}") 33 | IF(${varname}_INCLUDE_DIR) 34 | GET_FILENAME_COMPONENT(${varname}_INCLUDE_DIR "${${varname}_INCLUDE_DIR}" PATH) 35 | GET_FILENAME_COMPONENT(${varname}_INCLUDE_DIR "${${varname}_INCLUDE_DIR}" PATH) 36 | ELSE() 37 | SET(${varname}_INCLUDE_DIR "${varname}_INCLUDE_DIR-NOTFOUND") 38 | ENDIF() 39 | ENDIF() 40 | ENDIF() 41 | ENDIF() 42 | 43 | 44 | IF(${${varname}_INCLUDE_DIR} STREQUAL "${varname}_INCLUDE_DIR-NOTFOUND") 45 | MESSAGE(STATUS "Can't find includes for ${shortname}...") 46 | ELSE() 47 | MESSAGE(STATUS "Found ${shortname} include dirs: ${${varname}_INCLUDE_DIR}") 48 | 49 | # GET_DIRECTORY_PROPERTY(FFMPEG_PARENT DIRECTORY ${${varname}_INCLUDE_DIR} PARENT_DIRECTORY) 50 | GET_FILENAME_COMPONENT(FFMPEG_PARENT ${${varname}_INCLUDE_DIR} PATH) 51 | MESSAGE(STATUS "Using FFMpeg dir parent as hint: ${FFMPEG_PARENT}") 52 | 53 | IF(NOT WIN32) 54 | FIND_LIBRARY(${varname}_LIBRARIES NAMES ${shortname} 55 | HINTS ${PC_${varname}_LIBDIR} ${PC_${varname}_LIBRARY_DIR} ${FFMPEG_PARENT}) 56 | ELSE() 57 | # FIND_PATH(${varname}_LIBRARIES "${shortname}.dll.a" HINTS ${FFMPEG_PARENT}) 58 | FILE(GLOB_RECURSE ${varname}_LIBRARIES "${FFMPEG_PARENT}/*${shortname}.lib") 59 | # GLOBing is very bad... but windows sux, this is the only thing that works 60 | ENDIF() 61 | 62 | IF(${varname}_LIBRARIES STREQUAL "${varname}_LIBRARIES-NOTFOUND") 63 | MESSAGE(STATUS "look for newer structure for library") 64 | FIND_LIBRARY(${varname}_LIBRARIES NAMES lib${shortname} 65 | HINTS ${PC_${varname}_LIBDIR} ${PC_${varname}_LIBRARY_DIR} ${FFMPEG_PARENT}) 66 | ENDIF() 67 | 68 | 69 | IF(${varname}_LIBRARIES STREQUAL "${varname}_LIBRARIES-NOTFOUND") 70 | MESSAGE(STATUS "Can't find lib for ${shortname}...") 71 | ELSE() 72 | MESSAGE(STATUS "Found ${shortname} libs: ${${varname}_LIBRARIES}") 73 | ENDIF() 74 | 75 | 76 | IF(NOT ${varname}_INCLUDE_DIR STREQUAL "${varname}_INCLUDE_DIR-NOTFOUND" 77 | AND NOT ${varname}_LIBRARIES STREQUAL ${varname}_LIBRARIES-NOTFOUND) 78 | 79 | MESSAGE(STATUS "found ${shortname}: include ${${varname}_INCLUDE_DIR} lib ${${varname}_LIBRARIES}") 80 | SET(FFMPEG_${varname}_FOUND 1) 81 | SET(FFMPEG_${varname}_INCLUDE_DIRS ${${varname}_INCLUDE_DIR}) 82 | SET(FFMPEG_${varname}_LIBS ${${varname}_LIBRARIES}) 83 | ELSE() 84 | MESSAGE(STATUS "Can't find ${shortname}") 85 | ENDIF() 86 | 87 | ENDIF() 88 | 89 | ENDMACRO(FFMPEG_FIND) 90 | 91 | FFMPEG_FIND(LIBAVFORMAT avformat avformat.h) 92 | FFMPEG_FIND(LIBAVDEVICE avdevice avdevice.h) 93 | FFMPEG_FIND(LIBAVCODEC avcodec avcodec.h) 94 | FFMPEG_FIND(LIBAVUTIL avutil avutil.h) 95 | FFMPEG_FIND(LIBSWSCALE swscale swscale.h) 96 | 97 | SET(FFMPEG_FOUND "NO") 98 | IF (FFMPEG_LIBAVFORMAT_FOUND AND 99 | FFMPEG_LIBAVDEVICE_FOUND AND 100 | FFMPEG_LIBAVCODEC_FOUND AND 101 | FFMPEG_LIBAVUTIL_FOUND AND 102 | FFMPEG_LIBSWSCALE_FOUND 103 | ) 104 | 105 | SET(FFMPEG_FOUND "YES") 106 | 107 | SET(FFMPEG_INCLUDE_DIRS ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS}) 108 | 109 | SET(FFMPEG_LIBRARY_DIRS ${FFMPEG_LIBAVFORMAT_LIBRARY_DIRS}) 110 | 111 | SET(FFMPEG_LIBRARIES 112 | ${FFMPEG_LIBAVFORMAT_LIBRARIES} 113 | ${FFMPEG_LIBAVDEVICE_LIBRARIES} 114 | ${FFMPEG_LIBAVCODEC_LIBRARIES} 115 | ${FFMPEG_LIBAVUTIL_LIBRARIES} 116 | ${FFMPEG_LIBSWSCALE_LIBRARIES} 117 | ) 118 | 119 | ELSE () 120 | 121 | MESSAGE(STATUS "Could not find FFMPEG") 122 | 123 | ENDIF() 124 | -------------------------------------------------------------------------------- /kinectathome.cpp: -------------------------------------------------------------------------------- 1 | /**********************************************************\ 2 | 3 | Auto-generated kinectathome.cpp 4 | 5 | This file contains the auto-generated main plugin object 6 | implementation for the Kinect@Home Plugin project 7 | 8 | \**********************************************************/ 9 | 10 | #include "kinectathomeAPI.h" 11 | 12 | #include "kinectathome.h" 13 | 14 | #include "Logging.h" 15 | 16 | int kinect_main(int argc, char ** argv); 17 | 18 | /////////////////////////////////////////////////////////////////////////////// 19 | /// @fn kinectathome::StaticInitialize() 20 | /// 21 | /// @brief Called from PluginFactory::globalPluginInitialize() 22 | /// 23 | /// @see FB::FactoryBase::globalPluginInitialize 24 | /////////////////////////////////////////////////////////////////////////////// 25 | void kinectathome::StaticInitialize() 26 | { 27 | // Place one-time initialization stuff here; As of FireBreath 1.4 this should only 28 | // be called once per process 29 | 30 | 31 | } 32 | 33 | /////////////////////////////////////////////////////////////////////////////// 34 | /// @fn kinectathome::StaticInitialize() 35 | /// 36 | /// @brief Called from PluginFactory::globalPluginDeinitialize() 37 | /// 38 | /// @see FB::FactoryBase::globalPluginDeinitialize 39 | /////////////////////////////////////////////////////////////////////////////// 40 | void kinectathome::StaticDeinitialize() 41 | { 42 | // Place one-time deinitialization stuff here. As of FireBreath 1.4 this should 43 | // always be called just before the plugin library is unloaded 44 | } 45 | 46 | /////////////////////////////////////////////////////////////////////////////// 47 | /// @brief kinectathome constructor. Note that your API is not available 48 | /// at this point, nor the window. For best results wait to use 49 | /// the JSAPI object until the onPluginReady method is called 50 | /////////////////////////////////////////////////////////////////////////////// 51 | kinectathome::kinectathome() 52 | { 53 | } 54 | 55 | /////////////////////////////////////////////////////////////////////////////// 56 | /// @brief kinectathome destructor. 57 | /////////////////////////////////////////////////////////////////////////////// 58 | kinectathome::~kinectathome() 59 | { 60 | // This is optional, but if you reset m_api (the shared_ptr to your JSAPI 61 | // root object) and tell the host to free the retained JSAPI objects then 62 | // unless you are holding another shared_ptr reference to your JSAPI object 63 | // they will be released here. 64 | releaseRootJSAPI(); 65 | m_host->freeRetainedObjects(); 66 | } 67 | 68 | void kinectathome::onPluginReady() 69 | { 70 | // When this is called, the BrowserHost is attached, the JSAPI object is 71 | // created, and we are ready to interact with the page and such. The 72 | // PluginWindow may or may not have already fire the AttachedEvent at 73 | // this point. 74 | 75 | boost::shared_ptr _jsapi = FB::ptr_cast(createJSAPI()); 76 | _jsapi->Log("kinectathome::onPluginReady"); 77 | init_logging(_jsapi); 78 | kinect_main(0, 0); //initialize Kinect stuff... 79 | } 80 | 81 | void kinectathome::shutdown() 82 | { 83 | // This will be called when it is time for the plugin to shut down; 84 | // any threads or anything else that may hold a shared_ptr to this 85 | // object should be released here so that this object can be safely 86 | // destroyed. This is the last point that shared_from_this and weak_ptr 87 | // references to this object will be valid 88 | } 89 | 90 | /////////////////////////////////////////////////////////////////////////////// 91 | /// @brief Creates an instance of the JSAPI object that provides your main 92 | /// Javascript interface. 93 | /// 94 | /// Note that m_host is your BrowserHost and shared_ptr returns a 95 | /// FB::PluginCorePtr, which can be used to provide a 96 | /// boost::weak_ptr for your JSAPI class. 97 | /// 98 | /// Be very careful where you hold a shared_ptr to your plugin class from, 99 | /// as it could prevent your plugin class from getting destroyed properly. 100 | /////////////////////////////////////////////////////////////////////////////// 101 | FB::JSAPIPtr kinectathome::createJSAPI() 102 | { 103 | // m_host is the BrowserHost 104 | return boost::make_shared(FB::ptr_cast(shared_from_this()), m_host); 105 | } 106 | 107 | bool kinectathome::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *) 108 | { 109 | //printf("Mouse down at: %d, %d\n", evt->m_x, evt->m_y); 110 | return false; 111 | } 112 | 113 | bool kinectathome::onMouseUp(FB::MouseUpEvent *evt, FB::PluginWindow *) 114 | { 115 | //printf("Mouse up at: %d, %d\n", evt->m_x, evt->m_y); 116 | return false; 117 | } 118 | 119 | bool kinectathome::onMouseMove(FB::MouseMoveEvent *evt, FB::PluginWindow *) 120 | { 121 | //printf("Mouse move at: %d, %d\n", evt->m_x, evt->m_y); 122 | return false; 123 | } 124 | bool kinectathome::onWindowAttached(FB::AttachedEvent *evt, FB::PluginWindow *) 125 | { 126 | send_log("kinectathome::onWindowAttached"); 127 | // The window is attached; act appropriately 128 | return false; 129 | } 130 | 131 | bool kinectathome::onWindowDetached(FB::DetachedEvent *evt, FB::PluginWindow *) 132 | { 133 | // The window is about to be detached; act appropriately 134 | return false; 135 | } 136 | 137 | -------------------------------------------------------------------------------- /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 | 10 | #if defined(__APPLE__) 11 | # include 12 | #elif defined(__linux__) 13 | # include 14 | #else 15 | # include 16 | #endif 17 | 18 | #define MAX_DEPTH 10000 19 | float g_pDepthHist[MAX_DEPTH]; 20 | unsigned int getClosestPowerOfTwo(unsigned int n) 21 | { 22 | unsigned int m = 2; 23 | while(m < n) m<<=1; 24 | 25 | return m; 26 | } 27 | GLuint initTexture(void** buf, int& width, int& height) 28 | { 29 | GLuint texID = 0; 30 | glGenTextures(1,&texID); 31 | 32 | width = getClosestPowerOfTwo(width); 33 | height = getClosestPowerOfTwo(height); 34 | *buf = new unsigned char[width*height*4]; 35 | glBindTexture(GL_TEXTURE_2D,texID); 36 | 37 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 38 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 39 | 40 | return texID; 41 | } 42 | 43 | GLfloat texcoords[8]; 44 | void DrawRectangle(float topLeftX, float topLeftY, float bottomRightX, float bottomRightY) 45 | { 46 | GLfloat verts[8] = { topLeftX, topLeftY, 47 | topLeftX, bottomRightY, 48 | bottomRightX, bottomRightY, 49 | bottomRightX, topLeftY 50 | }; 51 | glVertexPointer(2, GL_FLOAT, 0, verts); 52 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); 53 | 54 | glFlush(); 55 | } 56 | void DrawTexture(float topLeftX, float topLeftY, float bottomRightX, float bottomRightY) 57 | { 58 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); 59 | glTexCoordPointer(2, GL_FLOAT, 0, texcoords); 60 | 61 | DrawRectangle(topLeftX, topLeftY, bottomRightX, bottomRightY); 62 | 63 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); 64 | } 65 | 66 | void DrawDepthMap(const xn::DepthMetaData& dm) 67 | { 68 | static bool bInitialized = false; 69 | static GLuint depthTexID; 70 | static unsigned char* pDepthTexBuf; 71 | static int texWidth, texHeight; 72 | 73 | float topLeftX; 74 | float topLeftY; 75 | float bottomRightY; 76 | float bottomRightX; 77 | float texXpos; 78 | float texYpos; 79 | 80 | if(!bInitialized) 81 | { 82 | XnUInt16 nXRes = dm.XRes(); 83 | XnUInt16 nYRes = dm.YRes(); 84 | texWidth = getClosestPowerOfTwo(nXRes); 85 | texHeight = getClosestPowerOfTwo(nYRes); 86 | 87 | depthTexID = initTexture((void**)&pDepthTexBuf,texWidth, texHeight) ; 88 | 89 | bInitialized = true; 90 | 91 | topLeftX = nXRes; 92 | topLeftY = 0; 93 | bottomRightY = nYRes; 94 | bottomRightX = 0; 95 | texXpos =(float)nXRes/texWidth; 96 | texYpos =(float)nYRes/texHeight; 97 | 98 | memset(texcoords, 0, 8*sizeof(float)); 99 | texcoords[0] = texXpos, texcoords[1] = texYpos, texcoords[2] = texXpos, texcoords[7] = texYpos; 100 | 101 | } 102 | unsigned int nValue = 0; 103 | unsigned int nHistValue = 0; 104 | unsigned int nIndex = 0; 105 | unsigned int nX = 0; 106 | unsigned int nY = 0; 107 | unsigned int nNumberOfPoints = 0; 108 | XnUInt16 g_nXRes = dm.XRes(); 109 | XnUInt16 g_nYRes = dm.YRes(); 110 | 111 | unsigned char* pDestImage = pDepthTexBuf; 112 | 113 | const XnUInt16* pDepth = dm.Data(); 114 | 115 | // Calculate the accumulative histogram 116 | memset(g_pDepthHist, 0, MAX_DEPTH*sizeof(float)); 117 | for (nY=0; nY