├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── android-arm64-cross-file.txt ├── android-armeabi-v7a-cross-file.txt ├── build_apk.py ├── install_glimpse.py ├── ios-11-arm64-cross-file.txt ├── ios-xcode-arm64-cross-file.txt ├── meson.build ├── meson_options.txt ├── remote_osx_codesign.sh ├── src ├── Roboto-Medium.ttf ├── UnityPluginAPI │ ├── IUnityEventQueue.h │ ├── IUnityGraphics.h │ ├── IUnityGraphicsD3D11.h │ ├── IUnityGraphicsD3D12.h │ ├── IUnityGraphicsMetal.h │ ├── IUnityInterface.h │ ├── IUnityProfilerCallbacks.h │ ├── IUnityRenderingExtensions.h │ └── IUnityShaderCompilerAccess.h ├── annotate_bone_map.cc ├── basename-compat.c ├── basename-compat.h ├── compare-tests.py ├── depth2labels.cc ├── example-bones.json ├── exr-to-pfm.cc ├── file_compat.h ├── getline-compat.c ├── getline-compat.h ├── getopt-compat.c ├── getopt-compat.h ├── glimpse.h ├── glimpse_assets.c ├── glimpse_assets.h ├── glimpse_context.cc ├── glimpse_context.h ├── glimpse_data.cc ├── glimpse_data.h ├── glimpse_device.cc ├── glimpse_device.h ├── glimpse_gl.c ├── glimpse_gl.h ├── glimpse_imgui_shell.cc ├── glimpse_imgui_shell.h ├── glimpse_log.c ├── glimpse_log.h ├── glimpse_mem_pool.cc ├── glimpse_mem_pool.h ├── glimpse_mutex.c ├── glimpse_mutex.h ├── glimpse_os.c ├── glimpse_os.h ├── glimpse_properties.cc ├── glimpse_properties.h ├── glimpse_rdt.cc ├── glimpse_rdt.h ├── glimpse_record.cc ├── glimpse_record.h ├── glimpse_shell_test.c ├── glimpse_target.cc ├── glimpse_target.h ├── glimpse_unity.cc ├── glimpse_viewer.cc ├── glimpse_viewer_android │ ├── AndroidManifest.xml │ └── res │ │ └── values │ │ └── strings.xml ├── half.hpp ├── image-pre-processor.cc ├── image_utils.cc ├── image_utils.h ├── imgui │ ├── imconfig.h │ ├── imgui.cpp │ ├── imgui.h │ ├── imgui_demo.cpp │ ├── imgui_draw.cpp │ ├── imgui_impl_glfm.cpp │ ├── imgui_impl_glfm.h │ ├── imgui_impl_glfw.cpp │ ├── imgui_impl_glfw.h │ ├── imgui_impl_opengl3.cpp │ ├── imgui_impl_opengl3.h │ ├── imgui_internal.h │ ├── imgui_widgets.cpp │ ├── imstb_rectpack.h │ ├── imstb_textedit.h │ ├── imstb_truetype.h │ ├── profiler.cpp │ ├── profiler.h │ ├── stb_rect_pack.h │ ├── stb_textedit.h │ ├── stb_truetype.h │ ├── timer.cpp │ └── timer.h ├── index-to-recording.cc ├── infer_labels.cc ├── infer_labels.h ├── ios_utils.h ├── ios_utils.m ├── java │ ├── com │ │ └── impossible │ │ │ └── glimpse │ │ │ ├── GlimpseConfig.java.in │ │ │ ├── GlimpseJNI.java │ │ │ ├── GlimpseNativeActivity.java │ │ │ ├── GlimpseUnityActivity.java │ │ │ └── meson.build │ └── meson.build ├── jip-to-json.c ├── jip.cc ├── jip.h ├── joints_inferrer.cc ├── joints_inferrer.h ├── json-to-rdt.c ├── labeled-human-mesh-instructions.txt ├── llist.c ├── llist.h ├── mocap-index.json ├── pack-info.py ├── pack-training-data.cc ├── pack.c ├── pack.h ├── parson.c ├── parson.h ├── perlin.c ├── perlin.h ├── pfm-debug.c ├── pfm-to-exr.cc ├── pthread_barrier │ ├── LICENSE │ ├── pthread_barrier.c │ └── pthread_barrier.h ├── py │ ├── __init__.py │ └── pack.py ├── python │ ├── Makefile │ ├── README.md │ ├── __init__.py │ ├── glimpse.i │ ├── glimpse_python.cc │ ├── glimpse_python.h │ ├── infer.py │ ├── numpy.i │ ├── setup.cfg │ └── setup.py ├── random.hpp ├── rdt-info.py ├── rdt-update.py ├── rdt_tree.cc ├── rdt_tree.h ├── recordings-tool.cc ├── simple.frag ├── simple.vert ├── tango-config.json ├── test_rdt.cc ├── tinyexr.cc ├── tinyexr.h ├── train_joint_params.cc ├── train_rdt.c ├── viewer │ ├── glimpse-viewer.js │ ├── index.html │ ├── package.json │ └── server.js ├── win32 │ └── dirent.h ├── wrapper_image.h ├── xalloc.c └── xalloc.h ├── subprojects ├── boost.wrap ├── dlib.wrap ├── eigen3.wrap ├── flann.wrap ├── glfm.wrap ├── glfw.wrap ├── glm.wrap ├── libepoxy.wrap ├── libfreenect.wrap ├── libpng.wrap ├── librealsense.wrap ├── packagecache │ ├── boost-wrap-1.69.0.tar │ ├── eigen-wrap-3.3.4.tar │ ├── glm-wrap-0.9.9-a2.tar │ ├── libpng-wrap-1.6.17.tar │ └── zlib-1.2.8-wrap.tar ├── pcl.wrap └── zlib.wrap ├── travis ├── Dockerfile ├── README.md ├── build-travis-docker-image.sh ├── travis-ci-build.sh ├── travis-ci-prep-docker-image.sh ├── travis-ci-render.sh └── travis-ci-train.sh ├── windows-cross-test ├── cross.sh └── hello.c ├── windows-sdk-build.py └── xcode └── GlimpseViewer ├── Glimpse Viewer.xcodeproj └── project.pbxproj └── GlimpseViewer ├── Assets.xcassets └── AppIcon.appiconset │ └── Contents.json ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist └── LaunchScreen.storyboard /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | *.swp 3 | tags 4 | cscope.* 5 | *.o 6 | imgui.ini 7 | joint-dist.json 8 | joint-params.json 9 | tree?.rdt 10 | tree?.json 11 | /blender 12 | /build* 13 | /src/.deps 14 | /src/depth2labels 15 | /src/exr-to-pfm 16 | /src/glimpse_viewer_recording 17 | /src/image-pre-processor 18 | /src/libglimpse.so 19 | /src/pack-training-data 20 | /src/pfm-debug 21 | /src/pfm-to-exr 22 | /src/rdt-to-json 23 | /src/train_joint_params 24 | /src/train_rdt 25 | /src/python/build 26 | /src/python/dist 27 | /src/python/glimpse.egg-info 28 | /src/python/glimpse.py 29 | /src/python/glimpse_wrap.cpp 30 | /subprojects/boost_1_65_1 31 | /subprojects/boost_1_69_0 32 | /subprojects/dlib 33 | /subprojects/eigen-git-mirror-3.3.4 34 | /subprojects/flann 35 | /subprojects/flann-1.9.1 36 | /subprojects/glm-0.9.9-a2 37 | /subprojects/glfw 38 | /subprojects/glfm 39 | /subprojects/libepoxy 40 | /subprojects/libfreenect 41 | /subprojects/libfreenect-glimpse 42 | /subprojects/libpng-1.6.17 43 | /subprojects/pcl 44 | /subprojects/packagecache/0.9.9-a2.tar.gz 45 | /subprojects/packagecache/1.9.1.tar.gz 46 | /subprojects/packagecache/boost_1_65_1.tar.bz2 47 | /subprojects/packagecache/boost_1_69_0.tar.bz2 48 | /subprojects/packagecache/eigen-git-mirror-3.3.4.zip 49 | /subprojects/packagecache/libpng-1.6.17.tar.xz 50 | /subprojects/packagecache/tmp* 51 | /subprojects/zlib-1.2.8 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2018 Glimp IP Ltd 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, copy, 7 | modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 18 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 19 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /android-arm64-cross-file.txt: -------------------------------------------------------------------------------- 1 | [binaries] 2 | name = 'android-arm64' 3 | c = 'aarch64-linux-android-clang' 4 | cpp = 'aarch64-linux-android-clang++' 5 | ar = 'aarch64-linux-android-ar' 6 | ld = 'aarch64-linux-android-ld' 7 | strip = 'aarch64-linux-android-strip' 8 | 9 | [host_machine] 10 | system = 'linux' 11 | cpu_family = 'arm64' 12 | cpu = 'arm64-v8a' 13 | endian = 'little' 14 | -------------------------------------------------------------------------------- /android-armeabi-v7a-cross-file.txt: -------------------------------------------------------------------------------- 1 | [binaries] 2 | name = 'android-armeabi-v7a' 3 | c = 'arm-linux-androideabi-clang' 4 | cpp = 'arm-linux-androideabi-clang++' 5 | ar = 'arm-linux-androideabi-ar' 6 | ld = 'arm-linux-androideabi-ld' 7 | strip = 'arm-linux-androideabi-strip' 8 | 9 | [host_machine] 10 | system = 'android' 11 | cpu_family = 'arm' 12 | cpu = 'armv7' 13 | endian = 'little' 14 | 15 | [properties] 16 | 17 | support_64bit_file_offsets = False 18 | 19 | # Note: The fix-coretex-a8 flag is recommended by upstream docs: 20 | # https://developer.android.com/ndk/guides/standalone_toolchain.html 21 | c_args = [ '-mfpu=neon', '-fno-omit-frame-pointer', '-funwind-tables' ] 22 | c_link_args = [ '-march=armv7-a', '-Wl,--fix-cortex-a8' ] 23 | cpp_args = [ '-mfpu=neon', '-fno-omit-frame-pointer', '-funwind-tables' ] 24 | cpp_link_args = [ '-march=armv7-a', '-Wl,--fix-cortex-a8' ] 25 | 26 | # As a hacky workaround for not being able to query the binaries 27 | # we need to specify the strip tool again for our install script 28 | _strip_binary = 'arm-linux-androideabi-strip' 29 | 30 | # So we can locate libc++_shared.so in the NDK we need to know 31 | # the arch directory name used within the NDK 32 | _ndk_arch = 'armeabi-v7a' 33 | -------------------------------------------------------------------------------- /ios-11-arm64-cross-file.txt: -------------------------------------------------------------------------------- 1 | [binaries] 2 | name = 'arm-apple-darwin11' 3 | c = 'arm-apple-darwin11-clang' 4 | objc = 'arm-apple-darwin11-clang' 5 | cpp = 'arm-apple-darwin11-clang++' 6 | ar = 'arm-apple-darwin11-ar' 7 | ld = 'arm-apple-darwin11-ld' 8 | strip = 'arm-apple-darwin11-strip' 9 | 10 | [host_machine] 11 | system = 'darwin' 12 | cpu_family = 'arm' 13 | cpu = 'arm64' 14 | endian = 'little' 15 | 16 | [properties] 17 | 18 | objc_args = [ '-ObjC', '-fobjc-arc', '-fmodules', '-gmodules' ] 19 | c_args = [ '-fmodules', '-gmodules' ] 20 | cpp_args = [ '-fmodules', '-gmodules' ] 21 | 22 | # As a hacky workaround for not being able to query the binaries 23 | # we need to specify the strip tool again for our install script 24 | _strip_binary = 'arm-apple-darwin11-strip' 25 | -------------------------------------------------------------------------------- /ios-xcode-arm64-cross-file.txt: -------------------------------------------------------------------------------- 1 | [binaries] 2 | c = 'clang' 3 | objc = 'clang' 4 | cpp = 'clang++' 5 | ar = 'ar' 6 | ld = 'ld' 7 | strip = 'strip' 8 | 9 | [host_machine] 10 | system = 'darwin' 11 | cpu_family = 'arm' 12 | cpu = 'arm64' 13 | endian = 'little' 14 | 15 | [properties] 16 | root = '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer' 17 | 18 | # XXX: Do not change the -isysroot path to point at a non-versioned 19 | # SDK like SDKs/iPhoneOS.sdk since clang will infer a min OS version from 20 | # the SDK name and -miphoneos-min-version does't seem to override and 21 | # duplicate -isysroot arguments (e.g. added later by evaulating xcrun) 22 | # also don't seem to override either. 23 | # ... 24 | c_args = ['-arch', 'arm64', '-fembed-bitcode', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk'] 25 | cpp_args = ['-arch', 'arm64', '-fembed-bitcode', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk'] 26 | c_link_args = ['-arch', 'arm64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk'] 27 | cpp_link_args = ['-arch', 'arm64', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk'] 28 | objc_args = [ '-ObjC', '-arch', 'arm64', '-fobjc-arc', '-fembed-bitcode', '-fstrict-aliasing', '-fmessage-length=0', '-fdiagnostics-show-note-include-stack', '-fmacro-backtrace-limit=0', '-fpascal-strings', '-fmodules', '-gmodules', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk'] 29 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | option('use_system_libs', type: 'boolean', value : true, 2 | description: 'Whether to generally link with system libraries') 3 | 4 | option('android_ndk', type: 'string', 5 | description: 'Absolute path to the Android NDK') 6 | option('android_sdk', type: 'string', 7 | description: 'Absolute path to the Android SDK') 8 | option('android_sdk_build_tools', type: 'string', value: '28.0.3', 9 | description: 'The version of Android SDK build tools to use') 10 | option('android_tango_sdk', type: 'string', 11 | description: 'Absolute path to unpacked Tango SDK for Android') 12 | option('use_asset_manager', type: 'boolean', value: false, 13 | description: 'Whether to use the Android asset manager') 14 | 15 | option('realsense', type: 'feature', value: 'auto', 16 | description: 'Whether to enable RealSense camera support') 17 | 18 | option('unity_project', type: 'string', 19 | description: 'Path to top of a Unity project where Glimpse plugin can be installed') 20 | option('unity_editor', type: 'string', 21 | description: 'Path to Unity Editor installation prefix (required for Android builds)') 22 | -------------------------------------------------------------------------------- /remote_osx_codesign.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -x 4 | 5 | OSX_IP=192.168.1.169 6 | OSX_USER=new 7 | 8 | #OSX_IP=192.168.0.10 9 | #OSX_USER=bob 10 | 11 | HOST=${OSX_USER}@${OSX_IP} 12 | 13 | rm -fr Payload 14 | cp ../build-ios-debug/Test PayloadUnsigned/Test.app/ 15 | cp -av PayloadUnsigned Payload 16 | rm GlimpseTest.zip 17 | echo "packing zip" 18 | zip -r GlimpseTest.zip Payload 19 | scp GlimpseTest.zip $HOST: 20 | 21 | echo "remote..." 22 | ssh $HOST rm -fr Payload 23 | echo "unpacking zip" 24 | ssh $HOST unzip GlimpseTest.zip 25 | echo "signing..." 26 | ssh $HOST <<-EOF 27 | security default-keychain -s /Users/$OSX_USER/Library/Keychains/glimpse.keychain-db 28 | security unlock-keychain -p glimpse1234 /Users/$OSX_USER/Library/Keychains/glimpse.keychain-db 29 | codesign -s "4R8435VF99" --force --entitlements ./Entitlements.plist Payload/Test.app/Test 30 | EOF 31 | echo "packing ipa" 32 | ssh $HOST rm GlimpseTest.ipa 33 | ssh $HOST zip -r GlimpseTest.ipa Payload 34 | 35 | echo "retrieving ipa" 36 | scp $HOST:GlimpseTest.ipa . 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/Roboto-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glimpse-project/glimpse/f7e0bee5800c72ea37928f7e0fd2e0b7b67cf904/src/Roboto-Medium.ttf -------------------------------------------------------------------------------- /src/UnityPluginAPI/IUnityGraphics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IUnityInterface.h" 3 | 4 | typedef enum UnityGfxRenderer 5 | { 6 | //kUnityGfxRendererOpenGL = 0, // Legacy OpenGL, removed 7 | //kUnityGfxRendererD3D9 = 1, // Direct3D 9, removed 8 | kUnityGfxRendererD3D11 = 2, // Direct3D 11 9 | kUnityGfxRendererNull = 4, // "null" device (used in batch mode) 10 | kUnityGfxRendererOpenGLES20 = 8, // OpenGL ES 2.0 11 | kUnityGfxRendererOpenGLES30 = 11, // OpenGL ES 3.0 12 | //kUnityGfxRendererGXM = 12, // PlayStation Vita, removed 13 | kUnityGfxRendererPS4 = 13, // PlayStation 4 14 | kUnityGfxRendererXboxOne = 14, // Xbox One 15 | kUnityGfxRendererMetal = 16, // iOS Metal 16 | kUnityGfxRendererOpenGLCore = 17, // OpenGL core 17 | kUnityGfxRendererD3D12 = 18, // Direct3D 12 18 | kUnityGfxRendererVulkan = 21, // Vulkan 19 | kUnityGfxRendererNvn = 22, // Nintendo Switch NVN API 20 | kUnityGfxRendererXboxOneD3D12 = 23 // MS XboxOne Direct3D 12 21 | } UnityGfxRenderer; 22 | 23 | typedef enum UnityGfxDeviceEventType 24 | { 25 | kUnityGfxDeviceEventInitialize = 0, 26 | kUnityGfxDeviceEventShutdown = 1, 27 | kUnityGfxDeviceEventBeforeReset = 2, 28 | kUnityGfxDeviceEventAfterReset = 3, 29 | } UnityGfxDeviceEventType; 30 | 31 | typedef void (UNITY_INTERFACE_API * IUnityGraphicsDeviceEventCallback)(UnityGfxDeviceEventType eventType); 32 | 33 | // Should only be used on the rendering thread unless noted otherwise. 34 | UNITY_DECLARE_INTERFACE(IUnityGraphics) 35 | { 36 | UnityGfxRenderer(UNITY_INTERFACE_API * GetRenderer)(); // Thread safe 37 | 38 | // This callback will be called when graphics device is created, destroyed, reset, etc. 39 | // It is possible to miss the kUnityGfxDeviceEventInitialize event in case plugin is loaded at a later time, 40 | // when the graphics device is already created. 41 | void(UNITY_INTERFACE_API * RegisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); 42 | void(UNITY_INTERFACE_API * UnregisterDeviceEventCallback)(IUnityGraphicsDeviceEventCallback callback); 43 | int(UNITY_INTERFACE_API * ReserveEventIDRange)(int count); // reserves 'count' event IDs. Plugins should use the result as a base index when issuing events back and forth to avoid event id clashes. 44 | }; 45 | UNITY_REGISTER_INTERFACE_GUID(0x7CBA0A9CA4DDB544ULL, 0x8C5AD4926EB17B11ULL, IUnityGraphics) 46 | 47 | 48 | // Certain Unity APIs (GL.IssuePluginEvent, CommandBuffer.IssuePluginEvent) can callback into native plugins. 49 | // Provide them with an address to a function of this signature. 50 | typedef void (UNITY_INTERFACE_API * UnityRenderingEvent)(int eventId); 51 | typedef void (UNITY_INTERFACE_API * UnityRenderingEventAndData)(int eventId, void* data); 52 | -------------------------------------------------------------------------------- /src/UnityPluginAPI/IUnityGraphicsD3D11.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IUnityInterface.h" 3 | 4 | 5 | // Should only be used on the rendering thread unless noted otherwise. 6 | UNITY_DECLARE_INTERFACE(IUnityGraphicsD3D11) 7 | { 8 | ID3D11Device* (UNITY_INTERFACE_API * GetDevice)(); 9 | 10 | ID3D11Resource* (UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer); 11 | ID3D11Resource* (UNITY_INTERFACE_API * TextureFromNativeTexture)(UnityTextureID texture); 12 | 13 | ID3D11RenderTargetView* (UNITY_INTERFACE_API * RTVFromRenderBuffer)(UnityRenderBuffer surface); 14 | ID3D11ShaderResourceView* (UNITY_INTERFACE_API * SRVFromNativeTexture)(UnityTextureID texture); 15 | }; 16 | 17 | UNITY_REGISTER_INTERFACE_GUID(0xAAB37EF87A87D748ULL, 0xBF76967F07EFB177ULL, IUnityGraphicsD3D11) 18 | -------------------------------------------------------------------------------- /src/UnityPluginAPI/IUnityGraphicsMetal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "IUnityInterface.h" 3 | 4 | #ifndef __OBJC__ 5 | #error metal plugin is objc code. 6 | #endif 7 | #ifndef __clang__ 8 | #error only clang compiler is supported. 9 | #endif 10 | 11 | @class NSBundle; 12 | @protocol MTLDevice; 13 | @protocol MTLCommandBuffer; 14 | @protocol MTLCommandEncoder; 15 | @protocol MTLTexture; 16 | @class MTLRenderPassDescriptor; 17 | 18 | 19 | UNITY_DECLARE_INTERFACE(IUnityGraphicsMetalV1) 20 | { 21 | NSBundle* (UNITY_INTERFACE_API * MetalBundle)(); 22 | id(UNITY_INTERFACE_API * MetalDevice)(); 23 | 24 | id(UNITY_INTERFACE_API * CurrentCommandBuffer)(); 25 | 26 | // for custom rendering support there are two scenarios: 27 | // you want to use current in-flight MTLCommandEncoder (NB: it might be nil) 28 | id(UNITY_INTERFACE_API * CurrentCommandEncoder)(); 29 | // or you might want to create your own encoder. 30 | // In that case you should end unity's encoder before creating your own and end yours before returning control to unity 31 | void(UNITY_INTERFACE_API * EndCurrentCommandEncoder)(); 32 | 33 | // returns MTLRenderPassDescriptor used to create current MTLCommandEncoder 34 | MTLRenderPassDescriptor* (UNITY_INTERFACE_API * CurrentRenderPassDescriptor)(); 35 | 36 | // converting trampoline UnityRenderBufferHandle into native RenderBuffer 37 | UnityRenderBuffer(UNITY_INTERFACE_API * RenderBufferFromHandle)(void* bufferHandle); 38 | 39 | // access to RenderBuffer's texure 40 | // NB: you pass here *native* RenderBuffer, acquired by calling (C#) RenderBuffer.GetNativeRenderBufferPtr 41 | // AAResolvedTextureFromRenderBuffer will return nil in case of non-AA RenderBuffer or if called for depth RenderBuffer 42 | // StencilTextureFromRenderBuffer will return nil in case of no-stencil RenderBuffer or if called for color RenderBuffer 43 | id(UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer); 44 | id(UNITY_INTERFACE_API * AAResolvedTextureFromRenderBuffer)(UnityRenderBuffer buffer); 45 | id(UNITY_INTERFACE_API * StencilTextureFromRenderBuffer)(UnityRenderBuffer buffer); 46 | }; 47 | UNITY_REGISTER_INTERFACE_GUID(0x29F8F3D03833465EULL, 0x92138551C15D823DULL, IUnityGraphicsMetalV1) 48 | 49 | 50 | // deprecated: please use versioned interface above 51 | 52 | UNITY_DECLARE_INTERFACE(IUnityGraphicsMetal) 53 | { 54 | NSBundle* (UNITY_INTERFACE_API * MetalBundle)(); 55 | id(UNITY_INTERFACE_API * MetalDevice)(); 56 | 57 | id(UNITY_INTERFACE_API * CurrentCommandBuffer)(); 58 | id(UNITY_INTERFACE_API * CurrentCommandEncoder)(); 59 | void(UNITY_INTERFACE_API * EndCurrentCommandEncoder)(); 60 | MTLRenderPassDescriptor* (UNITY_INTERFACE_API * CurrentRenderPassDescriptor)(); 61 | 62 | UnityRenderBuffer(UNITY_INTERFACE_API * RenderBufferFromHandle)(void* bufferHandle); 63 | 64 | id(UNITY_INTERFACE_API * TextureFromRenderBuffer)(UnityRenderBuffer buffer); 65 | id(UNITY_INTERFACE_API * AAResolvedTextureFromRenderBuffer)(UnityRenderBuffer buffer); 66 | id(UNITY_INTERFACE_API * StencilTextureFromRenderBuffer)(UnityRenderBuffer buffer); 67 | }; 68 | UNITY_REGISTER_INTERFACE_GUID(0x992C8EAEA95811E5ULL, 0x9A62C4B5B9876117ULL, IUnityGraphicsMetal) 69 | -------------------------------------------------------------------------------- /src/basename-compat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Robert Bragg 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "basename-compat.h" 26 | 27 | #ifdef _WIN32 28 | 29 | #include 30 | 31 | char * 32 | basename(char *filename) 33 | { 34 | int len = strlen(filename); 35 | 36 | char *fname = alloca(len + 1); 37 | char *ext = alloca(len + 1); 38 | 39 | _splitpath_s(filename, 40 | NULL, /* drive */ 41 | 0, 42 | NULL, /* dir */ 43 | 0, 44 | fname, /* base name (no ext) */ 45 | len + 1, 46 | ext, 47 | len + 1); 48 | snprintf(filename, len + 1, "%s%s", fname, ext); 49 | 50 | return filename; 51 | } 52 | 53 | char * 54 | dirname(char *filename) 55 | { 56 | int len = strlen(filename); 57 | 58 | char *drive = alloca(len + 1); 59 | char *dir = alloca(len + 1); 60 | 61 | _splitpath_s(filename, 62 | drive, /* drive */ 63 | len + 1, 64 | dir, /* dir */ 65 | len + 1, 66 | NULL, /* base name (no ext) */ 67 | 0, 68 | NULL, 69 | 0); 70 | snprintf(filename, len + 1, "%s/%s", drive, dir); 71 | 72 | return filename; 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/basename-compat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef _WIN32 4 | #include 5 | #else 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | char *basename(char *path); 11 | char *dirname(char *path); 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/getline-compat.c: -------------------------------------------------------------------------------- 1 | /* The original code is public domain -- Will Hartung 4/9/09 */ 2 | /* Modifications, public domain as well, by Antti Haapala, 11/10/17 */ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "getline-compat.h" 10 | 11 | // if typedef doesn't exist (msvc, blah) 12 | //typedef intptr_t ssize_t; 13 | 14 | intptr_t getline(char **lineptr, size_t *n, FILE *stream) { 15 | size_t pos; 16 | int c; 17 | 18 | if (lineptr == NULL || stream == NULL || n == NULL) { 19 | errno = EINVAL; 20 | return -1; 21 | } 22 | 23 | c = fgetc(stream); 24 | if (c == EOF) { 25 | return -1; 26 | } 27 | 28 | if (*lineptr == NULL) { 29 | *lineptr = malloc(128); 30 | if (*lineptr == NULL) { 31 | return -1; 32 | } 33 | *n = 128; 34 | } 35 | 36 | pos = 0; 37 | while(c != EOF) { 38 | if (pos + 1 >= *n) { 39 | size_t new_size = *n + (*n >> 2); 40 | if (new_size < 128) { 41 | new_size = 128; 42 | } 43 | char *new_ptr = realloc(*lineptr, new_size); 44 | if (new_ptr == NULL) { 45 | return -1; 46 | } 47 | *n = new_size; 48 | *lineptr = new_ptr; 49 | } 50 | 51 | ((unsigned char *)(*lineptr))[pos ++] = c; 52 | if (c == '\n') { 53 | break; 54 | } 55 | c = fgetc(stream); 56 | } 57 | 58 | (*lineptr)[pos] = '\0'; 59 | return pos; 60 | } 61 | -------------------------------------------------------------------------------- /src/getline-compat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __unix__ 4 | 5 | #include 6 | 7 | #else 8 | 9 | #include 10 | #include 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | // Defined with intptr_t instead of ssize_t which isn't defined on Windows 17 | intptr_t getline(char **lineptr, size_t *n, FILE *stream); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif // __unix__ 24 | -------------------------------------------------------------------------------- /src/getopt-compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * getopt - POSIX like getopt for Windows console Application 3 | * 4 | * win-c - Windows Console Library 5 | * Copyright (c) 2015 Koji Takami 6 | * Released under the MIT license 7 | * https://github.com/takamin/win-c/blob/master/LICENSE 8 | */ 9 | #pragma once 10 | 11 | #if defined(__APPLE__) 12 | #include 13 | #else 14 | #define TARGET_OS_MAC 0 15 | #define TARGET_OS_IOS 0 16 | #define TARGET_OS_OSX 0 17 | #endif 18 | 19 | 20 | #if defined(__unix__) || TARGET_OS_OSX == 1 21 | 22 | #include 23 | 24 | #else 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif // __cplusplus 29 | 30 | int getopt(int argc, char* const argv[], 31 | const char* optstring); 32 | 33 | extern char *optarg; 34 | extern int optind, opterr, optopt; 35 | 36 | #define no_argument 0 37 | #define required_argument 1 38 | #define optional_argument 2 39 | 40 | struct option { 41 | const char *name; 42 | int has_arg; 43 | int* flag; 44 | int val; 45 | }; 46 | 47 | int getopt_long(int argc, char* const argv[], 48 | const char* optstring, 49 | const struct option* longopts, int* longindex); 50 | /**************************************************************************** 51 | int getopt_long_only(int argc, char* const argv[], 52 | const char* optstring, 53 | const struct option* longopts, int* longindex); 54 | ****************************************************************************/ 55 | #ifdef __cplusplus 56 | } 57 | #endif // __cplusplus 58 | 59 | #endif // __unix__ 60 | -------------------------------------------------------------------------------- /src/glimpse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #pragma once 27 | 28 | #include "image_utils.h" 29 | #include "rdt_tree.h" 30 | #include "infer_labels.h" 31 | -------------------------------------------------------------------------------- /src/glimpse_assets.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | /* 27 | * Minimal API for portably accessing files/assets at runtime, mainly 28 | * based on the Android Asset Management API. 29 | */ 30 | 31 | #pragma once 32 | 33 | #include // off_t 34 | #include 35 | 36 | /* Note: currently compatible with Android's Asset mode enum which is 37 | * relied on internally 38 | */ 39 | enum { 40 | //GM_ASSET_MODE_UNKNOWN = 0, 41 | //GM_ASSET_MODE_RANDOM = 1, 42 | //GM_ASSET_MODE_STREAMING = 2, 43 | GM_ASSET_MODE_BUFFER = 3 44 | }; 45 | 46 | struct gm_asset; 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | /* To avoid assuming the path is specified by the GLIMPSE_ASSETS_ROOT 53 | * environment variable then middleware should set the path with 54 | * this api before opening assets 55 | */ 56 | void 57 | gm_set_assets_root(struct gm_logger *log, const char *root); 58 | 59 | const char * 60 | gm_get_assets_root(void); 61 | 62 | #ifdef USE_ANDROID_ASSET_MANAGER_API 63 | #include 64 | void 65 | gm_android_set_asset_manager(AAssetManager *manager); 66 | #endif 67 | 68 | struct gm_asset * 69 | gm_asset_open(struct gm_logger *log, 70 | const char *path, int mode, char **err); 71 | 72 | const void * 73 | gm_asset_get_buffer(struct gm_asset *asset); 74 | 75 | off_t 76 | gm_asset_get_length(struct gm_asset *asset); 77 | 78 | void 79 | gm_asset_close(struct gm_asset *asset); 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | -------------------------------------------------------------------------------- /src/glimpse_data.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | 31 | #include "half.hpp" 32 | 33 | #include "parson.h" 34 | 35 | struct gm_data_index; 36 | 37 | struct gm_data_index* 38 | gm_data_index_open(struct gm_logger* log, 39 | const char* top_dir, 40 | const char* index_name, 41 | char **err); 42 | 43 | void 44 | gm_data_index_destroy(struct gm_data_index* data_index); 45 | 46 | int 47 | gm_data_index_get_len(struct gm_data_index* data_index); 48 | 49 | const char* 50 | gm_data_index_get_top_dir(struct gm_data_index* data_index); 51 | 52 | JSON_Value* 53 | gm_data_index_get_meta(struct gm_data_index* data_index); 54 | 55 | int 56 | gm_data_index_get_width(struct gm_data_index* data_index); 57 | 58 | int 59 | gm_data_index_get_height(struct gm_data_index* data_index); 60 | 61 | int 62 | gm_data_index_get_n_labels(struct gm_data_index* data_index); 63 | 64 | const char * 65 | gm_data_index_get_frame_path(struct gm_data_index* data_index, int n); 66 | 67 | bool 68 | gm_data_index_foreach(struct gm_data_index* data_index, 69 | bool (*callback)(struct gm_data_index* data_index, 70 | int index, 71 | const char* frame_path, 72 | void* user_data, 73 | char** err), 74 | void* user_data, 75 | char** err); 76 | 77 | bool 78 | gm_data_index_load_joints(struct gm_data_index* data_index, 79 | const char* joint_map_file, 80 | int* out_n_joints, 81 | float** out_joints, 82 | char** err); 83 | 84 | JSON_Value* 85 | gm_data_load_simple(struct gm_logger *log, 86 | const char* data_dir, 87 | const char* index_name, 88 | const char* joint_map_path, 89 | int* out_n_images, 90 | int* out_n_joints, 91 | int* out_width, 92 | int* out_height, 93 | float** out_depth_images, 94 | uint8_t** out_label_images, 95 | float** out_joints, 96 | char** err); 97 | 98 | bool 99 | gm_data_parse_label_map(struct gm_logger* log, 100 | JSON_Value* label_map_js, 101 | int n_expected_labels, 102 | uint8_t* map, 103 | char** err); 104 | 105 | JSON_Value* 106 | gm_data_load_label_map_from_json(struct gm_logger* log, 107 | const char* filename, 108 | uint8_t* map, 109 | char** err); 110 | 111 | -------------------------------------------------------------------------------- /src/glimpse_gl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | 29 | #include "xalloc.h" 30 | #include "glimpse_log.h" 31 | 32 | static unsigned int 33 | load_shader(struct gm_logger *log, 34 | int type, 35 | const char *source, 36 | char **err) 37 | { 38 | GLuint shader = glCreateShader(type); 39 | if (!shader) 40 | return 0; 41 | 42 | glShaderSource(shader, 1, &source, NULL); 43 | glCompileShader(shader); 44 | GLint compiled = 0; 45 | glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled); 46 | 47 | if (!compiled) { 48 | GLint info_len = 0; 49 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_len); 50 | if (info_len) { 51 | char *buf = (char *)malloc(info_len); 52 | if (buf) { 53 | glGetShaderInfoLog(shader, info_len, NULL, buf); 54 | gm_throw(log, err, "Could not compile shader %d:\n%s\n", 55 | type, buf); 56 | free(buf); 57 | } 58 | glDeleteShader(shader); 59 | shader = 0; 60 | } 61 | } 62 | 63 | return shader; 64 | } 65 | 66 | unsigned int 67 | gm_gl_create_program(struct gm_logger *log, 68 | const char *vertex_source, 69 | const char *fragment_source, 70 | char **err) 71 | { 72 | GLuint vertex_shader = load_shader(log, GL_VERTEX_SHADER, vertex_source, err); 73 | if (!vertex_shader) 74 | return 0; 75 | 76 | GLuint fragment_shader = load_shader(log, GL_FRAGMENT_SHADER, fragment_source, err); 77 | if (!fragment_shader) { 78 | glDeleteShader(vertex_shader); 79 | return 0; 80 | } 81 | 82 | GLuint program = glCreateProgram(); 83 | if (!program) { 84 | glDeleteShader(vertex_shader); 85 | glDeleteShader(fragment_shader); 86 | return 0; 87 | } 88 | 89 | glAttachShader(program, vertex_shader); 90 | glAttachShader(program, fragment_shader); 91 | glLinkProgram(program); 92 | GLint link_status = GL_FALSE; 93 | glGetProgramiv(program, GL_LINK_STATUS, &link_status); 94 | if (link_status != GL_TRUE) { 95 | GLint buf_length = 0; 96 | glGetProgramiv(program, GL_INFO_LOG_LENGTH, &buf_length); 97 | if (buf_length) { 98 | char *buf = (char *)malloc(buf_length); 99 | if (buf) { 100 | glGetProgramInfoLog(program, buf_length, NULL, buf); 101 | gm_throw(log, err, "Could not link program:\n%s\n", buf); 102 | free(buf); 103 | } else { 104 | gm_throw(log, err, "Failed to link program: Could not get error log"); 105 | } 106 | } 107 | glDeleteProgram(program); 108 | program = 0; 109 | } 110 | 111 | glDeleteShader(vertex_shader); 112 | glDeleteShader(fragment_shader); 113 | 114 | return program; 115 | } 116 | 117 | 118 | -------------------------------------------------------------------------------- /src/glimpse_gl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "glimpse_log.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | unsigned int 34 | gm_gl_create_program(struct gm_logger *log, 35 | const char *vertex_source, 36 | const char *fragment_source, 37 | char **err); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /src/glimpse_imgui_shell.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | struct gm_imgui_shell; 13 | 14 | // If you want to create your own logger that the shell will use then call this 15 | // api to attach your custom logger to the shell before it's fully 16 | // initialized... (Normally gm_imgui_shell_init will automatically create a 17 | // gm_logger). 18 | void 19 | gm_imgui_shell_preinit_log(struct gm_imgui_shell *shell, 20 | struct gm_logger *log); 21 | 22 | // If you want to override what file the shell opens for logging, use 23 | // this api to set the log's filename 24 | void 25 | gm_imgui_shell_preinit_log_filename(struct gm_imgui_shell *shell, 26 | const char *log_filename); 27 | 28 | // As the shell is initialized it may itself need to read application assets 29 | // (such as loading a default font) and the 'assets root' is normally 30 | // determined automatically according to the platform we are running on. If 31 | // you want to override where assets are loaded from then call this 32 | // before the shell is fully initialized... 33 | void 34 | gm_imgui_shell_preinit_assets_root(struct gm_imgui_shell *shell, 35 | const char *assets_root); 36 | 37 | void 38 | gm_imgui_shell_preinit_log_ready_callback(struct gm_imgui_shell *shell, 39 | void (*callback)(struct gm_imgui_shell *shell, 40 | struct gm_logger *log, 41 | void *user_data), 42 | void *user_data); 43 | 44 | void 45 | gm_imgui_shell_preinit_surface_created_callback(struct gm_imgui_shell *shell, 46 | void (*callback)(struct gm_imgui_shell *shell, 47 | int width, 48 | int height, 49 | void *user_data), 50 | void *user_data); 51 | void 52 | gm_imgui_shell_preinit_surface_resized_callback(struct gm_imgui_shell *shell, 53 | void (*callback)(struct gm_imgui_shell *shell, 54 | int width, 55 | int height, 56 | void *user_data), 57 | void *user_data); 58 | void 59 | gm_imgui_shell_preinit_surface_destroyed_callback(struct gm_imgui_shell *shell, 60 | void (*callback)(struct gm_imgui_shell *shell, 61 | void *user_data), 62 | void *user_data); 63 | void 64 | gm_imgui_shell_preinit_app_focus_callback(struct gm_imgui_shell *shell, 65 | void (*callback)(struct gm_imgui_shell *shell, 66 | bool focused, 67 | void *user_data), 68 | void *user_data); 69 | void 70 | gm_imgui_shell_preinit_mainloop_callback(struct gm_imgui_shell *shell, 71 | void (*callback)(struct gm_imgui_shell *shell, 72 | uint64_t timestamp, 73 | void *user_data), 74 | void *user_data); 75 | void 76 | gm_imgui_shell_preinit_render_callback(struct gm_imgui_shell *shell, 77 | void (*callback)(struct gm_imgui_shell *shell, 78 | uint64_t timestamp, 79 | void *user_data), 80 | void *user_data); 81 | 82 | 83 | // Early on without glimpse_imgui_shell_main() your application should 84 | // complete the initialization of the given shell by calling this api. 85 | // (optionally using any _preinit apis as necessary to override the 86 | // default behaviour of initialization) 87 | bool 88 | gm_imgui_shell_init(struct gm_imgui_shell *shell, 89 | const char *app_name, 90 | const char *app_title, 91 | char **err); 92 | 93 | // Call this to be able to share the same logger as the shell 94 | struct gm_logger * 95 | gm_imgui_shell_get_log(struct gm_imgui_shell *shell); 96 | 97 | // Each application using this imgui shell needs to implement this 98 | // function where it can parse command line arguments (if command 99 | // line arguments aren't applicable for the current platform then 100 | // argc will == 0 and argv may be NULL) 101 | extern void 102 | glimpse_imgui_shell_main(struct gm_imgui_shell *shell, 103 | int argc, 104 | char **argv); 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | -------------------------------------------------------------------------------- /src/glimpse_mem_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | struct gm_mem_pool; 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | struct gm_mem_pool * 34 | mem_pool_alloc(struct gm_logger *log, 35 | const char *name, 36 | unsigned max_size, 37 | void *(*alloc_mem)(struct gm_mem_pool *pool, void *user_data), 38 | void (*free_mem)(struct gm_mem_pool *pool, void *mem, 39 | void *user_data), 40 | void *user_data); 41 | 42 | void 43 | mem_pool_free(struct gm_mem_pool *pool); 44 | 45 | void * 46 | mem_pool_acquire_resource(struct gm_mem_pool *pool); 47 | 48 | void 49 | mem_pool_recycle_resource(struct gm_mem_pool *pool, void *resource); 50 | 51 | void 52 | mem_pool_free_resources(struct gm_mem_pool *pool); 53 | 54 | const char * 55 | mem_pool_get_name(struct gm_mem_pool *pool); 56 | 57 | void 58 | mem_pool_foreach(struct gm_mem_pool *pool, 59 | void (*callback)(struct gm_mem_pool *pool, 60 | void *resource, 61 | void *user_data), 62 | void *user_data); 63 | 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | -------------------------------------------------------------------------------- /src/glimpse_mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 Intel Corporation. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining 5 | * a copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 19 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 20 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | */ 23 | 24 | #include 25 | 26 | #include "glimpse_mutex.h" 27 | 28 | #ifndef _WIN32 29 | 30 | #include 31 | #include 32 | 33 | void 34 | gm_mutex_init(gm_mutex_t *mutex) 35 | { 36 | pthread_mutex_t *m = (pthread_mutex_t *)mutex; 37 | pthread_mutexattr_t attr; 38 | 39 | /* NB: Windows CriticalSection and Mutex APIs don't support non-recursive 40 | * semantics, so for consistency... 41 | */ 42 | pthread_mutexattr_init(&attr); 43 | pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); 44 | 45 | pthread_mutex_init(m, NULL); 46 | } 47 | 48 | void 49 | gm_mutex_destroy(gm_mutex_t *mutex) 50 | { 51 | pthread_mutex_t *m = (pthread_mutex_t *)mutex; 52 | pthread_mutex_destroy(m); 53 | } 54 | 55 | void 56 | gm_mutex_lock(gm_mutex_t *mutex) 57 | { 58 | pthread_mutex_t *m = (pthread_mutex_t *)mutex; 59 | pthread_mutex_lock(m); 60 | } 61 | 62 | void 63 | gm_mutex_unlock(gm_mutex_t *mutex) 64 | { 65 | pthread_mutex_t *m = (pthread_mutex_t *)mutex; 66 | pthread_mutex_unlock(m); 67 | } 68 | 69 | bool 70 | gm_mutex_trylock(gm_mutex_t *mutex) 71 | { 72 | pthread_mutex_t *m = (pthread_mutex_t *)mutex; 73 | int ret = pthread_mutex_trylock(m); 74 | 75 | if (ret == 0) 76 | return true; 77 | else if (ret == EBUSY) 78 | return false; 79 | else { 80 | return false; 81 | } 82 | } 83 | 84 | #else 85 | 86 | void 87 | gm_mutex_init(gm_mutex_t *mutex) 88 | { 89 | InitializeCriticalSectionAndSpinCount((CRITICAL_SECTION *)mutex, 90 | 2000); 91 | } 92 | 93 | void 94 | gm_mutex_destroy(gm_mutex_t *mutex) 95 | { 96 | DeleteCriticalSection((CRITICAL_SECTION *)mutex); 97 | } 98 | 99 | void 100 | gm_mutex_lock(gm_mutex_t *mutex) 101 | { 102 | EnterCriticalSection((CRITICAL_SECTION *)mutex); 103 | } 104 | 105 | void 106 | gm_mutex_unlock(gm_mutex_t *mutex) 107 | { 108 | LeaveCriticalSection((CRITICAL_SECTION *)mutex); 109 | } 110 | 111 | bool 112 | gm_mutex_trylock(gm_mutex_t *mutex) 113 | { 114 | return TryEnterCriticalSection((CRITICAL_SECTION *)mutex); 115 | } 116 | 117 | #endif 118 | -------------------------------------------------------------------------------- /src/glimpse_mutex.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #ifdef _WIN32 5 | #include 6 | typedef CRITICAL_SECTION gm_mutex_t; 7 | #else 8 | #include 9 | typedef pthread_mutex_t gm_mutex_t; 10 | #endif 11 | 12 | /* N.B This is a recursive mutex (since those are the only semantics 13 | * supported by Windows' CriticalSection or Mutex APIs 14 | */ 15 | void gm_mutex_init(gm_mutex_t *mutex); 16 | void gm_mutex_destroy(gm_mutex_t *mutex); 17 | void gm_mutex_lock(gm_mutex_t *mutex); 18 | void gm_mutex_unlock(gm_mutex_t *mutex); 19 | bool gm_mutex_trylock(gm_mutex_t *mutex); 20 | -------------------------------------------------------------------------------- /src/glimpse_os.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | #if defined(__unix__) || defined(__APPLE__) 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #elif defined(_WIN32) 12 | #include 13 | #include 14 | #endif 15 | 16 | #include "glimpse_os.h" 17 | #include "glimpse_log.h" 18 | 19 | uint64_t 20 | gm_os_get_time(void) 21 | { 22 | #if defined(__unix__) || defined(__APPLE__) 23 | struct timespec ts; 24 | clock_gettime(CLOCK_MONOTONIC, &ts); 25 | 26 | return ((uint64_t)ts.tv_sec) * 1000000000ULL + (uint64_t)ts.tv_nsec; 27 | #elif defined(_WIN32) 28 | static double qpc_scale = 0; 29 | LARGE_INTEGER li; 30 | 31 | if (!qpc_scale) { 32 | QueryPerformanceFrequency(&li); 33 | qpc_scale = 1e9 / li.QuadPart; 34 | } 35 | QueryPerformanceCounter(&li); 36 | return li.QuadPart * qpc_scale; 37 | #endif 38 | } 39 | 40 | bool 41 | gm_os_mkdir(struct gm_logger *log, const char *path, char **err) 42 | { 43 | #if defined(__unix__) || defined(__APPLE__) 44 | int status = mkdir(path, 0777); 45 | if (status < 0 && errno != EEXIST) { 46 | gm_throw(log, err, "Failed to make directory %s: %s", 47 | path, strerror(errno)); 48 | return false; 49 | } 50 | return true; 51 | #elif defined(_WIN32) 52 | int status = _mkdir(path); 53 | if (status < 0 && errno != EEXIST) { 54 | gm_throw(log, err, "Failed to make directory %s: %s", 55 | path, strerror(errno)); 56 | return false; 57 | } 58 | return true; 59 | #endif 60 | } 61 | -------------------------------------------------------------------------------- /src/glimpse_os.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | // Convenience for including the right header for alloca... 6 | #ifdef _WIN32 7 | #include 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | #include "glimpse_log.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | uint64_t 20 | gm_os_get_time(void); 21 | 22 | bool 23 | gm_os_mkdir(struct gm_logger *log, const char *path, char **err); 24 | 25 | #if defined(__unix__) || defined(__APPLE__) 26 | 27 | #include 28 | 29 | #define gm_os_usleep(X) usleep(X) 30 | 31 | #elif defined(_WIN32) 32 | 33 | static inline int 34 | gm_os_usleep(unsigned long useconds) 35 | { 36 | if (useconds >= 1000000) { 37 | errno = EINVAL; 38 | return -1; 39 | } else { 40 | Sleep(useconds / 1000); 41 | return 0; 42 | } 43 | } 44 | 45 | #endif 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | -------------------------------------------------------------------------------- /src/glimpse_properties.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "glimpse_properties.h" 26 | #include "parson.h" 27 | 28 | void 29 | gm_props_from_json(struct gm_logger *log, 30 | struct gm_ui_properties *props, 31 | JSON_Value *props_object) 32 | { 33 | JSON_Object *config = json_object(props_object); 34 | 35 | for (size_t i = 0; i < json_object_get_count(config); ++i) { 36 | const char *name = json_object_get_name(config, i); 37 | 38 | for (int p = 0; p < props->n_properties; ++p) { 39 | struct gm_ui_property *prop = &props->properties[p]; 40 | 41 | if (prop->read_only) 42 | continue; 43 | 44 | if (strcmp(name, prop->name) != 0) 45 | continue; 46 | 47 | JSON_Value *value = 48 | json_object_get_value_at(config, i); 49 | 50 | switch (prop->type) { 51 | case GM_PROPERTY_INT: 52 | gm_prop_set_int(prop, json_value_get_number(value)); 53 | break; 54 | case GM_PROPERTY_ENUM: 55 | gm_prop_set_enum_by_name(prop, json_value_get_string(value)); 56 | break; 57 | case GM_PROPERTY_BOOL: 58 | gm_prop_set_bool(prop, json_value_get_boolean(value)); 59 | break; 60 | case GM_PROPERTY_FLOAT: 61 | gm_prop_set_float(prop, json_value_get_number(value)); 62 | break; 63 | case GM_PROPERTY_FLOAT_VEC3: { 64 | JSON_Array *array = json_value_get_array(value); 65 | gm_assert(log, json_array_get_count(array) == 3, 66 | "Invalid array size for vec3 in config"); 67 | float vec3[3]; 68 | for (int j = 0; j < 3; ++j) 69 | vec3[j] = json_array_get_number(array, j); 70 | gm_prop_set_vec3(prop, vec3); 71 | break; 72 | } 73 | case GM_PROPERTY_SWITCH: 74 | // SKIP 75 | break; 76 | case GM_PROPERTY_STRING: 77 | gm_prop_set_string(prop, json_value_get_string(value)); 78 | break; 79 | } 80 | } 81 | } 82 | } 83 | 84 | void 85 | gm_props_to_json(struct gm_logger *log, 86 | struct gm_ui_properties *props, 87 | JSON_Value *props_object) 88 | { 89 | JSON_Object *config = json_object(props_object); 90 | 91 | for (int p = 0; p < props->n_properties; ++p) { 92 | struct gm_ui_property *prop = &props->properties[p]; 93 | 94 | if (prop->read_only) 95 | continue; 96 | 97 | switch (prop->type) { 98 | case GM_PROPERTY_INT: 99 | json_object_set_number(config, prop->name, 100 | gm_prop_get_int(prop)); 101 | break; 102 | case GM_PROPERTY_ENUM: { 103 | int val = gm_prop_get_enum(prop); 104 | for (int i = 0; i < prop->enum_state.n_enumerants; i++) { 105 | const struct gm_ui_enumerant *enumerant = 106 | &prop->enum_state.enumerants[i]; 107 | if (enumerant->val == val) { 108 | json_object_set_string(config, prop->name, enumerant->name); 109 | break; 110 | } 111 | } 112 | break; 113 | } 114 | case GM_PROPERTY_BOOL: 115 | json_object_set_boolean(config, prop->name, gm_prop_get_bool(prop)); 116 | break; 117 | case GM_PROPERTY_FLOAT: 118 | json_object_set_number(config, prop->name, gm_prop_get_float(prop)); 119 | break; 120 | case GM_PROPERTY_FLOAT_VEC3: { 121 | JSON_Value *array_val = json_value_init_array(); 122 | JSON_Array *array = json_array(array_val); 123 | float vec3[3]; 124 | gm_prop_get_vec3(prop, vec3); 125 | for (int i = 0; i < 3; ++i) { 126 | json_array_append_number(array, vec3[i]); 127 | } 128 | json_object_set_value(config, prop->name, array_val); 129 | break; 130 | } 131 | case GM_PROPERTY_SWITCH: 132 | // SKIP 133 | break; 134 | case GM_PROPERTY_STRING: 135 | json_object_set_string(config, prop->name, gm_prop_get_string(prop)); 136 | break; 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/glimpse_rdt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include 28 | #include 29 | 30 | struct gm_rdt_context; 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | struct gm_rdt_context * 37 | gm_rdt_context_new(struct gm_logger *log); 38 | 39 | struct gm_ui_properties * 40 | gm_rdt_context_get_ui_properties(struct gm_rdt_context *ctx); 41 | 42 | bool 43 | gm_rdt_context_train(struct gm_rdt_context *ctx, char **err); 44 | 45 | void 46 | gm_rdt_context_destroy(struct gm_rdt_context *ctx); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /src/glimpse_record.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include 28 | #include 29 | #include "glimpse_log.h" 30 | #include "glimpse_context.h" 31 | #include "glimpse_device.h" 32 | 33 | struct gm_recording; 34 | 35 | #ifndef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | struct gm_recording * 40 | gm_recording_init(struct gm_logger *log, 41 | struct gm_device *device, 42 | const char *recordings_path, 43 | const char *rel_path, 44 | bool overwrite, 45 | uint64_t max_io_buffer_size, 46 | char **err); 47 | 48 | void gm_recording_append_frame(struct gm_recording *recording, 49 | struct gm_frame *frame); 50 | 51 | void 52 | gm_recording_stop(struct gm_recording *recording); 53 | 54 | bool 55 | gm_recording_is_stopped(struct gm_recording *recording); 56 | 57 | bool 58 | gm_recording_is_async_io_finished(struct gm_recording *recording); 59 | 60 | uint64_t 61 | gm_recording_get_io_buffer_size(struct gm_recording *recording); 62 | 63 | uint64_t 64 | gm_recording_get_max_io_buffer_size(struct gm_recording *recording); 65 | 66 | bool 67 | gm_recording_close(struct gm_recording *recording); 68 | 69 | 70 | #ifndef __cplusplus 71 | } 72 | #endif 73 | -------------------------------------------------------------------------------- /src/glimpse_shell_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct shell_test_app 6 | { 7 | struct gm_imgui_shell *shell; 8 | struct gm_logger *log; 9 | }; 10 | 11 | static void 12 | on_log_ready_cb(struct gm_imgui_shell *shell, 13 | struct gm_logger *log, 14 | void *user_data) 15 | { 16 | struct shell_test_app *app = user_data; 17 | 18 | // Use the shell's log for application logging too 19 | app->log = log; 20 | } 21 | 22 | static void 23 | on_surface_created_resized_cb(struct gm_imgui_shell *shell, 24 | int width, 25 | int height, 26 | void *user_data) 27 | { 28 | struct shell_test_app *app = user_data; 29 | 30 | gm_debug(app->log, "Surface Create/Resize Callback"); 31 | } 32 | 33 | static void 34 | on_surface_destroyed_cb(struct gm_imgui_shell *shell, 35 | void *user_data) 36 | { 37 | struct shell_test_app *app = user_data; 38 | 39 | gm_debug(app->log, "Surface Destroyed Callback"); 40 | } 41 | 42 | static void 43 | on_mainloop_cb(struct gm_imgui_shell *shell, 44 | uint64_t timestamp, 45 | void *user_data) 46 | { 47 | struct shell_test_app *app = user_data; 48 | 49 | gm_debug(app->log, "Mainloop Callback"); 50 | } 51 | 52 | static void 53 | on_render_cb(struct gm_imgui_shell *shell, 54 | uint64_t timestamp, 55 | void *user_data) 56 | { 57 | struct shell_test_app *app = user_data; 58 | 59 | gm_debug(app->log, "Render Callback"); 60 | } 61 | 62 | void 63 | glimpse_imgui_shell_main(struct gm_imgui_shell *shell, 64 | int argc, 65 | char **argv) 66 | { 67 | struct shell_test_app *app = xcalloc(1, sizeof(*app)); 68 | 69 | gm_imgui_shell_preinit_log_ready_callback(shell, 70 | on_log_ready_cb, 71 | app); 72 | 73 | gm_imgui_shell_preinit_surface_created_callback(shell, 74 | on_surface_created_resized_cb, 75 | app); 76 | gm_imgui_shell_preinit_surface_resized_callback(shell, 77 | on_surface_created_resized_cb, 78 | app); 79 | gm_imgui_shell_preinit_surface_destroyed_callback(shell, 80 | on_surface_destroyed_cb, 81 | app); 82 | gm_imgui_shell_preinit_mainloop_callback(shell, 83 | on_mainloop_cb, 84 | app); 85 | gm_imgui_shell_preinit_render_callback(shell, 86 | on_render_cb, 87 | app); 88 | 89 | gm_imgui_shell_init(shell, 90 | "glimpse_shell_test", 91 | "Glimpse Shell Test", 92 | NULL); // abort on error 93 | } 94 | -------------------------------------------------------------------------------- /src/glimpse_target.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "glimpse_log.h" 28 | #include "glimpse_context.h" 29 | 30 | struct gm_target; 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | struct gm_target * 37 | gm_target_new(struct gm_context *ctx, 38 | struct gm_logger *logger); 39 | 40 | struct gm_target * 41 | gm_target_new_from_file(struct gm_context *ctx, 42 | struct gm_logger *logger, 43 | const char *index_asset_name, 44 | char **err); 45 | 46 | int 47 | gm_target_get_n_frames(struct gm_target *target); 48 | 49 | int 50 | gm_target_get_frame(struct gm_target *target); 51 | 52 | void 53 | gm_target_set_frame(struct gm_target *target, int frame); 54 | 55 | struct gm_skeleton * 56 | gm_target_get_skeleton(struct gm_target *target); 57 | 58 | int 59 | gm_target_get_anchor_joint(struct gm_target *target); 60 | 61 | uint64_t 62 | gm_target_get_timestamp(struct gm_target *target); 63 | 64 | void 65 | gm_target_free(struct gm_target *target); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | -------------------------------------------------------------------------------- /src/glimpse_viewer_android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/glimpse_viewer_android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Glimpse Viewer 4 | 5 | -------------------------------------------------------------------------------- /src/image_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef enum { 37 | SUCCESS, // Everything went ok 38 | BAD_SPEC, // Invalid or unhandled specification 39 | NON_CONFORMANT, // File does not conform to given specification 40 | BAD_FORMAT, // File is not of the expected format 41 | IO_ERR, // File IO error 42 | PNG_ERR, // libpng error 43 | EXR_ERR // tinyexr error 44 | } IUReturnCode; 45 | 46 | typedef enum { 47 | IU_FORMAT_ANY, 48 | IU_FORMAT_U8, 49 | IU_FORMAT_U32, 50 | IU_FORMAT_HALF, 51 | IU_FORMAT_FLOAT, 52 | } IUImageFormat; 53 | 54 | typedef struct { 55 | int width; // Expected width, or 0 56 | int height; // Expected height, or 0 57 | 58 | IUImageFormat format; 59 | } IUImageSpec; 60 | 61 | // If output points to a non-NULL address, it is assumed to be pre-allocated, 62 | // otherwise it will be allocated with xmalloc. 63 | 64 | // If spec is non-NULL, it will be filled with the specification of the loaded 65 | // file. Any non-zero values are used as file validation. 66 | 67 | IUReturnCode iu_read_png_from_file(const char* filename, 68 | IUImageSpec* spec, 69 | uint8_t** output, 70 | void** pal_output, 71 | int* pal_size); 72 | 73 | IUReturnCode iu_read_png_from_memory(uint8_t* buffer, 74 | size_t len, 75 | IUImageSpec* spec, 76 | uint8_t** output, 77 | void** pal_output, 78 | int* pal_size); 79 | 80 | IUReturnCode iu_verify_png_from_memory(uint8_t* buffer, 81 | size_t len, 82 | IUImageSpec* spec); 83 | 84 | IUReturnCode iu_write_png_to_file(const char* filename, 85 | IUImageSpec* spec, 86 | void* data, 87 | void* pal, 88 | int pal_size); 89 | 90 | IUReturnCode iu_read_exr_from_file(const char* filename, 91 | IUImageSpec* spec, 92 | void** output); 93 | 94 | IUReturnCode iu_read_exr_from_memory(uint8_t* buffer, 95 | size_t len, 96 | IUImageSpec* spec, 97 | void** output); 98 | 99 | IUReturnCode iu_write_exr_to_file(const char* filename, 100 | IUImageSpec* spec, 101 | void* data, 102 | IUImageFormat format); 103 | 104 | const char *iu_code_to_string(IUReturnCode code); 105 | 106 | #ifdef __cplusplus 107 | }; 108 | #endif 109 | -------------------------------------------------------------------------------- /src/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating imgui, or maintain a patch/branch with your modifications to imconfig.h) 7 | // B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h" 8 | // If you do so you need to make sure that configuration settings are defined consistently _everywhere_ dear imgui is used, which include 9 | // the imgui*.cpp files but also _any_ of your code that uses imgui. This is because some compile-time options have an affect on data structures. 10 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 11 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using. 12 | //----------------------------------------------------------------------------- 13 | 14 | #pragma once 15 | 16 | //---- Define assertion handler. Defaults to calling assert(). 17 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 18 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 19 | 20 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows. 21 | //#define IMGUI_API __declspec( dllexport ) 22 | //#define IMGUI_API __declspec( dllimport ) 23 | 24 | //---- Don't define obsolete functions/enums names. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. 25 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 26 | 27 | //---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty) 28 | //---- It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp. 29 | //#define IMGUI_DISABLE_DEMO_WINDOWS 30 | 31 | //---- Don't implement some functions to reduce linkage requirements. 32 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. 33 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow. 34 | //#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself if you don't want to link with vsnprintf. 35 | //#define IMGUI_DISABLE_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 wrapper so you can implement them yourself. Declare your prototypes in imconfig.h. 36 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 37 | 38 | //---- Include imgui_user.h at the end of imgui.h as a convenience 39 | //#define IMGUI_INCLUDE_IMGUI_USER_H 40 | 41 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 42 | //#define IMGUI_USE_BGRA_PACKED_COLOR 43 | 44 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 45 | // By default the embedded implementations are declared static and not available outside of imgui cpp files. 46 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 47 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 48 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 49 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 50 | 51 | //---- Define constructor and implicit cast operators to convert back<>forth from your math types and ImVec2/ImVec4. 52 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 53 | /* 54 | #define IM_VEC2_CLASS_EXTRA \ 55 | ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ 56 | operator MyVec2() const { return MyVec2(x,y); } 57 | 58 | #define IM_VEC4_CLASS_EXTRA \ 59 | ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ 60 | operator MyVec4() const { return MyVec4(x,y,z,w); } 61 | */ 62 | 63 | //---- Use 32-bit vertex indices (default is 16-bit) to allow meshes with more than 64K vertices. Render function needs to support it. 64 | //#define ImDrawIdx unsigned int 65 | 66 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 67 | /* 68 | namespace ImGui 69 | { 70 | void MyFunction(const char* name, const MyMatrix44& v); 71 | } 72 | */ 73 | -------------------------------------------------------------------------------- /src/imgui/imgui_impl_glfm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // ImGui GLFM binding 4 | // In this binding, ImTextureID is used to store an OpenGL 'GLuint' texture identifier. Read the FAQ about ImTextureID in imgui.cpp. 5 | // (GLFM is a cross-platform general purpose library for handling surfaces, inputs, OpenGL graphics context creation, etc. on mobile devices) 6 | // (epoxy is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.) 7 | 8 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 9 | // If you use this binding you'll need to call 4 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXXX_NewFrame(), ImGui::Render() and ImGui_ImplXXXX_Shutdown(). 10 | // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp. 11 | // https://github.com/ocornut/imgui 12 | 13 | // dear imgui: Platform Binding for GLFM 14 | // This needs to be used along with a Renderer (e.g. OpenGL3) 15 | // (Info: GLFM is a cross-platform general purpose library for handling windows, inputs, OpenGL ES/ graphics context creation, etc.) 16 | 17 | // Implemented features: 18 | // [ ] Platform: Clipboard support. 19 | // [ ] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 20 | // [x] Platform: Mouse cursor shape and visibility. 21 | // [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE). 22 | 23 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 24 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 25 | // https://github.com/ocornut/imgui 26 | 27 | struct GLFMDisplay; 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | IMGUI_IMPL_API bool ImGui_ImplGlfm_Init(GLFMDisplay* display, bool install_callbacks); 34 | IMGUI_IMPL_API void ImGui_ImplGlfm_Shutdown(GLFMDisplay* display); 35 | IMGUI_IMPL_API void ImGui_ImplGlfm_NewFrame(GLFMDisplay* display, double frametime); 36 | 37 | // GLFM callbacks (installed by default if you enable 'install_callbacks' during initialization) 38 | // Provided here if you want to chain callbacks. 39 | // You can also handle inputs yourself and use those as a reference. 40 | IMGUI_IMPL_API bool ImGui_ImplGlfm_TouchCallback(GLFMDisplay* display, int touch, int phase, double x, double y); 41 | IMGUI_IMPL_API bool ImGui_ImplGlfm_KeyCallback(GLFMDisplay *display, int keyCode, int action, int modifiers); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /src/imgui/imgui_impl_glfw.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Binding for GLFW 2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan..) 3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) 4 | 5 | // Implemented features: 6 | // [X] Platform: Clipboard support. 7 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 8 | // [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. FIXME: 3 cursors types are missing from GLFW. 9 | // [X] Platform: Keyboard arrays indexed using GLFW_KEY_* codes, e.g. ImGui::IsKeyPressed(GLFW_KEY_SPACE). 10 | 11 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 12 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 13 | // https://github.com/ocornut/imgui 14 | 15 | // About GLSL version: 16 | // The 'glsl_version' initialization parameter defaults to "#version 150" if NULL. 17 | // Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! 18 | 19 | #pragma once 20 | 21 | struct GLFWwindow; 22 | 23 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 24 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 25 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 26 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 27 | 28 | // InitXXX function with 'install_callbacks=true': install GLFW callbacks. They will call user's previously installed callbacks, if any. 29 | // InitXXX function with 'install_callbacks=false': do not install GLFW callbacks. You will need to call them yourself from your own GLFW callbacks. 30 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 31 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 32 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 33 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 34 | -------------------------------------------------------------------------------- /src/imgui/imgui_impl_opengl3.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer for OpenGL3 / OpenGL ES2 / OpenGL ES3 (modern OpenGL with shaders / programmatic pipeline) 2 | // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..) 3 | // (Note: We are using GL3W as a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc..) 4 | 5 | // Implemented features: 6 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID in imgui.cpp. 7 | 8 | // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this. 9 | // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp. 10 | // https://github.com/ocornut/imgui 11 | 12 | // About OpenGL function loaders: 13 | // About OpenGL function loaders: modern OpenGL doesn't have a standard header file and requires individual function pointers to be loaded manually. 14 | // Helper libraries are often used for this purpose! Here we are supporting a few common ones: gl3w, glew, glad. 15 | // You may use another loader/header of your choice (glext, glLoadGen, etc.), or chose to manually implement your own. 16 | 17 | // About GLSL version: 18 | // The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string. 19 | // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" 20 | // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. 21 | 22 | #pragma once 23 | 24 | // Set default OpenGL loader to be gl3w 25 | #if !defined(IMGUI_IMPL_OPENGL_LOADER_GL3W) \ 26 | && !defined(IMGUI_IMPL_OPENGL_LOADER_GLEW) \ 27 | && !defined(IMGUI_IMPL_OPENGL_LOADER_GLAD) \ 28 | && !defined(IMGUI_IMPL_OPENGL_LOADER_CUSTOM) 29 | #define IMGUI_IMPL_OPENGL_LOADER_GL3W 30 | #endif 31 | 32 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); 33 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); 34 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); 35 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); 36 | 37 | // Called by Init/NewFrame/Shutdown 38 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); 39 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture(); 40 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects(); 41 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); 42 | -------------------------------------------------------------------------------- /src/imgui/profiler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "timer.h" 4 | 5 | #define ProfileInitialize(isPaused, commandHandler) ImGuiControl::globalInstance.Initialize(isPaused, commandHandler) 6 | #define ProfileShutdown() ImGuiControl::globalInstance.Shutdown() 7 | #define ProfileNewFrame() ImGuiControl::globalInstance.NewFrame() 8 | #define ProfileDrawUI() ImGuiControl::globalInstance.DrawUI() 9 | 10 | #define ProfileInitThread() ImGuiControl::globalInstance.InitThreadInternal() 11 | #define ProfileFinishThread() ImGuiControl::globalInstance.FinishThreadInternal() 12 | 13 | #define ProfilePushSection_1(x) ImGuiControl::globalInstance.PushSectionInternal( #x, 0x00000000, __FILE__, __LINE__ ) 14 | #define ProfilePushSection_2(x,y) ImGuiControl::globalInstance.PushSectionInternal( #x, y, __FILE__, __LINE__ ) 15 | #define ProfilePushSection_X(x,y,z,...) z 16 | 17 | #define ProfilePushSection_FUNC_RECOMPOSER(argsWithParentheses) ProfilePushSection_X argsWithParentheses 18 | #define ProfilePushSection_CHOOSE_FROM_ARG_COUNT(...) ProfilePushSection_FUNC_RECOMPOSER((__VA_ARGS__, ProfilePushSection_2, ProfilePushSection_1, )) 19 | #define ProfilePushSection_MACRO_CHOOSER(...) ProfilePushSection_CHOOSE_FROM_ARG_COUNT(__VA_ARGS__ ()) 20 | #define ProfilePushSection(...) ProfilePushSection_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__) 21 | 22 | #define ProfilePopSection() gProf.PopSectionInternal() 23 | 24 | #define ProfileScopedSection_1(x) ImGuiControl::ProfileScope S##x__LINE__( #x, 0x00000000, __FILE__, __LINE__ ) 25 | #define ProfileScopedSection_2(x,y) ImGuiControl::ProfileScope S##x__LINE__( #x, y, __FILE__, __LINE__ ) 26 | #define ProfileScopedSection_X(x,y,z,...) z 27 | #define ProfileScopedSection_FUNC_RECOMPOSER(argsWithParentheses) ProfileScopedSection_X argsWithParentheses 28 | #define ProfileScopedSection_CHOOSE_FROM_ARG_COUNT(...) ProfileScopedSection_FUNC_RECOMPOSER((__VA_ARGS__, ProfileScopedSection_2, ProfileScopedSection_1, )) 29 | #define ProfileScopedSection_MACRO_CHOOSER(...) ProfileScopedSection_CHOOSE_FROM_ARG_COUNT(__VA_ARGS__ ()) 30 | #define ProfileScopedSection(...) ProfileScopedSection_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__) 31 | 32 | #define ProfileFunction0() ImGuiControl::ProfileScope S##__LINE__( __FUNCTION__, 0x00000000, __FILE__, __LINE__ ) 33 | #define ProfileFunction1(x) ImGuiControl::ProfileScope S##__LINE__( __FUNCTION__, x, __FILE__, __LINE__ ) 34 | #define ProfileFunction2(x, y) ImGuiControl::ProfileScope S##__LINE__( x, y, __FILE__, __LINE__ ) 35 | 36 | 37 | namespace ImGuiControl 38 | { 39 | class Profiler 40 | { 41 | public: 42 | static const int MaxThreads = 4; 43 | static const int MaxFrames = 600; 44 | static const int MaxSections = 2000; 45 | 46 | enum Color : unsigned int 47 | { 48 | Yellow = 0xFF3594B7, 49 | Red = 0xFF3945D5, 50 | Blue = 0xFFC55344, 51 | Green = 0xFF4C8F00, 52 | Purple = 0xFF8B377A, 53 | Dark = 0xFF222222, 54 | }; 55 | 56 | void Initialize(bool* isPaused, void (*setPause)(bool)); 57 | void Shutdown(); 58 | void NewFrame(); 59 | void InitThreadInternal(); 60 | void FinishThreadInternal(); 61 | void PushSectionInternal(const char* sectionName, unsigned int color, const char* fileName, int line); 62 | void PopSectionInternal(); 63 | 64 | void DrawUI(); 65 | inline void LockCriticalSection2() {} 66 | inline void UnLockCriticalSection2() {} 67 | 68 | inline bool IsPaused() { return m_isPausedPtr != nullptr && *m_isPausedPtr; } 69 | inline void SetPause(bool value) { if (m_setPause != nullptr) { m_setPause(value); } } 70 | 71 | struct Section 72 | { 73 | const char* name; 74 | const char* fileName; 75 | int line; 76 | unsigned int color; 77 | int callStackDepth; 78 | double startTime; 79 | double endTime; 80 | int parentSectionIndex; 81 | }; 82 | 83 | struct Frame 84 | { 85 | int index; 86 | double startTime; 87 | double endTime; 88 | }; 89 | 90 | struct Thread 91 | { 92 | bool initialized; 93 | int callStackDepth; 94 | int sectionsCount; 95 | int sectionIndex; 96 | Section sections[MaxSections]; 97 | int activeSectionIndex; 98 | }; 99 | 100 | Timer m_timer; 101 | Frame m_frames[MaxFrames]; 102 | int m_frameCount; 103 | int m_frameIndex; 104 | Thread m_threads[MaxThreads]; 105 | int m_threadIndex; 106 | bool* m_isPausedPtr; 107 | void (*m_setPause)(bool); 108 | 109 | // Ui 110 | double m_timeOffset; 111 | double m_timeDuration; 112 | bool m_isWindowOpen; 113 | float m_frameAreaMaxDuration; 114 | int m_frameSelectionStart; 115 | int m_frameSelectionEnd; 116 | double m_sectionAreaDurationWhenZoomStarted; 117 | 118 | private: 119 | void RefreshFrameSelection(double recordsMaxTime); 120 | }; 121 | 122 | extern Profiler globalInstance; 123 | 124 | struct ProfileScope 125 | { 126 | ProfileScope(const char* name, unsigned int color, const char *fileName, int line) 127 | { 128 | globalInstance.PushSectionInternal(name, color, fileName, line); 129 | } 130 | 131 | ~ProfileScope() 132 | { 133 | globalInstance.PopSectionInternal(); 134 | } 135 | }; 136 | } 137 | 138 | -------------------------------------------------------------------------------- /src/imgui/timer.cpp: -------------------------------------------------------------------------------- 1 | #include "timer.h" 2 | 3 | using namespace ImGuiControl; 4 | 5 | #if defined(_WIN32) 6 | 7 | double Timer::s_frequency = 0.0f; 8 | 9 | #ifndef WIN32_LEAN_AND_MEAN 10 | #define WIN32_LEAN_AND_MEAN 11 | #endif 12 | 13 | #include 14 | 15 | Timer::Timer() 16 | { 17 | if (s_frequency == 0.0f) 18 | { 19 | QueryPerformanceFrequency((LARGE_INTEGER*)&s_frequency); 20 | } 21 | 22 | QueryPerformanceCounter((LARGE_INTEGER*)&m_start); 23 | } 24 | 25 | void Timer::Reset() 26 | { 27 | QueryPerformanceCounter((LARGE_INTEGER*)&m_start); 28 | } 29 | 30 | double Timer::GetTime() const 31 | { 32 | double counter; 33 | QueryPerformanceCounter((LARGE_INTEGER*)&counter); 34 | counter = (counter - m_start) / s_frequency; 35 | return counter; 36 | } 37 | 38 | float Timer::GetMilliseconds() const 39 | { 40 | double counter; 41 | QueryPerformanceCounter((LARGE_INTEGER*)&counter); 42 | float ms = (float)(1000.0f * (counter - m_start) / s_frequency); 43 | return ms; 44 | } 45 | 46 | #elif defined(__linux__) 47 | 48 | #include 49 | #include 50 | 51 | Timer::Timer() 52 | { 53 | Reset(); 54 | } 55 | 56 | void Timer::Reset() 57 | { 58 | struct timespec ts; 59 | clock_gettime(CLOCK_MONOTONIC, &ts); 60 | 61 | m_start = ((uint64_t)ts.tv_sec) * 1000000000ULL + (uint64_t)ts.tv_nsec; 62 | } 63 | 64 | float Timer::GetMilliseconds() const 65 | { 66 | struct timespec ts; 67 | clock_gettime(CLOCK_MONOTONIC, &ts); 68 | 69 | uint64_t end = ((uint64_t)ts.tv_sec) * 1000000000ULL + (uint64_t)ts.tv_nsec; 70 | uint64_t duration = end - m_start; 71 | 72 | return duration / 1000000.0f; 73 | } 74 | 75 | #elif defined (__APPLE__) 76 | 77 | #include 78 | #include 79 | #include 80 | #include 81 | 82 | static double mach_abs_time_scale; 83 | 84 | Timer::Timer() 85 | { 86 | Reset(); 87 | } 88 | 89 | void Timer::Reset() 90 | { 91 | if (!mach_abs_time_scale) { 92 | mach_timebase_info_data_t timebase; 93 | 94 | mach_timebase_info(&timebase); 95 | mach_abs_time_scale = timebase.numer / timebase.denom; 96 | } 97 | 98 | m_start = mach_absolute_time() * mach_abs_time_scale; 99 | } 100 | 101 | float Timer::GetMilliseconds() const 102 | { 103 | uint64_t end = mach_absolute_time() * mach_abs_time_scale; 104 | uint64_t duration = end - m_start; 105 | 106 | return duration / 1000000.0f; 107 | } 108 | 109 | #else 110 | 111 | Timer::Timer() 112 | { 113 | } 114 | 115 | void Timer::Reset() 116 | { 117 | } 118 | 119 | float Timer::GetMilliseconds() const 120 | { 121 | return 0.0f; 122 | } 123 | 124 | #endif 125 | -------------------------------------------------------------------------------- /src/imgui/timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace ImGuiControl 6 | { 7 | class Timer 8 | { 9 | public: 10 | Timer(); 11 | void Reset(); 12 | double GetTime() const; 13 | float GetMilliseconds() const; 14 | 15 | private: 16 | #if defined(_WIN32) 17 | double m_start; 18 | static double s_frequency; 19 | #elif defined(__linux__) 20 | uint64_t m_start; 21 | #elif defined (__APPLE__) 22 | uint64_t m_start; 23 | #endif 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /src/infer_labels.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include 28 | #include 29 | 30 | #include "rdt_tree.h" 31 | 32 | #define HUGE_DEPTH 1000.f 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | float* infer_labels(struct gm_logger* log, 39 | RDTree** forest, 40 | int n_trees, 41 | float* depth_image, 42 | int width, 43 | int height, 44 | float* out_labels, 45 | bool use_threads, 46 | bool flip_label_mapping); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /src/ios_utils.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "glimpse_properties.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | char * 11 | ios_util_get_documents_path(void); 12 | 13 | char * 14 | ios_util_get_resources_path(void); 15 | 16 | void 17 | ios_log(const char *msg); 18 | 19 | enum gm_rotation 20 | ios_get_device_rotation(void); 21 | 22 | void 23 | ios_begin_generating_device_orientation_notifications(void); 24 | 25 | void 26 | ios_end_generating_device_orientation_notifications(void); 27 | 28 | struct ios_av_session; 29 | 30 | enum ios_av_device_type 31 | { 32 | IOS_AV_DEVICE_BUILTIN_TRUEDEPTH_CAMERA_FRONT, 33 | IOS_AV_DEVICE_BUILTIN_DUAL_CAMERA_BACK, 34 | }; 35 | 36 | struct ios_av_session * 37 | ios_util_av_session_new(struct gm_logger *log, 38 | enum ios_av_device_type device_type, 39 | void (*configured_cb)(struct ios_av_session *session, void *user_data), 40 | void (*depth_cb)(struct ios_av_session *session, 41 | struct gm_intrinsics *intrinsics, 42 | float *acceleration, 43 | int stride, 44 | float *disparity, 45 | void *user_data), 46 | void (*video_cb)(struct ios_av_session *session, 47 | struct gm_intrinsics *intrinsics, 48 | int stride, 49 | uint8_t *video, 50 | void *user_data), 51 | void *user_data); 52 | 53 | void 54 | ios_util_session_configure(struct ios_av_session *_session); 55 | 56 | void 57 | ios_util_session_start(struct ios_av_session *session); 58 | 59 | void 60 | ios_util_session_stop(struct ios_av_session *_session); 61 | 62 | void 63 | ios_util_session_destroy(struct ios_av_session *session); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | -------------------------------------------------------------------------------- /src/java/com/impossible/glimpse/GlimpseConfig.java.in: -------------------------------------------------------------------------------- 1 | package com.impossible.glimpse; 2 | 3 | public class GlimpseConfig 4 | { 5 | public static final boolean USE_TANGO = @use_tango@; 6 | } 7 | -------------------------------------------------------------------------------- /src/java/com/impossible/glimpse/GlimpseJNI.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Google Inc. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.impossible.glimpse; 18 | 19 | import android.app.Activity; 20 | import android.content.res.AssetManager; 21 | import android.os.IBinder; 22 | import android.util.Log; 23 | 24 | import java.io.File; 25 | 26 | public class GlimpseJNI 27 | { 28 | public static final int ARCH_ERROR = -2; 29 | public static final int ARCH_FALLBACK = -1; 30 | public static final int ARCH_DEFAULT = 0; 31 | public static final int ARCH_ARM64 = 1; 32 | public static final int ARCH_ARM32 = 2; 33 | public static final int ARCH_X86_64 = 3; 34 | public static final int ARCH_X86 = 4; 35 | 36 | public static final int loadTangoSharedLibrary() { 37 | int loadedSoId = ARCH_ERROR; 38 | String basePath = "/data/data/com.google.tango/libfiles/"; 39 | if (!(new File(basePath).exists())) { 40 | basePath = "/data/data/com.projecttango.tango/libfiles/"; 41 | } 42 | Log.i("GlimpseJNI", "loadTangoSharedLibrary: basePath: " + basePath); 43 | 44 | try { 45 | System.load(basePath + "arm64-v8a/libtango_client_api.so"); 46 | loadedSoId = ARCH_ARM64; 47 | Log.i("GlimpseJNI", "Success! Using arm64-v8a/libtango_client_api."); 48 | } catch (UnsatisfiedLinkError e) { 49 | } 50 | if (loadedSoId < ARCH_DEFAULT) { 51 | try { 52 | System.load(basePath + "armeabi-v7a/libtango_client_api.so"); 53 | loadedSoId = ARCH_ARM32; 54 | Log.i("GlimpseJNI", "Success! Using armeabi-v7a/libtango_client_api."); 55 | } catch (UnsatisfiedLinkError e) { 56 | } 57 | } 58 | if (loadedSoId < ARCH_DEFAULT) { 59 | try { 60 | System.load(basePath + "x86_64/libtango_client_api.so"); 61 | loadedSoId = ARCH_X86_64; 62 | Log.i("GlimpseJNI", "Success! Using x86_64/libtango_client_api."); 63 | } catch (UnsatisfiedLinkError e) { 64 | } 65 | } 66 | if (loadedSoId < ARCH_DEFAULT) { 67 | try { 68 | System.load(basePath + "x86/libtango_client_api.so"); 69 | loadedSoId = ARCH_X86; 70 | Log.i("GlimpseJNI", "Success! Using x86/libtango_client_api."); 71 | } catch (UnsatisfiedLinkError e) { 72 | } 73 | } 74 | if (loadedSoId < ARCH_DEFAULT) { 75 | try { 76 | System.load(basePath + "default/libtango_client_api.so"); 77 | loadedSoId = ARCH_DEFAULT; 78 | Log.i("GlimpseJNI", "Success! Using default/libtango_client_api."); 79 | } catch (UnsatisfiedLinkError e) { 80 | } 81 | } 82 | if (loadedSoId < ARCH_DEFAULT) { 83 | try { 84 | System.loadLibrary("tango_client_api"); 85 | loadedSoId = ARCH_FALLBACK; 86 | Log.i("GlimpseJNI", "Falling back to libtango_client_api.so symlink."); 87 | } catch (UnsatisfiedLinkError e) { 88 | } 89 | } 90 | return loadedSoId; 91 | } 92 | 93 | public static native void onTangoServiceConnected(IBinder nativeTangoServiceBinder); 94 | } 95 | -------------------------------------------------------------------------------- /src/java/com/impossible/glimpse/GlimpseUnityActivity.java: -------------------------------------------------------------------------------- 1 | // Based on example from: 2 | // https://docs.unity3d.com/Manual/AndroidUnityPlayerActivity.html 3 | // 4 | package com.impossible.glimpse; 5 | 6 | import com.unity3d.player.UnityPlayerActivity; 7 | import android.os.Bundle; 8 | import android.os.IBinder; 9 | import android.util.Log; 10 | import android.content.Intent; 11 | import android.content.ServiceConnection; 12 | import android.content.Context; 13 | import android.content.ComponentName; 14 | import android.hardware.display.DisplayManager; 15 | import android.view.Display; 16 | 17 | import com.impossible.glimpse.GlimpseJNI; 18 | import com.impossible.glimpse.GlimpseConfig; 19 | 20 | 21 | public class GlimpseUnityActivity extends UnityPlayerActivity 22 | { 23 | ServiceConnection mTangoServiceConnection; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) 27 | { 28 | if (GlimpseConfig.USE_TANGO) { 29 | Log.d("GlimpseUnityActivity", "onCreate called! (With Tango support)"); 30 | 31 | // XXX: Make sure we try and load libtango_client_api.so before 32 | // the native activity tries to load our library which is linked 33 | // against libtango_client_api.so 34 | if (GlimpseJNI.loadTangoSharedLibrary() == GlimpseJNI.ARCH_ERROR) { 35 | Log.e("TangoJNINative", "ERROR! Unable to load libtango_client_api.so!"); 36 | } 37 | 38 | System.loadLibrary("glimpse-unity-plugin"); 39 | } else { 40 | Log.d("GlimpseUnityActivity", "onCreate called! (No Tango support)"); 41 | } 42 | 43 | // call UnityPlayerActivity.onCreate() 44 | super.onCreate(savedInstanceState); 45 | 46 | if (GlimpseConfig.USE_TANGO) { 47 | mTangoServiceConnection = new ServiceConnection() { 48 | public void onServiceConnected(ComponentName name, IBinder service) { 49 | GlimpseJNI.onTangoServiceConnected(service); 50 | forwardDisplayRotation(); 51 | Log.d("GlimpseUnityActivity", "Tango Service Connected!"); 52 | } 53 | public void onServiceDisconnected(ComponentName name) { 54 | // Handle this if you need to gracefully shutdown/retry 55 | // in the event that Tango itself crashes/gets upgraded while running. 56 | } 57 | }; 58 | } 59 | 60 | DisplayManager displayManager = 61 | (DisplayManager)getSystemService(DISPLAY_SERVICE); 62 | if (displayManager != null) { 63 | displayManager.registerDisplayListener(new DisplayManager.DisplayListener() { 64 | @Override 65 | public void onDisplayAdded(int displayId) {} 66 | 67 | @Override 68 | public void onDisplayChanged(int displayId) { 69 | synchronized (this) { 70 | forwardDisplayRotation(); 71 | } 72 | } 73 | 74 | @Override 75 | public void onDisplayRemoved(int displayId) {} 76 | }, null); 77 | } 78 | } 79 | 80 | public static final boolean bindTangoService(final Context context, 81 | ServiceConnection connection) 82 | { 83 | Intent intent = new Intent(); 84 | intent.setClassName("com.google.tango", "com.google.atap.tango.TangoService"); 85 | 86 | if (context.getPackageManager().resolveService(intent, 0) != null) 87 | { 88 | return context.bindService(intent, connection, Context.BIND_AUTO_CREATE); 89 | } 90 | else 91 | { 92 | // TODO: bubble something up to the user! 93 | return false; 94 | } 95 | } 96 | 97 | @Override 98 | protected void onResume() { 99 | super.onResume(); 100 | 101 | if (GlimpseConfig.USE_TANGO) { 102 | bindTangoService(this, mTangoServiceConnection); 103 | } 104 | } 105 | 106 | @Override 107 | protected void onPause() { 108 | super.onPause(); 109 | 110 | if (GlimpseConfig.USE_TANGO) { 111 | //TangoJNINative.onPause(); 112 | unbindService(mTangoServiceConnection); 113 | } 114 | } 115 | 116 | private void forwardDisplayRotation() { 117 | Display display = getWindowManager().getDefaultDisplay(); 118 | int rotation = display.getRotation(); 119 | Log.d("GlimpseUnityActivity", "calling OnDisplayRotation " + rotation); 120 | OnDisplayRotate(rotation); 121 | } 122 | 123 | native static void OnDisplayRotate(int rotation); 124 | } 125 | -------------------------------------------------------------------------------- /src/java/com/impossible/glimpse/meson.build: -------------------------------------------------------------------------------- 1 | 2 | conf_data = configuration_data() 3 | if tango_enabled 4 | conf_data.set('use_tango', 'true') 5 | else 6 | conf_data.set('use_tango', 'false') 7 | endif 8 | glimpse_config_file = configure_file(input : 'GlimpseConfig.java.in', 9 | output : 'GlimpseConfig.java', 10 | configuration : conf_data) 11 | -------------------------------------------------------------------------------- /src/java/meson.build: -------------------------------------------------------------------------------- 1 | # XXX: Meson configure_file() doesn't let us specify an output filename 2 | # with a subdirectory so we have to have *another* meson.build file 3 | # next to GlimpseConfig.java.in... 4 | subdir('com/impossible/glimpse') 5 | 6 | if need_unity_jar 7 | unity_java_src = [ 8 | glimpse_config_file, 9 | 'com/impossible/glimpse/GlimpseJNI.java', 10 | 'com/impossible/glimpse/GlimpseUnityActivity.java' 11 | ] 12 | unity_jar = join_paths(get_option('unity_editor'), 13 | 'Editor/Data/PlaybackEngines/AndroidPlayer/Variations/mono/Development/Classes/classes.jar') 14 | unity_java_jar = jar('GlimpseUnity', 15 | unity_java_src, 16 | 17 | # XXX: this is a workaround that results in meson 18 | # passing -sourcedir ../src/java (relative to the 19 | # build directory) so that the javac -implicit:class 20 | # behaviour is able to find the source code of 21 | # classes that the current file depends on... 22 | include_directories: include_directories('.'), 23 | 24 | java_args: [ 25 | '-classpath', android_sdk_jar + ':' + unity_jar, 26 | ]) 27 | endif 28 | 29 | if need_glimpse_native_jar 30 | native_java_src = [ 31 | glimpse_config_file, 32 | 'com/impossible/glimpse/GlimpseJNI.java', 33 | 'com/impossible/glimpse/GlimpseNativeActivity.java' 34 | ] 35 | glimpse_native_jar = jar('GlimpseNative', 36 | native_java_src, 37 | 38 | # XXX: this is a workaround that results in meson 39 | # passing -sourcedir ../src/java (relative to the 40 | # build directory) so that the javac -implicit:class 41 | # behaviour is able to find the source code of 42 | # classes that the current file depends on... 43 | include_directories: include_directories('.'), 44 | 45 | java_args: [ 46 | '-classpath', android_sdk_jar, 47 | ]) 48 | endif 49 | -------------------------------------------------------------------------------- /src/jip-to-json.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | #include 35 | 36 | #include "xalloc.h" 37 | #include "jip.h" 38 | #include "parson.h" 39 | 40 | 41 | static void 42 | usage(void) 43 | { 44 | printf( 45 | "Usage rdt-to-json [options] \n" 46 | "\n" 47 | " -p,--pretty Pretty print the JSON output\n" 48 | "\n" 49 | " -h,--help Display this help\n\n" 50 | "\n" 51 | "This tool converts the binary representation of .jip files output by the\n" 52 | "train_joint_params tool to a JSON representation which can be convenient\n" 53 | "for loading the trees in Python or JavaScript tools or inspecting manually.\n" 54 | "\n" 55 | "The schema looks like: FIXME\n" 56 | "\n" 57 | ); 58 | 59 | exit(1); 60 | } 61 | 62 | int 63 | main(int argc, char **argv) 64 | { 65 | struct gm_logger *log = gm_logger_new(NULL, NULL); 66 | int opt; 67 | bool pretty = false; 68 | 69 | const char *short_options="+hp"; 70 | const struct option long_options[] = { 71 | {"help", no_argument, 0, 'h'}, 72 | {"pretty", no_argument, 0, 'p'}, 73 | {0, 0, 0, 0} 74 | }; 75 | 76 | while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) 77 | != -1) 78 | { 79 | switch (opt) { 80 | case 'h': 81 | usage(); 82 | return 0; 83 | case 'p': 84 | pretty = true; 85 | break; 86 | default: 87 | usage(); 88 | break; 89 | } 90 | } 91 | 92 | if (argc - optind != 2) 93 | usage(); 94 | 95 | JIParams *params = jip_load_from_file(log, argv[optind], NULL); 96 | 97 | JSON_Value *jip = json_value_init_object(); 98 | 99 | int n_joints = params->header.n_joints; 100 | json_object_set_number(json_object(jip), "n_joints", n_joints); 101 | 102 | JSON_Value *jip_params = json_value_init_array(); 103 | for (int i = 0; i < n_joints; i++) { 104 | JIParam *param = params->joint_params + i; 105 | JSON_Value *jip_param = json_value_init_object(); 106 | 107 | json_object_set_number(json_object(jip_param), "bandwidth", param->bandwidth); 108 | json_object_set_number(json_object(jip_param), "threshold", param->threshold); 109 | json_object_set_number(json_object(jip_param), "offset", param->offset); 110 | 111 | json_array_append_value(json_array(jip_params), jip_param); 112 | } 113 | 114 | json_object_set_value(json_object(jip), "params", jip_params); 115 | 116 | if (pretty) 117 | json_serialize_to_file_pretty(jip, argv[optind+1]); 118 | else 119 | json_serialize_to_file(jip, argv[optind+1]); 120 | 121 | jip_free(params); 122 | 123 | return 0; 124 | } 125 | -------------------------------------------------------------------------------- /src/jip.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "jip.h" 35 | #include "parson.h" 36 | #include "xalloc.h" 37 | 38 | JIParams * 39 | jip_load_from_json(struct gm_logger* log, 40 | JSON_Value *root, 41 | char** err) 42 | { 43 | JIParams* jip = (JIParams*)xcalloc(1, sizeof(JIParams)); 44 | 45 | jip->header.tag[0] = 'J'; 46 | jip->header.tag[1] = 'I'; 47 | jip->header.tag[2] = 'P'; 48 | 49 | jip->header.version = 0; 50 | 51 | jip->header.n_joints = json_object_get_number(json_object(root), "n_joints"); 52 | 53 | JSON_Array *params = json_object_get_array(json_object(root), "params"); 54 | int len = json_array_get_count(params); 55 | if (len != jip->header.n_joints) 56 | { 57 | gm_throw(log, err, "Inconsistency between \"n_joints\" and length of \"params\" array\n"); 58 | free(jip); 59 | return NULL; 60 | } 61 | 62 | jip->joint_params = (JIParam*)xmalloc(jip->header.n_joints * sizeof(JIParam)); 63 | for (int i = 0; i < len; i++) 64 | { 65 | JSON_Object *param = json_array_get_object(params, i); 66 | 67 | jip->joint_params[i].bandwidth = json_object_get_number(param, "bandwidth"); 68 | jip->joint_params[i].threshold = json_object_get_number(param, "threshold"); 69 | jip->joint_params[i].offset = json_object_get_number(param, "offset"); 70 | } 71 | 72 | return jip; 73 | } 74 | 75 | JIParams* 76 | jip_load_from_file(struct gm_logger* log, 77 | const char* filename, 78 | char** err) 79 | { 80 | const char* ext; 81 | 82 | if ((ext = strstr(filename, ".json")) && ext[5] == '\0') 83 | { 84 | JSON_Value *js = json_parse_file(filename); 85 | if (!js) { 86 | gm_throw(log, err, "Failed to parse JSON file %s", filename); 87 | return NULL; 88 | } 89 | JIParams *ret = jip_load_from_json(log, js, err); 90 | json_value_free(js); 91 | return ret; 92 | } 93 | 94 | FILE* jip_file = fopen(filename, "r"); 95 | if (!jip_file) 96 | { 97 | gm_throw(log, err, "Error opening JIP file\n"); 98 | return NULL; 99 | } 100 | 101 | JIParams* jip = (JIParams*)xcalloc(1, sizeof(JIParams)); 102 | if (fread(&jip->header, sizeof(JIPHeader), 1, jip_file) != 1) 103 | { 104 | gm_throw(log, err, "Error reading header\n"); 105 | goto read_jip_error; 106 | } 107 | 108 | jip->joint_params = (JIParam*)xmalloc(jip->header.n_joints * sizeof(JIParam)); 109 | for (int i = 0; i < jip->header.n_joints; i++) 110 | { 111 | float params[3]; 112 | if (fread(params, sizeof(float), 3, jip_file) != 3) 113 | { 114 | gm_throw(log, err, "Error reading parameters\n"); 115 | goto read_jip_error; 116 | } 117 | 118 | jip->joint_params[i].bandwidth = params[0]; 119 | jip->joint_params[i].threshold = params[1]; 120 | jip->joint_params[i].offset = params[2]; 121 | } 122 | 123 | fclose(jip_file); 124 | 125 | return jip; 126 | 127 | read_jip_error: 128 | jip_free(jip); 129 | fclose(jip_file); 130 | return NULL; 131 | } 132 | 133 | void 134 | jip_free(JIParams* jip) 135 | { 136 | if (jip->joint_params) 137 | { 138 | xfree(jip->joint_params); 139 | } 140 | xfree(jip); 141 | } 142 | -------------------------------------------------------------------------------- /src/jip.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #include "parson.h" 33 | 34 | typedef struct { 35 | float bandwidth; 36 | float threshold; 37 | float offset; 38 | } JIParam; 39 | 40 | typedef struct __attribute__((__packed__)) { 41 | char tag[3]; 42 | uint8_t version; 43 | uint8_t n_joints; 44 | } JIPHeader; 45 | 46 | typedef struct { 47 | JIPHeader header; 48 | JIParam* joint_params; 49 | } JIParams; 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | JIParams *jip_load_from_json(struct gm_logger* log, 56 | JSON_Value* root, 57 | char** err); 58 | JIParams* jip_load_from_file(struct gm_logger* log, 59 | const char* filename, 60 | char** err); 61 | void jip_free(JIParams* jip); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/joints_inferrer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include 28 | #include 29 | 30 | #include "jip.h" 31 | #include "llist.h" 32 | #include "parson.h" 33 | 34 | #include "glimpse_context.h" 35 | 36 | typedef struct { 37 | float x; 38 | float y; 39 | float z; 40 | float confidence; 41 | } Joint; 42 | 43 | typedef struct { 44 | int n_joints; 45 | LList *joints[]; 46 | } InferredJoints; 47 | 48 | 49 | struct joints_inferrer; 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | struct joints_inferrer* 56 | joints_inferrer_new(struct gm_logger* logger, 57 | JSON_Value* joint_map, 58 | char** err); 59 | 60 | void 61 | joints_inferrer_destroy(struct joints_inferrer* inferrer); 62 | 63 | float* 64 | joints_inferrer_calc_pixel_weights(struct joints_inferrer* inferrer, 65 | float* depth_image, 66 | float* pr_table, 67 | int width, 68 | int height, 69 | int n_labels, 70 | float* out_weights); 71 | 72 | InferredJoints* 73 | joints_inferrer_infer_fast(struct joints_inferrer *inferrer, 74 | struct gm_intrinsics *intrinsics, 75 | int cluster_width, 76 | int cluster_height, 77 | int cluster_x0, 78 | int cluster_y0, 79 | float* cluster_depth_image, 80 | float* cluster_label_probs, 81 | float* cluster_weights, 82 | int n_labels, 83 | JIParam* params); 84 | 85 | InferredJoints* 86 | joints_inferrer_infer(struct joints_inferrer* inferrer, 87 | struct gm_intrinsics *intrinsics, 88 | int cluster_width, 89 | int cluster_height, 90 | int cluster_x0, 91 | int cluster_y0, 92 | float* cluster_depth_image, 93 | float* cluster_label_probs, 94 | float* cluster_weights, 95 | float bg_depth, 96 | int n_labels, 97 | JIParam* params); 98 | 99 | void 100 | joints_inferrer_free_joints(struct joints_inferrer* inferrer, 101 | InferredJoints* joints); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | -------------------------------------------------------------------------------- /src/json-to-rdt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include 34 | 35 | #include "rdt_tree.h" 36 | 37 | static void 38 | usage(void) 39 | { 40 | printf( 41 | "Usage json-to-rdt [options] \n" 42 | "\n" 43 | " -h,--help Display this help\n\n" 44 | "\n" 45 | "This tool converts the JSON representation of the randomised decision trees\n" 46 | "output by the train_rdt tool to a binary representation which can be\n" 47 | "convenient for fast loading of trees and more compact representation when\n" 48 | "compressed.\n" 49 | "\n" 50 | "Note: A packed RDT file only needs to contain the minimum information for\n" 51 | " efficient runtime inference so the conversion is lossy.\n" 52 | "\n" 53 | "This reads a JSON description of a randomized decision tree with the\n" 54 | "following schema:\n" 55 | "\n" 56 | " {\n" 57 | " \"n_labels\": 34,\n" 58 | " \"vertical_fov\": 50.4,\n" 59 | " \"depth\": 20,\n" 60 | " \"root\": {\n" 61 | " \"t\": 0.5, // threshold\n" 62 | " \"u\": [ 3, -0.5 ], // U vector\n" 63 | " \"v\": [ -2, 10.1 ], // V vector\n" 64 | "\n" 65 | " // left node...\n" 66 | " \"l\": {\n" 67 | " // children directly nested...\n" 68 | " \"t\": 0.2, // child's threshold\n" 69 | " \"u\": [ 1, -5.2 ], // child's U vector\n" 70 | " \"v\": [ -7, -0.1 ], // child's V vector\n" 71 | " \"l\": { ... }, // child's left node\n" 72 | " \"r\": { ... }, // child's right node\n" 73 | " },\n" 74 | "\n" 75 | " // right node is an example leaf node with label\n" 76 | " // probabilities...\n" 77 | " \"r\": {\n" 78 | " \"p\": [0, 0, 0, 0.2, 0, 0.2, 0, 0.6, 0, 0 ... ],\n" 79 | " }\n" 80 | " }\n" 81 | " }\n" 82 | ); 83 | } 84 | 85 | int 86 | main(int argc, char **argv) 87 | { 88 | struct gm_logger *log = gm_logger_new(NULL, NULL); 89 | int opt; 90 | const char *short_options="+hp"; 91 | const struct option long_options[] = { 92 | {"help", no_argument, 0, 'h'}, 93 | {0, 0, 0, 0} 94 | }; 95 | 96 | while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) 97 | != -1) 98 | { 99 | switch (opt) { 100 | case 'h': 101 | usage(); 102 | return 0; 103 | default: 104 | usage(); 105 | return 1; 106 | } 107 | } 108 | 109 | if (argc - optind != 2) { 110 | usage(); 111 | return 1; 112 | } 113 | 114 | RDTree *tree = rdt_tree_load_from_json_file(log, 115 | argv[optind], 116 | false, // don't load incomplete trees 117 | NULL); 118 | if (!tree) 119 | return 1; 120 | 121 | return rdt_tree_save(tree, argv[optind+1]) ? 0 : 1; 122 | } 123 | -------------------------------------------------------------------------------- /src/labeled-human-mesh-instructions.txt: -------------------------------------------------------------------------------- 1 | Basic steps for creating the different proportioned body models: 2 | 3 | - Open makehuman 4 | - Use sliders to define a body type 5 | - Under Pose/Animate->Skeleton select the 'Game engine' rig 6 | - Under Pose/Animate->Pose select Tpose 7 | - Under Files->Export: 8 | - select 'Mesh Format' = mh2 (need to install plugin for this first) 9 | - select 'Scale units' = meter 10 | - Choose export filename and export 11 | - Also save a .mhm file in case it's useful for future reference 12 | Notes: 13 | - The model must use the default mesh topology since we rely on this in 14 | Blender for transfering vertex colors according to the topology 15 | 16 | 17 | Open Blender 18 | (assuming you've added the mh2 import and the MakeWalk addon and the Glimpse 19 | paint rig addon) 20 | - Switch to an empty layer 21 | - Import .mh2, select the file exported from makehuman 22 | - Before import: check 'Override Exported Data' in left 'Import MHX2' panel 23 | - check 'Helper Geometry' needed for fitting clothes to the mesh 24 | - Select the body mesh in object mode 25 | - Use the left hand 'MHX2 Runtime' panel and select 'Add simple materials' 26 | (This will ensure that the clothing related parts will be transparent and 27 | invisible to rendering) 28 | - Use the right hand 'Make Clothes' panel to set the 'Mesh Type' to 'Human' 29 | (press the 'Clothes' button to toggle) 30 | - Go to Edit Mode and then to the far right Material properties tab 31 | - Select the Defaultskin material 32 | - Make sure no vertices are selected in Edit Mode and press the 'Select' by 33 | active material slot button in the properties tab. This should just select 34 | the body without any helper geometry. This will also select a small cube 35 | around the root bone which you should unselect (press 'c' for the circle 36 | select tool and press shift which brushing over the cube) 37 | - Shift-D to duplicate these vertices and press Esc without moving them 38 | - Press 'p' and separate these vertices by Selection 39 | - Delete associated materials then assign the JointLabelsMaterial 40 | - Rename the objects, mesh and pose like 'Woman1PoseObject'. E.g. for a 'Woman1' 41 | model there would be these named objects: 42 | Woman1PoseObject 43 | Woman1Pose 44 | Woman1BodyMeshObject 45 | Woman1BodyMesh 46 | Woman1BodyHelperMeshObject 47 | Woman1BodyHelperMesh 48 | - In the Outliner click the camera icon next to the *BodyHelperMeshObject and 49 | the other 'High-poly' mesh so they're not included in renders 50 | - Select the separated BodyMeshObject 51 | - Go to the modifiers panel and add a 'DataTransfer' modifer 52 | - Set 'Source Object' to 'BaseBodyMeshObject' 53 | - Check 'Face Corner Data', choose 'Topology' from the drop down, 54 | select 'VCol' and press 'Generate Data Layers' 55 | 56 | 57 | Adding new reference clothes 58 | 59 | - Select the BaseBodyHelperMeshObject in ObjectMode 60 | - From the Make Clothes tools panel press 'Test Clothes' and select the clothing 61 | - Select the new clothing object and the BasePoseObject and run the 'Rig Paint Operator' 62 | - Make sure the BasePoseObject is in the 'Reset Position' (so the pose isn't affecting the mesh) 63 | - Select just the new clothing object 64 | - Add a DataTransfer modifier 65 | - Set 'Source Object' to 'BaseBodyMeshObject' 66 | - Check 'Vertex Data', select 'Nearest Vertex', select 'Vertex Group(s)' and press 'Generate Data Layers' 67 | - Apply the modifier 68 | - Shift select the 'BasePoseObject' in addition to the clothing object and press 69 | Ctrl-P to re-parent the clothing under the base pose, selecting the 70 | 'With Empty Groups' option 71 | - Rename the object to something like 'clothing_item_reference' 72 | - Finally with just the clothing object selected press 'm' and move it to the 73 | top-right clothing layer 74 | -------------------------------------------------------------------------------- /src/llist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | 31 | typedef struct _LList LList; 32 | 33 | struct _LList { 34 | LList* prev; 35 | LList* next; 36 | void* data; 37 | }; 38 | 39 | typedef bool (*LListIterCallback)(LList* node, 40 | uint32_t index, 41 | void* userdata); 42 | 43 | typedef int (*LListSearchCallback)(LList* a, 44 | LList* b, 45 | void* userdata); 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | LList* llist_new(void* data); 52 | 53 | void llist_foreach(LList* list, 54 | LListIterCallback cb, 55 | void* userdata); 56 | 57 | bool llist_free_cb(LList* node, 58 | uint32_t index, 59 | void* userdata); 60 | 61 | void llist_free(LList* list, 62 | LListIterCallback free_cb, 63 | void* userdata); 64 | 65 | LList* llist_insert_before(LList* before, 66 | LList* node); 67 | 68 | LList* llist_insert_after(LList* after, 69 | LList* node); 70 | 71 | LList* llist_remove(LList* node); 72 | 73 | LList* llist_reverse(LList* node); 74 | 75 | LList* llist_first(LList* node); 76 | 77 | LList* llist_last(LList* node); 78 | 79 | uint32_t llist_length(LList* node); 80 | 81 | void** llist_as_array(LList* node, 82 | uint32_t* length); 83 | 84 | LList* llist_from_array(void** data, 85 | uint32_t length); 86 | 87 | LList* llist_shuffle(LList* node); 88 | 89 | LList* llist_slice(LList* node, 90 | uint32_t begin, 91 | uint32_t end, 92 | LListIterCallback free_cb, 93 | void* userdata); 94 | 95 | void* llist_pop(LList** node, 96 | LListIterCallback free_cb, 97 | void* userdata); 98 | 99 | LList* llist_sort(LList* node, 100 | LListSearchCallback sort_cb, 101 | void* userdata); 102 | 103 | #ifdef __cplusplus 104 | }; 105 | #endif 106 | -------------------------------------------------------------------------------- /src/pack-info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (c) 2017 Glimp IP Ltd 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | # 23 | 24 | import argparse 25 | from py import pack 26 | import copy 27 | 28 | def main(): 29 | parser = argparse.ArgumentParser() 30 | parser.add_argument("in_pack", nargs=1, help="Input Pack file") 31 | parser.add_argument("-o", "--output", nargs=1, help="Output Pack file") 32 | parser.add_argument("-v", "--verbose", action="store_true", help="Display verbose debug information") 33 | 34 | args = parser.parse_args() 35 | 36 | in_filename = args.in_pack[0] 37 | in_pack = pack.PackReader(in_filename) 38 | 39 | out = None 40 | if args.output: 41 | out = pack.PackWriter(args.output[0]) 42 | out.properties = in_pack.copy_properties() 43 | out.write_header() 44 | 45 | print("version = %u.%u" % (in_pack.major, in_pack.minor)) 46 | 47 | print("%u sections:" % len(in_pack.section_names)) 48 | for section_name in in_pack.section_names: 49 | print(" %s" % section_name) 50 | 51 | print("%u properties:" % len(in_pack.properties)) 52 | for key in in_pack.properties: 53 | print(" %s = %s" % (key, str(in_pack.properties[key]))) 54 | 55 | for frame in in_pack: 56 | if out: 57 | new_frame = out.new_frame() 58 | 59 | print("Frame:") 60 | 61 | for key in frame.properties: 62 | print(" %s = %s" % (key, str(frame.properties[key]))) 63 | 64 | if out: 65 | new_frame.properties = copy.deepcopy(frame.properties) 66 | 67 | print(" sections:") 68 | for section_name in in_pack.section_names: 69 | section = frame[section_name] 70 | print(" %s:" % section.name) 71 | #data = section.get_decompressed() 72 | #print(" %s" % str(data)) 73 | 74 | compressed = section.get_compressed() 75 | 76 | if out: 77 | new_section = new_frame[section_name] 78 | print(" copying across compressed section %s with len %u" % (section_name, len(compressed))) 79 | new_section.set_compressed(section.get_compressed()) 80 | 81 | if out: 82 | out.append_frame(new_frame) 83 | 84 | 85 | if __name__ == "__main__": 86 | main() 87 | 88 | -------------------------------------------------------------------------------- /src/perlin.c: -------------------------------------------------------------------------------- 1 | // 2 | // Source: 3 | // https://gist.github.com/nowl/828013 4 | // 5 | 6 | #include "perlin.h" 7 | 8 | static int hash[] = { 9 | 208,34,231,213,32,248,233,56,161,78,24,140,71,48,140,254,245,255,247,247,40, 10 | 185,248,251,245,28,124,204,204,76,36,1,107,28,234,163,202,224,245,128,167,204, 11 | 9,92,217,54,239,174,173,102,193,189,190,121,100,108,167,44,43,77,180,204,8,81, 12 | 70,223,11,38,24,254,210,210,177,32,81,195,243,125,8,169,112,32,97,53,195,13, 13 | 203,9,47,104,125,117,114,124,165,203,181,235,193,206,70,180,174,0,167,181,41, 14 | 164,30,116,127,198,245,146,87,224,149,206,57,4,192,210,65,210,129,240,178,105, 15 | 228,108,245,148,140,40,35,195,38,58,65,207,215,253,65,85,208,76,62,3,237,55,89, 16 | 232,50,217,64,244,157,199,121,252,90,17,212,203,149,152,140,187,234,177,73,174, 17 | 193,100,192,143,97,53,145,135,19,103,13,90,135,151,199,91,239,247,33,39,145, 18 | 101,120,99,3,186,86,99,41,237,203,111,79,220,135,158,42,30,154,120,67,87,167, 19 | 135,176,183,191,253,115,184,21,233,58,129,233,142,39,128,211,118,137,139,255, 20 | 114,20,218,113,154,27,127,246,250,1,8,198,250,209,92,222,173,21,88,102,219 21 | }; 22 | 23 | static int 24 | noise2(int x, int y, int seed) 25 | { 26 | int tmp = hash[(y + seed) % 256]; 27 | return hash[(tmp + x) % 256]; 28 | } 29 | 30 | static float 31 | lin_inter(float x, float y, float s) 32 | { 33 | return x + s * (y-x); 34 | } 35 | 36 | static float 37 | smooth_inter(float x, float y, float s) 38 | { 39 | return lin_inter(x, y, s * s * (3-2*s)); 40 | } 41 | 42 | static float 43 | noise2d(float x, float y, int seed) 44 | { 45 | int x_int = x; 46 | int y_int = y; 47 | float x_frac = x - x_int; 48 | float y_frac = y - y_int; 49 | int s = noise2(x_int, y_int, seed); 50 | int t = noise2(x_int+1, y_int, seed); 51 | int u = noise2(x_int, y_int+1, seed); 52 | int v = noise2(x_int+1, y_int+1, seed); 53 | float low = smooth_inter(s, t, x_frac); 54 | float high = smooth_inter(u, v, x_frac); 55 | return smooth_inter(low, high, y_frac); 56 | } 57 | 58 | float 59 | perlin2d(float x, float y, float freq, int octaves, int seed) 60 | { 61 | float xa = x*freq; 62 | float ya = y*freq; 63 | float amp = 1.0; 64 | float fin = 0; 65 | float div = 0.0; 66 | 67 | int i; 68 | for(i=0; i 30 | 31 | #ifdef __APPLE__ 32 | 33 | #define __unused __attribute__((unused)) 34 | 35 | int 36 | pthread_barrierattr_init(pthread_barrierattr_t *attr __unused) 37 | { 38 | return 0; 39 | } 40 | 41 | int 42 | pthread_barrierattr_destroy(pthread_barrierattr_t *attr __unused) 43 | { 44 | return 0; 45 | } 46 | 47 | int 48 | pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr __unused, 49 | int *pshared) 50 | { 51 | *pshared = PTHREAD_PROCESS_PRIVATE; 52 | return 0; 53 | } 54 | 55 | int 56 | pthread_barrierattr_setpshared(pthread_barrierattr_t *attr __unused, 57 | int pshared) 58 | { 59 | if (pshared != PTHREAD_PROCESS_PRIVATE) { 60 | errno = EINVAL; 61 | return -1; 62 | } 63 | return 0; 64 | } 65 | 66 | int 67 | pthread_barrier_init(pthread_barrier_t *barrier, 68 | const pthread_barrierattr_t *attr __unused, 69 | unsigned count) 70 | { 71 | if (count == 0) { 72 | errno = EINVAL; 73 | return -1; 74 | } 75 | 76 | if (pthread_mutex_init(&barrier->mutex, 0) < 0) { 77 | return -1; 78 | } 79 | if (pthread_cond_init(&barrier->cond, 0) < 0) { 80 | int errno_save = errno; 81 | pthread_mutex_destroy(&barrier->mutex); 82 | errno = errno_save; 83 | return -1; 84 | } 85 | 86 | barrier->limit = count; 87 | barrier->count = 0; 88 | barrier->phase = 0; 89 | 90 | return 0; 91 | } 92 | 93 | int 94 | pthread_barrier_destroy(pthread_barrier_t *barrier) 95 | { 96 | pthread_mutex_destroy(&barrier->mutex); 97 | pthread_cond_destroy(&barrier->cond); 98 | return 0; 99 | } 100 | 101 | int 102 | pthread_barrier_wait(pthread_barrier_t *barrier) 103 | { 104 | pthread_mutex_lock(&barrier->mutex); 105 | barrier->count++; 106 | if (barrier->count >= barrier->limit) { 107 | barrier->phase++; 108 | barrier->count = 0; 109 | pthread_cond_broadcast(&barrier->cond); 110 | pthread_mutex_unlock(&barrier->mutex); 111 | return PTHREAD_BARRIER_SERIAL_THREAD; 112 | } else { 113 | unsigned phase = barrier->phase; 114 | do 115 | pthread_cond_wait(&barrier->cond, &barrier->mutex); 116 | while (phase == barrier->phase); 117 | pthread_mutex_unlock(&barrier->mutex); 118 | return 0; 119 | } 120 | } 121 | 122 | #endif /* __APPLE__ */ 123 | -------------------------------------------------------------------------------- /src/pthread_barrier/pthread_barrier.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Aleksey Demakov 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, this 9 | * list of conditions and the following disclaimer. 10 | * 11 | * * Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef PTHREAD_BARRIER_H 28 | #define PTHREAD_BARRIER_H 29 | 30 | #include 31 | 32 | #ifdef __APPLE__ 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #if !defined(PTHREAD_BARRIER_SERIAL_THREAD) 39 | # define PTHREAD_BARRIER_SERIAL_THREAD (1) 40 | #endif 41 | 42 | #if !defined(PTHREAD_PROCESS_PRIVATE) 43 | # define PTHREAD_PROCESS_PRIVATE (42) 44 | #endif 45 | #if !defined(PTHREAD_PROCESS_SHARED) 46 | # define PTHREAD_PROCESS_SHARED (43) 47 | #endif 48 | 49 | typedef struct { 50 | } pthread_barrierattr_t; 51 | 52 | typedef struct { 53 | pthread_mutex_t mutex; 54 | pthread_cond_t cond; 55 | unsigned int limit; 56 | unsigned int count; 57 | unsigned int phase; 58 | } pthread_barrier_t; 59 | 60 | int pthread_barrierattr_init(pthread_barrierattr_t *attr); 61 | int pthread_barrierattr_destroy(pthread_barrierattr_t *attr); 62 | 63 | int pthread_barrierattr_getpshared(const pthread_barrierattr_t *attr, 64 | int *pshared); 65 | int pthread_barrierattr_setpshared(pthread_barrierattr_t *attr, 66 | int pshared); 67 | 68 | int pthread_barrier_init(pthread_barrier_t *barrier, 69 | const pthread_barrierattr_t *attr, 70 | unsigned int count); 71 | int pthread_barrier_destroy(pthread_barrier_t *barrier); 72 | 73 | int pthread_barrier_wait(pthread_barrier_t *barrier); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* __APPLE__ */ 80 | 81 | #endif /* PTHREAD_BARRIER_H */ 82 | -------------------------------------------------------------------------------- /src/py/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glimpse-project/glimpse/f7e0bee5800c72ea37928f7e0fd2e0b7b67cf904/src/py/__init__.py -------------------------------------------------------------------------------- /src/python/Makefile: -------------------------------------------------------------------------------- 1 | default: clean setup.cfg setup.py glimpse.i numpy.i glimpse_python.cc glimpse_python.h __init__.py 2 | ./setup.py bdist_wheel 3 | 4 | clean: 5 | rm -rf build dist glimpse.egg-info __pycache__ glimpse.py glimpse_wrap.cpp 6 | -------------------------------------------------------------------------------- /src/python/README.md: -------------------------------------------------------------------------------- 1 | # Glimpse Python bindings 2 | 3 | ## Building 4 | 5 | It's recommended to run this inside a virtualenv, so as not to pollute the 6 | system Python package index. 7 | 8 | Build the glimpse module by running the following: 9 | 10 | ``` 11 | make 12 | pip install --user --force-reinstall dist/glimpse*.whl 13 | ``` 14 | 15 | The 'glimpse' module will now be available in Python. Make sure that 16 | libglimpse-python-tools.so is available in the library path before importing. 17 | -------------------------------------------------------------------------------- /src/python/__init__.py: -------------------------------------------------------------------------------- 1 | from .glimpse import * 2 | -------------------------------------------------------------------------------- /src/python/glimpse.i: -------------------------------------------------------------------------------- 1 | %module glimpse 2 | 3 | %{ 4 | #define SWIG_FILE_WITH_INIT 5 | #include "glimpse_python.h" 6 | %} 7 | 8 | %include "numpy.i" 9 | %init %{ 10 | import_array(); 11 | %} 12 | 13 | %typemap(in) (char** IN_ARRAY1, int DIM1) { 14 | /* Check if is a list */ 15 | if (PyList_Check($input)) 16 | { 17 | $2 = PyList_Size($input); 18 | $1 = (char **) malloc($2*sizeof(char *)); 19 | for (Py_ssize_t i = 0; i < $2; i++) 20 | { 21 | PyObject *o = PyList_GetItem($input, i); 22 | if (PyUnicode_Check(o)) 23 | { 24 | $1[i] = PyUnicode_AsUTF8(PyList_GetItem($input,i)); 25 | } 26 | else 27 | { 28 | PyErr_Format(PyExc_TypeError, "list must contain strings. %d/%d element was not string.", i, $2); 29 | free($1); 30 | return NULL; 31 | } 32 | } 33 | } 34 | else 35 | { 36 | PyErr_SetString(PyExc_TypeError,"not a list"); 37 | return NULL; 38 | } 39 | } 40 | 41 | %typemap(freearg) (char** IN_ARRAY1, int DIM1) { 42 | free((char *) $1); 43 | } 44 | 45 | %apply (char** IN_ARRAY1, int DIM1) {(const char** aFiles, unsigned int aNFiles)}; 46 | %apply (float* IN_ARRAY2, int DIM1, int DIM2) {(float* aDepthImage, int aHeight, int aWidth)}; 47 | %apply (float* IN_ARRAY2, int DIM1, int DIM2) {(float* aPointCloud, int aNPoints, int aNDims)}; 48 | %apply (float** ARGOUTVIEWM_ARRAY2, int* DIM1, int* DIM2) {(float** aDepth, int* aOutHeight, int* aOutWidth)}; 49 | %apply (float** ARGOUTVIEWM_ARRAY2, int* DIM1, int* DIM2) {(float** aCloud, int* aOutNPoints, int* aOutNDims)}; 50 | %apply (float** ARGOUTVIEWM_ARRAY2, int* DIM1, int* DIM2) {(float** aJoints, int* aOutNJoints, int* aOutNDims)}; 51 | %apply (float** ARGOUTVIEWM_ARRAY3, int* DIM1, int* DIM2, int* DIM3) {(float** aLabelPr, int* aOutHeight, int* aOutWidth, int* aNLabels)}; 52 | 53 | %include "glimpse_python.h" 54 | -------------------------------------------------------------------------------- /src/python/glimpse_python.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #include "glimpse.h" 26 | 27 | namespace Glimpse 28 | { 29 | class DepthImage { 30 | friend class Forest; 31 | friend class JointMap; 32 | friend DepthImage* DepthImageFromPointCloud(float* aPointCloud, 33 | int aNPoints, 34 | int aNDims, 35 | int aHeight, 36 | int aWidth, 37 | float aVFOV, 38 | float aBackground); 39 | 40 | private: 41 | bool mValid; 42 | half_float::half* mDepthImage; 43 | uint32_t mWidth; 44 | uint32_t mHeight; 45 | 46 | DepthImage(half_float::half* aDepthImage, 47 | uint32_t aWidth, 48 | uint32_t aHeight); 49 | 50 | public: 51 | DepthImage(const char* aFileName); 52 | DepthImage(float* aDepthImage, 53 | int aHeight, 54 | int aWidth); 55 | ~DepthImage(); 56 | 57 | void writeEXR(const char* aFileName); 58 | void asArray(float** aDepth, int* aOutHeight, int* aOutWidth); 59 | void asPointCloud(float aVFOV, float aThreshold, float** aCloud, 60 | int* aOutNPoints, int* aOutNDims); 61 | }; 62 | 63 | DepthImage* DepthImageFromPointCloud(float* aPointCloud, 64 | int aNPoints, 65 | int aNDims, 66 | int aHeight, 67 | int aWidth, 68 | float aVFOV, 69 | float aBackground = 0.f); 70 | 71 | class Forest { 72 | friend class JointMap; 73 | 74 | private: 75 | RDTree** mForest; 76 | unsigned int mNTrees; 77 | 78 | public: 79 | Forest(const char** aFiles, 80 | unsigned int aNFiles); 81 | ~Forest(); 82 | 83 | void inferLabels(DepthImage* aDepthImage, 84 | float** aLabelPr, 85 | int* aOutHeight, 86 | int* aOutWidth, 87 | int* aNLabels); 88 | }; 89 | 90 | class JointMap { 91 | private: 92 | bool mValid; 93 | JIParams* mParams; 94 | JSON_Value* mJointMap; 95 | 96 | public: 97 | JointMap(char* aJointMap, char* aJointInferenceParams); 98 | ~JointMap(); 99 | 100 | void inferJoints(Forest* aForest, 101 | DepthImage* aDepthImage, 102 | float** aJoints, 103 | int* aOutNJoints, 104 | int* aOutNDims); 105 | }; 106 | } 107 | -------------------------------------------------------------------------------- /src/python/infer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import glimpse 4 | import sys 5 | 6 | if len(sys.argv) < 5: 7 | print('Usage: infer.py [tree2.json ...]') 8 | sys.exit(0) 9 | 10 | forest = glimpse.Forest(sys.argv[4:]) 11 | jointmap = glimpse.JointMap(sys.argv[1], sys.argv[2]) 12 | depth_image = glimpse.DepthImage(sys.argv[3]) 13 | 14 | joints = jointmap.inferJoints(forest, depth_image) 15 | 16 | for i in range(len(joints)): 17 | print('Joint %d: %f, %f, %f' % (i, joints[i][0], joints[i][1], joints[i][2])) 18 | -------------------------------------------------------------------------------- /src/python/setup.cfg: -------------------------------------------------------------------------------- 1 | [build_ext] 2 | include-dirs=../ 3 | library-dirs=../../build 4 | swig-opts=-c++ -keyword 5 | -------------------------------------------------------------------------------- /src/python/setup.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # 3 | # Copyright (c) 2017 Glimp IP Ltd 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | # 23 | 24 | from setuptools import setup, Extension 25 | from distutils.command.build import build 26 | 27 | import numpy 28 | 29 | try: 30 | numpy_include = numpy.get_include() 31 | except AttributeError: 32 | numpy_include = numpy.get_numpy_include() 33 | 34 | class BuildExtFirst(build): 35 | sub_commands = [('build_ext', build.has_ext_modules), 36 | ('build_py', build.has_pure_modules), 37 | ('build_clib', build.has_c_libraries), 38 | ('build_scripts', build.has_scripts)] 39 | 40 | glimpse = Extension('_glimpse', 41 | ['glimpse.i', 'glimpse_python.cc', 42 | '../image_utils.cc', 43 | '../infer.cc', 44 | '../loader.cc', 45 | '../tinyexr.cc', 46 | '../parson.c', 47 | '../llist.c', 48 | '../xalloc.c' 49 | ], 50 | include_dirs = [numpy_include], 51 | libraries = ['png']) 52 | 53 | setup(name = 'glimpse', 54 | description = 'A library for performing joint inference from depth images', 55 | author = 'Robert Bragg, Chris Lord', 56 | author_email = 'robert@impossible.com, chrisl@impossible.com', 57 | version = '0.0.1', 58 | package_dir = { 'glimpse': '.' }, 59 | packages = [ 'glimpse' ], 60 | cmdclass = { 'build': BuildExtFirst }, 61 | ext_modules = [ glimpse ], 62 | license = 'MIT', 63 | url = 'https://medium.com/impossible/glimpse-a-sneak-peak-into-your-creative-self-29bd2e656ff6', 64 | install_requires = [ 'numpy' ]) 65 | -------------------------------------------------------------------------------- /src/rdt-info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (c) 2017 Glimp IP Ltd 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | # 23 | # 24 | # This script takes a JSON randomized decision tree description and packs it 25 | # into a binary representation that's understood by our inferrence code. 26 | 27 | import os 28 | import argparse 29 | import textwrap 30 | import json 31 | import struct 32 | 33 | parser = argparse.ArgumentParser( 34 | formatter_class=argparse.RawDescriptionHelpFormatter, 35 | epilog=textwrap.dedent("""\ 36 | This tool prints information about a Glimpse decision trees in a JSON 37 | format. 38 | """)) 39 | parser.add_argument("json_file", nargs=1, help="Input JSON Decision Tree") 40 | parser.add_argument("-e", "--eval", help='Evaluate exression like "info[\'n_nodes\']" to read single JSON value') 41 | 42 | args = parser.parse_args() 43 | 44 | def log(*args): 45 | print(*args) 46 | 47 | with open(args.json_file[0], 'r') as json_fp: 48 | info = json.load(json_fp) 49 | root = info['root'] 50 | 51 | if '_rdt_version_was' in info: 52 | del info['_rdt_version_was'] 53 | del info['root'] 54 | del info['depth'] # rather read explicitly by traversing tree 55 | 56 | def traverse(info, depth, node): 57 | if len(info['depths']) < depth + 1: 58 | dinfo = { 59 | 'n_nodes': 0, 60 | 'n_leaves': 0 61 | } 62 | info['depths'].append(dinfo) 63 | else: 64 | dinfo = info['depths'][depth] 65 | if depth + 1 > info['depth']: 66 | info['depth'] = depth + 1 67 | info['n_nodes'] += 1 68 | dinfo['n_nodes'] += 1 69 | 70 | if 'p' in node: 71 | info['n_leaves'] += 1 72 | dinfo['n_leaves'] += 1 73 | if 'l' in node: 74 | traverse(info, depth + 1, node['l']) 75 | if 'r' in node: 76 | traverse(info, depth + 1, node['r']) 77 | 78 | info['depth'] = 0 79 | info['n_nodes'] = 0 80 | info['n_leaves'] = 0 81 | info['depths'] = [] 82 | traverse(info, 0, root) 83 | 84 | info['max_nodes'] = pow(2, info['depth']) - 1 85 | 86 | for d in info['depths']: 87 | resolved = (d['n_leaves'] / d['n_nodes']) * 100.0 88 | d['resolved_percent'] = resolved 89 | d['resolved_bar'] = '*' * int((resolved / 2) + 0.5) 90 | 91 | if args.eval != None: 92 | val = eval(args.eval) 93 | log(json.dumps(val, indent=2)) 94 | else: 95 | log(json.dumps(info, indent=2)) 96 | -------------------------------------------------------------------------------- /src/rdt-update.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (c) 2018 Glimp IP Ltd 4 | # 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy 6 | # of this software and associated documentation files (the "Software"), to deal 7 | # in the Software without restriction, including without limitation the rights 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | # copies of the Software, and to permit persons to whom the Software is 10 | # furnished to do so, subject to the following conditions: 11 | # 12 | # The above copyright notice and this permission notice shall be included in 13 | # all copies or substantial portions of the Software. 14 | # 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | # SOFTWARE. 22 | # 23 | # 24 | 25 | import os 26 | import argparse 27 | import textwrap 28 | import json 29 | import sys 30 | 31 | parser = argparse.ArgumentParser( 32 | formatter_class=argparse.RawDescriptionHelpFormatter, 33 | epilog=textwrap.dedent("""\ 34 | This tool updates pre-existing .json decision trees to conform to newer 35 | schemas. 36 | """)) 37 | parser.add_argument("json_file", nargs=1, help="JSON decision tree to update") 38 | parser.add_argument("-p", "--pretty", action='store_true', help='Write indented JSON') 39 | 40 | args = parser.parse_args() 41 | 42 | default_labels = [ 43 | { 44 | "name": "head left", 45 | "opposite": "head right" 46 | }, 47 | { 48 | "name": "head right", 49 | "opposite": "head left" 50 | }, 51 | { 52 | "name": "head top left", 53 | "opposite": "head top right" 54 | }, 55 | { 56 | "name": "head top right", 57 | "opposite": "head top left" 58 | }, 59 | { 60 | "name": "neck", 61 | }, 62 | { 63 | "name": "clavicle left", 64 | "opposite": "clavicle right" 65 | }, 66 | { 67 | "name": "clavicle right", 68 | "opposite": "clavicle left" 69 | }, 70 | { 71 | "name": "shoulder left", 72 | "opposite": "shoulder right" 73 | }, 74 | { 75 | "name": "upper-arm left", 76 | "opposite": "upper-arm right" 77 | }, 78 | { 79 | "name": "shoulder right", 80 | "opposite": "shoulder left" 81 | }, 82 | { 83 | "name": "upper-arm right", 84 | "opposite": "upper-arm left" 85 | }, 86 | { 87 | "name": "elbow left", 88 | "opposite": "elbow right" 89 | }, 90 | { 91 | "name": "forearm left", 92 | "opposite": "forearm right" 93 | }, 94 | { 95 | "name": "elbow right", 96 | "opposite": "elbow left" 97 | }, 98 | { 99 | "name": "forearm right", 100 | "opposite": "forearm left" 101 | }, 102 | { 103 | "name": "left wrist", 104 | "opposite": "right wrist" 105 | }, 106 | { 107 | "name": "left hand", 108 | "opposite": "right hand" 109 | }, 110 | { 111 | "name": "right wrist", 112 | "opposite": "left wrist" 113 | }, 114 | { 115 | "name": "right hand", 116 | "opposite": "left hand" 117 | }, 118 | { 119 | "name": "left hip", 120 | "opposite": "right hip" 121 | }, 122 | { 123 | "name": "left thigh", 124 | "opposite": "right thigh" 125 | }, 126 | { 127 | "name": "right hip", 128 | "opposite": "left hip" 129 | }, 130 | { 131 | "name": "right thigh", 132 | "opposite": "left thigh" 133 | }, 134 | { 135 | "name": "left knee", 136 | "opposite": "right knee" 137 | }, 138 | { 139 | "name": "left shin", 140 | "opposite": "right shin" 141 | }, 142 | { 143 | "name": "right knee", 144 | "opposite": "left knee" 145 | }, 146 | { 147 | "name": "right shin", 148 | "opposite": "left shin" 149 | }, 150 | { 151 | "name": "left ankle", 152 | "opposite": "right ankle" 153 | }, 154 | { 155 | "name": "left toes", 156 | "opposite": "right toes" 157 | }, 158 | { 159 | "name": "right ankle", 160 | "opposite": "left ankle" 161 | }, 162 | { 163 | "name": "right toes", 164 | "opposite": "left toes" 165 | }, 166 | { 167 | "name": "left waist", 168 | "opposite": "right waist" 169 | }, 170 | { 171 | "name": "right waist", 172 | "opposite": "left waist" 173 | }, 174 | { 175 | "name": "background", 176 | } 177 | ] 178 | 179 | tree = None 180 | 181 | changed = False 182 | 183 | with open(args.json_file[0], 'r') as json_fp: 184 | tree = json.load(json_fp) 185 | 186 | if 'root' not in tree or 'n_labels' not in tree: 187 | sys.exit("Not a decision tree") 188 | 189 | if 'labels' not in tree: 190 | print("Adding labels") 191 | tree['labels'] = default_labels 192 | changed = True 193 | 194 | if not changed: 195 | sys.exit("No changes") 196 | 197 | if tree != None: 198 | print("Writting new file") 199 | with open(args.json_file[0], 'w') as json_fp: 200 | if args.pretty: 201 | json.dump(tree, json_fp, indent=4) 202 | else: 203 | json.dump(tree, json_fp) 204 | -------------------------------------------------------------------------------- /src/rdt_tree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | 34 | #include "parson.h" 35 | 36 | #define vector(type,size) type __attribute__ ((vector_size(sizeof(type)*(size)))) 37 | 38 | #define RDT_VERSION 6 39 | 40 | typedef struct { 41 | /* XXX: Note that (at least with gcc) then uv will have a 16 byte 42 | * aligment resulting in a total struct size of 32 bytes with 4 bytes 43 | * alignment padding at the end 44 | */ 45 | vector(float,4) uv; // U in [0:2] and V in [2:4] 46 | float t; // Threshold 47 | uint32_t label_pr_idx; // Index into label probability table (1-based) 48 | } Node; 49 | 50 | typedef struct { 51 | char tag[3]; 52 | uint8_t version; 53 | uint8_t depth; 54 | uint8_t n_labels; 55 | uint8_t bg_label; 56 | // 1 byte padding 57 | float fov; 58 | float bg_depth; // v5+ 59 | uint8_t flip_map[256]; // v6+ 60 | } RDTHeader; 61 | 62 | typedef struct { 63 | RDTHeader header; 64 | Node* nodes; 65 | uint32_t n_pr_tables; 66 | float* label_pr_tables; 67 | } RDTree; 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif 72 | 73 | RDTree* 74 | rdt_tree_load_from_json(struct gm_logger* log, 75 | JSON_Value* json_tree_value, 76 | bool allow_incomplete_leaves, 77 | char** err); 78 | RDTree* 79 | rdt_tree_load_from_json_file(struct gm_logger* log, 80 | const char* filename, 81 | bool allow_incomplete_leaves, 82 | char** err); 83 | 84 | RDTree* 85 | rdt_tree_load_from_buf(struct gm_logger* log, 86 | uint8_t* tree, 87 | int len, 88 | char** err); 89 | RDTree* 90 | rdt_tree_load_from_file(struct gm_logger* log, 91 | const char* filename, 92 | char** err); 93 | 94 | void 95 | rdt_tree_destroy(RDTree* tree); 96 | 97 | bool 98 | rdt_tree_save(RDTree* tree, const char* filename); 99 | 100 | RDTree** 101 | rdt_forest_load_from_files(struct gm_logger* log, 102 | const char** files, 103 | int n_files, 104 | char **err); 105 | 106 | void 107 | rdt_forest_destroy(RDTree** forest, int n_trees); 108 | 109 | bool 110 | rdt_util_load_flip_map_from_label_map(struct gm_logger* log, 111 | JSON_Value* js_label_map, 112 | uint8_t* flip_map, 113 | char** err); 114 | #ifdef __cplusplus 115 | }; 116 | #endif 117 | -------------------------------------------------------------------------------- /src/simple.frag: -------------------------------------------------------------------------------- 1 | 2 | varying lowp vec3 v_color; 3 | 4 | void main() { 5 | gl_FragColor = vec4(v_color, 1.0); 6 | } 7 | -------------------------------------------------------------------------------- /src/simple.vert: -------------------------------------------------------------------------------- 1 | 2 | attribute highp vec3 a_position; 3 | attribute lowp vec3 a_color; 4 | 5 | varying lowp vec3 v_color; 6 | 7 | void main() { 8 | gl_Position = vec4(a_position, 1.0); 9 | v_color = a_color; 10 | } 11 | -------------------------------------------------------------------------------- /src/tango-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "gap_dist": 1, 3 | "gap_tolerance": 0.02, 4 | "depth_gap_fill": true, 5 | "apply_depth_distortion": true, 6 | "cloud_res": 1, 7 | "min_depth": 0.25, 8 | "max_depth": 4.0, 9 | "seg_res": 1, 10 | "normal_depth_change": 0.03, 11 | "normal_smooth": 4.0, 12 | "min_inliers": 60, 13 | "angular_threshold": 11.0, 14 | "distance_threshold": 0.1, 15 | "refinement_distance_threshold": 0.05, 16 | "max_curvature": 0.007, 17 | "cluster_tolerance": 0.13 18 | } 19 | -------------------------------------------------------------------------------- /src/tinyexr.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #define TINYEXR_IMPLEMENTATION 26 | #include "tinyexr.h" 27 | -------------------------------------------------------------------------------- /src/viewer/index.html: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 21 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 |
Training index Loading...
42 |
Device index Loading...
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 51 |
52 |
53 |
54 |
fooooo
55 |
56 |
57 |
58 | 59 |
60 |
61 | 62 | 73 | 74 | 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/viewer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "glimpse-viewer", 3 | "version": "1.0.0", 4 | "description": "A graphical viewer for Glimpse training data", 5 | "main": "server.js", 6 | "scripts": { 7 | "prepare": "browserify node_modules/pngjs/lib/png.js -s png > png.js", 8 | "start": "node server.js", 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://gitlab.com/impossible/glimpse-sdk.git" 14 | }, 15 | "author": "", 16 | "license": "MIT", 17 | "bugs": { 18 | "url": "https://gitlab.com/impossible/glimpse-sdk/issues" 19 | }, 20 | "homepage": "https://gitlab.com/impossible/glimpse-sdk#README", 21 | "dependencies": { 22 | "connect": "^3.6.5", 23 | "jquery": "^3.2.1", 24 | "jquery-ui-dist": "^1.12.1", 25 | "pngjs": "^3.3.0", 26 | "serve-static": "^1.13.1", 27 | "three": "^0.87.1" 28 | }, 29 | "devDependencies": { 30 | "browserify": "^14.4.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/viewer/server.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var connect = require('connect'); 4 | var serveStatic = require('serve-static'); 5 | connect().use(serveStatic(__dirname)).listen(8080, function(){ 6 | console.log('Server running on 8080...'); 7 | }); 8 | -------------------------------------------------------------------------------- /src/wrapper_image.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2006-2014 Davis E. King (davis@dlib.net) 2 | // Copyright (C) 2017 Impossible Labs 3 | // 4 | // Boost Software License - Version 1.0 - August 17th, 2003 5 | // 6 | // Permission is hereby granted, free of charge, to any person or organization 7 | // obtaining a copy of the software and accompanying documentation covered by 8 | // this license (the "Software") to use, reproduce, display, distribute, 9 | // execute, and transmit the Software, and to prepare derivative works of the 10 | // Software, and to permit third-parties to whom the Software is furnished to 11 | // do so, all subject to the following: 12 | // 13 | // The copyright notices in the Software and this entire statement, including 14 | // the above license grant, this restriction and the following disclaimer, 15 | // must be included in all copies of the Software, in whole or in part, and 16 | // all derivative works of the Software, unless such copies or derivative 17 | // works are solely in the form of machine-executable object code generated by 18 | // a source language processor. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 23 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 24 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 25 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 | // DEALINGS IN THE SOFTWARE. 27 | 28 | #pragma once 29 | 30 | #include 31 | #include 32 | 33 | namespace glimpse 34 | { 35 | template < 36 | typename T, 37 | typename mem_manager = dlib::default_memory_manager 38 | > 39 | class wrapped_image 40 | { 41 | public: 42 | void set_size (long rows, long cols); 43 | 44 | long nc() const { return nc_; } 45 | long nr() const { return nr_; } 46 | long width_step() const { return stride_; } 47 | const T *data() const { return data_; } 48 | 49 | void wrap(long width, 50 | long height, 51 | long stride, 52 | const T *data) 53 | { 54 | assert(stride >= width * (long)sizeof(T)); 55 | 56 | nc_ = width; 57 | stride_ = stride; 58 | nr_ = height; 59 | data_ = data; 60 | } 61 | 62 | private: 63 | const T* data_; 64 | long nc_; 65 | long nr_; 66 | long stride_; 67 | }; 68 | 69 | template < 70 | typename T, 71 | typename mem_manager 72 | > 73 | void glimpse::wrapped_image::set_size(long rows, 74 | long cols) 75 | { 76 | // make sure requires clause is not broken 77 | DLIB_ASSERT((cols >= 0 && rows >= 0) , 78 | "\tvoid array2d::set_size(long rows, long cols)" 79 | << "\n\tThe array2d can't have negative rows or columns." 80 | << "\n\tthis: " << this 81 | << "\n\tcols: " << cols 82 | << "\n\trows: " << rows 83 | ); 84 | } 85 | } 86 | 87 | 88 | /* Allow dlib to use our wrapper as an image by implementing dlib's 89 | * generic image trait... 90 | */ 91 | namespace dlib 92 | { 93 | template 94 | struct image_traits > 95 | { 96 | typedef T pixel_type; 97 | }; 98 | template 99 | struct image_traits > 100 | { 101 | typedef T pixel_type; 102 | }; 103 | 104 | template 105 | inline long num_rows( const glimpse::wrapped_image& img) { return img.nr(); } 106 | template 107 | inline long num_columns( const glimpse::wrapped_image& img) { return img.nc(); } 108 | 109 | template 110 | inline void set_image_size( 111 | glimpse::wrapped_image& img, 112 | long rows, 113 | long cols 114 | ) { 115 | /* We don't own the buffer storage so we can't resize it. 116 | * 117 | * Also don't bother considering the case where the image becomes 118 | * smaller - simpler to just disallow resizing entirely. 119 | */ 120 | assert(!"reached"); 121 | //img.set_size(rows,cols); 122 | } 123 | 124 | template 125 | inline void* image_data(glimpse::wrapped_image& img) 126 | { 127 | return (void *)(img.data()); 128 | } 129 | 130 | template 131 | inline const void *image_data(const glimpse::wrapped_image& img) 132 | { 133 | return static_cast(img.data()); 134 | } 135 | 136 | template 137 | inline long width_step(const glimpse::wrapped_image& img) 138 | { 139 | return img.width_step(); 140 | } 141 | 142 | } 143 | 144 | 145 | -------------------------------------------------------------------------------- /src/xalloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | #define _GNU_SOURCE // vasprintf 26 | #define _XOPEN_SOURCE 600 // posix_memalign 27 | 28 | #if defined(__APPLE__) 29 | #include 30 | #else 31 | #define TARGET_OS_MAC 0 32 | #define TARGET_OS_IOS 0 33 | #define TARGET_OS_OSX 0 34 | #endif 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "xalloc.h" 41 | 42 | #define return_if_valid(x) ({ if (x == NULL) abort(); return x; }) 43 | 44 | void* 45 | xmalloc(size_t size) 46 | { 47 | void* mem = malloc(size); 48 | return_if_valid(mem); 49 | } 50 | 51 | void* 52 | xaligned_alloc(size_t alignment, size_t size) 53 | { 54 | void* mem = NULL; 55 | 56 | #ifdef _WIN32 57 | mem = _aligned_malloc(size, alignment); 58 | #else 59 | posix_memalign(&mem, alignment, size); 60 | #endif 61 | 62 | return_if_valid(mem); 63 | } 64 | 65 | void 66 | xfree(void *ptr) 67 | { 68 | free(ptr); 69 | } 70 | 71 | void* 72 | xcalloc(size_t nmemb, size_t size) 73 | { 74 | void* mem = calloc(nmemb, size); 75 | return_if_valid(mem); 76 | } 77 | 78 | void * 79 | xrealloc(void *ptr, size_t size) 80 | { 81 | if (size == 0) { 82 | free(ptr); 83 | return NULL; 84 | } 85 | ptr = realloc(ptr, size); 86 | return_if_valid(ptr); 87 | } 88 | 89 | void 90 | xvasprintf(char **strp, const char *fmt, va_list ap) 91 | { 92 | if (!strp) { 93 | fprintf(stderr, "NULL xvasprintf dest ptr, for string: '"); 94 | vfprintf(stderr, fmt, ap); 95 | fprintf(stderr, "'\n"); 96 | abort(); 97 | } 98 | 99 | #if defined(__linux__) 100 | if (vasprintf(strp, fmt, ap) < 0) 101 | abort(); 102 | #else 103 | va_list len_ap; 104 | va_copy(len_ap, ap); 105 | int len = vsnprintf(NULL, 0, fmt, len_ap); 106 | if (len < 0) 107 | abort(); 108 | 109 | char *str = xmalloc(len + 1); 110 | va_list copy_ap; 111 | va_copy(copy_ap, ap); 112 | vsnprintf(str, len + 1, fmt, copy_ap); 113 | *strp = str; 114 | #endif 115 | } 116 | 117 | void 118 | xasprintf(char **strp, const char *fmt, ...) 119 | { 120 | va_list ap; 121 | 122 | va_start(ap, fmt); 123 | xvasprintf(strp, fmt, ap); 124 | va_end(ap); 125 | } 126 | 127 | 128 | -------------------------------------------------------------------------------- /src/xalloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017 Glimp IP Ltd 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be 13 | * included in all copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 19 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | void* xmalloc(size_t size); 36 | void* xaligned_alloc(size_t alignment, size_t size); 37 | void xfree(void *ptr); 38 | void* xcalloc(size_t nmemb, size_t size); 39 | void* xrealloc(void *ptr, size_t size); 40 | void xvasprintf(char **strp, const char *fmt, va_list ap); 41 | void xasprintf(char **strp, const char *fmt, ...); 42 | 43 | #ifdef __cplusplus 44 | }; 45 | #endif 46 | -------------------------------------------------------------------------------- /subprojects/boost.wrap: -------------------------------------------------------------------------------- 1 | [wrap-file] 2 | directory = boost_1_69_0 3 | 4 | source_url = https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.bz2 5 | source_filename = boost_1_69_0.tar.bz2 6 | source_hash = 8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406 7 | 8 | patch_url = https://fake.url.to.please.meson.but.file.in.packagecache/ 9 | patch_filename = boost-wrap-1.69.0.tar 10 | patch_hash = 48d00adcb2b6569836263adbd863cfa8776593fa0f5f0b47dded8723a8677c98 11 | -------------------------------------------------------------------------------- /subprojects/dlib.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = dlib 3 | url = https://github.com/glimpse-project/dlib.git 4 | revision = b96be2eec2795e9262c9281e2494179e2d6825b3 5 | -------------------------------------------------------------------------------- /subprojects/eigen3.wrap: -------------------------------------------------------------------------------- 1 | [wrap-file] 2 | directory = eigen-git-mirror-3.3.4 3 | 4 | source_url = https://github.com/eigenteam/eigen-git-mirror/archive/3.3.4.zip 5 | source_filename = eigen-git-mirror-3.3.4.zip 6 | source_hash = f5580adc34ea45a4c30200e4100f8a55c55af22b77d4ed05985118fd0b15b77e 7 | 8 | patch_url = https://fake.url.to.please.meson.but.file.in.packagecache/ 9 | patch_filename = eigen-wrap-3.3.4.tar 10 | patch_hash = 34470889daf9223af30fd72f80f7660c6aab3aeeb32053a5ebddfadd7f7b864d 11 | -------------------------------------------------------------------------------- /subprojects/flann.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = flann 3 | url = https://github.com/glimpse-project/flann.git 4 | revision = 5ecfc1c9be1d3e2add09e664e0ede308e439569a 5 | -------------------------------------------------------------------------------- /subprojects/glfm.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = glfm 3 | url = https://github.com/glimpse-project/glfm 4 | revision = 601d251026985b85fbe406d6da3f3c78f490d4dd 5 | -------------------------------------------------------------------------------- /subprojects/glfw.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = glfw 3 | url = https://github.com/rib/glfw 4 | revision = 70fab1f0eb504032845481cd142fe01dc6f62a55 5 | -------------------------------------------------------------------------------- /subprojects/glm.wrap: -------------------------------------------------------------------------------- 1 | [wrap-file] 2 | directory = glm-0.9.9-a2 3 | 4 | source_url = https://github.com/g-truc/glm/archive/0.9.9-a2.tar.gz 5 | source_filename = 0.9.9-a2.tar.gz 6 | source_hash = c0e4d12d242cfd08a02bff114c9ac5e0892ac6f54a116168b7d9faa8b89350bc 7 | 8 | patch_url = https://fake.url.to.please.meson.but.file.in.packagecache/ 9 | patch_filename = glm-wrap-0.9.9-a2.tar 10 | patch_hash = 16b799178fc0aaa9e7562eb5301b89c357b2c79dbcae627a3442e003285be6da 11 | -------------------------------------------------------------------------------- /subprojects/libepoxy.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = libepoxy 3 | url = https://github.com/glimpse-project/libepoxy 4 | revision = 42e4809fcd6deaeeb93f1c2aff90cdee9a1f817d 5 | -------------------------------------------------------------------------------- /subprojects/libfreenect.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = libfreenect 3 | url = https://github.com/glimpse-project/libfreenect.git 4 | revision = ef5e782f9e243ce7a98649dacca9544c4a05b6d9 5 | -------------------------------------------------------------------------------- /subprojects/libpng.wrap: -------------------------------------------------------------------------------- 1 | [wrap-file] 2 | directory = libpng-1.6.17 3 | 4 | source_url = https://ftp.osuosl.org/pub/blfs/conglomeration/libpng/libpng-1.6.17.tar.xz 5 | source_filename = libpng-1.6.17.tar.xz 6 | source_hash = 98507b55fbe5cd43c51981f2924e4671fd81fe35d52dc53357e20f2c77fa5dfd 7 | 8 | patch_url = https://fake.url.to.please.meson.but.file.in.packagecache/ 9 | patch_filename = libpng-wrap-1.6.17.tar 10 | patch_hash = b9433503fe4987ecb8e1275581994005e387b6d4a7e2a352cb976ace2d289e5a 11 | -------------------------------------------------------------------------------- /subprojects/librealsense.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = librealsense 3 | url = https://github.com/glimpse-project/librealsense 4 | revision = c88e2f84a8a859d7c27a06b4a246d2e1e6e3692b 5 | -------------------------------------------------------------------------------- /subprojects/pcl.wrap: -------------------------------------------------------------------------------- 1 | [wrap-git] 2 | directory = pcl 3 | url = https://github.com/glimpse-project/pcl.git 4 | revision = 383d4fd95f3ef9b9e832e4c48e90cd10fd494d76 5 | -------------------------------------------------------------------------------- /subprojects/zlib.wrap: -------------------------------------------------------------------------------- 1 | [wrap-file] 2 | directory = zlib-1.2.8 3 | 4 | source_url = http://zlib.net/fossils/zlib-1.2.8.tar.gz 5 | source_filename = zlib-1.2.8.tar.gz 6 | source_hash = 36658cb768a54c1d4dec43c3116c27ed893e88b02ecfcb44f2166f9c0b7f2a0d 7 | 8 | patch_url = https://fake.url.to.please.meson.but.file.in.packagecache/ 9 | patch_filename = zlib-1.2.8-wrap.tar 10 | patch_hash = 01860637a3f7b1a80cb2b9dbbff9ad6eff764283e3b4bcbb118acf2764f71d54 11 | -------------------------------------------------------------------------------- /travis/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:bionic 2 | ENV LANG C.UTF-8 3 | ENV LC_ALL C.UTF-8 4 | 5 | RUN apt-get update -qq 6 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests \ 7 | sudo \ 8 | unzip \ 9 | gnupg2 \ 10 | wget 11 | 12 | RUN echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main" >> /etc/apt/sources.list 13 | RUN echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-6.0 main" >> /etc/apt/sources.list 14 | RUN wget --no-check-certificate -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - 15 | RUN apt-get update -qq 16 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests \ 17 | curl \ 18 | unzip \ 19 | build-essential \ 20 | ninja-build \ 21 | clang-6.0 \ 22 | lld-6.0 \ 23 | clang-8 \ 24 | lld-8 \ 25 | python3-minimal \ 26 | python3-pip \ 27 | python3-setuptools \ 28 | git \ 29 | pkg-config \ 30 | libz-dev \ 31 | libpng-dev \ 32 | libepoxy-dev \ 33 | libfreenect-dev \ 34 | libglfw3-dev \ 35 | libglm-dev \ 36 | libpcl-dev \ 37 | openjdk-8-jdk 38 | 39 | RUN apt-get clean 40 | 41 | # Workaround multiple bugs in Ubuntu's libpcl-dev package :( 42 | # Re: https://bugs.launchpad.net/ubuntu/+source/pcl/+bug/1738902 43 | RUN sed -i 's/pcl_2d-1.8//' /usr/lib/x86_64-linux-gnu/pkgconfig/pcl_features-1.8.pc && \ 44 | sed -i 's/Requires:/Requires: eigen3 /g' /usr/lib/x86_64-linux-gnu/pkgconfig/pcl_common-1.8.pc 45 | 46 | # Installs Android NDK and creates the toolchain 47 | ENV ANDROID_NDK_VERSION r18b 48 | ENV ANDROID_TARGET_API 28 49 | ENV ANDROID_NDK_HOME /android-ndk-${ANDROID_NDK_VERSION} 50 | ENV ANDROID_NDK_FILENAME android-ndk-${ANDROID_NDK_VERSION}-linux-x86_64.zip 51 | ENV ANDROID_TOOLCHAIN /android-arm-toolchain-${ANDROID_TARGET_API} 52 | ENV PATH ${ANDROID_TOOLCHAIN}/bin:$PATH 53 | RUN echo "Downloading android-ndk" >&2 && \ 54 | wget --no-check-certificate --no-verbose https://dl.google.com/android/repository/${ANDROID_NDK_FILENAME} && \ 55 | echo "Extracting android-ndk" >&2 && \ 56 | unzip ${ANDROID_NDK_FILENAME} && \ 57 | mkdir -p ${ANDROID_TOOLCHAIN} && \ 58 | ${ANDROID_NDK_HOME}/build/tools/make_standalone_toolchain.py \ 59 | --force \ 60 | --install-dir ${ANDROID_TOOLCHAIN} \ 61 | --arch arm \ 62 | --api ${ANDROID_TARGET_API} \ 63 | --stl libc++ && \ 64 | rm ${ANDROID_NDK_FILENAME} 65 | 66 | # Installs Android SDK 67 | ENV ANDROID_BUILD_TOOLS 28.0.3 68 | ENV ANDROID_SDK_VERSION 4333796 69 | ENV ANDROID_SDK_FILENAME sdk-tools-linux-${ANDROID_SDK_VERSION}.zip 70 | ENV ANDROID_HOME /android-sdk 71 | ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools 72 | 73 | RUN mkdir -p ${ANDROID_HOME} && \ 74 | echo "Downloading android-sdk" >&2 && \ 75 | wget --no-check-certificate --no-verbose https://dl.google.com/android/repository/${ANDROID_SDK_FILENAME} && \ 76 | echo "Extracting android-sdk" >&2 && \ 77 | unzip ${ANDROID_SDK_FILENAME} -d ${ANDROID_HOME} && \ 78 | rm ${ANDROID_SDK_FILENAME} 79 | 80 | RUN yes | sdkmanager --licenses 81 | RUN sdkmanager "tools" "platform-tools" 82 | RUN yes | sdkmanager \ 83 | "platforms;android-${ANDROID_TARGET_API}" \ 84 | "build-tools;${ANDROID_BUILD_TOOLS}" \ 85 | "platform-tools" 86 | 87 | ADD windows-sdk /windows-sdk 88 | 89 | CMD ["/bin/bash"] 90 | -------------------------------------------------------------------------------- /travis/README.md: -------------------------------------------------------------------------------- 1 | Appart from the .travis.yml at the top of the repo these scripts help support 2 | our Travis-CI-based continuous integration. 3 | 4 | `build-travis-docker-image.sh` builds a Docker image with most of our 5 | build-time prerequisites which helps speed up repeat builds of Glimpse. 6 | 7 | To use, this you should review and edit the `Dockerfile` that's here and run: 8 | 9 | ``` 10 | ./build-travis-docker-image.sh 11 | docker login 12 | docker push 13 | ``` 14 | 15 | *(Note: the image we're using currently is named rib1/glimpse-travis, but since 16 | that implies being able to login as rib1 you might need to replace references 17 | to that name within these scripts and .travis.yml to use an alternative name)* 18 | *(Note: Dodkerfile expects there to be an adjacent windows-sdk/ and absolute 19 | paths for the -cross-files under windows-sdk/meson/ should assume the SDK will 20 | be copied to /windows-sdk in the docker image)* 21 | 22 | `travis-ci-prep-docker-ubuntu.sh` derives a final docker image which knows 23 | about the travis user so that it's possible to mount the travis build directory 24 | into our running Docker image with compatible permissions. 25 | 26 | `travis-ci-build.sh` encapsulates all our build instructions so we don't have 27 | to describe everything with the more awkward .travis.yml syntax. 28 | 29 | -------------------------------------------------------------------------------- /travis/build-travis-docker-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo docker build -t rib1/glimpse-travis . 4 | -------------------------------------------------------------------------------- /travis/travis-ci-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | python3 --version 7 | pip3 --version 8 | ninja --version 9 | 10 | pip3 install git+https://github.com/glimpse-project/meson 11 | export PATH=$HOME/.local/bin:$PATH 12 | 13 | mkdir build 14 | cd build 15 | 16 | # Have had builds fail just because Meson hasn't been able to download 17 | # subproject tarballs, so we allow configurations to fail and back off 18 | # for five seconds before testing that configuration succeeds (at 19 | # which point subprojects should have been downloaded and unpacked) 20 | set +e 21 | for i in 1 2 3 22 | do 23 | meson .. --errorlogs $CONFIG_OPTS || sleep 5 24 | if test -f build.ninja; then 25 | break 26 | fi 27 | done 28 | set -e 29 | 30 | ninja 31 | -------------------------------------------------------------------------------- /travis/travis-ci-prep-docker-image.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if ! test $# -eq 2; then 6 | echo "usage: $0 docker-base-image-name new-image-name" 7 | exit 1 8 | fi 9 | 10 | _USER=`id -un` 11 | _UID=`id -u` 12 | _GID=`id -g` 13 | _GROUP=`id -gn` 14 | 15 | if test $_UID -eq 0; then 16 | echo "Not expected to be run as root" 17 | echo "" 18 | echo "This script should be run as the user that will" 19 | echo "be building glimpse" 20 | exit 1 21 | fi 22 | 23 | cat << EOF > Dockerfile 24 | FROM $1 25 | USER root 26 | ENV LANG C.UTF-8 27 | ENV LC_ALL C.UTF-8 28 | RUN groupadd -g $_GID $_GROUP && useradd -u $_UID -g $_GID -G sudo -m $_USER 29 | RUN echo "%sudo ALL=NOPASSWD: ALL">>/etc/sudoers 30 | 31 | USER $_USER 32 | RUN touch /home/$_USER/.sudo_as_admin_successfull 33 | RUN mkdir /home/$_USER/build 34 | WORKDIR /home/$_USER/build 35 | 36 | CMD ["/bin/bash"] 37 | EOF 38 | 39 | echo "Deriving final $2 build image from base $1 image..." 40 | echo "" 41 | echo " This is adding a '$_USER' user that matches the current host user" 42 | echo " to allow seamless mounting of host directories" 43 | echo "" 44 | sudo docker build -t $2 . 45 | 46 | cat << EOF > build.sh 47 | sudo docker run -t -i -v \$PWD:/home/$USER/src $2 build/travis-ci-build.sh 48 | EOF 49 | chmod +x ./build.sh 50 | 51 | echo "" 52 | echo "Ready!" 53 | echo "" 54 | echo "To enter the build environment run:" 55 | echo "" 56 | echo "$ sudo docker run -t -i -v \$PWD:/home/$USER/build $2" 57 | echo "" 58 | echo "This will mount the host's current working directory in ~/build" 59 | echo "" 60 | -------------------------------------------------------------------------------- /travis/travis-ci-render.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | if test -d rendered-training-data/rendered; then 7 | exit 0 8 | fi 9 | 10 | python3 --version 11 | pip3 --version 12 | ninja --version 13 | 14 | export PATH=$HOME/.local/bin:$PATH 15 | 16 | # Even though it's an out-of-date version we install Blender via apt-get 17 | # as an easy way of installing dependencies 18 | # sudo apt-get install blender -y --no-install-recommends --no-install-suggests 19 | 20 | if ! test -f blender-2.79-linux-glibc219-x86_64/blender; then 21 | wget https://ftp.nluug.nl/pub/graphics/blender/release/Blender2.79/blender-2.79-linux-glibc219-x86_64.tar.bz2 22 | tar -xf blender-2.79-linux-glibc219-x86_64.tar.bz2; 23 | fi 24 | export PATH=$PWD/blender-2.79-linux-glibc219-x86_64:$PATH 25 | blender --version 26 | 27 | pip3 install numpy 28 | git clone --depth=1 https://github.com/glimpse-project/glimpse-training-data 29 | pushd glimpse-training-data 30 | ./unpack.sh 31 | popd 32 | pushd glimpse-training-data/blender 33 | ./install-addons.sh 34 | popd 35 | 36 | export PATH=$PWD/glimpse-training-data:$PATH 37 | 38 | mkdir -p rendered-training-data/rendered 39 | 40 | glimpse-generator.py \ 41 | preload \ 42 | --start 25 \ 43 | --end 26 44 | 45 | glimpse-generator.py \ 46 | render \ 47 | --start 25 \ 48 | --end 26 \ 49 | --dest rendered-training-data/rendered \ 50 | --name test-render 51 | 52 | find rendered-training-data 53 | -------------------------------------------------------------------------------- /travis/travis-ci-train.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | if ! test -d rendered-training-data/rendered; then 7 | echo "Training data expected under rendered-training-data/rendered" 8 | exit 1 9 | fi 10 | 11 | find rendered-training-data 12 | 13 | python3 --version 14 | pip3 --version 15 | ninja --version 16 | 17 | pip3 install git+https://github.com/glimpse-project/meson 18 | export PATH=$HOME/.local/bin:$PATH 19 | 20 | git clone --depth=1 https://github.com/glimpse-project/glimpse-training-data 21 | 22 | # We rely on the cached, rendered, training images so we don't currently need 23 | # the unpack training data here.... 24 | # 25 | #pushd glimpse-training-data 26 | # ./unpack.sh 27 | #popd 28 | 29 | #git clone --depth=1 https://github.com/glimpse-project/glimpse-models 30 | #pushd glimpse-models 31 | # ./unpack.sh 32 | #popd 33 | 34 | export CC=clang-6.0 CXX=clang++-6.0 35 | 36 | mkdir build 37 | pushd build 38 | 39 | # Have had builds fail just because Meson hasn't been able to download 40 | # subproject tarballs, so we allow configurations to fail and back off 41 | # for five seconds before testing that configuration succeeds (at 42 | # which point subprojects should have been downloaded and unpacked) 43 | set +e 44 | for i in 1 2 3 45 | do 46 | meson .. --errorlogs --warnlevel 3 $CONFIG_OPTS || sleep 5 47 | if test -f build.ninja; then 48 | break 49 | fi 50 | done 51 | set -e 52 | 53 | ninja -v 54 | 55 | popd 56 | 57 | export PATH=$PWD/src:$PATH 58 | export PATH=$PWD/build:$PATH 59 | 60 | image-pre-processor \ 61 | rendered-training-data/rendered/test-render \ 62 | rendered-training-data/pre-processed/test-render \ 63 | glimpse-training-data/label-maps/2018-11-render-to-2018-08-rdt-map.json \ 64 | --config glimpse-training-data/pre-processor-configs/iphone-x-config.json 65 | 66 | glimpse-training-data/glimpse-data-indexer.py rendered-training-data/pre-processed/test-render 67 | 68 | JOBS=$(cat<<'EOF' 69 | [ 70 | { 71 | "index_name": "full", 72 | "out_file": "full-d2.json", 73 | "max_depth": 2, 74 | "n_pixels": 500, 75 | "n_thresholds": 25, 76 | "n_uvs": 500, 77 | "pretty": true 78 | }, 79 | { 80 | "index_name": "full", 81 | "reload": "full-d2.json", 82 | "out_file": "full-d3.json", 83 | "max_depth": 3, 84 | "n_pixels": 500, 85 | "n_thresholds": 25, 86 | "n_uvs": 500, 87 | "pretty": true 88 | } 89 | ] 90 | EOF 91 | ) 92 | 93 | train_rdt --log-stderr -q "$JOBS" -d rendered-training-data/pre-processed/test-render full full-tree.json 94 | -------------------------------------------------------------------------------- /windows-cross-test/cross.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # TODO: remove me - this script was just used to figure out how to cross-compile 4 | # for windows using Clang 5 | 6 | set -x 7 | 8 | VC_INCLUDES="/mnt/c/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/include" 9 | VC_LIBS="/mnt/c/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.15.26726/lib/x64" 10 | 11 | # Universal C Runtime Library (UCRT): 12 | CRT_INCLUDES="/mnt/c/Program Files (x86)/Windows Kits/10/Include/10.0.17134.0/ucrt" 13 | CRT_LIBS="/mnt/c/Program Files (x86)/Windows Kits/10/Lib/10.0.17134.0/ucrt/x64" 14 | 15 | # User-Mode Library (UM): 16 | UM_INCLUDES="/mnt/c/Program Files (x86)/Windows Kits/10/Include/10.0.17134.0/um" 17 | UM_LIBS="/mnt/c/Program Files (x86)/Windows Kits/10/Lib/10.0.17134.0/um/x64" 18 | 19 | 20 | # Comment out to directly use headers/include from Windows 21 | VC_INCLUDES=../windows-sdk/vc/include 22 | VC_LIBS=../windows-sdk/vc/lib/x64 23 | CRT_INCLUDES=../windows-sdk/ucrt/include 24 | CRT_LIBS=../windows-sdk/ucrt/lib/x64 25 | UM_INCLUDES=../windows-sdk/sdk/um/include 26 | UM_LIBS=../windows-sdk/sdk/um/lib/x64 27 | 28 | clang-8 \ 29 | -target x86_64-pc-windows \ 30 | -fms-extensions \ 31 | -fms-compatibility \ 32 | -fdelayed-template-parsing \ 33 | -Wno-expansion-to-defined \ 34 | -Wno-ignored-attributes \ 35 | -isystem "$VC_INCLUDES" \ 36 | -isystem "$CRT_INCLUDES" \ 37 | -isystem "$UM_INCLUDES" \ 38 | -D_WINSOCK_DEPRECATED_NO_WARNINGS=1 \ 39 | -D_CRT_NONSTDC_NO_DEPRECATE \ 40 | -D_CRT_SECURE_NO_DEPRECATE \ 41 | -D_CRT_NONSTDC_NO_WARNINGS \ 42 | -D_CRT_SECURE_NO_WARNINGS \ 43 | -march=native \ 44 | -mtune=native \ 45 | -fuse-ld=lld \ 46 | -DIS_DLL \ 47 | -g \ 48 | -c \ 49 | -o hello.obj \ 50 | -v \ 51 | hello.c 52 | 53 | clang-8 \ 54 | -target x86_64-pc-windows \ 55 | -fms-extensions \ 56 | -fms-compatibility \ 57 | -fdelayed-template-parsing \ 58 | "-L$VC_LIBS" \ 59 | "-L$CRT_LIBS" \ 60 | "-L$UM_LIBS" \ 61 | -march=native \ 62 | -mtune=native \ 63 | -fuse-ld=lld \ 64 | -nostdlib \ 65 | -nostdlib++ \ 66 | -lmsvcrtd \ 67 | -lvcruntimed \ 68 | -lucrtd \ 69 | -lopengl32 \ 70 | -Wl,/implib:hello.lib \ 71 | -shared \ 72 | -o hello.dll \ 73 | hello.obj 74 | 75 | clang-8 \ 76 | -target x86_64-pc-windows \ 77 | -fms-extensions \ 78 | -fms-compatibility \ 79 | -Wno-expansion-to-defined \ 80 | -Wno-ignored-attributes \ 81 | -isystem "$VC_INCLUDES" "-L$VC_LIBS" \ 82 | -isystem "$CRT_INCLUDES" "-L$CRT_LIBS" \ 83 | -isystem "$UM_INCLUDES" "-L$UM_LIBS" \ 84 | -D_WINSOCK_DEPRECATED_NO_WARNINGS=1 \ 85 | -D_CRT_NONSTDC_NO_DEPRECATE \ 86 | -D_CRT_SECURE_NO_DEPRECATE \ 87 | -D_CRT_NONSTDC_NO_WARNINGS \ 88 | -D_CRT_SECURE_NO_WARNINGS \ 89 | -march=native \ 90 | -mtune=native \ 91 | -fuse-ld=lld \ 92 | -nostdlib \ 93 | -nostdlib++ \ 94 | -lmsvcrtd \ 95 | -lvcruntimed \ 96 | -lucrtd \ 97 | -lopengl32 \ 98 | -lhello \ 99 | -o hello.exe \ 100 | -g \ 101 | -v \ 102 | hello.c 103 | 104 | -------------------------------------------------------------------------------- /windows-cross-test/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int __declspec(dllexport) 7 | hello_func(void); 8 | 9 | #ifdef IS_DLL 10 | int __declspec(dllexport) 11 | hello_func(void) 12 | { 13 | return 1; 14 | } 15 | #else 16 | int 17 | main(int argc, char **argv) 18 | { 19 | __m128d a, b; 20 | double vals[2] = {1.0, 2.0}; 21 | a = _mm_loadu_pd (vals); 22 | b = _mm_add_pd (a,a); 23 | _mm_storeu_pd (vals,b); 24 | 25 | printf("Hello, World! %d, vals[0]=%f,[1]=%f\n", hello_func(), vals[0], vals[1]); 26 | return 0; 27 | } 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /xcode/GlimpseViewer/GlimpseViewer/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /xcode/GlimpseViewer/GlimpseViewer/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /xcode/GlimpseViewer/GlimpseViewer/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /xcode/GlimpseViewer/GlimpseViewer/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | NSCameraUsageDescription 24 | Stuff 25 | UIFileSharingEnabled 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIRequiresFullScreen 34 | 35 | UIStatusBarHidden 36 | 37 | UISupportedInterfaceOrientations 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationLandscapeLeft 41 | UIInterfaceOrientationLandscapeRight 42 | 43 | UISupportedInterfaceOrientations~ipad 44 | 45 | UIInterfaceOrientationPortrait 46 | UIInterfaceOrientationPortraitUpsideDown 47 | UIInterfaceOrientationLandscapeLeft 48 | UIInterfaceOrientationLandscapeRight 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /xcode/GlimpseViewer/GlimpseViewer/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | --------------------------------------------------------------------------------