├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── CMakeLists.txt.user ├── COPYING.txt ├── README.md ├── apps ├── CMakeLists.txt ├── colorpick │ └── colorpick.cpp ├── cuda_thrust_helloworld │ ├── CMakeLists.txt │ ├── CMakeLists2.txt │ └── main.cu ├── cuda_thrust_sort │ ├── CMakeLists.txt │ └── main.cu ├── helloworld │ ├── CMakeLists.txt │ └── main.cpp ├── helloworld_atb │ ├── CMakeLists.txt │ ├── main.cpp │ └── main_new.cpp ├── helloworld_cublas │ ├── CMakeLists.txt │ ├── gnuplot_i.h │ ├── main_performance.cpp │ └── main_simple.cpp ├── helloworld_cudagl │ ├── CMakeLists.txt │ └── main.cpp ├── helloworld_opencv │ ├── CMakeLists.txt │ ├── input.png │ └── main.cpp ├── helloworld_openmp │ ├── CMakeLists.txt │ └── main.cpp ├── helloworld_openni │ ├── CMakeLists.txt │ └── main.cpp ├── helloworld_qglviewer │ ├── CMakeLists.txt │ └── main.cpp ├── helloworld_qtopengl │ ├── CMakeLists.txt │ └── main.cpp ├── helloworld_realsense │ ├── CMakeLists.txt │ └── main.cpp ├── helloworld_thrust │ ├── CMakeLists.txt │ └── main.cu ├── hmodel_atb │ ├── AntTweakBarEventFilter.h │ ├── CMakeLists.txt │ └── main.cpp └── synthgen │ └── synthgen.cpp ├── cmake ├── CompileSynthgen.cmake ├── ConfigureAntTweakBar.cmake ├── ConfigureCUDA.cmake ├── ConfigureCeres.cmake ├── ConfigureCompiler.cmake ├── ConfigureEigen.cmake ├── ConfigureGLEW.cmake ├── ConfigureGLFW.cmake ├── ConfigureOpenCV.cmake ├── ConfigureOpenGL.cmake ├── ConfigureOpenGP.cmake ├── ConfigureOpenMP.cmake ├── ConfigureOpenNI.cmake ├── ConfigureQGLViewer.cmake ├── ConfigureQt.cmake ├── ConfigureRealSense.cmake ├── ConfigureSoftKinetic.cmake ├── FindAntTweakBar.cmake ├── FindEigen3.cmake ├── FindGLEW.cmake ├── FindGLFW.cmake ├── FindGLM.cmake ├── FindOpenCV2.cmake ├── FindOpenGP.cmake ├── FindOpenNI2.cmake ├── FindQGLViewer.cmake └── FindSoftKinetic.cmake ├── cudax ├── CMakeLists.txt ├── CublasHelper.h ├── CudaHelper.h ├── CudaTimer.h ├── KinectCamera.h ├── Kinematic.h ├── PixelIndexer.h ├── Timer.h ├── cuda_glm.h ├── externs.h ├── functors │ ├── ComputeJacobianData.h │ ├── ComputeJacobianRow.h │ ├── ComputeJacobianSilhouette.h │ ├── CorrespondencesFinder.h │ └── IsSilhouette.h ├── helper_cuda.h ├── kernel.cu ├── kernel.h ├── kernel_debug.h ├── kernel_init.h ├── kernel_upload.h └── outer_product.cu ├── data ├── models │ └── anastasia │ │ ├── B.txt │ │ ├── C.txt │ │ ├── I.txt │ │ └── R.txt ├── pose_space │ ├── fingers │ │ ├── Limits │ │ ├── P │ │ ├── Sigma │ │ └── pca.png │ ├── mu │ └── thumb │ │ ├── Limits │ │ ├── P │ │ ├── Sigma │ │ └── pca.png └── shaders │ ├── model_FB_fshader.glsl │ ├── model_fshader.glsl │ ├── model_rastorizer_fshader.glsl │ ├── model_vshader.glsl │ └── skin_texture.png ├── tracker ├── CMakeLists.txt ├── Data │ ├── Camera.cpp │ ├── Camera.h │ ├── DataFrame.h │ ├── DataStream.cpp │ ├── DataStream.h │ ├── SolutionStream.h │ ├── TextureColor8UC3.h │ └── TextureDepth16UC1.h ├── DataStructure │ └── CustomJointInfo.h ├── Detection │ ├── DetectionStream.h │ ├── FindFingers.cpp │ ├── FindFingers.h │ ├── QianDetection.cpp │ ├── QianDetection.h │ ├── TrivialDetector.cpp │ ├── TrivialDetector.h │ └── matlab_helpers.h ├── Energy │ ├── Collision.cpp │ ├── Collision.h │ ├── Damping.cpp │ ├── Damping.h │ ├── Energy.cpp │ ├── Energy.h │ ├── Fitting.cpp │ ├── Fitting.h │ ├── Fitting │ │ ├── DistanceTransform.h │ │ ├── OnlinePerformanceMetrics.h │ │ ├── Settings.h │ │ └── TrackingMonitor.h │ ├── JointLimits.cpp │ ├── JointLimits.h │ ├── PoseSpace.cpp │ ├── PoseSpace.h │ ├── PoseSpace_PCA │ │ ├── Limits │ │ ├── P │ │ ├── Sigma │ │ ├── fingers │ │ │ ├── Limits │ │ │ ├── P │ │ │ ├── Sigma │ │ │ ├── mu │ │ │ └── pca.png │ │ ├── mu │ │ ├── pca.png │ │ ├── pca_light.png │ │ └── thumb │ │ │ ├── Limits │ │ │ ├── P │ │ │ ├── Sigma │ │ │ ├── mu │ │ │ └── pca.png │ ├── Temporal.cpp │ └── Temporal.h ├── ForwardDeclarations.h ├── GLWidget.cpp ├── GLWidget.h ├── HModel │ ├── DataLoader.h │ ├── GeometryHelpers.h │ ├── Model.cpp │ ├── Model.h │ ├── ModelSemantics.cpp │ ├── ModelSemantics.h │ ├── ModelSerializer.cpp │ ├── ModelSerializer.h │ ├── OutlineFinder.cpp │ └── OutlineFinder.h ├── HandFinder │ ├── HandFinder.cpp │ ├── HandFinder.h │ ├── connectedComponents.cpp │ ├── connectedComponents.h │ └── wristband.txt ├── OpenGL │ ├── ConvolutionRenderer │ │ ├── ConvolutionRenderer.cpp │ │ ├── ConvolutionRenderer.h │ │ ├── data_points_fshader.glsl │ │ ├── data_points_vshader.glsl │ │ ├── lines_fshader.glsl │ │ ├── lines_vshader.glsl │ │ ├── model_FB_fshader.glsl │ │ ├── model_fshader.glsl │ │ ├── model_points_fshader.glsl │ │ ├── model_points_vshader.glsl │ │ ├── model_rastorizer_fshader.glsl │ │ ├── model_vshader.glsl │ │ ├── outside_points_fshader.glsl │ │ ├── outside_points_vshader.glsl │ │ ├── skin.png │ │ └── skin.tga │ ├── CustomFrameBuffer.cpp │ ├── CustomFrameBuffer.h │ ├── CylindersRenderer │ │ ├── Cylinders_FB_fshader.glsl │ │ ├── Cylinders_FB_vshader.glsl │ │ ├── Cylinders_fshader.glsl │ │ └── Cylinders_vshader.glsl │ ├── DebugRenderer │ │ ├── ArcRenderer.cpp │ │ ├── ArcRenderer.h │ │ ├── CloudRenderer_fshader.glsl │ │ ├── CloudRenderer_vshader.glsl │ │ ├── DebugRenderer.cpp │ │ ├── DebugRenderer.h │ │ ├── PointRenderer.cpp │ │ ├── PointRenderer.h │ │ ├── SegmentRenderer.cpp │ │ └── SegmentRenderer.h │ ├── GeometricPrimitiveRenderer.cpp │ ├── GeometricPrimitiveRenderer.h │ ├── KinectDataRenderer │ │ ├── KinectDataRenderer.cpp │ │ ├── KinectDataRenderer.h │ │ ├── KinectDataRenderer_fshader.glsl │ │ └── KinectDataRenderer_vshader.glsl │ ├── ObjectRenderer.cpp │ ├── ObjectRenderer.h │ ├── OffscreenRenderer.cpp │ ├── OffscreenRenderer.h │ ├── QuadRenderer │ │ ├── QuadRenderer_color_fshader.glsl │ │ ├── QuadRenderer_depth_fshader.glsl │ │ └── QuadRenderer_vshader.glsl │ └── shaders.qrc ├── Sensor │ ├── Sensor.h │ ├── Sensor_openni.cpp │ ├── Sensor_realsense.cpp │ └── Sensor_softkin.cpp ├── Tracker.h ├── TwSettings.cpp ├── TwSettings.h ├── Types.h ├── Worker.cpp └── Worker.h └── util ├── CMakeLists.txt ├── MathUtils.cpp ├── MathUtils.h ├── OpenGL32Format.h ├── Sleeper.h ├── check_error_gl.h ├── gl_wrapper.h ├── mylogger.h ├── opencv_wrapper.h ├── openmp_helpers.h ├── qDebug_helpers.h ├── qfile_helper.h ├── qt2eigen.h ├── singleton.h └── tictoc.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | data/teaser_short/hmodel_rastorized_error.txt 49 | data/teaser_short/hmodel_solutions.txt 50 | data/teaser_short/hmodel_tracking_error.txt 51 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(hmodel) 3 | 4 | #--- Gets rid of annoying CMake 3 warnings 5 | if(NOT (CMAKE_MAJOR_VERSION LESS 3)) 6 | cmake_policy(SET CMP0043 OLD) 7 | cmake_policy(SET CMP0020 OLD) 8 | cmake_policy(SET CMP0005 OLD) 9 | endif() 10 | 11 | #--- Where to find the FindPackageName.cmake 12 | set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) 13 | 14 | #--- Where exes/libs will be deployed 15 | set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}) 16 | set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) 17 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}) 18 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}) 19 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}) 20 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}) 21 | 22 | #--- Compiler setup 23 | include(cmake/ConfigureCompiler.cmake) 24 | 25 | #--- Configure the libraries 26 | include(cmake/ConfigureQt.cmake) 27 | include(cmake/ConfigureOpenGL.cmake) 28 | include(cmake/ConfigureGLEW.cmake) 29 | include(cmake/ConfigureEigen.cmake) 30 | include(cmake/ConfigureOpenCV.cmake) 31 | include(cmake/ConfigureOpenNI.cmake) 32 | include(cmake/ConfigureRealSense.cmake) 33 | include(cmake/ConfigureSoftKinetic.cmake) 34 | include(cmake/ConfigureCUDA.cmake) 35 | include(cmake/ConfigureAntTweakBar.cmake) 36 | #include(cmake/ConfigureCeres.cmake) 37 | 38 | #--- sub-projects 39 | add_subdirectory(util) 40 | add_subdirectory(cudax) 41 | add_subdirectory(tracker) 42 | add_subdirectory(apps/hmodel_atb) 43 | #add_subdirectory(apps/hmodel_qt) 44 | #add_subdirectory(apps/synthgen) #<<< NOT READY 45 | #add_subdirectory(apps/colopick) #<<< NOT READY 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sphere-Meshes for Real-Time Hand Modeling and Tracking 2 | 3 | - **Video**: http://lgg.epfl.ch/publications/2016/HModel/video.mp4 4 | - **Paper PDF**: http://lgg.epfl.ch/publications/2016/HModel/paper.pdf 5 | - **Dataset**: http://lgg.epfl.ch/publications/2016/HModel/teaser.zip 6 | 7 | ## Disclaimer 8 | To obtain the results shown in the video proper hardware is necessary: 9 | - **Windows 8** 10 | - Intel Core **i7 @4GhZ** 11 | - CUDA Graphic card (**NVIDIA GTX980** used in our demo) 12 | - Inter RealSense depth camera 13 | 14 | Other notes: 15 | - note the software must be compiled in **64bits** 16 | - **Wristband** color calibration (make sure the wristband is detected robustly otherwise the tracking might not perform as effectively, you can check this by enabling "show wband" in the hmodel_atb application) 17 | 18 | ## BibTex 19 | @article{hmodel, 20 | title = {Sphere-Meshes for Real-Time Hand Modeling and Tracking}, 21 | author = {Anastasia Tkach and Mark Pauly and Andrea Tagliasacchi}, 22 | journal = {ACM Transactions on Graphics (Proceedings of SIGGRAPH Asia)}, 23 | year = {2016}} 24 | 25 | ## Running "Teaser" Sequence 26 | 27 | in `hmodel/apps/hmodel_atb/main.cpp` 28 | 29 | - change `21 | std::string sequence_path` to the path to teaser dataset in you machine 30 | - change `22 | std::string data_path` to the path to `hmodel/data/` folder on your machine 31 | - set `17 | bool benchmark`to `true` 32 | 33 | ## Running Live 34 | 35 | in `hmodel/apps/hmodel_atb/main.cpp` 36 | 37 | - set `17 | bool benchmark` to false 38 | - wear a blue wristband and make sure that the wristband is always in the view of the sensor 39 | - c++ implementation of automatic hand model calibration is coming 40 | - for now to approximately adjust the model for your hand 41 | * press `key 1` for *uniform scaling up* 42 | * press `key 2` for *uniform scaling down* 43 | * press `key 3` for *width scaling up* 44 | * press `key 4` for *width scaling down* 45 | * press `key 5` for *thickness scaling up* 46 | * press `key 6` for *thickness scaling down* 47 | 48 | -------------------------------------------------------------------------------- /apps/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(hmodel-helloworlds) 3 | 4 | #--- Gets rid of annoying CMake 3 warnings 5 | if(NOT (CMAKE_MAJOR_VERSION LESS 3)) 6 | cmake_policy(SET CMP0043 OLD) 7 | cmake_policy(SET CMP0020 OLD) 8 | cmake_policy(SET CMP0005 OLD) 9 | endif() 10 | 11 | #--- Helloworld applications 12 | add_subdirectory(helloworld) 13 | add_subdirectory(helloworld_opencv) 14 | add_subdirectory(helloworld_qtopengl) 15 | add_subdirectory(helloworld_atb) # only for htrack-atb 16 | add_subdirectory(helloworld_cudagl) 17 | add_subdirectory(helloworld_cublas) 18 | add_subdirectory(helloworld_thrust) 19 | add_subdirectory(helloworld_openmp) # linux-only 20 | add_subdirectory(helloworld_qglviewer) # only for htrack-qt 21 | 22 | #--- Sensors Testing 23 | add_subdirectory(helloworld_realsense) # windows only!! 24 | add_subdirectory(helloworld_openni) # any os 25 | -------------------------------------------------------------------------------- /apps/cuda_thrust_helloworld/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | get_filename_component(PROJECT ${CMAKE_CURRENT_LIST_DIR} NAME) 3 | project(${PROJECT}) 4 | 5 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) 6 | 7 | ############################################################################## 8 | ############################# CONFIGURE COMPILER ############################# 9 | ############################################################################## 10 | 11 | if(NOT CMAKE_BUILD_TYPE) 12 | set(CMAKE_BUILD_TYPE "Release") 13 | endif() 14 | message(STATUS "CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}") 15 | 16 | message(STATUS "Compiler(Windows): Visual Studio 12 2013 Win64") 17 | if (CMAKE_BUILD_TYPE STREQUAL "Release") 18 | message(STATUS "--> NOTE: enabled windows performance flags") 19 | add_definitions(-DNDEBUG) #assert macro will be preprocessed away for better performance 20 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox /Ot /fp:fast /GS- /GL") 21 | # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG") 22 | endif() 23 | 24 | ############################################################################## 25 | ############################### CONFIGURE CUDA ############################### 26 | ############################################################################## 27 | 28 | 29 | set(WITH_CUDA TRUE) 30 | add_definitions(-DWITH_CUDA) 31 | set(CUDA_TOOLKIT_ROOT_DIR "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.0") 32 | 33 | #--- Import CUDA/CUBLAS 34 | find_package(CUDA REQUIRED) 35 | include_directories(${CUDA_INCLUDE_DIRS}) 36 | list(APPEND LIBRARIES ${CUDA_LIBRARIES}) 37 | list(APPEND LIBRARIES ${CUDA_CUBLAS_LIBRARIES}) 38 | 39 | #--- For matrix operations within Kernels (Eigen not supported) 40 | find_package(GLM REQUIRED) 41 | include_directories(${GLM_INCLUDE_DIRS}) 42 | add_definitions(-DGLM_FORCE_CUDA) #< as mentioned in docs 43 | 44 | #--- Card needs appropriate version 45 | site_name(HOSTNAME) 46 | message(STATUS "HOSTNAME ${HOSTNAME}") 47 | 48 | set(CUDA_NVCC_FLAGS "-gencode arch=compute_50,code=sm_50")# GTX980 49 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -w -Xcompiler -fPIC" ) 50 | 51 | #--- Enable debugging flags 52 | #set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -g") # HOST debug mode 53 | #set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -G") # DEV debug mode 54 | #set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -lineinfo") 55 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -DNDEBUG") #< disable asserts 56 | 57 | set(CUDA_PROPAGATE_HOST_FLAGS True) 58 | if (CMAKE_BUILD_TYPE STREQUAL "Release") 59 | #set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O3") 60 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -use_fast_math") 61 | endif() 62 | 63 | include_directories(../../) 64 | cuda_add_executable(${PROJECT} main.cu) 65 | target_link_libraries(${PROJECT} ${LIBRARIES}) 66 | -------------------------------------------------------------------------------- /apps/cuda_thrust_helloworld/CMakeLists2.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(cuda_thrust_helloworld) 3 | 4 | find_package(CUDA REQUIRED) 5 | find_package(OpenGL REQUIRED) 6 | 7 | 8 | include_directories(${CUDA_INCLUDE_DIRS}) 9 | include_directories(${OPENGL_INCLUDE_DIRS}) 10 | 11 | 12 | #--- NVCC Compiler Flags 13 | site_name(HOSTNAME) 14 | if(HOSTNAME STREQUAL "lagrange") 15 | set(CUDA_NVCC_FLAGS "-gencode arch=compute_50,code=sm_50") # OK!!!! 16 | else() 17 | set(CUDA_NVCC_FLAGS "-gencode arch=compute_30,code=sm_30") # OK!!!! 18 | endif() 19 | 20 | cuda_add_executable(cuda_thrust_helloworld main.cu) 21 | target_link_libraries(cuda_thrust_helloworld ${OPENGL_LIBRARIES}) 22 | -------------------------------------------------------------------------------- /apps/cuda_thrust_sort/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Use thrust to sort pixels of a PIXEL_BUFFER that will then be used to render on screen 2 | # 3 | # Tested on OSX MOUNTAIN LION and Cuda6.0 4 | cmake_minimum_required(VERSION 2.8) 5 | project(cuda_thrust_sort) 6 | 7 | find_package(CUDA REQUIRED) 8 | find_package(OpenGL REQUIRED) 9 | find_package(GLUT REQUIRED) 10 | 11 | include_directories(${CUDA_INCLUDE_DIRS}) 12 | include_directories(${OPENGL_INCLUDE_DIRS}) 13 | include_directories(${GLUT_INCLUDE_DIRS}) 14 | 15 | #--- Compiler for C++ side 16 | if(APPLE) 17 | set(CUDA_HOST_COMPILER "/usr/bin/clang++") 18 | endif() 19 | 20 | #--- NVCC Compiler Flags 21 | site_name(HOSTNAME) 22 | if(HOSTNAME STREQUAL "lagrange") 23 | set(CUDA_NVCC_FLAGS "-gencode arch=compute_50,code=sm_50") # OK!!!! 24 | else() 25 | set(CUDA_NVCC_FLAGS "-gencode arch=compute_30,code=sm_30") # OK!!!! 26 | endif() 27 | 28 | cuda_add_executable(cuda_thrust_sort main.cu) 29 | target_link_libraries(cuda_thrust_sort ${OPENGL_LIBRARIES} ${GLUT_LIBRARY}) 30 | -------------------------------------------------------------------------------- /apps/helloworld/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | get_filename_component(FOLDERNAME ${CMAKE_CURRENT_LIST_DIR} NAME) 3 | project(${FOLDERNAME}) 4 | file(GLOB_RECURSE SOURCES "*.cpp") 5 | file(GLOB_RECURSE HEADERS "*.h") 6 | file(GLOB_RECURSE SHADERS "*.glsl") 7 | add_executable(${FOLDERNAME} ${SOURCES} ${HEADERS} ${SHADERS}) 8 | target_link_libraries(${FOLDERNAME} ${COMMON_LIBS}) 9 | -------------------------------------------------------------------------------- /apps/helloworld/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int /*argc*/, char ** /*argv*/) 3 | { 4 | std::cout << "hello world!" << std::endl; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /apps/helloworld_atb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | get_filename_component(PROJECT ${CMAKE_CURRENT_LIST_DIR} NAME) 3 | project(${PROJECT}) 4 | 5 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) 6 | include(../../cmake/ConfigureCompiler.cmake) 7 | include(../../cmake/ConfigureQt.cmake) 8 | include(../../cmake/ConfigureOpenGL.cmake) 9 | include(../../cmake/ConfigureAntTweakBar.cmake) 10 | 11 | INCLUDE_DIRECTORIES(../../) 12 | #set(CMAKE_BUILD_TYPE "Release") 13 | set(CMAKE_BUILD_TYPE "Debug") 14 | add_executable(${PROJECT} main.cpp) 15 | target_link_libraries(${PROJECT} ${LIBRARIES}) 16 | #set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}) 17 | -------------------------------------------------------------------------------- /apps/helloworld_atb/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "../htrack_atb/AntTweakBarEventFilter.h" 8 | #include "AntTweakBar.h" 9 | TwBar* _bar = NULL; 10 | 11 | float v1; 12 | float g1_v1; 13 | float g1_v2; 14 | 15 | 16 | /// Format class to enable OpenGL4 core profile 17 | class OpenGLFormat : public QGLFormat{ 18 | public: 19 | OpenGLFormat(){ 20 | setVersion(3,2); 21 | setProfile(QGLFormat::CoreProfile); 22 | setSampleBuffers(false); ///< no anti-aliasing 23 | // setSamples(1); ///< no anti-aliasing 24 | } 25 | }; 26 | 27 | class GLWidget : public QGLWidget{ 28 | QOpenGLVertexArrayObject vao; 29 | public: 30 | GLWidget():QGLWidget(OpenGLFormat()){ 31 | std::cout << "OpenGL " << this->format().majorVersion() << "." << this->format().minorVersion() << std::endl; 32 | this->installEventFilter( new AntTweakBarEventFilter(this) ); ///< all actions pass through filter 33 | } 34 | ~GLWidget(){ 35 | TwTerminate(); 36 | } 37 | void initializeGL(){ 38 | bool success = vao.create(); 39 | if(!success) exit(EXIT_FAILURE); 40 | vao.bind(); 41 | TwInit(TW_OPENGL_CORE, NULL); 42 | TwWindowSize(this->width(), this->height()); 43 | _bar = TwNewBar ("Settings"); 44 | TwAddVarRW(_bar, "p", TW_TYPE_FLOAT, &v1, "min=.5 max=50 step=0.4"); 45 | TwAddVarRW(_bar, "V1", TW_TYPE_FLOAT, &g1_v1, " group=g1 "); 46 | TwAddVarRW(_bar, "V2", TW_TYPE_FLOAT, &g1_v2, " group=g1 "); 47 | } 48 | 49 | void paintGL() { 50 | glClearColor(0,1,0,1); ///< green 51 | glClear(GL_COLOR_BUFFER_BIT); 52 | TwWindowSize(this->width(), this->height()); 53 | TwDraw(); 54 | } 55 | }; 56 | 57 | int main(int argc, char* argv[]){ 58 | QApplication app(argc, argv); 59 | GLWidget glarea; 60 | glarea.show(); 61 | return app.exec(); 62 | } 63 | -------------------------------------------------------------------------------- /apps/helloworld_atb/main_new.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "gui/AntTweakBarEventFilter.h" 9 | #include "AntTweakBar.h" 10 | TwBar* _bar = NULL; 11 | 12 | float v1; 13 | float g1_v1; 14 | float g1_v2; 15 | 16 | class GLWidget : public QOpenGLWidget{ 17 | QOpenGLVertexArrayObject vao; 18 | public: 19 | GLWidget():QOpenGLWidget(){ 20 | std::cout << "OpenGL " << this->format().majorVersion() << "." << this->format().minorVersion() << std::endl; 21 | this->installEventFilter( new AntTweakBarEventFilter(this) ); ///< all actions pass through filter 22 | } 23 | ~GLWidget(){ 24 | TwTerminate(); 25 | } 26 | void initializeGL(){ 27 | bool success = vao.create(); 28 | if(!success) exit(EXIT_FAILURE); 29 | vao.bind(); 30 | TwInit(TW_OPENGL_CORE, NULL); 31 | TwWindowSize(this->width()*2, this->height()*2); 32 | _bar = TwNewBar ("Settings"); 33 | TwAddVarRW(_bar, "p", TW_TYPE_FLOAT, &v1, "min=.5 max=50 step=0.4"); 34 | TwAddVarRW(_bar, "V1", TW_TYPE_FLOAT, &g1_v1, " group=g1 "); 35 | TwAddVarRW(_bar, "V2", TW_TYPE_FLOAT, &g1_v2, " group=g1 "); 36 | glViewport(0, 0, this->width(), this->height()); 37 | } 38 | 39 | void paintGL() { 40 | glViewport(0,0,this->width(), this->height()); 41 | glClearColor(0,1,0,1); ///< green 42 | glClear(GL_COLOR_BUFFER_BIT); 43 | TwDraw(); 44 | } 45 | }; 46 | 47 | int main(int argc, char* argv[]){ 48 | QApplication app(argc, argv); 49 | 50 | QSurfaceFormat format; 51 | format.setVersion(4, 3); 52 | format.setProfile(QSurfaceFormat::CoreProfile); 53 | format.setDepthBufferSize(24); 54 | format.setStencilBufferSize(8); 55 | QSurfaceFormat::setDefaultFormat(format); 56 | 57 | GLWidget glarea; 58 | glarea.show(); 59 | return app.exec(); 60 | } 61 | -------------------------------------------------------------------------------- /apps/helloworld_cublas/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | get_filename_component(PROJECT ${CMAKE_CURRENT_LIST_DIR} NAME) 3 | project(${PROJECT}) 4 | 5 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) 6 | include(../../cmake/ConfigureCompiler.cmake) 7 | include(../../cmake/ConfigureQt.cmake) 8 | include(../../cmake/ConfigureCUDA.cmake) 9 | include(../../cmake/ConfigureEigen.cmake) 10 | include_directories(../../) 11 | 12 | #--- only compile a tiny fraction of cudax 13 | set(CUDAX_CU "../../cudax/outer_product.cu") 14 | cuda_add_library(cudax STATIC ${CUDAX_CU}) 15 | list(APPEND LIBRARIES cudax) 16 | 17 | #--- exec1 18 | add_executable(${PROJECT}_simple main_simple.cpp) 19 | target_link_libraries(${PROJECT}_simple ${LIBRARIES}) 20 | 21 | #--- exec2 (needs gnuplot!) 22 | if(UNIX AND NOT APPLE) 23 | add_executable(${PROJECT}_perfomance main_performance.cpp) 24 | target_link_libraries(${PROJECT}_perfomance ${LIBRARIES}) 25 | endif() 26 | 27 | -------------------------------------------------------------------------------- /apps/helloworld_cublas/main_simple.cpp: -------------------------------------------------------------------------------- 1 | ///--- Computes matrix products on GPU 2 | /// this example is broken, but if it runs it's "okay" 3 | /// TODO: matthias, it runs but frobenius is non-zero... why? 4 | 5 | #include 6 | #include "util/gl_wrapper.h" 7 | #include "util/OpenGL32Format.h" 8 | #include 9 | #include 10 | #include 11 | #include "cudax/CublasHelper.h" 12 | #include "cudax/CudaHelper.h" 13 | #include "cudax/CublasHelper.h" 14 | 15 | using namespace std; 16 | using namespace cudax; 17 | 18 | typedef float Scalar; 19 | typedef Eigen::Matrix Matrix_MxN; 20 | extern "C" void outer_product(float* input, float* output, int rows, int cols); 21 | 22 | int main(int argc, char *argv[]){ 23 | QApplication app(argc, argv); 24 | OpenGL32Format fmt; 25 | QGLWidget widget(fmt); 26 | widget.makeCurrent(); 27 | CudaHelper::init(); 28 | CublasHelper::init(); 29 | 30 | { 31 | Matrix_MxN J = Matrix_MxN::Random(100,10); 32 | Matrix_MxN JtJ(J.cols(),J.cols()); 33 | outer_product(J.data(), JtJ.data(), J.rows(), J.cols()); 34 | cout << J.transpose() * J << endl; 35 | cout << endl << endl; 36 | cout << JtJ << endl; 37 | cout << endl << endl; 38 | cout << "Frobenius norm: " << (J.transpose()*J - JtJ).norm() << endl; 39 | } 40 | 41 | CublasHelper::cleanup(); 42 | CudaHelper::cleanup(); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /apps/helloworld_cudagl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | get_filename_component(PROJECTNAME ${CMAKE_CURRENT_LIST_DIR} NAME) 3 | project(${PROJECTNAME}) 4 | 5 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) 6 | include(../../cmake/ConfigureCompiler.cmake) 7 | include(../../cmake/ConfigureQt.cmake) 8 | include(../../cmake/ConfigureOpenGL.cmake) 9 | include(../../cmake/ConfigureGLEW.cmake) 10 | include(../../cmake/ConfigureCUDA.cmake) 11 | include(../../cmake/ConfigureEigen.cmake) 12 | include(../../cmake/ConfigureOpenGL.cmake) 13 | 14 | set(CMAKE_BUILD_TYPE "Release") 15 | #set(CMAKE_BUILD_TYPE "Debug") 16 | 17 | include_directories(../../) #< #include "tracker/..." 18 | file(GLOB SOURCES "*.h") 19 | file(GLOB HEADERS "*.cpp") 20 | add_executable(${PROJECTNAME} ${SOURCES} ${HEADERS}) 21 | target_link_libraries(${PROJECTNAME} ${LIBRARIES}) 22 | -------------------------------------------------------------------------------- /apps/helloworld_opencv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | get_filename_component(PROJECT ${CMAKE_CURRENT_LIST_DIR} NAME) 3 | project(${PROJECT}) 4 | # cmake_policy(SET CMP0046 OLD) 5 | 6 | #set(CMAKE_BUILD_TYPE "Release") 7 | #set(CMAKE_BUILD_TYPE "Debug") 8 | 9 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) 10 | include(../../cmake/ConfigureCompiler.cmake) 11 | include(../../cmake/ConfigureOpenCV.cmake) 12 | 13 | add_executable(${PROJECT} main.cpp) 14 | target_link_libraries(${PROJECT} ${LIBRARIES}) 15 | file(COPY "input.png" DESTINATION ${PROJECT_BINARY_DIR}) 16 | -------------------------------------------------------------------------------- /apps/helloworld_opencv/input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/apps/helloworld_opencv/input.png -------------------------------------------------------------------------------- /apps/helloworld_opencv/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "stdlib.h" 4 | #include "opencv2/core/core.hpp" 5 | #include "opencv2/core/types_c.h" ///< CV_RGB2GRAY 6 | #include "opencv2/imgproc/imgproc.hpp" ///< cvtColor 7 | #include "opencv2/highgui/highgui.hpp" 8 | 9 | int main(int, char **) { 10 | cv::Mat image = cv::imread("input.png"); 11 | std::cout << "image size: " << image.rows << " " << image.cols << std::endl; 12 | assert(image.rows > 0); 13 | assert(image.cols > 0); 14 | cv::cvtColor(image, image, CV_RGB2GRAY); 15 | cv::imshow("input", image); 16 | cv::waitKey(0); 17 | exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /apps/helloworld_openmp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(UNIX AND NOT APPLE) 2 | return() 3 | endif() 4 | 5 | cmake_minimum_required(VERSION 3.0) 6 | get_filename_component(PROJECT ${CMAKE_CURRENT_LIST_DIR} NAME) 7 | project(${PROJECT}) 8 | 9 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) 10 | include(../../cmake/ConfigureCompiler.cmake) 11 | include(../../cmake/ConfigureOpenMP.cmake) 12 | 13 | add_executable(${PROJECT} main.cpp) 14 | target_link_libraries(${PROJECT} ${LIBRARIES}) 15 | -------------------------------------------------------------------------------- /apps/helloworld_openmp/main.cpp: -------------------------------------------------------------------------------- 1 | // COMPILE: /usr/local/bin/g++-4.8 -fopenmp openmp.cpp 2 | #include 3 | #include 4 | #include 5 | 6 | int main (int argc, char *argv[]) 7 | { 8 | int nthreads, tid; 9 | 10 | /* Fork a team of threads giving them their own copies of variables */ 11 | #pragma omp parallel private(nthreads, tid) 12 | { 13 | /* Obtain thread number */ 14 | tid = omp_get_thread_num(); 15 | printf("Hello World from thread = %d\n", tid); 16 | 17 | /* Only master thread does this */ 18 | if (tid == 0) 19 | { 20 | nthreads = omp_get_num_threads(); 21 | printf("Number of threads = %d\n", nthreads); 22 | } 23 | 24 | } /* All threads join master thread and disband */ 25 | } -------------------------------------------------------------------------------- /apps/helloworld_openni/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | get_filename_component(PROJECT ${CMAKE_CURRENT_LIST_DIR} NAME) 3 | project(${PROJECT}) 4 | 5 | # cmake_policy(SET CMP0043 OLD) 6 | # cmake_policy(SET CMP0020 OLD) 7 | 8 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) 9 | include(../../cmake/ConfigureCompiler.cmake) 10 | include(../../cmake/ConfigureOpenNI.cmake) 11 | include(../../cmake/ConfigureOpenCV.cmake) 12 | include(../../cmake/ConfigureQt.cmake) 13 | include(../../cmake/ConfigureEigen.cmake) 14 | 15 | if(OPENNI2_FOUND) 16 | set(CMAKE_BUILD_TYPE "Debug") 17 | INCLUDE_DIRECTORIES(../../) 18 | list(APPEND SOURCES ../../tracker/Data/Camera.cpp) 19 | list(APPEND SOURCES ../../tracker/Sensor/Sensor_openni.cpp) 20 | add_executable(${PROJECT} main.cpp ${SOURCES}) 21 | target_link_libraries(${PROJECT} ${LIBRARIES}) 22 | else() 23 | message(STATUS "Cannot compile this helloworld") 24 | endif() 25 | -------------------------------------------------------------------------------- /apps/helloworld_openni/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "util/tictoc.h" 3 | #include "util/opencv_wrapper.h" 4 | #include "tracker/Sensor/Sensor.h" 5 | #include "tracker/Data/DataFrame.h" 6 | 7 | int main(int /*argc*/, char ** /*argv*/){ 8 | Camera* camera = new Camera(QVGA, 60 /*FPS*/); 9 | Sensor* sensor = new SensorOpenNI(camera); 10 | 11 | ///--- start the sensor 12 | sensor->start(); 13 | bool success = sensor->spin_wait_for_data(5 /*seconds*/); 14 | assert(success); 15 | 16 | DataFrame frame(0); 17 | for(int i=0; i<30 /*seconds*/ *60 /*60FPS*/; i++){ 18 | bool success = sensor->fetch_streams(frame); 19 | assert(success); 20 | // cv::normalize(frame.color, frame.color, 0, 255, cv::NORM_MINMAX); 21 | 22 | ///--- Show color 23 | cvtColor(frame.color, frame.color, CV_BGRA2RGBA); 24 | cv::imshow("color", frame.color); 25 | 26 | ///--- Show depth 27 | cv::normalize(frame.depth, frame.depth, 0, USHRT_MAX, cv::NORM_MINMAX); 28 | cv::imshow("depth", frame.depth); 29 | 30 | ///--- Wait a sec 31 | cv::waitKey(15 /*ms -> 60fps*/); 32 | } 33 | 34 | std::cout << "finished!" << std::endl; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /apps/helloworld_qglviewer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | get_filename_component(PROJECT ${CMAKE_CURRENT_LIST_DIR} NAME) 3 | project(${PROJECT}) 4 | cmake_policy(SET CMP0020 OLD) 5 | 6 | #set(CMAKE_BUILD_TYPE "Release") 7 | #set(CMAKE_BUILD_TYPE "Debug") 8 | 9 | #--- Where to find the FindPackageName.cmake 10 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) 11 | include(../../cmake/ConfigureCompiler.cmake) 12 | include(../../cmake/ConfigureQt.cmake) 13 | include(../../cmake/ConfigureOpenGL.cmake) 14 | include(../../cmake/ConfigureQGLViewer.cmake) 15 | 16 | #--- Create exe and link 17 | add_executable(${PROJECT} main.cpp) 18 | target_link_libraries(${PROJECT} ${LIBRARIES}) 19 | -------------------------------------------------------------------------------- /apps/helloworld_qglviewer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class Viewer : public QGLViewer { 5 | void draw() { 6 | /// @note this would not work in Mac as there is no compatibility profile 7 | /// and this is OpenGL2 stuff. 8 | const float nbSteps = 200.0; 9 | glBegin(GL_QUAD_STRIP); 10 | for (int i=0; i 2 | #include 3 | #include 4 | #include 5 | 6 | /// Format class to enable OpenGL4 core profile 7 | class OpenGLFormat : public QGLFormat{ 8 | public: 9 | OpenGLFormat(){ 10 | setVersion(3,2); 11 | setProfile(QGLFormat::CoreProfile); 12 | setSampleBuffers(false); ///< no anti-aliasing 13 | // setSamples(1); ///< no anti-aliasing 14 | } 15 | }; 16 | 17 | class GLWidget : public QGLWidget{ 18 | QOpenGLVertexArrayObject vao; 19 | public: 20 | GLWidget():QGLWidget(OpenGLFormat()){ 21 | std::cout << "OpenGL " << this->format().majorVersion() << "." << this->format().minorVersion() << std::endl; 22 | } 23 | void initializeGL(){ 24 | bool success = vao.create(); 25 | if(!success) exit(EXIT_FAILURE); 26 | vao.bind(); 27 | } 28 | 29 | void paintGL() { 30 | glClearColor(0,1,0,1); ///< green 31 | glClear(GL_COLOR_BUFFER_BIT); 32 | } 33 | }; 34 | 35 | 36 | int main(int argc, char* argv[]){ 37 | QApplication app(argc, argv); 38 | GLWidget glarea; 39 | glarea.show(); 40 | return app.exec(); 41 | } 42 | -------------------------------------------------------------------------------- /apps/helloworld_realsense/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(NOT WIN32) 2 | return() 3 | endif() 4 | 5 | cmake_minimum_required(VERSION 3.0) 6 | get_filename_component(PROJECT ${CMAKE_CURRENT_LIST_DIR} NAME) 7 | project(${PROJECT}) 8 | 9 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) 10 | include(../../cmake/ConfigureCompiler.cmake) 11 | include(../../cmake/ConfigureOpenNI.cmake) 12 | include(../../cmake/ConfigureOpenCV.cmake) 13 | include(../../cmake/ConfigureQt.cmake) 14 | include(../../cmake/ConfigureEigen.cmake) 15 | include(../../cmake/ConfigureRealSense.cmake) 16 | 17 | set(CMAKE_BUILD_TYPE "Debug") 18 | INCLUDE_DIRECTORIES(../../) 19 | list(APPEND EXTRA_SOURCES ../../tracker/Data/Camera.cpp) 20 | list(APPEND EXTRA_SOURCES ../../tracker/Sensor/Sensor_realsense.cpp) 21 | 22 | add_executable(${PROJECT} main.cpp ${EXTRA_SOURCES}) 23 | target_link_libraries(${PROJECT} ${LIBRARIES}) 24 | -------------------------------------------------------------------------------- /apps/helloworld_thrust/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | get_filename_component(PROJECT ${CMAKE_CURRENT_LIST_DIR} NAME) 3 | project(${PROJECT}) 4 | 5 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) 6 | include(../../cmake/ConfigureCompiler.cmake) 7 | include(../../cmake/ConfigureCUDA.cmake) 8 | 9 | include_directories(../../) 10 | cuda_add_executable(${PROJECT} main.cu) 11 | target_link_libraries(${PROJECT} ${LIBRARIES}) 12 | -------------------------------------------------------------------------------- /apps/helloworld_thrust/main.cu: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "util/tictoc.h" 7 | #include "cudax/CudaHelper.h" 8 | 9 | int main(void) 10 | { 11 | int major = THRUST_MAJOR_VERSION; 12 | int minor = THRUST_MINOR_VERSION; 13 | std::cout << "Thrust version: " << major << "." << minor << std::endl; 14 | thrust::device_vector d_vec; 15 | thrust::host_vector h_vec(1 << 24); 16 | 17 | TICTOC_BLOCK(t_gen,"Generate randoms + h2d transfer") 18 | { 19 | thrust::generate(h_vec.begin(), h_vec.end(), rand); 20 | d_vec = h_vec; ///< 21 | } 22 | 23 | TICTOC_BLOCK(t_sort,"GPU sort") 24 | { 25 | thrust::sort(d_vec.begin(), d_vec.end()); 26 | cudaDeviceSynchronize(); ///< otherwise time is 0!! 27 | } 28 | 29 | TICTOC_BLOCK(t_back,"d2h transfer") 30 | { 31 | thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin()); 32 | } 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /apps/hmodel_atb/AntTweakBarEventFilter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #ifdef WITH_ANTTWEAKBAR 5 | #include "AntTweakBar.h" 6 | #endif 7 | 8 | /// QGLWidget support for AntTweakBar (event forwarding) 9 | class AntTweakBarEventFilter : public QObject{ 10 | private: 11 | QGLWidget* parent; 12 | public: 13 | AntTweakBarEventFilter(QGLWidget* parent) : QObject(parent){ 14 | this->parent = parent; 15 | // all move events detected, not just when clicked 16 | parent->setMouseTracking(true); 17 | } 18 | 19 | /// Forward events to AntTweakBar 20 | bool eventFilter(QObject* obj, QEvent* event){ 21 | #ifdef WITH_ANTTWEAKBAR 22 | bool event_on_atb = false; 23 | if (obj == parent) { 24 | QMouseEvent* me = dynamic_cast(event); 25 | QKeyEvent* ke = static_cast(event); 26 | 27 | TwMouseButtonID mouse_button; 28 | if(me!=NULL){ 29 | if(me->button()==Qt::LeftButton) mouse_button = TW_MOUSE_LEFT; 30 | if(me->button()==Qt::RightButton) mouse_button = TW_MOUSE_RIGHT; 31 | if(me->button()==Qt::MiddleButton) mouse_button = TW_MOUSE_MIDDLE; 32 | } 33 | 34 | switch(event->type()){ 35 | case QEvent::Resize: 36 | event_on_atb = TwWindowSize(parent->width()*2, parent->height()*2); 37 | // qDebug() << "Resize" F<< status; 38 | break; 39 | case QEvent::KeyRelease: 40 | event_on_atb = TwKeyPressed(ke->key(), TW_KMOD_NONE); 41 | // qDebug() << "Key" << status; 42 | break; 43 | case QEvent::MouseMove: 44 | event_on_atb = TwMouseMotion(me->pos().x(), me->pos().y()); 45 | // qDebug() << "Move" << status << e->pos(); 46 | break; 47 | case QEvent::MouseButtonPress: 48 | event_on_atb = TwMouseButton(TW_MOUSE_PRESSED, mouse_button); 49 | // qDebug() << "Press" << status; 50 | break; 51 | case QEvent::MouseButtonRelease: 52 | event_on_atb = TwMouseButton(TW_MOUSE_RELEASED, mouse_button); 53 | // qDebug() << "Release" << status; 54 | return true; 55 | default: 56 | break; 57 | } 58 | if(event_on_atb == true){ 59 | parent->update(); 60 | return true; 61 | } 62 | else 63 | return false; // Super::eventFilter(obj, event); 64 | } else { 65 | // pass the event on to the parent class 66 | return false; // Super::eventFilter(obj, event); 67 | } 68 | #else 69 | return false; 70 | #endif 71 | } 72 | }; 73 | -------------------------------------------------------------------------------- /apps/hmodel_atb/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | INCLUDE_DIRECTORIES(../../) #< #include "tracker/..." 2 | file(GLOB_RECURSE SRC "*.cpp") 3 | file(GLOB_RECURSE HDR "*.h") 4 | add_executable(hmodel_atb ${HDR} ${SRC}) 5 | target_link_libraries(hmodel_atb hmodelsdk) 6 | 7 | -------------------------------------------------------------------------------- /apps/hmodel_atb/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "tracker/Sensor/Sensor.h" 5 | #include "tracker/Data/Camera.h" 6 | 7 | #include "tracker/Tracker.h" 8 | #include "tracker/GLWidget.h" 9 | //#include 10 | 11 | int main(int argc, char* argv[]) { 12 | bool htrack = false; 13 | bool test = false; //J' * J on CPU 14 | bool real_color = false; 15 | bool save_rastorized_model = false; 16 | 17 | bool benchmark = false; 18 | bool playback = false; 19 | int user_name = 0; 20 | 21 | std::string sequence_path = "E:/Data/sensor-sequences/"; 22 | std::string data_path = "C:/Developer/hmodel-cpp-public/data/"; 23 | std::string sequence_name = "teaser"; 24 | 25 | Q_INIT_RESOURCE(shaders); 26 | QApplication app(argc, argv); 27 | 28 | Camera camera(QVGA, 60); 29 | SensorRealSense sensor(&camera, real_color); 30 | 31 | DataStream datastream(&camera); 32 | SolutionStream solutions; 33 | 34 | Worker worker(&camera, test, benchmark, save_rastorized_model, user_name, data_path); 35 | 36 | { 37 | worker.settings->termination_max_iters = 8; 38 | 39 | worker.E_fitting.settings->fit2D_enable = true; 40 | worker.E_fitting.settings->fit2D_weight = 0.7; 41 | 42 | worker.E_fitting.settings->fit3D_enable = true; 43 | 44 | worker.E_limits.jointlimits_enable = true; 45 | 46 | worker.E_pose._settings.enable_split_pca = true; 47 | worker.E_pose._settings.weight_proj = 4 * 10e2; 48 | 49 | worker.E_collision._settings.collision_enable = true; 50 | worker.E_collision._settings.collision_weight = 1e3; 51 | 52 | worker.E_temporal._settings.temporal_coherence1_enable = true; 53 | worker.E_temporal._settings.temporal_coherence2_enable = true; 54 | worker.E_temporal._settings.temporal_coherence1_weight = 0.05; 55 | worker.E_temporal._settings.temporal_coherence2_weight = 0.05; 56 | 57 | worker.E_damping._settings.abduction_damping = 1500000; 58 | worker._settings.termination_max_rigid_iters = 1; 59 | } 60 | 61 | GLWidget glwidget(&worker, &datastream, &solutions, playback, false /*real_color*/, data_path); 62 | worker.bind_glwidget(&glwidget); 63 | glwidget.show(); 64 | 65 | Tracker tracker(&worker, camera.FPS(), sequence_path + sequence_name + "/", real_color); 66 | tracker.sensor = &sensor; 67 | tracker.datastream = &datastream; 68 | tracker.solutions = &solutions; 69 | 70 | ///--- Starts the tracking 71 | tracker.toggle_tracking(!benchmark && !playback); 72 | tracker.toggle_benchmark(benchmark); 73 | tracker.toggle_playback(playback); 74 | 75 | return app.exec(); 76 | } 77 | -------------------------------------------------------------------------------- /cmake/CompileSynthgen.cmake: -------------------------------------------------------------------------------- 1 | set(WITH_SYNTHGEN TRUE) 2 | LIST(APPEND SRC_OPENGL2 "opengl/Cylinders_renderer.cpp" "opengl/Renderer_interface.cpp") 3 | add_executable(synthgen apps/synthgen.cpp ${SRC_MATH} ${SRC_UTIL} ${SRC_GEOMETRY} ${SRC_OPENGL2} ${MATH} ${UTIL} ${GEOMETRY} ${QT_RESOURCES}) 4 | target_link_libraries(synthgen ${LIBRARIES}) 5 | qt5_use_modules(synthgen OpenGL Xml) 6 | -------------------------------------------------------------------------------- /cmake/ConfigureAntTweakBar.cmake: -------------------------------------------------------------------------------- 1 | #--- AntTweakBar 2 | find_package(AntTweakBar) 3 | if(ANTTWEAKBAR_FOUND) 4 | include_directories(${ANTTWEAKBAR_INCLUDE_DIR}) 5 | list(APPEND LIBRARIES ${ANTTWEAKBAR_LIBRARY}) 6 | add_definitions(-DWITH_ANTTWEAKBAR) 7 | 8 | message(STATUS "AntTweakBar: ${ANTTWEAKBAR_LIBRARY}") 9 | 10 | #--- X11 (required by AntTweakBar) 11 | if(UNIX AND NOT APPLE) 12 | find_package(X11) 13 | if(NOT X11_FOUND) 14 | message(FATAL_ERROR "Cannot found X11 on Linux. Necessary") 15 | endif() 16 | list(APPEND LIBRARIES ${X11_LIBRARIES}) 17 | endif() 18 | else() 19 | # message(STATUS ANTTWEAKBAR_INCLUDE_DIR: ${ANTTWEAKBAR_INCLUDE_DIR}) 20 | # message(STATUS ANTTWEAKBAR_LIBRARY: ${ANTTWEAKBAR_LIBRARY}) 21 | message(STATUS "WARNING: AntTweakbar not found") 22 | endif() 23 | -------------------------------------------------------------------------------- /cmake/ConfigureCUDA.cmake: -------------------------------------------------------------------------------- 1 | set(WITH_CUDA TRUE) 2 | add_definitions(-DWITH_CUDA) 3 | 4 | # Anastasia: what is this for? 5 | if(WIN32) 6 | # set(CUDA_TOOLKIT_ROOT_DIR "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v6.5") 7 | set(CUDA_TOOLKIT_ROOT_DIR "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.0") 8 | endif() 9 | 10 | #--- Import CUDA/CUBLAS 11 | find_package(CUDA REQUIRED) 12 | include_directories(${CUDA_INCLUDE_DIRS}) 13 | list(APPEND LIBRARIES ${CUDA_LIBRARIES}) 14 | list(APPEND LIBRARIES ${CUDA_CUBLAS_LIBRARIES}) 15 | 16 | #--- For matrix operations within Kernels (Eigen not supported) 17 | find_package(GLM REQUIRED) 18 | include_directories(${GLM_INCLUDE_DIRS}) 19 | add_definitions(-DGLM_FORCE_CUDA) #< as mentioned in docs 20 | 21 | #--- Card needs appropriate version 22 | site_name(HOSTNAME) 23 | message(STATUS "HOSTNAME ${HOSTNAME}") 24 | 25 | if(HOSTNAME STREQUAL "lagrange") #--- Andrea/Linux 26 | set(CUDA_NVCC_FLAGS "-gencode arch=compute_50,code=sm_50")# GTX980 27 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -w -Xcompiler -fPIC" ) 28 | #elseif(HOSTNAME STREQUAL "IC-LGG-DPC-06") #--- Andrea,Fridge,Windows 29 | # set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode arch=compute_50,code=sm_50") # GTX980 30 | elseif(HOSTNAME STREQUAL "tsf-460-wpa-4-107.epfl.ch") # Euler MAC-PRO Retina 31 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode arch=compute_30,code=sm_30") # Geforce 650m 32 | elseif(HOSTNAME STREQUAL "waluigi") #--- Matthias/Linux 33 | set(CUDA_NVCC_FLAGS "-gencode arch=compute_30,code=sm_30")# GTX660 Ti 34 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -w -Xcompiler -fPIC" ) 35 | elseif(HOSTNAME STREQUAL "nastylinux") #--- Anastasia 36 | set(CUDA_NVCC_FLAGS "-gencode arch=compute_30,code=sm_30")# GTX660 Ti 37 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -w -Xcompiler -fPIC -D__CUDACC__" ) 38 | 39 | #--- Generic 40 | else() 41 | #set(CUDA_NVCC_FLAGS "-gencode arch=compute_32,code=sm_32") # invalid device function 42 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode arch=compute_30,code=sm_30") # Geforce 650m (MBPro Retina) 43 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode arch=compute_32,code=sm_32") # ? 44 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode arch=compute_35,code=sm_35") # ? 45 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode arch=compute_50,code=sm_50") # GTX980 (Win/Linux Machine) 46 | endif() 47 | 48 | #--- Enable debugging flags 49 | #set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -g") # HOST debug mode 50 | #set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -G") # DEV debug mode 51 | #set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -lineinfo") 52 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -DNDEBUG") #< disable asserts 53 | 54 | if(WIN32) 55 | set(CUDA_PROPAGATE_HOST_FLAGS True) 56 | if (CMAKE_BUILD_TYPE STREQUAL "Release") 57 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O3") 58 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -use_fast_math") 59 | endif() 60 | else() 61 | #--- CUDA doesn't like "--compiler-options -std=c++11" 62 | set(CUDA_PROPAGATE_HOST_FLAGS False) 63 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std c++11") 64 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -O3") 65 | set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -use_fast_math") 66 | endif() 67 | 68 | message(STATUS "CUDA_PROPAGATE_HOST_FLAGS: ${CUDA_PROPAGATE_HOST_FLAGS}") 69 | message(STATUS "CUDA_HOST_COMPILER: ${CUDA_HOST_COMPILER}") 70 | message(STATUS "CUDA_NVCC_FLAGS: ${CUDA_NVCC_FLAGS}") 71 | -------------------------------------------------------------------------------- /cmake/ConfigureCeres.cmake: -------------------------------------------------------------------------------- 1 | find_package(Ceres CONFIG REQUIRED) 2 | 3 | include_directories(${CERES_INCLUDE_DIRS}}) 4 | include_directories(${MINIGLOG_INCLUDE_DIR}) 5 | include_directories(${CERES_EXPORTED_SOURCE_DIR}) 6 | 7 | LIST(APPEND LIBRARIES ${CERES_LIBRARIES}) -------------------------------------------------------------------------------- /cmake/ConfigureCompiler.cmake: -------------------------------------------------------------------------------- 1 | #--- Build type 2 | set(CMAKE_BUILD_TYPE "Release") #<<< FORCE SET 3 | if(NOT CMAKE_BUILD_TYPE) 4 | set(CMAKE_BUILD_TYPE "Release") 5 | endif() 6 | message(STATUS "CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE}") 7 | 8 | if(APPLE) 9 | message(STATUS "Compiler(Apple): clang") 10 | set(CMAKE_CXX_COMPILER "/usr/bin/clang++") 11 | set(CMAKE_CC_COMPILER "/usr/bin/clang") 12 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") 13 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 14 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") 15 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ferror-limit=1") # max number of compiler errors 16 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") # enable warnings 17 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") # only for clangomp 18 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast -march=native -mtune=native -mno-avx -DNDEBUG") 19 | elseif(UNIX) 20 | message(STATUS "Compiler(Linux): g++-4.8") 21 | set(CMAKE_CXX_COMPILER "/usr/bin/g++-4.8") 22 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") 23 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 24 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") 26 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") 27 | #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") 28 | #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast -march=native -DNDEBUG") 29 | #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto -fwhole-program") 30 | elseif(WIN32) 31 | message(STATUS "Compiler(Windows): Visual Studio 12 2013 Win64") 32 | if (CMAKE_BUILD_TYPE STREQUAL "Release") 33 | message(STATUS "--> NOTE: enabled windows performance flags") 34 | add_definitions(-DNDEBUG) 35 | # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox /Ot /fp:fast /GS- /GL") 36 | # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LTCG") 37 | endif() 38 | endif() 39 | -------------------------------------------------------------------------------- /cmake/ConfigureEigen.cmake: -------------------------------------------------------------------------------- 1 | find_package(Eigen3 REQUIRED) 2 | include_directories(${EIGEN3_INCLUDE_DIRS}) -------------------------------------------------------------------------------- /cmake/ConfigureGLEW.cmake: -------------------------------------------------------------------------------- 1 | #--- STATICALLY LINKED!!! 2 | find_package(GLEW REQUIRED) 3 | include_directories(${GLEW_INCLUDE_DIRS}) 4 | link_directories(${GLEW_LIBRARY_DIRS}) 5 | add_definitions(-DGLEW_STATIC) 6 | add_definitions(-DWITH_GLEW) 7 | LIST(APPEND LIBRARIES ${GLEW_LIBRARIES}) 8 | message(STATUS "GLEW_LIBRARIES: ${GLEW_LIBRARIES}") 9 | -------------------------------------------------------------------------------- /cmake/ConfigureGLFW.cmake: -------------------------------------------------------------------------------- 1 | #--- CMake extension to load GLFW 2 | find_package(GLFW REQUIRED) 3 | include_directories(${GLFW_INCLUDE_DIRS}) 4 | add_definitions(${GLFW_DEFINITIONS}) 5 | if(NOT GLFW_FOUND) 6 | message(ERROR " GLFW not found!") 7 | endif() 8 | LIST(APPEND LIBRARIES ${GLFW_LIBRARIES}) 9 | -------------------------------------------------------------------------------- /cmake/ConfigureOpenCV.cmake: -------------------------------------------------------------------------------- 1 | find_package(OpenCV2 REQUIRED) 2 | 3 | if(OpenCV2_FOUND) 4 | include_directories(${OpenCV2_INCLUDE_DIRS}) 5 | LIST(APPEND LIBRARIES ${OpenCV2_LIBRARIES}) 6 | add_definitions(-DWITH_OPENCV) 7 | else() 8 | message(FATAL_ERROR "OpenCV required") 9 | endif() 10 | 11 | #message(STATUS "OpenCV2_LIBRARIES: ${OpenCV2_LIBRARIES}") 12 | #message(STATUS "OpenCV2_INCLUDE_DIRS: ${OpenCV2_INCLUDE_DIRS}") 13 | 14 | #--- (OBSOLETE) find it with PkgConfig 15 | #find_package(PkgConfig REQUIRED) 16 | #pkg_check_modules(OPENCV REQUIRED opencv) 17 | #list(APPEND LIBRARIES ${OPENCV_LDFLAGS}) 18 | #include_directories(${OPENCV_INCLUDE_DIRS}) 19 | 20 | -------------------------------------------------------------------------------- /cmake/ConfigureOpenGL.cmake: -------------------------------------------------------------------------------- 1 | #--- OpenGL 2 | find_package(OpenGL REQUIRED) 3 | if(NOT OPENGL_FOUND) 4 | message(ERROR " OPENGL not found!") 5 | endif(NOT OPENGL_FOUND) 6 | 7 | include_directories(${OpenGL_INCLUDE_DIRS}) 8 | link_directories(${OpenGL_LIBRARY_DIRS}) 9 | add_definitions(${OpenGL_DEFINITIONS}) 10 | LIST(APPEND LIBRARIES ${OPENGL_LIBRARIES}) 11 | 12 | if(UNIX) 13 | LIST(APPEND LIBRARIES ${OPENGL_glu_LIBRARY}) 14 | endif() 15 | -------------------------------------------------------------------------------- /cmake/ConfigureOpenGP.cmake: -------------------------------------------------------------------------------- 1 | #--- OPENGP 2 | find_package(OpenGP REQUIRED) 3 | include_directories(${OpenGP_INCLUDE_DIRS}) 4 | add_definitions(-DHEADERONLY) 5 | add_definitions(-DUSE_EIGEN) 6 | if(NOT OPENGP_FOUND) 7 | message(ERROR " OPENGP not found!") 8 | endif() -------------------------------------------------------------------------------- /cmake/ConfigureOpenMP.cmake: -------------------------------------------------------------------------------- 1 | if(UNIX) 2 | # only for g++ or for the Clang+OpenMP compiler 3 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") 4 | elseif(WIN32) 5 | message(STATUS "OpenMP not tested on windows!") 6 | endif() 7 | 8 | add_definitions(-DWITH_OPENMP) 9 | -------------------------------------------------------------------------------- /cmake/ConfigureOpenNI.cmake: -------------------------------------------------------------------------------- 1 | #--- OpenNI2 2 | find_package(OpenNI2) 3 | if(OPENNI2_FOUND) 4 | include_directories(${OPENNI2_INCLUDE_DIR}) 5 | list(APPEND LIBRARIES ${OPENNI2_LIBRARY}) 6 | add_definitions(-DWITH_OPENNI) 7 | else() 8 | message(STATUS "WARNING: OpenNI2 not found!") 9 | endif() 10 | 11 | #message(STATUS "OpenNI2: ${OPENNI2_LIBRARY}") 12 | #message(STATUS "OpenNI2: ${OPENNI2_INCLUDE_DIR}") 13 | -------------------------------------------------------------------------------- /cmake/ConfigureQGLViewer.cmake: -------------------------------------------------------------------------------- 1 | #--- QGLViewer 2 | find_package(QGLViewer REQUIRED) 3 | if(QGLVIEWER_FOUND) 4 | include_directories(${QGLVIEWER_INCLUDE_DIR}) 5 | add_definitions(-DQGLVIEWER) 6 | LIST(APPEND LIBRARIES ${QGLVIEWER_LIBRARIES}) 7 | add_definitions(-DWITH_QGLVIEWER) 8 | #message(STATUS "INCLUDE DIR" ${QGLVIEWER_INCLUDE_DIR}) 9 | endif() 10 | -------------------------------------------------------------------------------- /cmake/ConfigureQt.cmake: -------------------------------------------------------------------------------- 1 | # @see http://doc.qt.io/qt-5/cmake-manual.html 2 | #--- Tell cmake where to find Qt5. (Unfortunately cmake3 does not support Qt5 yet) 3 | 4 | #--- Debug 5 | #message(STATUS QT5_CMAKE_DIR $ENV{QT5_CMAKE_DIR}) 6 | #message(STATUS CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH}) 7 | 8 | if(DEFINED ENV{CMAKE_PREFIX_PATH}) 9 | # If user has specified it, just use it... 10 | set(CMAKE_PREFIX_PATH $ENV{CMAKE_PREFIX_PATH}) 11 | message(STATUS "Qt5: Using environment CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") 12 | 13 | elseif(DEFINED ENV{QT5_CMAKE_DIR}) 14 | # User could have also specified QT5_CMAKE_DIR 15 | set(CMAKE_PREFIX_PATH $ENV{QT5_CMAKE_DIR}) 16 | message(STATUS "Qt5: Using environment variable QT5_CMAKE_DIR: ${CMAKE_PREFIX_PATH}") 17 | 18 | else() 19 | # Otherwise just resort to some built-in stuff 20 | if(WIN32) 21 | set(CMAKE_PREFIX_PATH "C:/Developer/Qt/5.4/msvc2013_64_opengl/lib/cmake") 22 | elseif(APPLE) 23 | set(CMAKE_PREFIX_PATH "/usr/local/Cellar/qt5/5.4.1/lib/cmake") 24 | elseif(UNIX) 25 | set(CMAKE_PREFIX_PATH "/usr/local/qt/5.3/gcc_64/lib/cmake") 26 | endif() 27 | message(STATUS "!!!WARNING Qt5: resorting to default Qt5 paths (might fail): ${CMAKE_PREFIX_PATH}") 28 | endif() 29 | 30 | #--- Needed for GUI 31 | find_package(Qt5Widgets REQUIRED) 32 | include_directories(${Qt5Widgets_INCLUDE_DIRS}) 33 | list(APPEND LIBRARIES Qt5::Widgets) 34 | 35 | #--- Needed for OpenGL 36 | find_package(Qt5OpenGL REQUIRED) 37 | include_directories(${Qt5OpenGL_INCLUDE_DIRS}) 38 | list(APPEND LIBRARIES Qt5::OpenGL) 39 | 40 | #--- Needed for the QGLViewer library 41 | find_package(Qt5Xml REQUIRED) 42 | include_directories(${Qt5Xml_INCLUDE_DIRS}) 43 | list(APPEND LIBRARIES Qt5::Xml) 44 | 45 | -------------------------------------------------------------------------------- /cmake/ConfigureRealSense.cmake: -------------------------------------------------------------------------------- 1 | # TODO: use the find_file macro 2 | 3 | if(WIN32) 4 | set(REALSENSE_INCLUDE_DIR "C:/Developer/RealSense/r6/RSSDK/include") 5 | set(REALSENSE_UTILITY_DIR "C:/Developer/RealSense/r6/RSSDK/sample/common/include") 6 | 7 | if(${CMAKE_BUILD_TYPE} STREQUAL "Debug") 8 | set(REALSENSE_LIBRARY "C:/Developer/RealSense/r6/RSSDK/lib/x64/libpxcmd_d.lib") 9 | set(REALSENSE_UTILITY_LIBRARY "C:/Developer/RealSense/r6/RSSDK/sample/common/lib/x64/v120/libpxcutilsmd_d.lib") 10 | endif() 11 | 12 | if(${CMAKE_BUILD_TYPE} STREQUAL "Release") 13 | set(REALSENSE_LIBRARY "C:/Developer/RealSense/r6/RSSDK/lib/x64/libpxcmd.lib") 14 | set(REALSENSE_UTILITY_LIBRARY "C:/Developer/RealSense/r6/RSSDK/sample/common/lib/x64/v120/libpxcutilsmd.lib") 15 | endif() 16 | 17 | 18 | include_directories(${REALSENSE_INCLUDE_DIR} ${REALSENSE_UTILITY_DIR}) 19 | 20 | list(APPEND LIBRARIES ${REALSENSE_LIBRARY}) 21 | list(APPEND LIBRARIES ${REALSENSE_UTILITY_LIBRARY}) 22 | 23 | #--- DEBUG 24 | # message(STATUS "REALSENSE_LIBRARY ${REALSENSE_LIBRARY}") 25 | # message(STATUS "REALSENSE_UTILITY_LIBRARY ${REALSENSE_UTILITY_LIBRARY}") 26 | 27 | #--- Mark as available 28 | add_definitions(-DHAS_REALSENSE) 29 | endif() 30 | -------------------------------------------------------------------------------- /cmake/ConfigureSoftKinetic.cmake: -------------------------------------------------------------------------------- 1 | #--- OpenNI2 2 | find_package(SoftKinetic) #NOT REQUIRED (mac doesn't have it) 3 | if(SOFTKINETIC_FOUND) 4 | include_directories(${SOFTKINETIC_INCLUDE_DIR}) 5 | list(APPEND LIBRARIES ${SOFTKINETIC_LIBRARIES}) 6 | add_definitions(-DHAS_SOFTKINETIC) 7 | endif() -------------------------------------------------------------------------------- /cmake/FindAntTweakBar.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Try to find AntTweakBar library and include path. 3 | # Once done this will define 4 | # 5 | # ANTTWEAKBAR_FOUND 6 | # ANTTWEAKBAR_INCLUDE_DIR 7 | # ANTTWEAKBAR_LIBRARY 8 | # 9 | 10 | FIND_PATH(ANTTWEAKBAR_INCLUDE_DIR AntTweakBar.h PATHS 11 | $ENV{ANTTWEAKBAR_ROOT}/include 12 | #--- External folder 13 | ${CMAKE_CURRENT_LIST_DIR}/../external/AntTweakBar/include/ 14 | #--- Windows 15 | C:/Developer/include/AntTweakBar 16 | #--- Mac 17 | /usr/local/include 18 | /usr/X11/include 19 | /usr/include 20 | NO_DEFAULT_PATH 21 | DOC "The directory where AntTweakBar.h resides") 22 | 23 | if(WIN32) 24 | set(BITS "64") 25 | endif() 26 | 27 | FIND_LIBRARY( ANTTWEAKBAR_LIBRARY AntTweakBar${BITS} PATHS 28 | $ENV{ANTTWEAKBAR_ROOT}/lib 29 | #--- Windows 30 | C:/Developer/lib 31 | #--- 32 | /usr/local 33 | /usr/X11 34 | /usr 35 | PATH_SUFFIXES a lib64 lib dylib NO_DEFAULT_PATH 36 | DOC "The AntTweakBar library") 37 | 38 | if(ANTTWEAKBAR_INCLUDE_DIR AND ANTTWEAKBAR_LIBRARY) 39 | message(STATUS "Found ANTTWEAKBAR: ${ANTTWEAKBAR_LIBRARY}") 40 | set(ANTTWEAKBAR_FOUND TRUE) 41 | endif() 42 | 43 | #--- DEBUG 44 | #message(STATUS "ANTTWEAKBAR_INCLUDE_DIR: ${ANTTWEAKBAR_INCLUDE_DIR}") 45 | #message(STATUS "ANTTWEAKBAR_LIBRARY: ${ANTTWEAKBAR_LIBRARY}") 46 | -------------------------------------------------------------------------------- /cmake/FindEigen3.cmake: -------------------------------------------------------------------------------- 1 | if(WIN32) 2 | set(EIGEN3_INCLUDE_DIRS "C:/Developer/include") 3 | else() 4 | FIND_PATH( EIGEN3_INCLUDE_DIRS Eigen/Geometry 5 | $ENV{EIGEN3DIR}/include 6 | /usr/local/include/eigen3 7 | /usr/local/include 8 | /usr/local/X11R6/include 9 | /usr/X11R6/include 10 | /usr/X11/include 11 | /usr/include/X11 12 | /usr/include/eigen3/ 13 | /usr/include 14 | /opt/X11/include 15 | /opt/include 16 | ${CMAKE_SOURCE_DIR}/external/eigen/include) 17 | endif() 18 | 19 | SET(EIGEN3_FOUND "NO") 20 | IF(EIGEN3_INCLUDE_DIRS) 21 | SET(EIGEN3_FOUND "YES") 22 | ENDIF() 23 | -------------------------------------------------------------------------------- /cmake/FindGLEW.cmake: -------------------------------------------------------------------------------- 1 | FIND_PATH( GLEW_INCLUDE_DIRS GL/glew.h 2 | $ENV{GLEWDIR}/include 3 | /usr/local/include 4 | /usr/local/X11R6/include 5 | /usr/X11R6/include 6 | /usr/X11/include 7 | /usr/include/X11 8 | /usr/include 9 | /opt/X11/include 10 | /opt/include 11 | # FOR WINDOWS 12 | C:/Developer/include 13 | ${CMAKE_SOURCE_DIR}/external/glew/include) 14 | 15 | if(WIN32) 16 | SET(GLEWLIBNAME glew32s) # static 17 | # SET(GLEWLIBNAME glew32) # dyn 18 | else() 19 | # IMPORTANT: uppercase otherwise problem on linux 20 | SET(GLEWLIBNAME GLEW) 21 | endif() 22 | 23 | FIND_LIBRARY( GLEW_LIBRARIES NAMES ${GLEWLIBNAME} PATHS 24 | $ENV{GLEWDIR}/lib 25 | /usr/local/lib 26 | /usr/local/X11R6/lib 27 | /usr/X11R6/lib 28 | /usr/X11/lib 29 | /usr/lib/X11 30 | /usr/lib 31 | /opt/X11/lib 32 | /opt/lib 33 | # FOR UBUNTU 12.04 LTS 34 | /usr/lib/x86_64-linux-gnu 35 | # FOR WINDOWS 36 | C:/Developer/lib 37 | ${CMAKE_SOURCE_DIR}/external/glew/lib) 38 | 39 | 40 | SET(GLEW_FOUND "NO") 41 | IF(GLEW_LIBRARIES AND GLEW_INCLUDE_DIRS) 42 | SET(GLEW_FOUND "YES") 43 | ENDIF() 44 | 45 | #message(STATUS "GLEW_LIBRARIES: ${GLEW_LIBRARIES}") 46 | #message(STATUS "GLEW_INCLUDE_DIRS: ${GLEW_INCLUDE_DIRS}") 47 | -------------------------------------------------------------------------------- /cmake/FindGLFW.cmake: -------------------------------------------------------------------------------- 1 | # Locate the GLFW library (version 2.0) 2 | # This module defines the following variables: 3 | # GLFW_LIBRARIES, the name of the library; 4 | # GLFW_INCLUDE_DIRS, where to find GLFW include files. 5 | # GLFW_FOUND, true if library path was resolved 6 | # 7 | # Usage example to compile an "executable" target to the glfw library: 8 | # 9 | # FIND_PACKAGE (GLFW REQUIRED) 10 | # INCLUDE_DIRECTORIES (${GLFW_INCLUDE_DIRS}) 11 | # ADD_EXECUTABLE (executable ${YOUR_EXECUTABLE_SRCS}) 12 | # TARGET_LINK_LIBRARIES (executable ${GLFW_LIBRARIES}) 13 | # 14 | # TODO: 15 | # Lookup for windows 16 | # Allow the user to select to link to a shared library or to a static library. 17 | # 18 | # SEE: 19 | # - https://raw.github.com/progschj/OpenGL-Examples/master/cmake_modules/FindGLFW.cmake 20 | # 21 | 22 | FIND_PATH( GLFW_INCLUDE_DIRS GL/glfw.h 23 | $ENV{GLFWDIR}/include 24 | /usr/local/include 25 | /usr/local/X11R6/include 26 | /usr/X11R6/include 27 | /usr/X11/include 28 | /usr/include/X11 29 | /usr/include 30 | /opt/X11/include 31 | /opt/include 32 | #--- FOR WINDOWS 33 | C:/Developer/include 34 | #--- Deployed 35 | ${CMAKE_SOURCE_DIR}/external/glfw/include) 36 | 37 | message(STATUS "GLFW_INCLUDE_DIRS: ${GLFW_INCLUDE_DIRS}") 38 | 39 | FIND_LIBRARY( GLFW_LIBRARIES NAMES glfw PATHS 40 | $ENV{GLFWDIR}/lib 41 | /usr/local/lib 42 | /usr/local/X11R6/lib 43 | /usr/X11R6/lib 44 | /usr/X11/lib 45 | /usr/lib/X11 46 | /usr/lib 47 | /opt/X11/lib 48 | /opt/lib 49 | #--- FOR WINDOWS 50 | C:/Developer/lib 51 | #--- Deployed 52 | ${CMAKE_SOURCE_DIR}/external/glfw/lib) 53 | 54 | SET(GLFW_FOUND "NO") 55 | IF(GLFW_LIBRARIES AND GLFW_INCLUDE_DIRS) 56 | SET(GLFW_FOUND "YES") 57 | ENDIF(GLFW_LIBRARIES AND GLFW_INCLUDE_DIRS) 58 | -------------------------------------------------------------------------------- /cmake/FindGLM.cmake: -------------------------------------------------------------------------------- 1 | # FIND_PACKAGE (GLM REQUIRED) 2 | # INCLUDE_DIRECTORIES (${GLM_INCLUDE_DIRS}) 3 | # ADD_EXECUTABLE (executable ${YOUR_EXECUTABLE_SRCS}) 4 | 5 | if(WIN32) 6 | set(GLM_INCLUDE_DIRS "C:/Developer/include") 7 | else() 8 | FIND_PATH( GLM_INCLUDE_DIRS glm/glm.hpp 9 | $ENV{GLM_DIR} 10 | /usr/local/include 11 | /usr/include 12 | /opt/include 13 | ${CMAKE_SOURCE_DIR}/external) 14 | endif() 15 | 16 | SET(GLM_FOUND "NO") 17 | IF(GLM_INCLUDE_DIRS) 18 | SET(GLM_FOUND "YES") 19 | ENDIF() 20 | -------------------------------------------------------------------------------- /cmake/FindOpenGP.cmake: -------------------------------------------------------------------------------- 1 | # Locate the OpenGP library (version 1.0) 2 | # This module defines the following variables: 3 | # OpenGP_INCLUDE_DIRS, where to find OpenGP include files. 4 | # OpenGP_FOUND and OPENGP_FOUND true if library path was resolved 5 | # 6 | # Usage example to compile an "executable" target: 7 | # 8 | # FIND_PACKAGE (OpenGP REQUIRED) 9 | # INCLUDE_DIRECTORIES (${OpenGP_INCLUDE_DIRS}) 10 | # ADD_EXECUTABLE (executable ${YOUR_EXECUTABLE_SRCS}) 11 | # 12 | # DEBUG: outputs given environment variable 13 | # message(STATUS OpenGPDIR $ENV{OpenGP_DIR}) 14 | 15 | FIND_PATH( OpenGP_INCLUDE_DIRS OpenGP/Surface_mesh.h 16 | $ENV{OpenGP_DIR} 17 | /usr/local/include 18 | /usr/local/X11R6/include 19 | /usr/X11R6/include 20 | /usr/X11/include 21 | /usr/include/X11 22 | /usr/include 23 | /opt/X11/include 24 | /opt/include 25 | /Users/andrea/Developer/OpenGP/src # local build 26 | ${CMAKE_SOURCE_DIR}/external/opengp/include) 27 | 28 | SET(OPENGP_FOUND "NO") 29 | SET(OpenGP_FOUND "NO") 30 | IF(OpenGP_INCLUDE_DIRS) 31 | SET(OPENGP_FOUND "YES") 32 | SET(OpenGP_FOUND "YES") 33 | ENDIF() 34 | -------------------------------------------------------------------------------- /cmake/FindOpenNI2.cmake: -------------------------------------------------------------------------------- 1 | # OPENNI2_INCLUDE_DIR 2 | # OPENNI2_LIBRARY 3 | # OPENNI2_FOUND 4 | 5 | find_path(OPENNI2_INCLUDE_DIR "OpenNI.h" 6 | PATHS 7 | #--- MAC 8 | /usr/include/ni2 9 | /usr/local/include/ni2 10 | #--- WINDOWS 11 | C:/Developer/include/openni 12 | #--- LINUX (self deployed) 13 | ${CMAKE_SOURCE_DIR}/openni/include 14 | DOC "OpenNI c++ interface header") 15 | 16 | find_library(OPENNI2_LIBRARY "OpenNI2" 17 | PATHS 18 | #--- MAC 19 | /usr/lib/ni2 20 | /usr/local/lib/ni2 21 | #--- LINUX (self deployed) 22 | /usr/lib 23 | #--- WINDOWS 24 | C:/Developer/lib 25 | C:/Program Files/OpenNI2/Lib 26 | ${CMAKE_SOURCE_DIR}/openni/lib 27 | DOC "OpenNI2 library") 28 | 29 | #message(STATUS "OPENNI2_LIBRARY: ${OPENNI2_LIBRARY}") 30 | #message(STATUS "OPENNI2_INCLUDE_DIR: ${OPENNI2_INCLUDE_DIR}") 31 | 32 | if(OPENNI2_INCLUDE_DIR AND OPENNI2_LIBRARY) 33 | set(OPENNI2_FOUND TRUE) 34 | endif() 35 | 36 | #--- Notifications 37 | if(OPENNI2_FOUND AND NOT OpenNI2__FIND_QUIETLY) 38 | message(STATUS "Found OpenNI: ${OPENNI2_LIBRARY}") 39 | else() 40 | if(OpenNI2_FIND_REQUIRED) 41 | message(STATUS OPENNI2_INCLUDE_DIR: ${OPENNI2_INCLUDE_DIR}) 42 | message(STATUS OPENNI2_LIBRARY: ${OPENNI2_LIBRARY}) 43 | message(FATAL_ERROR "Could not find OpenNI2") 44 | endif() 45 | endif() 46 | -------------------------------------------------------------------------------- /cmake/FindQGLViewer.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find QGLViewer 2 | # Once done this will define 3 | # 4 | # QGLVIEWER_FOUND - system has QGLViewer 5 | # QGLVIEWER_INCLUDE_DIR - the QGLViewer include directory 6 | # QGLVIEWER_LIBRARIES - Link these to use QGLViewer 7 | # QGLVIEWER_DEFINITIONS - Compiler switches required for using QGLViewer 8 | # 9 | 10 | find_path(QGLVIEWER_INCLUDE_DIR 11 | NAMES QGLViewer/qglviewer.h 12 | PATHS 13 | #--- Windows 14 | C:/Developer/include 15 | #--- Mac 16 | /Library/Frameworks 17 | #--- Linux 18 | /usr/include 19 | /usr/local/include 20 | #--- Environment 21 | ENV QGLVIEWERROOT 22 | PATH_SUFFIXES Headers) 23 | 24 | find_library(QGLVIEWER_LIBRARY_RELEASE 25 | NAMES QGLViewer QGLViewer2 QGLViewer2 26 | HINTS 27 | #--- Windows 28 | C:/Developer/lib 29 | #--- Linux 30 | /usr/lib 31 | /usr/local/lib 32 | #--- Mac 33 | /Library/Frameworks 34 | #--- Environment 35 | ENV QGLVIEWERROOT 36 | ENV LD_LIBRARY_PATH 37 | ENV LIBRARY_PATH 38 | PATH_SUFFIXES 39 | QGLViewer 40 | QGLViewer/release) 41 | 42 | find_library(QGLVIEWER_LIBRARY_DEBUG 43 | NAMES 44 | dqglviewer 45 | dQGLViewer 46 | dQGLViewer2 47 | QGLViewerd2 48 | PATHS 49 | #--- Windows 50 | C:/Developer/lib 51 | #--- Linux 52 | /usr/lib 53 | /usr/local/lib 54 | #--- Mac 55 | /Library/Frameworks 56 | #--- Environment 57 | ENV QGLVIEWERROOT 58 | ENV LD_LIBRARY_PATH 59 | ENV LIBRARY_PATH 60 | PATH_SUFFIXES 61 | QGLViewer 62 | QGLViewer/debug) 63 | 64 | if(QGLVIEWER_LIBRARY_RELEASE) 65 | if(QGLVIEWER_LIBRARY_DEBUG) 66 | set(QGLVIEWER_LIBRARIES_ optimized ${QGLVIEWER_LIBRARY_RELEASE} debug ${QGLVIEWER_LIBRARY_DEBUG}) 67 | else() 68 | set(QGLVIEWER_LIBRARIES_ ${QGLVIEWER_LIBRARY_RELEASE}) 69 | endif() 70 | set(QGLVIEWER_LIBRARIES ${QGLVIEWER_LIBRARIES_} CACHE FILEPATH "The QGLViewer library") 71 | endif() 72 | 73 | #message(STATUS "QGLVIEWER_INCLUDE_DIR: ${QGLVIEWER_INCLUDE_DIR}") 74 | #message(STATUS "QGLVIEWER_LIBRARIES: ${QGLVIEWER_LIBRARIES}") 75 | 76 | IF(QGLVIEWER_INCLUDE_DIR AND QGLVIEWER_LIBRARIES) 77 | SET(QGLVIEWER_FOUND TRUE) 78 | ENDIF() 79 | 80 | IF(QGLVIEWER_FOUND) 81 | IF(NOT CMAKE_FIND_QUIETLY) 82 | MESSAGE(STATUS "Found QGLViewer: ${QGLVIEWER_LIBRARIES}") 83 | ENDIF() 84 | ELSE() 85 | IF(QGLViewer_FIND_REQUIRED) 86 | MESSAGE(FATAL_ERROR "Could not find QGLViewer") 87 | ENDIF() 88 | ENDIF() 89 | 90 | -------------------------------------------------------------------------------- /cmake/FindSoftKinetic.cmake: -------------------------------------------------------------------------------- 1 | FIND_PATH( SOFTKINETIC_INCLUDE_DIR DepthSenseTypes.h 2 | $ENV{SOFTKINETIC_DIR} 3 | /opt/softkinetic/DepthSenseSDK/include 4 | ${CMAKE_SOURCE_DIR}/external/softkinetic/DepthSenseSDK/include) 5 | 6 | find_library(TURBOJPEG_LIB 7 | NAMES turbojpeg 8 | PATHS /opt/softkinetic/DepthSenseSDK/lib) 9 | find_library(DEPTHSENSE_LIB 10 | NAMES DepthSense 11 | PATHS /opt/softkinetic/DepthSenseSDK/lib) 12 | find_library(DEPTHSENSEPLUGINS_LIB 13 | NAMES DepthSensePlugins 14 | PATHS /opt/softkinetic/DepthSenseSDK/lib) 15 | 16 | #message(STATUS "INCLUDES ${SOFTKINETIC_INCLUDE_DIRS}") 17 | #message(STATUS "LIBS ${DEPTHSENSE_LIB}, ${TURBOJPEG_LIB}, ${DEPTHSENSEPLUGINS_LIB}") 18 | 19 | if(TURBOJPEG_LIB AND DEPTHSENSE_LIB AND DEPTHSENSEPLUGINS_LIB) 20 | LIST(APPEND SOFTKINETIC_LIBRARIES ${TURBOJPEG_LIB}) 21 | LIST(APPEND SOFTKINETIC_LIBRARIES ${DEPTHSENSE_LIB}) 22 | LIST(APPEND SOFTKINETIC_LIBRARIES ${DEPTHSENSEPLUGINS_LIB}) 23 | endif() 24 | 25 | 26 | IF(SOFTKINETIC_INCLUDE_DIR AND SOFTKINETIC_LIBRARIES) 27 | SET(SOFTKINETIC_FOUND TRUE) 28 | else() 29 | SET(SOFTKINETIC_FOUND FALSE) 30 | ENDIF() 31 | 32 | IF(SOFTKINETIC_FOUND) 33 | IF(NOT CMAKE_FIND_QUIETLY) 34 | MESSAGE(STATUS "Found SoftKinetic: ${SOFTKINETIC_INCLUDE_DIR}") 35 | ENDIF() 36 | ELSE() 37 | IF(SOFTKINETIC_FOUND_REQUIRED) 38 | MESSAGE(FATAL_ERROR "Could not find SoftKinetic") 39 | ENDIF() 40 | ENDIF() 41 | -------------------------------------------------------------------------------- /cudax/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(NOT WITH_CUDA) 2 | return() 3 | endif() 4 | 5 | #--- Dummy rule to show whole cudax folder in explorer 6 | file(GLOB CUDA_FILES "*") 7 | add_custom_target(cudax_files SOURCES ${CUDA_FILES}) 8 | 9 | #--- C++ sources (non-kernel) that need cuda are appended 10 | file(GLOB_RECURSE CUDAX_CPP "${CMAKE_CURRENT_LIST_DIR}/*.cpp") 11 | file(GLOB_RECURSE CUDAX_CU "${CMAKE_CURRENT_LIST_DIR}/*.cu") 12 | file(GLOB_RECURSE CUDAX_H "${CMAKE_CURRENT_LIST_DIR}/*.h") 13 | 14 | #--- Create the cudax static library & add it 15 | INCLUDE_DIRECTORIES(.) 16 | INCLUDE_DIRECTORIES(../) #so we can say #include "cudax/..." 17 | cuda_add_library(cudax STATIC ${CUDAX_CPP} ${CUDAX_CU} ${CUDAX_H}) 18 | 19 | -------------------------------------------------------------------------------- /cudax/CudaHelper.h: -------------------------------------------------------------------------------- 1 | /// @warning this cannot contain any c++11!! 2 | #pragma once 3 | #include 4 | #include "util/gl_wrapper.h" 5 | #include 6 | #include "util/singleton.h" 7 | #include "cudax/helper_cuda.h" 8 | 9 | //== NAMESPACE ================================================================ 10 | namespace cudax { 11 | //============================================================================= 12 | 13 | class CudaHelper{ 14 | SINGLETON(CudaHelper) 15 | 16 | public: 17 | /// @note to be done ***after*** OpenGL for optimal OpenGL/CUDA performance 18 | static void init(){ 19 | int devID = gpuGetMaxGflopsDeviceId(); 20 | cudaError status = cudaGLSetGLDevice(devID); 21 | if(status!=cudaSuccess){ 22 | std::cout << "Could not get OpenGL compliant device... exiting" << std::endl; 23 | exit(0); 24 | } 25 | } 26 | static void cleanup(){ 27 | std::cout << "Shutting down CUDA device" << std::endl; 28 | cudaDeviceReset(); 29 | } 30 | 31 | public: 32 | /// To debug calls to: cudaBindTextureToArray 33 | static void check_array(cudaArray* array){ 34 | struct cudaChannelFormatDesc desc; 35 | checkCudaErrors(cudaGetChannelDesc(&desc, array)); 36 | printf("CUDA Array channel descriptor, bits per component:\n"); 37 | printf("X %d Y %d Z %d W %d, kind %d\n", 38 | desc.x,desc.y,desc.z,desc.w,desc.f); 39 | printf("Possible values for channel format kind: i %d, u%d, f%d:\n", 40 | cudaChannelFormatKindSigned, cudaChannelFormatKindUnsigned, 41 | cudaChannelFormatKindFloat); 42 | } 43 | }; 44 | 45 | //============================================================================= 46 | } // namespace cudax 47 | //============================================================================= 48 | 49 | -------------------------------------------------------------------------------- /cudax/CudaTimer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | //== NAMESPACE ================================================================ 7 | namespace cudax { 8 | //============================================================================= 9 | 10 | // http://devblogs.nvidia.com/parallelforall/how-implement-performance-metrics-cuda-cc/ 11 | struct CudaTimer{ 12 | cudaEvent_t _start, _stop; 13 | std::string message; 14 | std::string prefix; 15 | bool event_on_destroy; 16 | /// Same as create + restart 17 | CudaTimer(const std::string& message){ 18 | cudaEventCreate(&_start); 19 | cudaEventCreate(&_stop); 20 | this->message = message; 21 | cudaEventRecord(_start); 22 | event_on_destroy = true; 23 | std::cout << std::setprecision(3); 24 | prefix = "Executed "; 25 | } 26 | CudaTimer(){ 27 | prefix = "Executed "; 28 | event_on_destroy = false; 29 | cudaEventCreate(&_start); 30 | cudaEventCreate(&_stop); 31 | } 32 | ~CudaTimer(){ 33 | if(event_on_destroy) 34 | display(); 35 | cudaEventDestroy(_start); 36 | cudaEventDestroy(_stop); 37 | } 38 | void set_prefix(const std::string& prefix){ 39 | this->prefix = prefix; 40 | } 41 | void restart(const std::string& message){ 42 | this->message = message; 43 | cudaEventRecord(_start); 44 | } 45 | void display(){ 46 | static std::ofstream out("cuda.log"); 47 | cudaEventRecord(_stop); 48 | cudaEventSynchronize(_stop); 49 | float milliseconds = 0; 50 | cudaEventElapsedTime(&milliseconds, _start, _stop); 51 | 52 | std::cout << prefix << "["<< message <<"] in [" << milliseconds << "ms]" << std::endl; 53 | } 54 | float elapsed(){ 55 | cudaEventRecord(_stop); 56 | cudaEventSynchronize(_stop); 57 | float milliseconds = 0; 58 | cudaEventElapsedTime(&milliseconds, _start, _stop); 59 | return milliseconds; 60 | } 61 | }; 62 | 63 | //============================================================================= 64 | } // namespace cudax 65 | //============================================================================= 66 | 67 | #define CUDA_TIMED_BLOCK(obj, blockName) for ( struct { int i; cudax::CudaTimer timer; } obj = { 0, cudax::CudaTimer(blockName) }; obj.i < 1; ++obj.i) 68 | -------------------------------------------------------------------------------- /cudax/KinectCamera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "cuda_runtime.h" 4 | #include "cuda_glm.h" 5 | 6 | //== NAMESPACE ================================================================ 7 | namespace cudax { 8 | //============================================================================= 9 | 10 | struct KinectCamera{ 11 | thrust::device_vector inv_proj_matrix; ///< only containts one 12 | glm::mat3x3* D_mat_ptr; ///< device pointer to its content 13 | 14 | KinectCamera(const float* H_inv_proj_matrix){ 15 | inv_proj_matrix.resize(1); 16 | thrust::device_ptr mat = &inv_proj_matrix[0]; 17 | D_mat_ptr = thrust::raw_pointer_cast(mat); 18 | cudaMemcpy((void*) D_mat_ptr, H_inv_proj_matrix, 9*sizeof(float), cudaMemcpyHostToDevice); 19 | } 20 | const glm::mat3x3& D_inv_proj_matrix(){ 21 | return (*D_mat_ptr); 22 | } 23 | }; 24 | 25 | //============================================================================= 26 | } // namespace cudax 27 | //============================================================================= 28 | -------------------------------------------------------------------------------- /cudax/Kinematic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "tracker/DataStructure/CustomJointInfo.h" 4 | 5 | //== NAMESPACE ================================================================ 6 | namespace cudax { 7 | //============================================================================= 8 | 9 | struct Kinematic{ 10 | /// These hold memory 11 | thrust::device_vector D_jointinfos; 12 | thrust::device_vector D_chains; 13 | /// These are used to access data in the kernel 14 | CustomJointInfo* jointinfos; ///< @note device raw pointer 15 | ChainElement* chains; ///< @note device raw pointer 16 | }; 17 | 18 | //============================================================================= 19 | } // namespace cudax 20 | //============================================================================= 21 | 22 | 23 | -------------------------------------------------------------------------------- /cudax/Timer.h: -------------------------------------------------------------------------------- 1 | /// @note this measures wall clock times, not GPU times!! 2 | /// You'd need to sync the GPU (at the cost of a stall) to get 3 | /// the real times 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | //== NAMESPACE ================================================================ 12 | namespace cudax { 13 | //============================================================================= 14 | 15 | struct Timer { 16 | clock_t start; 17 | clock_t end; 18 | static const size_t buffer_length=256; 19 | char buffer[buffer_length]; 20 | 21 | Timer(void) { 22 | restart(""); 23 | //std::cout << "!!! WARNING: obsolete, why are you using it?" << std::endl; 24 | } 25 | 26 | void restart(const char* format, ...) { 27 | va_list args; 28 | va_start (args, format); 29 | /// @note http://www.tin.org/bin/man.cgi?section=3&topic=vsnprintf 30 | vsnprintf (buffer, buffer_length, format, args); 31 | va_end (args); 32 | start = clock(); 33 | } 34 | 35 | double elapsed(void) { 36 | end = clock(); 37 | return static_cast(end - start) / static_cast(CLOCKS_PER_SEC); 38 | } 39 | 40 | double epsilon(void) { 41 | return 1.0 / static_cast(CLOCKS_PER_SEC); 42 | } 43 | 44 | void display() { 45 | #ifndef DISABLE_TIMER_PRINTF 46 | printf("[%s]: %.2fms\n",buffer,1e3 * elapsed()); 47 | fflush(stdout); 48 | #endif 49 | } 50 | }; 51 | 52 | //============================================================================= 53 | } // namespace cudax 54 | //============================================================================= 55 | -------------------------------------------------------------------------------- /cudax/cuda_glm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | //#define GLM_COMPILER 0 3 | #define CUDA_VERSION 7000 4 | 5 | #if __unix__ 6 | // GLM wants to redefine these functions, which causes 7 | // compilation errors in Linux. Undef'ing them WorksForMe... 8 | #undef isnan 9 | #undef isinf 10 | #endif 11 | 12 | #include "glm/glm.hpp" 13 | 14 | /// To access raw pointer: glm::value_ptr(glm_mat4_variable) 15 | // #include 16 | -------------------------------------------------------------------------------- /cudax/externs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "cudax/cuda_glm.h" 6 | #include 7 | 8 | namespace energy{namespace fitting{struct Settings;}} 9 | struct CustomJointInfo; 10 | struct ChainElement; 11 | typedef unsigned char uchar; 12 | 13 | //== NAMESPACE ================================================================ 14 | namespace cudax { 15 | //============================================================================= 16 | 17 | ///--- Jacobian type 18 | #define NUM_THETAS 29 ///< hand parameter size (size of jacobian row) 19 | struct J_row{ float data[NUM_THETAS]; }; ///< Row of Jacobian 20 | typedef thrust::device_vector Jacobian; ///< ROW major!!! 21 | 22 | ///--- Externally defined resources 23 | extern cudaArray* sensor_depth; 24 | 25 | //============================================================================= 26 | } // namespace cudax 27 | //============================================================================= 28 | 29 | extern "C" 30 | void kernel_init(energy::fitting::Settings* settings, 31 | int _width, 32 | int _height, 33 | int thetas_size, 34 | float H_focal_length_x, 35 | float H_focal_length_y, 36 | const float *H_inv_proj_matrix, 37 | int d, int num_centers, int num_blocks, int max_num_outlines, int num_tangent_fields, int num_outline_fields, bool htrack, bool test, int model_type); 38 | 39 | extern "C" 40 | void kernel_upload_kinematic(const std::vector& jointinfos, const std::vector& H_kinchains); 41 | 42 | extern "C" 43 | void kernel_upload_model(int d, int num_centers, int num_blocks, int num_outlines, int num_tangent_fields, int num_outline_fields, 44 | const float * host_pointer_centers, const float * host_pointer_radii, const int * host_pointer_blocks, 45 | const float * host_pointer_tangent_points, const float * host_pointer_outline, const int * host_pointer_blockid_to_jointid_map); 46 | 47 | extern "C" 48 | void kernel_upload_sensor_silhouette(uchar * H_silhouette_sensor); 49 | 50 | extern "C" 51 | void kernel_upload_sensor_indicator(int * sensor_indicator, int num_sensor_points); 52 | 53 | extern "C" 54 | void kernel_upload_rendered_indicator(int * rendered_pixels, float * rendered_points, int * rendered_block_ids, int num_rendered_points); 55 | 56 | extern "C" 57 | void kernel_upload_dtform_idxs(int* H_dtform_idxs); 58 | 59 | extern "C" 60 | void kernel_bind(); 61 | 62 | extern "C" 63 | void kernel(float* eigen_JtJ, float* eigen_Jte, float & push_error, float & pull_error, bool eval_metric, bool reweight, int id, int iter, 64 | int num_sensor_points, int num_rendered_points); 65 | 66 | extern "C" 67 | void kernel_unbind(); 68 | 69 | extern "C" 70 | void kernel_copy_extra_corresp(thrust::host_vector& H_queries, thrust::host_vector& H_target, thrust::host_vector& H_idxs); 71 | 72 | extern "C" 73 | void kernel_cleanup(); 74 | 75 | extern "C" 76 | void kernel_memory_tests(); 77 | 78 | extern "C" 79 | void kernel_constraint_type_image(uchar *, int, int); 80 | 81 | extern "C" 82 | void kernel_simplify_jacobian(); 83 | 84 | extern "C" 85 | void kernel_delete(); 86 | 87 | -------------------------------------------------------------------------------- /cudax/functors/ComputeJacobianRow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cudax/kernel.h" 3 | 4 | //== NAMESPACE ================================================================ 5 | namespace cudax { 6 | //============================================================================= 7 | 8 | class ComputeJacobianRow { 9 | protected: 10 | J_row* J_raw; ///< array of rows 11 | float* e_raw; ///< right hand side (constraints) 12 | int2* cnstr_indexes; ///< raw 13 | CustomJointInfo* jointinfos; ///< raw 14 | ChainElement* chains; ///< raw 15 | public: 16 | ComputeJacobianRow(J_row* J_raw, float* e_raw){ 17 | assert(J_raw!=NULL); 18 | assert(e_raw!=NULL); 19 | this->J_raw = J_raw; 20 | this->e_raw = e_raw; 21 | this->cnstr_indexes = ::pixel_indexer->cnstr_indexes; 22 | this->jointinfos = ::kinematic->jointinfos; 23 | this->chains = ::kinematic->chains; 24 | } 25 | 26 | protected: 27 | __device__ 28 | glm::mat3x2 projection_jacobian(const glm::vec3& pos){ 29 | // printf("focal length: %f", focal_length); 30 | glm::mat3x2 M(0); ///< remember column major! 31 | M[0][0] = focal_length_x / pos[2]; 32 | M[1][1] = focal_length_y / pos[2]; 33 | M[2][0] = -pos[0] * focal_length_x / ( pos[2]*pos[2] ); 34 | M[2][1] = -pos[1] * focal_length_y / ( pos[2]*pos[2] ); 35 | return M; 36 | } 37 | }; 38 | 39 | //============================================================================= 40 | } // namespace cudax 41 | //============================================================================= 42 | -------------------------------------------------------------------------------- /cudax/functors/IsSilhouette.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cudax/kernel.h" 3 | 4 | namespace cudax { 5 | 6 | /*struct IsRenderedSilhouette{ 7 | __device__ 8 | bool operator()(const int4& off){ 9 | return (tex2D(color_tex, off.x, off.y)<255); 10 | } 11 | __device__ 12 | bool operator()(int x, int y){ 13 | return (tex2D(color_tex, x, y)<255); 14 | } 15 | };*/ 16 | 17 | struct IsSensorSilhouette{ 18 | uchar* silhouette_sensor; 19 | IsSensorSilhouette(thrust::device_vector& silhouette_sensor){ 20 | this->silhouette_sensor = thrust::raw_pointer_cast(&silhouette_sensor[0]); 21 | } 22 | 23 | __device__ 24 | bool operator()(const int4& off){ 25 | return (silhouette_sensor[off.z] > 125); 26 | } 27 | }; 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /cudax/kernel_debug.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "kernel.h" 3 | #include 4 | #include 5 | 6 | using namespace cudax; 7 | 8 | //-----------------------------------------------------------------// 9 | 10 | struct ConstraintTypeFunctor{ 11 | uchar* opencv_image_d_raw; 12 | int2* cnstr_indexes; 13 | float* e_raw; 14 | 15 | ConstraintTypeFunctor(uchar *opencv_image_d_raw, float* e_raw){ 16 | this->opencv_image_d_raw = opencv_image_d_raw; 17 | this->cnstr_indexes = pixel_indexer->cnstr_indexes; 18 | this->e_raw = e_raw; 19 | } 20 | 21 | }; 22 | 23 | struct SetZeroFunctor{ 24 | J_row* J_raw; 25 | SetZeroFunctor(J_row* J_raw):J_raw(J_raw){} 26 | __device__ 27 | void operator()(const int i){ 28 | J_row &Ji = *(J_raw + i); 29 | for(int j=6; j it(0); 38 | thrust::for_each(it, it+n_total, SetZeroFunctor(thrust::raw_pointer_cast(J->data()))); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /cudax/kernel_upload.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "kernel.h" 3 | #include "Kinematic.h" 4 | 5 | using namespace cudax; 6 | 7 | void kernel_upload_dtform_idxs(int* H_dtform_idxs){ 8 | thrust::copy(H_dtform_idxs, H_dtform_idxs+H_width*H_height, sensor_dtform_idxs->begin()); 9 | } 10 | 11 | void kernel_upload_sensor_silhouette(uchar* H_silhouette_sensor) 12 | { 13 | thrust::copy(H_silhouette_sensor, H_silhouette_sensor+H_width*H_height, silhouette_sensor->begin()); 14 | } 15 | 16 | void kernel_upload_sensor_indicator(int * sensor_indicator, int num_sensor_points) { 17 | thrust::copy(sensor_indicator, sensor_indicator + num_sensor_points, _sensor_indicator->begin()); 18 | cudaMemcpyToSymbol(_num_sensor_points, &num_sensor_points, sizeof(int)); 19 | } 20 | 21 | 22 | void kernel_upload_rendered_indicator(int * rendered_pixels, float * rendered_points, int * rendered_block_ids, int num_rendered_points) { 23 | thrust::copy(rendered_pixels, rendered_pixels + num_rendered_points, _rendered_pixels->begin()); 24 | thrust::copy(rendered_points, rendered_points + 3 * num_rendered_points, _rendered_points->begin()); 25 | thrust::copy(rendered_block_ids, rendered_block_ids + num_rendered_points, _rendered_block_ids->begin()); 26 | cudaMemcpyToSymbol(_num_rendered_points, &num_rendered_points, sizeof(int)); 27 | } 28 | 29 | void kernel_upload_kinematic(const JointTransformations& H_jointinfos, const KinematicChain& H_kinchains) 30 | { 31 | kinematic->D_jointinfos.resize(H_jointinfos.size()); 32 | thrust::copy(H_jointinfos.begin(), H_jointinfos.end(), kinematic->D_jointinfos.begin()); 33 | kinematic->D_chains.resize(H_kinchains.size()); 34 | thrust::copy(H_kinchains.begin(), H_kinchains.end(), kinematic->D_chains.begin()); 35 | 36 | // printf("#jointinfos: %ld\n", kinematic->D_jointinfos.size()); 37 | // printf("#kinematic: %ld\n", kinematic->D_chains.size()); 38 | 39 | /// Fetch raw pointers that can be accessed in the kernels 40 | kinematic->jointinfos = thrust::raw_pointer_cast(&kinematic->D_jointinfos[0]); 41 | kinematic->chains = thrust::raw_pointer_cast(&kinematic->D_chains[0]); 42 | } 43 | 44 | void kernel_upload_model(int d, int num_centers, int num_blocks, int num_outlines, int num_tangent_fields, int num_outline_fields, 45 | const float * host_pointer_centers, const float * host_pointer_radii, const int * host_pointer_blocks, 46 | const float * host_pointer_tangent_points, const float * host_pointer_outline, const int * host_pointer_blockid_to_jointid_map) { 47 | 48 | /*printf("D = %d\n", d); 49 | printf("num_centers = %d\n", num_centers); 50 | printf("num_blocks = %d\n", num_blocks); 51 | printf("num_outlines = %d\n", num_outlines); 52 | printf("num_tangent_fields = %d\n", num_tangent_fields); 53 | printf("num_outline_fields = %d\n", num_outline_fields);*/ 54 | 55 | /*printf("\n CENTERS: \n"); 56 | for (size_t i = 0; i < NUM_CENTERS; i++) { 57 | printf("%f, %f, %f\n", host_pointer_centers[d * i], host_pointer_centers[d * i + 1], host_pointer_centers[d * i + 2]); 58 | } 59 | printf("\n RADII: \n"); 60 | for (size_t i = 0; i < NUM_CENTERS; i++) { 61 | printf("%f\n", host_pointer_radii[i]); 62 | } 63 | printf("\n BLOCKS: \n"); 64 | for (size_t i = 0; i < num_blocks; i++) { 65 | printf("%d, %d, %d\n", host_pointer_blocks[d * i], host_pointer_blocks[d * i + 1], host_pointer_blocks[d * i + 2]); 66 | }*/ 67 | 68 | cudaMemcpyToSymbol(NUM_OUTLINES, &num_outlines, sizeof(int)); 69 | thrust::copy(host_pointer_centers, host_pointer_centers + d * num_centers, device_pointer_centers->begin()); 70 | thrust::copy(host_pointer_radii, host_pointer_radii + num_centers, device_pointer_radii->begin()); 71 | thrust::copy(host_pointer_blocks, host_pointer_blocks + d * num_blocks, device_pointer_blocks->begin()); 72 | thrust::copy(host_pointer_tangent_points, host_pointer_tangent_points + d * num_tangent_fields * num_blocks, device_pointer_tangent_points->begin()); 73 | thrust::copy(host_pointer_outline, host_pointer_outline + d * num_outline_fields * num_outlines, device_pointer_outline->begin()); 74 | thrust::copy(host_pointer_blockid_to_jointid_map, host_pointer_blockid_to_jointid_map + num_centers, device_pointer_blockid_to_jointid_map->begin()); 75 | } 76 | 77 | -------------------------------------------------------------------------------- /cudax/outer_product.cu: -------------------------------------------------------------------------------- 1 | #include "thrust/device_vector.h" 2 | #include "thrust/host_vector.h" 3 | #include "thrust/copy.h" 4 | #include "cudax/Timer.h" 5 | #include "cudax/CudaTimer.h" 6 | 7 | #include "CublasHelper.h" 8 | 9 | using namespace cudax; 10 | 11 | extern "C" void outer_product(float* input, float* output, int rows, int cols){ 12 | thrust::device_vector J(input, input+(rows*cols)); 13 | thrust::device_vector JtJ(cols*cols); 14 | CublasHelper::outer_product(J, JtJ, rows, cols); 15 | thrust::copy(JtJ.begin(), JtJ.end(), output); 16 | } 17 | 18 | extern "C" void vector_product(float* J_in, float* e_in, float* Jte_out, int rows, int cols){ 19 | thrust::device_vector J(J_in, J_in+(rows*cols)); 20 | thrust::device_vector e(e_in, e_in+(rows)); 21 | thrust::device_vector Jte(cols); 22 | CublasHelper::vector_product(J, e, Jte, rows, cols); 23 | thrust::copy(Jte.begin(), Jte.end(), Jte_out); 24 | } 25 | 26 | //-- 27 | 28 | thrust::device_vector _test_J; 29 | thrust::device_vector _test_JtJ; 30 | 31 | extern "C" void outer_product_init(float* input, int rows, int cols){ 32 | _test_J = thrust::device_vector(input, input+(rows*cols)); 33 | _test_JtJ = thrust::device_vector(cols*cols); 34 | } 35 | 36 | extern "C" void outer_product_compute(int rows, int cols){ 37 | CublasHelper::outer_product(_test_J, _test_JtJ, rows, cols); 38 | } 39 | 40 | extern "C" void outer_product_copy(float* output){ 41 | thrust::copy(_test_JtJ.begin(), _test_JtJ.end(), output); 42 | } 43 | 44 | //-- 45 | 46 | thrust::device_vector _test_J2; 47 | thrust::device_vector _test_e; 48 | thrust::device_vector _test_Jte; 49 | 50 | extern "C" void vector_product_init(float* J_in, float* e_in, int rows, int cols){ 51 | _test_J2 = thrust::device_vector(J_in, J_in+(rows*cols)); 52 | _test_e = thrust::device_vector(e_in, e_in+(rows)); 53 | _test_Jte = thrust::device_vector(cols); 54 | } 55 | 56 | extern "C" void vector_product_compute(int rows, int cols){ 57 | CublasHelper::vector_product(_test_J2, _test_e, _test_Jte, rows, cols); 58 | } 59 | 60 | extern "C" void vector_product_copy(float* Jte_out){ 61 | thrust::copy(_test_Jte.begin(), _test_Jte.end(), Jte_out); 62 | } 63 | 64 | 65 | -------------------------------------------------------------------------------- /data/models/anastasia/B.txt: -------------------------------------------------------------------------------- 1 | 30 2 | 1 0 32767 2 1 32767 3 2 32767 5 4 32767 6 5 32767 7 6 32767 9 8 32767 10 9 32767 11 10 32767 13 12 32767 14 13 32767 15 14 32767 17 16 32767 18 17 32767 19 18 33 26 21 20 25 26 21 25 22 21 25 27 22 27 22 23 20 29 28 21 20 29 21 30 29 22 21 30 22 23 30 23 30 31 19 33 24 16 32 32767 36 34 35 37 36 35 -------------------------------------------------------------------------------- /data/models/anastasia/C.txt: -------------------------------------------------------------------------------- 1 | 38 2 | -39.1921010036571 104.42914690526 -2.03345317132301 -36.4219529183199 92.1801271620935 0.546700057100143 -30.1593239820926 74.2435104185241 2.80195787383723 -18.1006274829058 44.8872189558057 6.89779885175684 -15.961499192477 123.394423445008 3.96469521085454 -15.4991239712589 110.035264772398 6.47634811440922 -11.9816869020692 86.4515472992845 8.14998781146569 -5.93252833208436 49.1045715198562 10.7990745655024 3.94151798468563 132.348650392571 12.3794798691294 5.23563478772852 116.501684967454 12.8708126150782 7.45063177664098 93.3529393243844 12.0578696001538 8.13206093136712 52.8925337300225 10.5462597198908 36.5828948203801 120.304655710991 8.22434819016473 33.6977430081962 107.801724820444 8.02237711930881 30.998569724308 87.4094524185472 6.97584287318811 25.3963014758116 50.8191271908063 5.28707421284505 58.8494401682182 61.8887563590976 -28.3816114964767 52.3324885138967 50.0437715911652 -24.6250694698376 36.3487867184322 27.6729832330458 -17.3672321427731 9.72575025957954 3.87206312066022 -7.1604627581242 -17.9329458594479 38.5720121100473 3.26178933462043 -6.55444438542295 42.5952776864151 6.32104603513129 5.55773283700264 45.0206826906809 6.94770747925078 23.937065383421 45.6289775954587 3.48159531302545 28.5966853981623 41.2309736294272 1.30522236582156 0 0 0 -10.0083042480548 1.01374285060873 0.437150571696773 7.31059158265142 3.0928009903835 -0.0489973098355871 -25.2322135133901 60.8667733160735 0.0655308160968786 -7.66261253423953 66.684123835526 5.10591862699012 7.45339748885971 68.1337189972611 6.36451763617509 24.1939771699258 64.373856660983 0.365075871711399 62.8668882141749 67.1738090866495 -30.2867132413268 29.1982351526817 25.353636004807 -9.29490335239345 9.739752 -4.05823 0 -6.493168 -4.05823 0 4.05823 -48.69876 0 -4.05823 -48.69876 0 -------------------------------------------------------------------------------- /data/models/anastasia/I.txt: -------------------------------------------------------------------------------- 1 | 19 2 | 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 -0.00201515813042759 -0.392221656582072 -0.919868529326732 0 0.716811424453506 0.640827408076895 -0.274811962677001 0 0.697264168669698 -0.659926060377574 0.279857595794521 0 9.72575025957954 3.87206312066022 -7.1604627581242 1 0.997074347254334 0.0764378574225116 0 0 -0.0749141893415977 0.977199243366845 -0.198669330795061 0 -0.0151858579815387 0.198088093321941 0.980066577841242 0 0 37.14092096 0 1 0.998709243927458 -0.0507921853619798 0 0 0.0497797232887936 0.978801550954397 -0.198669330795061 0 0.0100908494754832 0.19841289714991 0.980066577841242 0 0 28.43601761 0 1 -0.900232361095006 -0.395266713244405 -0.182608656526121 0 -0.376837959840443 0.917393101653923 -0.127996285340975 0 0.218116592813574 -0.0464125245893881 -0.974818459766041 0 -18.1006274829058 44.8872189558057 6.89779885175684 1 0.998521152855459 0.0543645776237127 0 0 -0.0543645776237127 0.998521152855459 0 0 0 0 1 0 0 31.9996862956494 0 1 0.99691733373313 0.0784590957278228 0 0 -0.0784590957278228 0.99691733373313 0 0 0 0 1 0 0 19.1318825320073 0 1 -0.987194746758647 -0.158906995685241 0.013967773423907 0 -0.159497594870159 0.984724196527031 -0.0698482212001764 0 -0.00265503347725032 -0.0711816233060546 -0.997459837437453 0 -5.93252833208436 49.1045715198562 10.7990745655024 1 0.99992197194125 0.0124919986039986 0 0 -0.0124919986039986 0.99992197194125 0 0 0 0 1 0 0 37.9263309575871 0 1 0.99691733373313 0.0784590957278228 0 0 -0.0784590957278228 0.99691733373313 0 0 0 0 1 0 0 23.9032458721182 0 1 -0.99945486575555 -0.0157486359789382 -0.0290164054003808 0 -0.0168277518819214 0.999161338580319 0.0373288930050996 0 0.0284041913131996 0.0377968246177979 -0.99888167565766 0 8.13206093136712 52.8925337300225 10.5462597198908 1 0.99691733373313 -0.0784590957278228 0 0 0.0784590957278228 0.99691733373313 0 0 0 0 1 0 0 40.4943666573916 0 1 0.999890964179309 0.0147668463990244 0 0 -0.0147668463990244 0.999890964179309 0 0 0 0 1 0 0 23.2686809435768 0 1 -0.958710241041859 0.135239938939454 0.250169607740655 0 0.151187023350914 0.987454029197676 0.0455743808686961 0 -0.240867510660426 0.0815150239951366 -0.967128814156274 0 25.3963014758116 50.8191271908063 5.28707421284505 1 0.999780082859422 -0.0209710733537235 0 0 0.0209710733537235 0.999780082859422 0 0 0 0 1 0 0 37.0552189224151 0 1 0.999344312884204 0.0362069648824284 0 0 -0.0362069648824284 0.999344312884204 0 0 0 0 1 0 0 20.5967362477139 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 -------------------------------------------------------------------------------- /data/models/anastasia/R.txt: -------------------------------------------------------------------------------- 1 | 38 2 | 4.18002035771824 4.77166227568556 6.22558983914463 7.84562144034084 4.84958816768162 5.01216506502471 6.9709212730233 7.26767841009809 5.58431683084491 5.67620711346111 7.64301749776874 7.68834320351026 5.17426623433049 5.85299454578163 7.55251446128349 8.4414270686924 7.03110437997716 7.30846289109628 10.3117827421962 15.682683691356 8.98482241647984 10.2172130318293 10.7259848388701 9.50547822862919 4.76349877950367 13.6244259561432 13.4193126494237 13.299440742023 1.75341263256337 2.81212214172847 3.15774565276551 1.29623202061041 4.9916229 6.60392417029187 12.986336 12.986336 15.421274 15.421274 -------------------------------------------------------------------------------- /data/pose_space/fingers/Limits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/data/pose_space/fingers/Limits -------------------------------------------------------------------------------- /data/pose_space/fingers/P: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/data/pose_space/fingers/P -------------------------------------------------------------------------------- /data/pose_space/fingers/Sigma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/data/pose_space/fingers/Sigma -------------------------------------------------------------------------------- /data/pose_space/fingers/pca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/data/pose_space/fingers/pca.png -------------------------------------------------------------------------------- /data/pose_space/mu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/data/pose_space/mu -------------------------------------------------------------------------------- /data/pose_space/thumb/Limits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/data/pose_space/thumb/Limits -------------------------------------------------------------------------------- /data/pose_space/thumb/P: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/data/pose_space/thumb/P -------------------------------------------------------------------------------- /data/pose_space/thumb/Sigma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/data/pose_space/thumb/Sigma -------------------------------------------------------------------------------- /data/pose_space/thumb/pca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/data/pose_space/thumb/pca.png -------------------------------------------------------------------------------- /data/shaders/model_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | in vec3 position; 3 | in vec2 vtexcoord; 4 | out vec2 uv; 5 | 6 | void main() { 7 | gl_Position = vec4(position, 1.0); 8 | uv = vtexcoord; 9 | } 10 | -------------------------------------------------------------------------------- /data/shaders/skin_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/data/shaders/skin_texture.png -------------------------------------------------------------------------------- /tracker/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #--- TODO: fully decouple library in subdirectory 2 | # http://stackoverflow.com/questions/7819647/cmake-build-library-and-link-against-it 3 | 4 | #--- Add the "tracker" folder (recursively) 5 | file(GLOB_RECURSE SRC_TRACKER "*.cpp") 6 | file(GLOB_RECURSE HDR_TRACKER "*.h") 7 | list(APPEND SOURCES ${SRC_TRACKER}) 8 | list(APPEND HEADERS ${HDR_TRACKER}) 9 | 10 | #--- Makes DebugRenderer visible 11 | include_directories(OpenGL) 12 | include_directories(OpenGL/DebugRenderer) 13 | include_directories(OpenGL/CylindersRenderer) 14 | include_directories(OpenGL/QuadRenderer) 15 | include_directories(OpenGL/KinectDataRenderer) 16 | include_directories(OpenGL/ConvolutionRenderer) 17 | 18 | #--- Shaders 19 | # Dummy Target to have shaders appear in project 20 | file(GLOB_RECURSE SHADER_SOURCES "tracker/OpenGL/*.glsl") 21 | add_custom_target(shaders SOURCES ${SHADER_SOURCES}) 22 | # @see note on Q_INIT_RESOURCE http://qt-project.org/wiki/QtResources 23 | qt5_add_resources(SHADERS_QRC OpenGL/shaders.qrc) 24 | 25 | #--- Deploy data to the executable folder (only when CMake is run) 26 | # @see http://www.cmake.org/cmake/help/v3.0/command/file.html 27 | file(COPY HandFinder/wristband.txt DESTINATION ${PROJECT_BINARY_DIR}) 28 | file(COPY Energy/PoseSpace_PCA DESTINATION ${PROJECT_BINARY_DIR}) 29 | 30 | #--- To simplify our life 31 | include_directories(../) # #include "tracker/..." 32 | 33 | #--- Add library to the dependencies 34 | if(WITH_CUDA) 35 | list(APPEND LIBRARIES cudax) 36 | endif() 37 | 38 | #--- Generate moc files (anywhere you have Q_OBJECT) 39 | #set(CMAKE_AUTOMOC OFF) 40 | add_library(hmodelsdk STATIC ${SOURCES} ${HEADERS} ${SHADERS_QRC}) 41 | target_link_libraries(hmodelsdk ${LIBRARIES}) 42 | 43 | -------------------------------------------------------------------------------- /tracker/Data/Camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/Types.h" 3 | #include 4 | 5 | /// The running modes for cameras 6 | enum CAMERAMODE{ INVALID=-1, QVGA, VGA, Tompson, Chen, Tang, Intel}; 7 | 8 | class Camera{ 9 | typedef Eigen::Matrix Matrix33f; 10 | typedef Eigen::Matrix Matrix44f; 11 | private: 12 | CAMERAMODE _mode; 13 | Matrix3 proj; 14 | Matrix3 iproj; 15 | Scalar _zNear; ///< near clip plane (mm) 16 | Scalar _zFar; ///< far clip plane (mm) 17 | int _width; 18 | int _height; 19 | Scalar _focal_length_x=nan(); 20 | Scalar _focal_length_y=nan(); 21 | int _fps=30; ///< frame per second 22 | public: 23 | 24 | /// @{ 25 | public: 26 | Camera(CAMERAMODE mode, int FPS=30); 27 | public: 28 | CAMERAMODE mode() const { return _mode; } 29 | int width() const { return _width; } 30 | int height() const { return _height; } 31 | Scalar focal_length_x() const{ return _focal_length_x; } 32 | Scalar focal_length_y() const{ return _focal_length_y; } 33 | Scalar zSpan() const { return (_zFar-_zNear); } 34 | Scalar zNear() const { return _zNear; } 35 | Scalar zFar() const { return _zFar; } 36 | bool is_valid(Scalar depth){ return ((depth>_zNear) && (depth<_zFar)); } 37 | Scalar FPS() const { return _fps; } 38 | const Matrix3& inv_projection_matrix() const{ return iproj; } 39 | /// @} 40 | 41 | public: 42 | /// View+Projection matrix (part of MVP) that considers the kinect sensor intrinsics 43 | Matrix44f view_matrix(){ return Matrix44f::Identity(); } 44 | Matrix44f view_projection_matrix(); 45 | Matrix_2x3 projection_jacobian(const Vector3& p); 46 | 47 | public: 48 | Vector2 world_to_image(const Vector3& wrld); 49 | Vector3 depth_to_world(Real i, Real j, Real depth); 50 | Vector3 unproject(int i, int j, Scalar depth); 51 | Vector3 pixel_to_image_plane(int i, int j); 52 | }; 53 | -------------------------------------------------------------------------------- /tracker/Data/DataFrame.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "opencv2/core/core.hpp" /// cv::Mat 3 | #include "tracker/Types.h" 4 | #include "Camera.h" 5 | 6 | typedef unsigned short DepthPixel; 7 | typedef cv::Vec3b ColorPixel; 8 | 9 | struct DataFrame{ 10 | int id; ///< unique id (not necessarily sequential!!) 11 | cv::Mat color; ///< CV_8UC3 12 | cv::Mat depth; ///< CV_16UC1 13 | cv::Mat silhouette; 14 | cv::Mat full_color; 15 | 16 | DataFrame(int id):id(id){} 17 | 18 | /// @param horizontal pixel 19 | /// @param vertical pixel 20 | /// @param camera parameters to invert the transformation 21 | Vector3 point_at_pixel(int x, int y, Camera* camera){ 22 | Integer z = depth_at_pixel(x,y); 23 | return camera->depth_to_world(x,y,z); 24 | } 25 | 26 | Real depth_at_pixel(const Vector2i& pixel /*row,col*/){ 27 | return depth.at(pixel[0],pixel[1]); 28 | } 29 | 30 | Real depth_at_pixel(int x, int y){ 31 | /// Access is done as (row,colum) 32 | return depth.at(y,x); 33 | } 34 | }; 35 | -------------------------------------------------------------------------------- /tracker/Data/DataStream.cpp: -------------------------------------------------------------------------------- 1 | #include "DataStream.h" 2 | #include 3 | #include 4 | #include 5 | 6 | #include "util/qt2eigen.h" 7 | #include "util/mylogger.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | DataStream::DataStream(Camera *camera) : _camera(camera){ 14 | assert( camera != NULL); 15 | } 16 | 17 | DataStream::~DataStream(){ 18 | for(uint i=0; idepth); 45 | filename = path + "color-" + stringstream.str() + ".png"; 46 | cv::imwrite(filename, frames.at(i)->color); 47 | if (frames.at(i)->full_color.data) { 48 | filename = path + "full_color-" + stringstream.str() + ".png"; 49 | cv::imwrite(filename, frames.at(i)->full_color); 50 | } 51 | //filename = path + "mask-" + stringstream.str() + ".png"; 52 | //cv::imwrite(filename, frames.at(i)->silhouette); 53 | cout << filename << endl; 54 | } 55 | 56 | /*for (size_t i = 0; i < current.rows; i++) { 57 | for (size_t j = 0; j < current.cols; j++) { 58 | uint16_t a = current.at(i, j); 59 | cout << a << " "; 60 | } 61 | }*/ 62 | } 63 | -------------------------------------------------------------------------------- /tracker/Data/DataStream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "tracker/ForwardDeclarations.h" 5 | #include "tracker/Types.h" 6 | #include "Camera.h" 7 | #include "DataFrame.h" 8 | #include 9 | 10 | class DataStream{ 11 | private: 12 | QList frames; 13 | private: 14 | Camera* _camera; 15 | public: 16 | Camera& camera(){ return *_camera; } 17 | public: 18 | int width() const { return _camera->width(); } 19 | int height() const { return _camera->height(); } 20 | int size() const{ return frames.size(); } 21 | public: 22 | int add_frame(const void* color_buffer, const void* depth_buffer, const void* full_color_buffer); 23 | public: 24 | DataStream(Camera* camera); 25 | ~DataStream(); 26 | public: 27 | void save_as_images(std::string path); 28 | }; 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /tracker/Data/SolutionStream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/Types.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "tracker/Data/DataStream.h" 8 | 9 | ///--- This is only valid when we record a stream 10 | class SolutionStream{ 11 | public: 12 | std::vector< Thetas > frames; 13 | std::vector> joint_locations; 14 | bool _valid = false; 15 | 16 | public: 17 | bool isValid(int fid = 0){ 18 | return _valid; // || ( (fid <= _valid_id) && (fid >= 0) ); 19 | } 20 | 21 | void reserve(int size){ 22 | frames.reserve(size); 23 | } 24 | 25 | void resize(int num_frames){ 26 | frames.resize(num_frames); 27 | } 28 | 29 | void set(int frame_id, const std::vector& theta ){ 30 | Eigen::Map _theta(theta.data()); 31 | frames[frame_id] = _theta; 32 | } 33 | 34 | }; 35 | -------------------------------------------------------------------------------- /tracker/Data/TextureColor8UC3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "util/gl_wrapper.h" 3 | #include "util/mylogger.h" 4 | 5 | class ColorTexture8UC3{ 6 | private: 7 | GLuint texture = 0; 8 | int width, height; 9 | bool _is_init = false; 10 | int fid = -1; ///< loaded frame data (avoid unnecessary loads) 11 | public: 12 | GLuint texid(){ CHECK(_is_init); return texture; } 13 | 14 | ColorTexture8UC3(int width, int height){ 15 | this->width = width; 16 | this->height = height; 17 | CHECK(!_is_init); 18 | glGenTextures(1, &texture); 19 | glBindTexture(GL_TEXTURE_2D, texture); 20 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 21 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 22 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 23 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 24 | 25 | std::vector data(width*height*3, 0); ///< initialization 26 | /// @see Table.2 https://www.khronos.org/opengles/sdk/docs/man3/docbook4/xhtml/glTexImage2D.xml 27 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data.data()); 28 | glBindTexture(GL_TEXTURE_2D, 0); 29 | _is_init=true; 30 | CHECK_ERROR_GL(); 31 | } 32 | 33 | /// @note -1 forces refresh 34 | void load(GLvoid* pixels, int fid=-1){ 35 | if(this->fid != fid || fid==-1){ 36 | glBindTexture(GL_TEXTURE_2D, texture); 37 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); 38 | glBindTexture(GL_TEXTURE_2D, 0); 39 | this->fid = fid; 40 | } 41 | CHECK_ERROR_GL(); 42 | } 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /tracker/Data/TextureDepth16UC1.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "util/gl_wrapper.h" 3 | #include "util/mylogger.h" 4 | #include "stdint.h" ///< uint16_t 5 | 6 | class DepthTexture16UC1 { 7 | private: 8 | GLuint texture = 0; 9 | int width, height; 10 | bool _is_init = false; 11 | int fid = -1; ///< loaded frame data (avoid unnecessary loads) 12 | public: 13 | GLuint texid(){ CHECK(_is_init); return texture; } 14 | 15 | DepthTexture16UC1(int width, int height) { 16 | this->width = width; 17 | this->height = height; 18 | CHECK(!_is_init); 19 | glGenTextures(1, &texture); 20 | glBindTexture(GL_TEXTURE_2D, texture); 21 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 22 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 23 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 24 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 25 | std::vector data(width*height, 0); ///< initialization 26 | /// @see Table.2 https://www.khronos.org/opengles/sdk/docs/man3/docbook4/xhtml/glTexImage2D.xml 27 | glTexImage2D(GL_TEXTURE_2D, 0, GL_R16UI, width, height, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, data.data()); 28 | glBindTexture(GL_TEXTURE_2D, 0); 29 | _is_init=true; 30 | } 31 | 32 | /// @note Pixels must be a 16 bits unsigned short data!!! 33 | /// @see http://stackoverflow.com/questions/9863969/updating-a-texture-in-opengl-with-glteximage2d 34 | void load(GLvoid* pixels, int fid){ 35 | if(this->fid != fid || fid==-1){ 36 | glBindTexture(GL_TEXTURE_2D, texture); 37 | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RED_INTEGER, GL_UNSIGNED_SHORT, pixels); 38 | glBindTexture(GL_TEXTURE_2D, 0); 39 | this->fid = fid; 40 | } 41 | } 42 | 43 | bool check_loaded(int fid){ return this->fid == fid; } 44 | 45 | #if 0 46 | cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindUnsigned); 47 | cudaArray* myArray; 48 | cudaMallocArray(&myArray, 49 | &refTex.channelDesc, /* with this you don't need to fill a channel descriptor */ 50 | width, 51 | height); 52 | } 53 | #endif 54 | }; 55 | -------------------------------------------------------------------------------- /tracker/DataStructure/CustomJointInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #ifdef __CUDACC__ 6 | #include "cudax/cuda_glm.h" 7 | #else 8 | #include "tracker/Types.h" 9 | #endif 10 | 11 | ///--- Complexity below is to handle CPU/GPU types transparently 12 | struct CustomJointInfo{ 13 | #ifdef __CUDACC__ 14 | glm::mat4x4 mat; 15 | glm::vec3 axis; 16 | #else 17 | float mat[16]; ///< joint name associated with this constraint 18 | float axis[3]; ///< axis to assemble jacobian column 19 | #endif 20 | int type; ///< how to assemble the column 21 | int index; ///< index of jacobian column 22 | }; 23 | 24 | typedef std::vector JointTransformations; 25 | 26 | /// Ability to output CustomJointInfo to std::cout (make sure transferred correctly) 27 | inline std::ostream& operator<< (std::ostream& d, CustomJointInfo val) { 28 | d << "Jointinfo #" << val.index << std::endl; 29 | d << "type: " << val.type << std::endl; 30 | d << "matrix" << std::endl; 31 | #ifndef __CUDACC__ 32 | Eigen::Map mat(val.mat); 33 | #endif 34 | 35 | for (int row = 0; row<4; ++row) { 36 | for (int col = 0; col<4; ++col){ 37 | #ifdef __CUDACC__ 38 | /// @note in column major, operator[] is not very intuitive! 39 | /// this is because you first fetch the column in memory 40 | d << " " << val.mat[col][row] << " "; 41 | #else 42 | /// @note eigen operator() does it right instead 43 | d << " " << mat(row,col) << " "; 44 | #endif 45 | } 46 | d << std::endl; 47 | } 48 | d << "axis: \n " << val.axis[0] << " " << val.axis[1] << " " << val.axis[2] << std::endl; 49 | return d; 50 | } 51 | 52 | #define CHAIN_MAX_LENGTH 15 53 | struct ChainElement{ int data[CHAIN_MAX_LENGTH]; }; 54 | typedef std::vector KinematicChain; ///< row major! 55 | 56 | inline void clear_kinematic(KinematicChain& chain){ 57 | for (int i = 0; i < chain.size(); ++i) 58 | for(int j=0; j& theta_0, Eigen::Matrix & theta, size_t permutation_index); 29 | void my_damping_track(LinearSystem &system); 30 | 31 | void draw_detected_features(bool verbose); 32 | void draw_point_constraints(size_t permutation, size_t index, bool verbose); 33 | void draw_line_constraints(size_t permutation, size_t index, size_t j, Vector3 p, bool verbose); 34 | void draw_plane_constraints(size_t j, Vector3 p, bool verbose); 35 | void draw_direction_constraints(size_t permutation, size_t direction, size_t index, size_t i, bool verbose); 36 | 37 | void detect_compute_points_update(LinearSystem &system_detection, size_t permutation, bool verbose); 38 | void detect_compute_lines_update(LinearSystem &system_detection, size_t permutation, bool verbose); 39 | void detect_compute_planes_update(LinearSystem &system_detection, bool verbose); 40 | void detect_compute_direction_update(LinearSystem &system_detection, size_t permutation, size_t direction, bool verbose); 41 | 42 | Scalar compute_detection_energy(size_t permutation, size_t direction); 43 | void optimize_current_permutation(size_t permutation, size_t direction, const Eigen::Matrix & theta_0, bool verbose, std::vector & theta_std); 44 | }; 45 | -------------------------------------------------------------------------------- /tracker/Detection/TrivialDetector.cpp: -------------------------------------------------------------------------------- 1 | #include "TrivialDetector.h" 2 | 3 | #include "util/mylogger.h" 4 | #include "util/opencv_wrapper.h" 5 | #include "tracker/Data/DataFrame.h" 6 | #include "tracker/OpenGL/OffscreenRenderer.h" 7 | #include "tracker/OpenGL/CustomFrameBuffer.h" 8 | #include "tracker/HandFinder/HandFinder.h" 9 | #include "tracker/Worker.h" 10 | 11 | bool TrivialDetector::compute_centroid_render(cv::Mat color_render, cv::Mat depth_render, Vector3& retval) 12 | { 13 | Vector3 tot(0,0,0); 14 | int count = 0; 15 | for(int row = 0; row < depth_render.rows; row++){ 16 | for(int col = 0; col < depth_render.cols; col++){ 17 | if(color_render.at(row,col)==255) 18 | continue; 19 | cv::Vec4f p = depth_render.at(row, col); 20 | tot += Vector3(p[0], p[1], p[2]); 21 | count++; 22 | } 23 | } 24 | 25 | if(count==0){ 26 | retval = Vector3(0,0,0); 27 | return false; 28 | } else { 29 | retval = tot / count; 30 | return true; 31 | } 32 | } 33 | 34 | bool TrivialDetector::compute_centroid_sensor(DataFrame& frame, cv::Mat sensor_silhouette, Vector3& retval) 35 | { 36 | Vector3 tot(0,0,0); 37 | int count = 0; 38 | for(int row=0; row(row,col)<125) 41 | continue; 42 | Vector3 p_sensor = frame.point_at_pixel(col,row,camera); 43 | tot += p_sensor; 44 | count++; 45 | } 46 | } 47 | 48 | if(count==0){ 49 | retval = Vector3(0,0,0); 50 | return false; 51 | } else { 52 | retval = tot / count; 53 | return true; 54 | } 55 | } 56 | 57 | void TrivialDetector::copy_rendered_images_to_cpu(){ 58 | ///--- Depth 59 | //depth_render = offscreenrend->frame_buffer->fetch_extra_attachment(); 60 | //cv::flip(depth_render, depth_render, 0 /*flip rows*/ ); 61 | 62 | ///--- Color 63 | //color_render = offscreenrend->frame_buffer->fetch_color_attachment(); 64 | //cv::flip(color_render, color_render, 0 /*flip rows*/ ); 65 | } 66 | 67 | TrivialDetector::TrivialDetector(Camera *camera, OffscreenRenderer *offscreenrend) : 68 | camera(camera), offscreenrend(offscreenrend) { 69 | CHECK_NOTNULL(camera); 70 | CHECK_NOTNULL(offscreenrend); 71 | } 72 | 73 | Vector3 TrivialDetector::exec(DataFrame& frame, const cv::Mat& sensor_silhouette) 74 | { 75 | LOG(INFO) << "Worker::initialize_offset"; 76 | bool success = true; 77 | Vector3 c1; 78 | Vector3 c2; 79 | 80 | ///--- Make hand in standard pose 81 | success &= compute_centroid_sensor(frame, sensor_silhouette, /*=*/c2); 82 | if(!success) Vector3(0, 0, 0); 83 | 84 | ///--- Get cloud 85 | offscreenrend->render_offscreen(false, true); 86 | this->copy_rendered_images_to_cpu(); 87 | 88 | success &= compute_centroid_render(this->color_render, this->depth_render, /*=*/c1); 89 | 90 | if(!success){ 91 | LOG(INFO) << "WARNING: init failed"; 92 | return Vector3(0, 0, 0); 93 | } 94 | 95 | ///--- Apply the transformation 96 | Vector3 translation = c2-c1; 97 | 98 | ///--- Just to be sure 99 | assert(!isnan(translation[0])); 100 | assert(!isnan(translation[1])); 101 | assert(!isnan(translation[2])); 102 | 103 | return translation; 104 | 105 | } 106 | 107 | -------------------------------------------------------------------------------- /tracker/Detection/TrivialDetector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/Types.h" 3 | #include "tracker/ForwardDeclarations.h" 4 | #include "util/opencv_wrapper.h" 5 | 6 | class TrivialDetector{ 7 | private: 8 | Camera*const camera; 9 | OffscreenRenderer*const offscreenrend; 10 | private: 11 | cv::Mat color_render; ///< [0..N] joint ID, 255 is background 12 | cv::Mat depth_render; ///< 3D points in camera space 13 | 14 | public: 15 | TrivialDetector(Camera* camera, OffscreenRenderer* offscreenrend); 16 | Vector3 exec(DataFrame &frame, const cv::Mat& sensor_silhouette); 17 | private: 18 | void copy_rendered_images_to_cpu(); 19 | bool compute_centroid_sensor(DataFrame &frame, cv::Mat sensor_silhouette, Vector3 &retval); 20 | bool compute_centroid_render(cv::Mat color_render, cv::Mat depth_render, Vector3 &retval); 21 | }; 22 | -------------------------------------------------------------------------------- /tracker/Detection/matlab_helpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/Types.h" 3 | 4 | namespace matlab{ 5 | 6 | /// see matlab randn 7 | static inline Real randn( const double mean, const double stddev ){ 8 | double u1 = ( static_cast ( std::rand() ) + 1 ) / ( (double)RAND_MAX + 1 ); 9 | double u2 = ( static_cast ( std::rand() ) + 1 ) / ( (double)RAND_MAX + 1 ); 10 | assert( -2 * std::log( u1 ) >= 0 ); 11 | double t1 = std::sqrt( -2 * std::log( u1 ) ) * cos( 2 * M_PI * u2 ); 12 | return mean + stddev * t1; 13 | } 14 | static inline Real rand(){ 15 | /// @todo check this one actually gives [0..1] 16 | return ( static_cast ( std::rand() ) ) / ( (double)RAND_MAX ); 17 | } 18 | 19 | 20 | inline Matrix_MxN rand(int rows, int cols){ 21 | Matrix_MxN m(rows,cols); 22 | for(int i=0; i 30 | inline size_t nnz(const T & A) { 31 | size_t M = A.rows(); 32 | size_t N = A.cols(); 33 | size_t k = 0; 34 | for (size_t i = 0; i < M; i++) { 35 | for (size_t j = 0; j < N; j++) { 36 | if (A(i, j) != 0.0) 37 | k++; 38 | } 39 | } 40 | return k; 41 | } 42 | 43 | 44 | inline size_t sub2ind(size_t R, size_t C, Vector2s s) { 45 | size_t r = s(0); 46 | size_t c = s(1); 47 | return c * R + r; 48 | } 49 | 50 | 51 | inline Vector2s ind2sub(size_t R, size_t C, size_t i) { 52 | size_t c = i / R; 53 | size_t r = i % R; 54 | Vector2s s = Vector2s(r, c); 55 | return s; 56 | } 57 | 58 | 59 | template 60 | inline int sign(T val) { 61 | return (T(0) < val) - (val < T(0)); 62 | } 63 | 64 | 65 | template 66 | inline void find(const T & A, VectorNs & R, VectorNs & C) { 67 | size_t num_non_zeros = nnz(A); 68 | R = VectorNs::Zero(num_non_zeros); 69 | C = VectorNs::Zero(num_non_zeros); 70 | size_t M = A.rows(); 71 | size_t N = A.cols(); 72 | size_t k = 0; 73 | for (size_t r = 0; r < M; r++) { 74 | for (size_t c = 0; c < N; c++) { 75 | if (A(r, c) > 0) { 76 | R(k) = r; 77 | C(k) = c; 78 | k++; 79 | } 80 | } 81 | } 82 | } 83 | 84 | 85 | template 86 | inline void find(const T & A, VectorNs & I) { 87 | size_t num_non_zeros = nnz(A); 88 | I = VectorNs::Zero(num_non_zeros); 89 | size_t M = A.rows(); 90 | size_t N = A.cols(); 91 | size_t k = 0; 92 | for (size_t r = 0; r < M; r++) { 93 | for (size_t c = 0; c < N; c++) { 94 | size_t i = sub2ind(M, N, Vector2s(r, c)); 95 | if (A(r, c) > 0) { 96 | I(k) = i; 97 | k++; 98 | } 99 | } 100 | } 101 | } 102 | 103 | 104 | template 105 | inline void find(const T & A, VectorNs & R, VectorNs & C, VectorN & V) { 106 | size_t num_non_zeros = nnz(A); 107 | R = VectorNs::Zero(num_non_zeros); 108 | C = VectorNs::Zero(num_non_zeros); 109 | V = VectorNs::Zero(num_non_zeros); 110 | size_t M = A.rows(); 111 | size_t N = A.cols(); 112 | size_t k = 0; 113 | for (size_t r = 0; r < M; r++) { 114 | for (size_t c = 0; c < N; c++) { 115 | if (A(r, c) > 0) { 116 | R(k) = r; 117 | C(k) = c; 118 | V(k) = (float) A(r, c); 119 | k++; 120 | } 121 | } 122 | } 123 | } 124 | 125 | 126 | template 127 | inline float mean(const T & a) { 128 | float sum = a.sum(); 129 | return sum / a.size(); 130 | } 131 | 132 | 133 | template 134 | inline float stddev(const T & a) { 135 | return sqrt((a.array() - mean(a)).array().pow(2).sum() / (a.size() - 1)); 136 | } 137 | 138 | 139 | } ///< matlab:: 140 | -------------------------------------------------------------------------------- /tracker/Energy/Collision.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/ForwardDeclarations.h" 3 | #include "Energy.h" 4 | #include "tracker/Types.h" 5 | #include 6 | 7 | namespace energy{ 8 | 9 | class Collision : public Energy{ 10 | public: 11 | struct Settings{ 12 | bool collision_enable = true; 13 | float collision_weight = 10e2; 14 | float collision_fraction = 0.01f; 15 | bool collision_new = false; 16 | } _settings; 17 | Settings*const settings=&_settings; 18 | 19 | public: 20 | struct Point{ 21 | Vector3 p; 22 | size_t id; 23 | Point(Vector3 p, size_t id){ 24 | this->p = p; 25 | this->id = id; 26 | } 27 | }; 28 | 29 | private: 30 | Model * model = NULL; 31 | std::vector s; 32 | std::vector t; 33 | std::vector n; 34 | 35 | public: 36 | void init(Model * model); 37 | void track(LinearSystem& system); 38 | 39 | private: 40 | void collision_compute_update(LinearSystem &system, Scalar omega); 41 | Scalar create_collision_constraints(); 42 | }; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /tracker/Energy/Damping.cpp: -------------------------------------------------------------------------------- 1 | #include "Damping.h" 2 | #include "tracker/TwSettings.h" 3 | #include "tracker/HModel/Model.h" 4 | 5 | namespace energy { 6 | 7 | void Damping::init(Model * model) { 8 | this->model = model; 9 | tw_settings->tw_add(settings->translation_damping, "translations", "group=Damping"); 10 | tw_settings->tw_add(settings->rotation_damping, "rotations", "group=Damping"); 11 | } 12 | 13 | void Damping::track(LinearSystem &system) { 14 | 15 | Eigen::Matrix D = Eigen::Matrix::Identity(system.lhs.rows(), system.lhs.cols()); 16 | Eigen::Matrix d = Eigen::Matrix::Ones(system.lhs.rows(), 1); 17 | 18 | float max_JtJ = 0; 19 | /*for (int i = 0; i < num_thetas; ++i) { 20 | if (max_JtJ < abs(system.lhs(i, i))) 21 | max_JtJ = abs(system.lhs(i, i)); 22 | }*/ 23 | 24 | for (int i = 0; i < num_thetas; ++i) { 25 | if (model->dofs[i].type == TRANSLATION_AXIS) 26 | d(i) = settings->translation_damping; 27 | else 28 | d(i) = settings->rotation_damping; 29 | if (i == 13 || i == 17 || i == 21 || i == 25) d(i) = settings->abduction_damping; 30 | if (i == 16 || i == 20 || i == 24 || i == 28) d(i) = settings->top_phalange_damping; 31 | 32 | //d(i) = d(i) * system.lhs(i, i) / max_JtJ; 33 | } 34 | //cout << d.transpose() << endl; 35 | D.diagonal() = d; 36 | system.lhs = system.lhs + D; 37 | 38 | if (Energy::safety_check) Energy::has_nan(system); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /tracker/Energy/Damping.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/ForwardDeclarations.h" 3 | #include "Energy.h" 4 | #include "tracker/Types.h" 5 | #include 6 | 7 | namespace energy{ 8 | 9 | class Damping : public Energy{ 10 | Model * model = NULL; 11 | 12 | public: 13 | struct Settings { 14 | Scalar translation_damping = 1; 15 | Scalar rotation_damping = 3000; 16 | Scalar abduction_damping = 1500000; 17 | Scalar top_phalange_damping = 10000; 18 | } _settings; 19 | Settings*const settings = &_settings; 20 | 21 | 22 | void init(Model * model); 23 | void track(LinearSystem& system); 24 | }; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /tracker/Energy/Energy.cpp: -------------------------------------------------------------------------------- 1 | #include "Energy.h" 2 | #include "util/mylogger.h" 3 | namespace energy{ 4 | 5 | static bool debug_print_delta_theta = false; 6 | 7 | bool Energy::has_nan(LinearSystem& system){ 8 | for(int i=0; i 3 | #include 4 | #include "tracker/Types.h" 5 | 6 | class TrackingMonitor{ 7 | private: 8 | std::queue failure_metric_history; 9 | float failure_metric_sum = 0; 10 | int moving_window_size = 10; 11 | 12 | 13 | public: 14 | bool is_failure_frame(float pull_error, float push_error, bool fit2D_enable) { 15 | float metric, threshold; 16 | /*if (fit2D_enable) { 17 | Vector3 gamma = Vector3(23.6f, 8.20843f, -4.07201f); // gamma(0) = 30 for DeepPrior, gamma = 23.6 18 | Vector3 x = Vector3(1.0, push_error, pull_error); 19 | /// Failure: 0 , Success: 1 20 | metric = 1.0 / (1.0 + pow((float)exp(1.0), -x.transpose() * gamma)); 21 | threshold = 0.5; 22 | if (metric < threshold) metric = 0; 23 | else metric = 1; 24 | } 25 | else {*/ 26 | metric = pull_error; 27 | threshold = 6.0; 28 | if(metric > threshold) metric = 0; 29 | else metric = 1; 30 | // 31 | 32 | // ofstream errors_file; 33 | //if (!errors_file.is_open()) errors_file.open("...", ios::app); 34 | //errors_file << push_error << " " << pull_error << " " << metric << endl; 35 | 36 | failure_metric_history.push(metric); 37 | failure_metric_sum = failure_metric_sum + metric; 38 | if (failure_metric_history.size() > moving_window_size) { 39 | failure_metric_sum = failure_metric_sum - failure_metric_history.front(); 40 | failure_metric_history.pop(); 41 | } 42 | if ((failure_metric_history.size() == moving_window_size) && (failure_metric_sum == 0)) 43 | return true; 44 | return false; 45 | } 46 | }; 47 | 48 | -------------------------------------------------------------------------------- /tracker/Energy/JointLimits.cpp: -------------------------------------------------------------------------------- 1 | #include "JointLimits.h" 2 | #include "tracker/Hmodel/Model.h" 3 | 4 | void energy::JointLimits::init(Model * model) { 5 | this->model = model; 6 | } 7 | 8 | void energy::JointLimits::track(LinearSystem& sys, const std::vector& theta_0) 9 | { 10 | //cout << "LOW JOINTLIMITS" << endl; 11 | if(!jointlimits_enable) return; 12 | 13 | Eigen::Matrix LHS = Eigen::Matrix::Identity(sys.lhs.rows(), sys.lhs.cols()); 14 | Eigen::Matrix rhs = Eigen::Matrix::Ones( sys.lhs.rows(),1 ); 15 | 16 | 17 | bool show_constraints = jointlimits_show_constraints; 18 | 19 | for(size_t i = 0; i < theta_0.size(); ++i) { 20 | 21 | float qmin = model->dofs[i].min; 22 | float qmax = model->dofs[i].max; 23 | 24 | if(theta_0[i] > qmax) { 25 | //cout << "i = " << i << ", theta = " << theta_0[i] << endl; 26 | rhs(i)=(qmax - theta_0[i]) - std::numeric_limits::epsilon(); 27 | LHS(i, i) = 1; 28 | } 29 | else if(theta_0[i] < qmin) { 30 | //cout << "i = " << i << ", theta = " << theta_0[i] << endl; 31 | rhs(i) = (qmin - theta_0[i]) + std::numeric_limits::epsilon(); 32 | LHS(i, i) = 1; 33 | } 34 | else { 35 | LHS(i, i) = 0; 36 | rhs(i) = 0; 37 | } 38 | } 39 | 40 | ///--- Add constraints to the solve 41 | Scalar omega = jointlimits_weight; 42 | sys.lhs.noalias() += omega * LHS.transpose() * LHS; 43 | sys.rhs.noalias() += omega * LHS.transpose() * rhs; 44 | 45 | ///--- Check 46 | if(Energy::safety_check) 47 | Energy::has_nan(sys); 48 | } 49 | -------------------------------------------------------------------------------- /tracker/Energy/JointLimits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/ForwardDeclarations.h" 3 | #include "Energy.h" 4 | #include "tracker/Types.h" 5 | #include 6 | 7 | namespace energy{ 8 | 9 | class JointLimits : public Energy{ 10 | SkeletonSerializer* skeleton = NULL; 11 | Model * model = NULL; 12 | bool htrack; 13 | public: 14 | bool jointlimits_enable = false; 15 | private: 16 | float jointlimits_weight = 10000000; 17 | //float jointlimits_weight = 100000; 18 | bool jointlimits_show_constraints = false; 19 | 20 | public: 21 | void init(Model * model); 22 | void track(LinearSystem& sys, const std::vector &theta_0); 23 | }; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/ForwardDeclarations.h" 3 | #include "tracker/Energy/Energy.h" 4 | #include "tracker/Types.h" 5 | #include 6 | 7 | namespace energy{ 8 | 9 | enum PoseSpaceType { THUMB, FINGERS }; 10 | 11 | class PoseSpace : public Energy{ 12 | Worker * worker = NULL; 13 | 14 | public: 15 | struct Settings{ 16 | bool enable_split_pca = true; 17 | float weight_proj = 1 * 10e2; //7 * 10e2 18 | float weight_mean = 0.5 * 10e1; 19 | int latent_size = 2; 20 | bool enable_joint_pca = false; ///< no thumb/fingers split 21 | bool debug_display_latent_space = false; 22 | } _settings; 23 | Settings* settings = &_settings; 24 | 25 | public: 26 | 27 | void init(Worker * worker); 28 | void explore_pose_space(int pose_space_type); 29 | void track(LinearSystem &system, std::vector theta); 30 | private: 31 | void find_pixel_coordinates_pca(int rows, int cols, const VectorN &x, const Matrix_MxN &Limits, float &pixels_x, float &pixels_y); 32 | void draw_latent_positions_pca(const VectorN &x, const Matrix_MxN &Limits, string path, string window_name, std::vector &x_history); 33 | void compute_linear_approximation(int n, int m, const VectorN &y, const VectorN &x, const Matrix_MxN &P, Matrix_MxN &LHS_E1, VectorN &rhs_E1); 34 | void compute_objective(int n, int m, const VectorN &y, const VectorN &x, const Matrix_MxN &P, const Matrix_MxN &invSigma, Matrix_MxN &LHS_E1_y, Matrix_MxN &LHS_E1_x, VectorN &rhs_E1_y, VectorN &rhs_E1_x, Matrix_MxN &LHS_E2_y, Matrix_MxN &LHS_E2_x, VectorN &rhs_E2_y, VectorN &rhs_E2_x, Matrix_MxN &LHS_E3_y, Matrix_MxN &LHS_E3_x, VectorN &rhs_E3_y, VectorN &rhs_E3_x); 35 | void assemble_joint_system(int n, int m, const Matrix_MxN &LHS_y, const Matrix_MxN &LHS_x, const VectorN &rhs_y, const VectorN &rhs_x, Matrix_MxN &LHS, VectorN &rhs); 36 | void compose_system(int n, int m, Scalar alpha, Scalar beta, const VectorN &y, const VectorN &x, const Matrix_MxN &P, const Matrix_MxN &invSigma, Matrix_MxN &LHS, VectorN &rhs); 37 | public: 38 | int m = 2; ///< latent space dimension 39 | int m1 = 2; ///< latent space dimension (split/1) 40 | int m4 = 2; ///< latent space dimension (split/2) 41 | 42 | const int p = num_thetas_ignore; // number of pose parameters 43 | const int q = num_thetas; // total number of parameters 44 | const int n = 20; // number of articulation parameters 45 | const int n1 = num_thetas_thumb; 46 | const int n4 = num_thetas_fingers; 47 | bool first_frame = true; 48 | 49 | string subfolder_pca = "PoseSpace_PCA/"; 50 | string path_pca; 51 | 52 | VectorN mu; 53 | 54 | Matrix_MxN P; 55 | Matrix_MxN Sigma; 56 | Matrix_MxN invSigma; 57 | Matrix_MxN Limits; 58 | 59 | Matrix_MxN P1; 60 | Matrix_MxN Sigma1; 61 | Matrix_MxN invSigma1; 62 | Matrix_MxN Limits1; 63 | 64 | Matrix_MxN P4; 65 | Matrix_MxN Sigma4; 66 | Matrix_MxN invSigma4; 67 | Matrix_MxN Limits4; 68 | 69 | VectorN theta_recovered; 70 | 71 | /// @{ used to visualize path in latent space 72 | std::vector x_history; 73 | std::vector x1_history; 74 | std::vector x4_history; 75 | /// @} 76 | }; 77 | 78 | } ///< energy:: 79 | -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/Limits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/Limits -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/P: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/P -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/Sigma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/Sigma -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/fingers/Limits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/fingers/Limits -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/fingers/P: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/fingers/P -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/fingers/Sigma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/fingers/Sigma -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/fingers/mu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/fingers/mu -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/fingers/pca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/fingers/pca.png -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/mu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/mu -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/pca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/pca.png -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/pca_light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/pca_light.png -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/thumb/Limits: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/thumb/Limits -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/thumb/P: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/thumb/P -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/thumb/Sigma: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/thumb/Sigma -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/thumb/mu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/thumb/mu -------------------------------------------------------------------------------- /tracker/Energy/PoseSpace_PCA/thumb/pca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/Energy/PoseSpace_PCA/thumb/pca.png -------------------------------------------------------------------------------- /tracker/Energy/Temporal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "tracker/ForwardDeclarations.h" 4 | #include "tracker/Types.h" 5 | #include "tracker/Energy/Energy.h" 6 | class SolutionQueue; 7 | 8 | namespace energy{ 9 | class Temporal : public Energy{ 10 | Model * model = NULL; 11 | 12 | SolutionQueue* solution_queue = NULL; 13 | std::vector joint_ids; 14 | std::vector center_ids; 15 | std::vector phalange_ids; 16 | std::vector pos_prev1; 17 | std::vector pos_prev2; 18 | int fid_curr = -1; 19 | 20 | public: 21 | struct Settings{ 22 | bool temporal_coherence1_enable = true; 23 | bool temporal_coherence2_enable = true; 24 | float temporal_coherence1_weight = 0.05; 25 | float temporal_coherence2_weight = 0.05; 26 | } _settings; 27 | Settings*const settings = &_settings; 28 | 29 | public: 30 | void init(Model * model); 31 | ~Temporal(); 32 | void track(LinearSystem& system, DataFrame& frame); 33 | void update(int frame_id, const std::vector& Solution); 34 | private: 35 | void track(LinearSystem& system, int fid, bool first_order); 36 | void temporal_coherence_init(); 37 | }; 38 | 39 | } /// energy:: 40 | -------------------------------------------------------------------------------- /tracker/ForwardDeclarations.h: -------------------------------------------------------------------------------- 1 | ///--- Global Forward Declaration of classes 2 | 3 | /// @note keep this super-lightweight (no includes here) 4 | #pragma once 5 | 6 | /// Forward Declares 7 | struct DataFrame; 8 | class Cloud; 9 | class Camera; 10 | class Cylinders; 11 | class Detector; 12 | class DataStream; 13 | class Worker; 14 | class SkeletonSerializer; 15 | class Tracker; 16 | class SolutionStream; 17 | class DetectionStream; 18 | class FindFingers; 19 | class SolutionQueue; 20 | class HandFinder; 21 | class DetectionStream; 22 | class OffscreenRenderer; 23 | class TrivialDetector; 24 | class Skeleton; ///< Legacy 25 | class ICP; ///< Legacy 26 | class Model; 27 | 28 | class Sensor; 29 | class SensorOpenNI; 30 | class SensorSoftKin; 31 | 32 | /// UI/OpenGL 33 | class TwSettings; 34 | class QGLWidget; 35 | class ColorTexture8UC3; 36 | class DepthTexture16UC1; 37 | 38 | /// Rendering 39 | class DebugRenderer; 40 | class CloudRenderer; 41 | class Cylinders_renderer; 42 | class ConvolutionRenderer; 43 | class CustomFrameBuffer; 44 | class QuadRenderer; 45 | class KinectDataRenderer; 46 | 47 | /// Externally Defined 48 | namespace cv{ class Mat; } 49 | namespace cudax{class CudaHelper;} 50 | -------------------------------------------------------------------------------- /tracker/GLWidget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "tracker/ForwardDeclarations.h" 4 | #include "tracker/OpenGL/KinectDataRenderer/KinectDataRenderer.h" 5 | #include "tracker/OpenGL/ConvolutionRenderer/ConvolutionRenderer.h" 6 | 7 | class GLWidget : public QGLWidget { 8 | public: 9 | Worker * worker; 10 | DataStream * const datastream; 11 | SolutionStream * const solutions; 12 | 13 | Camera*const _camera; 14 | KinectDataRenderer kinect_renderer; 15 | ConvolutionRenderer convolution_renderer; 16 | 17 | bool playback; 18 | bool real_color; 19 | 20 | std::string data_path; 21 | 22 | public: 23 | 24 | GLWidget(Worker* worker, DataStream * datastream, SolutionStream * solutions, bool playback, bool real_color, std::string data_path); 25 | 26 | ~GLWidget(); 27 | 28 | void initializeGL(); 29 | 30 | void paintGL(); 31 | 32 | private: 33 | Eigen::Vector3f camera_center = Eigen::Vector3f(0, 0, 0); 34 | Eigen::Vector3f image_center = Eigen::Vector3f(0, 0, 400); 35 | Eigen::Vector3f camera_up = Eigen::Vector3f(0, 1, 0); 36 | Eigen::Matrix4f view = Eigen::Matrix4f::Identity(); 37 | 38 | bool mouse_button_pressed = true; 39 | Eigen::Vector2f cursor_position = Eigen::Vector2f(640, 480); 40 | Eigen::Vector2f euler_angles = Eigen::Vector2f(-6.411, -1.8); 41 | Eigen::Vector2f initial_euler_angles = Eigen::Vector2f(-6.411, -1.8); 42 | float cursor_sensitivity = 0.003f; 43 | 44 | void process_mouse_movement(GLfloat cursor_x, GLfloat cursor_y); 45 | 46 | void process_mouse_button_pressed(GLfloat cursor_x, GLfloat cursor_y); 47 | 48 | void process_mouse_button_released(); 49 | 50 | void mouseMoveEvent(QMouseEvent *event); 51 | 52 | void mousePressEvent(QMouseEvent *event); 53 | 54 | void wheelEvent(QWheelEvent * event); 55 | 56 | void keyPressEvent(QKeyEvent *event); 57 | }; 58 | -------------------------------------------------------------------------------- /tracker/HModel/DataLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "cudax/cuda_glm.h" 5 | 6 | void read_float_matrix(std::string data_path, std::string name, std::vector & input) { 7 | FILE *fp = fopen((data_path + name + ".txt").c_str(), "r"); 8 | int N; 9 | fscanf(fp, "%d", &N); 10 | for (int j = 0; j < N; ++j) { 11 | glm::vec3 v; 12 | fscanf(fp, "%f%f%f", &v[0], &v[1], &v[2]); 13 | input.push_back(v); 14 | } 15 | fclose(fp); 16 | } 17 | 18 | void read_float_vector(std::string data_path, std::string name, std::vector & input) { 19 | FILE *fp = fopen((data_path + name + ".txt").c_str(), "r"); 20 | int N; 21 | fscanf(fp, "%d", &N); 22 | for (int i = 0; i < N; ++i) { 23 | float a; 24 | fscanf(fp, "%f", &a); 25 | input.push_back(a); 26 | } 27 | fclose(fp); 28 | } 29 | 30 | void read_int_matrix(std::string data_path, std::string name, std::vector & input) { 31 | FILE *fp = fopen((data_path + name + ".txt").c_str(), "r"); 32 | int N; 33 | fscanf(fp, "%d", &N); 34 | for (int j = 0; j < N; ++j) { 35 | glm::ivec3 v; 36 | fscanf(fp, "%d%d%d", &v[0], &v[1], &v[2]); 37 | input.push_back(v); 38 | } 39 | fclose(fp); 40 | } 41 | 42 | /*void write_float_vector(std::string name, thrust::host_vector output) { 43 | std::ofstream output_file; 44 | output_file.open(data_path + name + ".txt"); 45 | for (size_t i = 0; i < output.size(); i++) { 46 | output_file << output[i] << " "; 47 | } 48 | output_file.close(); 49 | }*/ 50 | 51 | void write_floats(std::string data_path, std::string name, float * output, size_t size) { 52 | std::ofstream output_file; 53 | output_file.open(data_path + name + ".txt"); 54 | for (size_t i = 0; i < size; i++) { 55 | output_file << output[i] << " "; 56 | } 57 | output_file.close(); 58 | } 59 | 60 | -------------------------------------------------------------------------------- /tracker/HModel/ModelSemantics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Model; 4 | class Cylinders; 5 | class Skeleton; 6 | 7 | class ModelSemantics { 8 | 9 | Model * model; 10 | 11 | public: 12 | 13 | ModelSemantics(Model * _model); 14 | 15 | void setup_kinematic_chain(); 16 | 17 | // Hmodel 18 | 19 | void setup_outline(); 20 | 21 | void setup_centers_name_to_id_map(); 22 | 23 | void setup_phalanges_to_centers_map(); 24 | 25 | void setup_jointid_to_centerid_map(); 26 | 27 | void setup_blockid_to_jointid_map(); 28 | 29 | void setup_topology(); 30 | 31 | void setup_dofs(); 32 | 33 | void setup_phalanges(); 34 | 35 | }; 36 | -------------------------------------------------------------------------------- /tracker/HModel/ModelSerializer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Model; 4 | 5 | class ModelSerializer { 6 | 7 | void serialize_centers(); 8 | 9 | void serialize_radii(); 10 | 11 | void serialize_blocks(); 12 | 13 | void serialize_tangent_points(); 14 | 15 | void serialize_outline(); 16 | 17 | void serialize_blockid_to_jointid_map(); 18 | 19 | void serialize_transformations(); 20 | 21 | public: 22 | Model * model; 23 | 24 | ModelSerializer(Model * _model); 25 | 26 | void serialize_model(); 27 | 28 | }; 29 | -------------------------------------------------------------------------------- /tracker/HModel/OutlineFinder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "cudax/cuda_glm.h" 3 | #include 4 | #include 5 | 6 | class Model; 7 | 8 | struct Outline { 9 | glm::vec2 t1; 10 | glm::vec2 t2; 11 | glm::ivec2 indices; 12 | glm::vec2 start; 13 | glm::vec2 end; 14 | size_t block; 15 | }; 16 | 17 | struct Outline3D { 18 | glm::vec3 start; 19 | glm::vec3 end; 20 | glm::ivec2 indices; 21 | size_t block; 22 | }; 23 | 24 | class OutlineFinder { 25 | public: 26 | std::vector outline3D; 27 | Model * const model; 28 | 29 | OutlineFinder(Model * _model); 30 | 31 | void print_outline(const std::vector & outline); 32 | 33 | void print_outline3D(const std::vector & outline); 34 | 35 | Outline crop_outline_segment(const glm::dvec3 & c1, const glm::dvec3 & c2, double r1, double r2, const glm::dvec2 & t, Outline outline); 36 | 37 | void adjust_fingers_outline(std::vector & outline); 38 | 39 | std::vector find_3D_outline(const std::vector & outline); 40 | 41 | void find_outline(); 42 | 43 | void write_outline(); 44 | 45 | void compute_projections_outline(const std::vector & centers, const std::vector & radii, const std::vector & points, const glm::vec3 & camera_ray); 46 | }; 47 | -------------------------------------------------------------------------------- /tracker/HandFinder/HandFinder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/ForwardDeclarations.h" 3 | #include "tracker/Types.h" 4 | #include "util/opencv_wrapper.h" 5 | #include "tracker/Detection/TrivialDetector.h" 6 | 7 | class HandFinder{ 8 | private: 9 | Camera*const camera=NULL; 10 | TrivialDetector*const trivial_detector=NULL; 11 | public: 12 | HandFinder(Camera * camera); 13 | ~HandFinder() { 14 | delete[] sensor_indicator; 15 | } 16 | 17 | /// @{ Settings 18 | public: 19 | struct Settings{ 20 | bool show_hand = false; 21 | bool show_wband = false; 22 | float depth_range = 150; 23 | float wband_size = 30; 24 | cv::Scalar hsv_min = cv::Scalar( 94, 111, 37); ///< potentially read from file 25 | cv::Scalar hsv_max = cv::Scalar(120, 255, 255); ///< potentially read from file 26 | } _settings; 27 | Settings*const settings=&_settings; 28 | /// @} 29 | 30 | public: 31 | bool _has_useful_data = false; 32 | bool _wristband_found; 33 | Vector3 _wband_center; 34 | Vector3 _wband_dir; 35 | public: 36 | cv::Mat sensor_silhouette; ///< created by binary_classifier 37 | cv::Mat mask_wristband; ///< created by binary_classifier, not used anywhere else 38 | int * sensor_indicator; 39 | int num_sensor_points; 40 | 41 | public: 42 | bool has_useful_data(){ return _has_useful_data; } 43 | bool wristband_found(){ return _wristband_found; } 44 | Vector3 wristband_center(){ return _wband_center; } 45 | Vector3 wristband_direction(){ return _wband_dir; } 46 | void wristband_direction_flip(){ _wband_dir=-_wband_dir; } 47 | public: 48 | void binary_classification(cv::Mat& depth, cv::Mat& color); 49 | }; 50 | -------------------------------------------------------------------------------- /tracker/HandFinder/connectedComponents.h: -------------------------------------------------------------------------------- 1 | //Snipped of opencv3 imgproc.hpp containing these functions 2 | 3 | #include "opencv2/core/core.hpp" 4 | 5 | /// andrea: also on linux, this file does not exist!!! 6 | #if 0 // !defined(__APPLE__) 7 | #include "opencv2/imgproc.hpp" ///< declares the elements below, prevent re-declaration 8 | #else 9 | 10 | namespace cv{ 11 | 12 | //! connected components algorithm output formats 13 | enum { CC_STAT_LEFT = 0, 14 | CC_STAT_TOP = 1, 15 | CC_STAT_WIDTH = 2, 16 | CC_STAT_HEIGHT = 3, 17 | CC_STAT_AREA = 4, 18 | CC_STAT_MAX = 5 19 | }; 20 | 21 | // computes the connected components labeled image of boolean image ``image`` 22 | // with 4 or 8 way connectivity - returns N, the total 23 | // number of labels [0, N-1] where 0 represents the background label. 24 | // ltype specifies the output label image type, an important 25 | // consideration based on the total number of labels or 26 | // alternatively the total number of pixels in the source image. 27 | int connectedComponents(InputArray image, OutputArray labels, 28 | int connectivity = 8, int ltype = CV_32S); 29 | 30 | int connectedComponentsWithStats(InputArray image, OutputArray labels, 31 | OutputArray stats, OutputArray centroids, 32 | int connectivity = 8, int ltype = CV_32S); 33 | 34 | } // cv:: 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /tracker/HandFinder/wristband.txt: -------------------------------------------------------------------------------- 1 | hsv_min: 94 111 37 2 | hsv_max: 120 255 255 -------------------------------------------------------------------------------- /tracker/OpenGL/ConvolutionRenderer/data_points_fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec3 color; 3 | in vec2 uv; 4 | uniform sampler2D tex; 5 | uniform sampler2D tex_mirror; 6 | 7 | void main() { 8 | vec2 coord = gl_PointCoord - vec2(0.5); 9 | if(length(coord) > 0.5) discard; 10 | color = vec3(0.65, 0.1, 0.5); 11 | 12 | /*float window_width = textureSize(tex_mirror, 0).x; 13 | float window_height = textureSize(tex_mirror, 0).y; 14 | float u = gl_FragCoord.x/window_width; 15 | float v = 1 - gl_FragCoord.y/window_height; 16 | color = texture(tex, uv).rgb;*/ 17 | //gl_FragDepth = 0; 18 | gl_FragDepth = gl_FragCoord.z * 0.99; 19 | } 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /tracker/OpenGL/ConvolutionRenderer/data_points_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | uniform mat4 MVP; 3 | in vec3 vpoint; 4 | in vec2 vtexcoord; 5 | out vec2 uv; 6 | 7 | void main() { 8 | gl_Position = MVP * vec4(vpoint, 1.0); 9 | uv = vtexcoord; 10 | } 11 | -------------------------------------------------------------------------------- /tracker/OpenGL/ConvolutionRenderer/lines_fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec3 color; 3 | in vec2 uv; 4 | uniform sampler2D tex; 5 | uniform sampler2D tex_mirror; 6 | 7 | void main() { 8 | color = vec3(0.75, 0.75, 0.75); 9 | 10 | gl_FragDepth = gl_FragCoord.z * 0.99; 11 | } 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /tracker/OpenGL/ConvolutionRenderer/lines_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | uniform mat4 MVP; 3 | in vec3 vpoint; 4 | in vec2 vtexcoord; 5 | out vec2 uv; 6 | 7 | void main() { 8 | gl_Position = MVP * vec4(vpoint, 1.0); 9 | uv = vtexcoord; 10 | } 11 | -------------------------------------------------------------------------------- /tracker/OpenGL/ConvolutionRenderer/model_points_fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec3 color; 3 | in vec2 uv; 4 | uniform sampler2D tex; 5 | uniform sampler2D tex_mirror; 6 | 7 | void main() { 8 | vec2 coord = gl_PointCoord - vec2(0.5); 9 | if(length(coord) > 0.5) discard; 10 | color = vec3(0, 0.7, 1); 11 | 12 | /*float window_width = textureSize(tex_mirror, 0).x; 13 | float window_height = textureSize(tex_mirror, 0).y; 14 | float u = gl_FragCoord.x/window_width; 15 | float v = 1 - gl_FragCoord.y/window_height; 16 | color = texture(tex, uv).rgb;*/ 17 | //gl_FragDepth = 0; 18 | gl_FragDepth = gl_FragCoord.z * 0.99; 19 | } 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /tracker/OpenGL/ConvolutionRenderer/model_points_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | uniform mat4 MVP; 3 | in vec3 vpoint; 4 | in vec2 vtexcoord; 5 | out vec2 uv; 6 | 7 | void main() { 8 | gl_Position = MVP * vec4(vpoint, 1.0); 9 | uv = vtexcoord; 10 | } 11 | -------------------------------------------------------------------------------- /tracker/OpenGL/ConvolutionRenderer/model_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | in vec3 position; 3 | in vec2 vtexcoord; 4 | out vec2 uv; 5 | 6 | void main() { 7 | gl_Position = vec4(position, 1.0); 8 | uv = vtexcoord; 9 | } 10 | -------------------------------------------------------------------------------- /tracker/OpenGL/ConvolutionRenderer/outside_points_fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | out vec3 color; 3 | in vec2 uv; 4 | uniform sampler2D tex; 5 | uniform sampler2D tex_mirror; 6 | 7 | void main() { 8 | vec2 coord = gl_PointCoord - vec2(0.5); 9 | if(length(coord) > 0.5) discard; 10 | color = vec3(1, 1, 0); 11 | gl_FragDepth = gl_FragCoord.z * 0.99; 12 | } 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tracker/OpenGL/ConvolutionRenderer/outside_points_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | uniform mat4 MVP; 3 | in vec3 vpoint; 4 | in vec2 vtexcoord; 5 | out vec2 uv; 6 | 7 | void main() { 8 | gl_Position = MVP * vec4(vpoint, 1.0); 9 | uv = vtexcoord; 10 | } 11 | -------------------------------------------------------------------------------- /tracker/OpenGL/ConvolutionRenderer/skin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/OpenGL/ConvolutionRenderer/skin.png -------------------------------------------------------------------------------- /tracker/OpenGL/ConvolutionRenderer/skin.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenGP/hmodel/a610f8c9f09505a88730ea5151e1521d71639035/tracker/OpenGL/ConvolutionRenderer/skin.tga -------------------------------------------------------------------------------- /tracker/OpenGL/CustomFrameBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "util/gl_wrapper.h" 3 | #include "opencv2/core/core.hpp" 4 | 5 | 6 | class CustomFrameBuffer { 7 | private: 8 | int image_width; 9 | int image_height; 10 | GLuint framebuffer; // to bind the proper targets 11 | GLuint color_tex; // where we render the face indices 12 | GLuint normals_tex; 13 | bool needs_cleanup; 14 | 15 | GLuint create_framebuffer(bool render_block_id); 16 | 17 | public: 18 | 19 | CustomFrameBuffer(); 20 | 21 | CustomFrameBuffer(int image_width, int image_height, bool render_block_id); 22 | 23 | ~CustomFrameBuffer(); 24 | 25 | bool ready(); 26 | 27 | void bind(bool render_block_id); 28 | 29 | void unbind(); 30 | 31 | void init(int image_width, int image_height, bool render_block_id); 32 | 33 | void cleanup(); 34 | 35 | GLuint create_color_attachment(int image_width, int image_height); 36 | 37 | GLuint create_depth_attachment(int image_width, int image_height); 38 | 39 | GLuint create_normals_attachment(int image_width, int image_height); 40 | 41 | void fetch_color_attachment(cv::Mat& image); 42 | 43 | void fetch_depth_attachment(cv::Mat& image); 44 | 45 | void fetch_normals_attachment(cv::Mat& image); 46 | 47 | void display_color_attachment(); 48 | 49 | void display_depth_attachment(); 50 | 51 | void display_normals_attachment(); 52 | 53 | }; 54 | -------------------------------------------------------------------------------- /tracker/OpenGL/CylindersRenderer/Cylinders_FB_fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform float instance_id; ///< technically a int, but not allowed in this GLSL version 3 | in vec3 vpoint_camera; ///< interpolated 3D location in camera space 4 | // in vec3 fnormal; 5 | 6 | layout(location=0) out uint out_color; 7 | layout(location=1) out vec4 out_extra; 8 | layout(location=2) out vec4 out_norms; 9 | 10 | void main(){ 11 | out_color = uint(instance_id); ///< draw the instance_id 12 | 13 | ///--- [3D point, NaN ] @todo results in CUDA crash :( 14 | // out_extra = vec4(vpoint_camera, 0.0/0.0); 15 | 16 | ///--- [3D point, isSilhouette ] @todo check if it's advantageous to do here? 17 | // out_extra = vec4(vpoint_camera, (instance_id<255)); 18 | 19 | ///--- [3D point, squared distance from camera (origin) ] 20 | // out_extra = vec4(vpoint_camera, dot(vpoint_camera,vpoint_camera)); 21 | 22 | //---------------------------------------------------------------- 23 | //--- Screen space normals 24 | vec3 vx = normalize( dFdx(vpoint_camera) ); 25 | vec3 vy = normalize( dFdy(vpoint_camera) ); 26 | vec3 normal = -cross(vx, vy); 27 | out_norms = vec4( normal, 0 ); 28 | //--- Normals from model (needs to be computed) 29 | // out_norms = vec4(fnormal,0); 30 | //---------------------------------------------------------------- 31 | 32 | ///--- [3D point, normal front facing angle ] 33 | out_extra = vec4(vpoint_camera, dot(normal,vec3(0,0,-1))); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /tracker/OpenGL/CylindersRenderer/Cylinders_FB_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | // uniform mat4 view; ///< identity!!! 4 | uniform mat4 view_projection; 5 | uniform mat4 joint_transform; 6 | 7 | in vec3 vpoint; 8 | out vec3 vpoint_camera; 9 | 10 | in vec3 vnormal; 11 | // out vec3 fnormal; 12 | 13 | void main() { 14 | gl_Position = view_projection * joint_transform * vec4(vpoint, 1.0); 15 | vpoint_camera = vec3( joint_transform * vec4(vpoint, 1.0) ); 16 | 17 | ///--- NOTE: vnormals were not re-computed, let's do it in screen space. 18 | // fnormal = normalize( /*mat3(view)*/ mat3(joint_transform)*vec3(vnormal)); 19 | } 20 | -------------------------------------------------------------------------------- /tracker/OpenGL/CylindersRenderer/Cylinders_fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | in vec3 fnormal; 3 | out vec4 out_color; 4 | const vec3 vdir = vec3(0,0,1); 5 | 6 | uniform vec3 color; 7 | 8 | void main(){ 9 | float shaded = abs(dot(fnormal, vdir)); 10 | out_color = vec4(shaded*color,1); ///< Colored shaded 11 | // out_color = vec4(shaded,0,0,1); /// RED shaded 12 | // out_color = vec4(1,0,0,1); ///solid 13 | // out_color = vec4(color, 1); 14 | } 15 | -------------------------------------------------------------------------------- /tracker/OpenGL/CylindersRenderer/Cylinders_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | uniform mat4 view; ///< not identity because of freeform viewer 4 | uniform mat4 view_projection; 5 | uniform mat4 joint_transform; 6 | 7 | in vec3 vpoint; 8 | in vec3 vnormal; 9 | out vec3 fnormal; 10 | 11 | void main() { 12 | gl_Position = view_projection * joint_transform * vec4(vpoint, 1.0); 13 | ///< this is only possible because model_view is uniform scale!! 14 | fnormal = normalize( mat3(view)*mat3(joint_transform)*vec3(vnormal)); 15 | } 16 | -------------------------------------------------------------------------------- /tracker/OpenGL/DebugRenderer/ArcRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "ArcRenderer.h" 2 | #define M_PI 3.14159265358979323846 3 | 4 | ArcRenderer::ArcRenderer(const std::vector>& endpoints, std::vector centers, std::vector radii, Vector3 color) { 5 | this->init(); ///< compile shaders 6 | 7 | int num_samples = 10; 8 | Vector3 u = Vector3(1, 0, 0); 9 | Vector3 v = Vector3(0, 1, 0); 10 | Matrix_3xN _segments(3, 2 * endpoints.size() * num_samples); 11 | int count = 0; 12 | float phi; 13 | for (size_t i = 0; i < endpoints.size(); i++) { 14 | Vector3 v1 = endpoints[i].first - centers[i]; 15 | Vector3 v2 = endpoints[i].second - centers[i]; 16 | float alpha = atan2(v1[0], v1[1]); 17 | float beta = atan2(v2[0], v2[1]); 18 | if (beta > alpha) alpha = alpha + 2 * M_PI; 19 | for (size_t j = 0; j < num_samples; j++) { 20 | phi = alpha + j * (beta - alpha) / (num_samples - 1); 21 | //phi = j * 2 * M_PI / num_samples; 22 | _segments.col(count++) = centers[i] + radii[i] * (u * sin(phi) + v * cos(phi)); 23 | phi = alpha + (j + 1) * (beta - alpha) / (num_samples - 1); 24 | //phi = (j + 1) * 2 * M_PI / num_samples; 25 | _segments.col(count++) = centers[i] + radii[i] * (u * sin(phi) + v * cos(phi)); 26 | } 27 | } 28 | 29 | Matrix_3xN _colors(3, 2 * endpoints.size() * num_samples); 30 | for (int i = 0; i < 3; i++) 31 | _colors.row(i).array().setConstant(color(i)); 32 | setup(&_segments, &_colors); 33 | } 34 | 35 | void ArcRenderer::render() { 36 | if (num_primitives == 0) return; 37 | vao.bind(); 38 | program.bind(); 39 | glEnable(GL_LINE_SMOOTH); 40 | glDrawArrays(GL_LINES, 0, num_primitives); 41 | glDisable(GL_LINE_SMOOTH); 42 | program.release(); 43 | vao.release(); 44 | } 45 | -------------------------------------------------------------------------------- /tracker/OpenGL/DebugRenderer/ArcRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/Types.h" 3 | #include "tracker/OpenGL/GeometricPrimitiveRenderer.h" 4 | 5 | class ArcRenderer : public GeometricPrimitiveRenderer { 6 | 7 | public: 8 | ArcRenderer(const std::vector>& endpoints, std::vector centers, std::vector radii, Vector3 color); 9 | 10 | void render(); 11 | }; 12 | -------------------------------------------------------------------------------- /tracker/OpenGL/DebugRenderer/CloudRenderer_fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | in vec3 fcolor; 3 | out vec4 color; 4 | const vec3 camera_dir = vec3(0,0,-1); 5 | void main(){ 6 | color = vec4(fcolor,1); 7 | } 8 | -------------------------------------------------------------------------------- /tracker/OpenGL/DebugRenderer/CloudRenderer_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform mat4 view; 3 | uniform mat4 view_projection; 4 | in vec3 vpoint; 5 | in vec3 vcolor; 6 | out vec3 fcolor; 7 | 8 | void main() { 9 | gl_Position = view_projection * vec4(vpoint, 1.0); 10 | gl_PointSize = 3; 11 | fcolor = vcolor; 12 | } 13 | -------------------------------------------------------------------------------- /tracker/OpenGL/DebugRenderer/DebugRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "DebugRenderer.h" 2 | 3 | void DebugRenderer::add_points(const std::vector &points, Vector3 color){ 4 | add( new PointRenderer(points, color) ); 5 | } 6 | 7 | void DebugRenderer::add_points(const std::vector &points, const std::vector &colors) { 8 | add(new PointRenderer(points, colors)); 9 | } 10 | 11 | void DebugRenderer::add_segments(const std::vector > &segments, const std::vector &colors) { 12 | add(new SegmentRenderer(segments, colors)); 13 | } 14 | 15 | void DebugRenderer::add_segments(const std::vector > &segments, Vector3 color) { 16 | add(new SegmentRenderer(segments, color)); 17 | } 18 | 19 | void DebugRenderer::add_arcs(const std::vector > &endpoints, std::vector centers, std::vector radii, Vector3 color) { 20 | add(new ArcRenderer(endpoints, centers, radii, color)); 21 | } 22 | -------------------------------------------------------------------------------- /tracker/OpenGL/DebugRenderer/DebugRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "util/singleton.h" 5 | #include "tracker/Types.h" 6 | #include "tracker/OpenGL/ObjectRenderer.h" 7 | #include "PointRenderer.h" 8 | #include "SegmentRenderer.h" 9 | #include "ArcRenderer.h" 10 | 11 | class DebugRenderer : public QObject{ 12 | SINGLETON(DebugRenderer) 13 | 14 | public: 15 | void add_points(const std::vector& points, Vector3 color); 16 | void add_points(const std::vector& points, const std::vector& colors); 17 | void add_segments(const std::vector>& segments, Vector3 color); 18 | void add_segments(const std::vector>& segments, const std::vector& colors); 19 | void add_arcs(const std::vector > &endpoints, std::vector centers, std::vector radii, Vector3 color); 20 | 21 | private: 22 | int next_free_id=0; 23 | std::multimap> debug_objects; 24 | public: 25 | void clear(){ debug_objects.clear(); } 26 | private: 27 | template 28 | Derived* add(Derived* object) { 29 | std::shared_ptr sptr(object); 30 | debug_objects.insert( std::make_pair(next_free_id++,sptr) ); 31 | return static_cast(sptr.get()); 32 | } 33 | public: 34 | void init(){} 35 | void render(){ 36 | for(auto& entry: debug_objects){ 37 | entry.second->render(); 38 | } 39 | } 40 | void set_uniform(const char* name, const Eigen::Matrix4f& value){ 41 | for(auto& entry: debug_objects){ 42 | entry.second->set_uniform(name, value); 43 | } 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /tracker/OpenGL/DebugRenderer/PointRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "PointRenderer.h" 2 | 3 | PointRenderer::PointRenderer(Matrix_3xN& points) { 4 | this->init(); ///< compile shaders 5 | setup(&points, NULL); 6 | } 7 | 8 | PointRenderer::PointRenderer(const std::vector& points, const std::vector& colors) { 9 | this->init(); 10 | Matrix_3xN _points(3, points.size()); 11 | for (int i = 0; i < points.size(); i++) 12 | _points.col(i) = points[i]; 13 | Matrix_3xN _colors(3, colors.size()); 14 | for (int i = 0; i < colors.size(); i++) 15 | _colors.col(i) = colors[i]; 16 | setup(&_points, &_colors); 17 | } 18 | 19 | PointRenderer::PointRenderer(const std::vector& points, Vector3 color) { 20 | this->init(); ///< compile shaders 21 | Matrix_3xN data(3, points.size()); 22 | for (int i = 0; i < points.size(); i++) 23 | data.col(i) = points[i]; 24 | Matrix_3xN colors(3, points.size()); 25 | for (int i = 0; i < 3; i++) 26 | colors.row(i).array().setConstant(color(i)); 27 | setup(&data, &colors); 28 | } 29 | 30 | void PointRenderer::render() { 31 | if (num_primitives == 0) return; 32 | vao.bind(); 33 | program.bind(); 34 | glEnable(GL_PROGRAM_POINT_SIZE); 35 | glDrawArrays(GL_POINTS, 0, num_primitives); 36 | glDisable(GL_PROGRAM_POINT_SIZE); 37 | program.release(); 38 | vao.release(); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /tracker/OpenGL/DebugRenderer/PointRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/Types.h" 3 | #include "tracker/OpenGL/GeometricPrimitiveRenderer.h" 4 | 5 | class PointRenderer : public GeometricPrimitiveRenderer { 6 | 7 | public: 8 | PointRenderer(Matrix_3xN& points); 9 | PointRenderer(const std::vector& points, const std::vector& colors); 10 | PointRenderer(const std::vector& points, Vector3 color); 11 | void render(); 12 | }; 13 | -------------------------------------------------------------------------------- /tracker/OpenGL/DebugRenderer/SegmentRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "SegmentRenderer.h" 2 | 3 | SegmentRenderer::SegmentRenderer(const std::vector>& segments, const std::vector& colors) { 4 | this->init(); 5 | Matrix_3xN _segments(3, segments.size() * 2); 6 | for (int i = 0; i < segments.size(); i++) { 7 | _segments.col(i * 2) = segments[i].first; 8 | _segments.col(i * 2 + 1) = segments[i].second; 9 | } 10 | Matrix_3xN _colors(3, colors.size() * 2); 11 | for (int i = 0; i < colors.size(); i++) { 12 | _colors.col(i * 2) = colors[i]; 13 | _colors.col(i * 2 + 1) = colors[i]; 14 | } 15 | setup(&_segments, &_colors); 16 | } 17 | 18 | SegmentRenderer::SegmentRenderer(const std::vector>& segments, Vector3 color) { 19 | this->init(); ///< compile shaders 20 | Matrix_3xN _segments(3, segments.size() * 2); 21 | for (int i = 0; i < segments.size(); i++) { 22 | _segments.col(i * 2) = segments[i].first; 23 | _segments.col(i * 2 + 1) = segments[i].second; 24 | } 25 | Matrix_3xN _colors(3, segments.size() * 2); 26 | for (int i = 0; i < 3; i++) 27 | _colors.row(i).array().setConstant(color(i)); 28 | setup(&_segments, &_colors); 29 | } 30 | 31 | void SegmentRenderer::render() { 32 | if (num_primitives == 0) return; 33 | vao.bind(); 34 | program.bind(); 35 | glEnable(GL_LINE_SMOOTH); 36 | glDrawArrays(GL_LINES, 0, num_primitives); 37 | glDisable(GL_LINE_SMOOTH); 38 | program.release(); 39 | vao.release(); 40 | } 41 | -------------------------------------------------------------------------------- /tracker/OpenGL/DebugRenderer/SegmentRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/Types.h" 3 | #include "tracker/OpenGL/GeometricPrimitiveRenderer.h" 4 | 5 | class SegmentRenderer : public GeometricPrimitiveRenderer { 6 | 7 | public: 8 | SegmentRenderer(const std::vector>& segments, const std::vector& colors); 9 | 10 | SegmentRenderer(const std::vector>& segments, Vector3 color); 11 | 12 | void render(); 13 | }; 14 | -------------------------------------------------------------------------------- /tracker/OpenGL/GeometricPrimitiveRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "tracker/OpenGL/GeometricPrimitiveRenderer.h" 2 | #include "util/mylogger.h" 3 | 4 | void GeometricPrimitiveRenderer::setup(Matrix_3xN* primitives, Matrix_3xN* colors) { 5 | CHECK_NOTNULL(primitives); 6 | if (colors) CHECK(primitives->cols() == colors->cols()); 7 | this->num_primitives = primitives->cols(); 8 | 9 | vao.bind(); 10 | program.bind(); 11 | 12 | ///--- Create vertex buffer/attributes "position" 13 | { 14 | bool success = vertexbuffer.create(); 15 | assert(success); 16 | vertexbuffer.setUsagePattern(QGLBuffer::StaticDraw); 17 | success = vertexbuffer.bind(); 18 | assert(success); 19 | vertexbuffer.allocate(primitives->data(), sizeof(Scalar) * primitives->size()); 20 | program.setAttributeBuffer("vpoint", GL_FLOAT, 0, 3); 21 | program.enableAttributeArray("vpoint"); 22 | } 23 | 24 | ///--- Create vertex buffer/attributes "colors" 25 | if (!colors) { 26 | static Matrix_3xN _colors(primitives->rows(), primitives->cols()); 27 | _colors.row(0).array().setConstant(1); ///< force red 28 | colors = &_colors; 29 | } 30 | { 31 | bool success = vcolor_buf.create(); 32 | assert(success); 33 | vcolor_buf.setUsagePattern(QGLBuffer::StaticDraw); 34 | success = vcolor_buf.bind(); 35 | assert(success); 36 | vcolor_buf.allocate(colors->data(), sizeof(Scalar) * primitives->size()); 37 | program.setAttributeBuffer("vcolor", GL_FLOAT, 0, 3); 38 | program.enableAttributeArray("vcolor"); 39 | } 40 | 41 | ///--- Create vertex buffer/attributes "sizes" 42 | { 43 | static VectorN _sizes(primitives->cols()); 44 | VectorN* sizes = &_sizes; 45 | bool success = vsize_buf.create(); assert(success); 46 | vsize_buf.setUsagePattern(QGLBuffer::StaticDraw); 47 | success = vsize_buf.bind(); assert(success); 48 | vsize_buf.allocate(colors->data(), sizeof(Scalar) * sizes->size()); 49 | program.setAttributeBuffer("vsize", GL_FLOAT, 0, 1); 50 | program.enableAttributeArray("vsize"); 51 | } 52 | 53 | program.release(); 54 | vao.release(); 55 | } 56 | 57 | void GeometricPrimitiveRenderer::init() { 58 | ///--- Load/compile shaders 59 | if (!program.isLinked()) { 60 | const char* vshader = "C://Developer//hmodel-build-vs//CloudRenderer_vshader.glsl"; 61 | const char* fshader = "C://Developer//hmodel-build-vs//CloudRenderer_fshader.glsl"; 62 | bool vok = program.addShaderFromSourceFile(QGLShader::Vertex, vshader); 63 | bool fok = program.addShaderFromSourceFile(QGLShader::Fragment, fshader); 64 | bool lok = program.link(); 65 | assert(lok && vok && fok); 66 | bool success = program.bind(); 67 | assert(success); 68 | } 69 | 70 | ///--- Create vertex array object 71 | if (!vao.isCreated()) { 72 | bool success = vao.create(); 73 | assert(success); 74 | } 75 | 76 | ///--- Avoid pollution 77 | program.release(); 78 | vao.release(); 79 | } -------------------------------------------------------------------------------- /tracker/OpenGL/GeometricPrimitiveRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/Types.h" 3 | #include "tracker/OpenGL/ObjectRenderer.h" 4 | 5 | class GeometricPrimitiveRenderer :public ObjectRenderer { 6 | protected: 7 | int num_primitives = 0; 8 | QGLBuffer vertexbuffer = QGLBuffer(QGLBuffer::VertexBuffer); 9 | QGLBuffer vsize_buf = QGLBuffer(QGLBuffer::VertexBuffer); 10 | QGLBuffer vcolor_buf = QGLBuffer(QGLBuffer::VertexBuffer); 11 | 12 | void setup(Matrix_3xN* primitives, Matrix_3xN* colors); 13 | void init(); 14 | }; -------------------------------------------------------------------------------- /tracker/OpenGL/KinectDataRenderer/KinectDataRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/ForwardDeclarations.h" 3 | #include "tracker/Types.h" 4 | #include "tracker/OpenGL/ObjectRenderer.h" 5 | 6 | class KinectDataRenderer : public ObjectRenderer{ 7 | QGLBuffer vertexbuffer = QGLBuffer(QGLBuffer::VertexBuffer); 8 | QGLBuffer uvbuffer = QGLBuffer(QGLBuffer::VertexBuffer); 9 | QGLBuffer indexbuffer = QGLBuffer(QGLBuffer::IndexBuffer); 10 | int num_indexes = 0; 11 | int num_vertices = 0; 12 | GLuint texture_id_color = 0; 13 | GLuint texture_id_depth = 0; 14 | GLuint texture_id_cmap = 0; 15 | Camera* camera = NULL; 16 | float alpha = 1.0; 17 | 18 | public: 19 | void init(Camera* camera); 20 | void setup(GLuint texture_id_color, GLuint texture_id_depth); 21 | void render(); 22 | 23 | void set_alpha(float alpha); 24 | void set_zNear(float alpha); 25 | void set_zFar(float alpha); 26 | void enable_colormap(bool enable); 27 | void set_discard_cosalpha_th(float val); 28 | }; 29 | -------------------------------------------------------------------------------- /tracker/OpenGL/KinectDataRenderer/KinectDataRenderer_fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 core 2 | ///--- Stuff to colormap the depth mesh 3 | uniform sampler1D colormap; 4 | uniform float zNear; 5 | uniform float zFar; 6 | uniform usampler2D tex_depth; 7 | uniform float enable_colormap; 8 | 9 | ///--- Stuff to discard not front-facing 10 | in vec3 f_position; 11 | uniform float discard_cosalpha_th; ///< .4? 12 | uniform sampler2D tex_color; ///< sensor color texture 13 | 14 | in vec2 frag_uv; ///< UVs to access tex_color 15 | uniform float alpha; ///< alpha blending value 16 | in float depth; ///< interpolated depth value 17 | in float discardme; ///< used to discard grazing angle triangles 18 | out vec4 color; 19 | 20 | void main() { 21 | 22 | if(discardme>0) discard; 23 | 24 | //--- Discard out of z-range 25 | if(depthzFar) discard; 26 | 27 | vec3 vx = dFdx(f_position); 28 | vec3 vy = dFdy(f_position); 29 | vec3 vray = normalize( f_position ); 30 | vec3 n = normalize( cross(vx,vy) ); 31 | float cosalpha = abs( dot(n, vray) ); 32 | if( cosalpha0) 35 | { 36 | ///--- Apply a colormap 37 | float range = zFar-zNear; 38 | float w = (depth-zNear)/range; 39 | color = vec4( texture(colormap, w).rgb, alpha); 40 | } 41 | else 42 | { 43 | ///--- Apply the color texture 44 | color = vec4( texture(tex_color, frag_uv).rgb, alpha); 45 | } 46 | 47 | vec2 pc = gl_PointCoord - vec2(0.5); 48 | float distance_to_center = 0.5 - length(pc); 49 | if (distance_to_center < 0.0) discard; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /tracker/OpenGL/KinectDataRenderer/KinectDataRenderer_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | /// texture with depth from sensor 3 | uniform usampler2D tex_depth; 4 | uniform float zNear; 5 | uniform float zFar; 6 | ///--- 7 | uniform mat4 view_projection; ///< for visualization 8 | uniform mat3 inv_proj_matrix; ///< depth-to-3D conversion 9 | in vec2 vpoint; 10 | in vec2 uv; 11 | 12 | 13 | out float depth; 14 | out vec2 frag_uv; 15 | out float discardme; 16 | out vec3 f_position; 17 | 18 | void main() { 19 | ///--- Tex coords for color fetch 20 | frag_uv = uv; 21 | 22 | ///--- Depth evaluation 23 | depth = float( texture(tex_depth, uv).x ); 24 | discardme = float(depthzFar); 25 | vec3 p = inv_proj_matrix * vec3(vpoint[0]*depth, vpoint[1]*depth, depth); 26 | gl_Position = view_projection * vec4(p[0],-p[1],p[2], 1.0); 27 | f_position = p; 28 | 29 | ///--- Splat size 30 | gl_PointSize = 2.9; ///< Screen 31 | //gl_PointSize = 4; ///< RETINA 32 | } 33 | 34 | -------------------------------------------------------------------------------- /tracker/OpenGL/ObjectRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "tracker/OpenGL/ObjectRenderer.h" 2 | 3 | // had to separate declaration from implementation due to compilation errors on linux 4 | void ObjectRenderer::set_uniform(const char* name, const Eigen::Matrix4f& value){ 5 | assert(program.isLinked()); 6 | program.bind(); 7 | GLuint id = glGetUniformLocation(program.programId(),name); 8 | if(id==-1) 9 | printf("!!!WARNING: shader '%d' does not contain uniform variable '%s'\n", program.programId(), name); 10 | glUniformMatrix4fv(id, 1, GL_FALSE, value.data()); 11 | program.release(); 12 | } 13 | 14 | void ObjectRenderer::set_uniform(const char* name, const Eigen::Matrix3f& value) 15 | { 16 | assert(program.isLinked()); 17 | program.bind(); 18 | GLuint id = glGetUniformLocation(program.programId(),name); 19 | if(id==-1) 20 | printf("!!!WARNING: shader '%d' does not contain uniform variable '%s'\n", program.programId(), name); 21 | glUniformMatrix3fv(id, 1, GL_FALSE, value.data()); 22 | program.release(); 23 | } 24 | 25 | void ObjectRenderer::set_uniform(const char* name, float value) 26 | { 27 | assert(program.isLinked()); 28 | program.bind(); 29 | GLuint id = glGetUniformLocation(program.programId(),name); 30 | if(id==-1) 31 | printf("!!!WARNING: shader '%d' does not contain uniform variable '%s'\n", program.programId(), name); 32 | glUniform1f(id, value); 33 | program.release(); 34 | } 35 | 36 | void ObjectRenderer::set_texture(const char* name, int value) 37 | { 38 | assert(program.isLinked()); 39 | program.bind(); 40 | glUniform1i(glGetUniformLocation(program.programId(), name), value /*GL_TEXTURE_{VALUE}*/); 41 | program.release(); 42 | } 43 | 44 | void ObjectRenderer::set_uniform_uint(const char* name, unsigned int value) 45 | { 46 | assert(program.isLinked()); 47 | program.bind(); 48 | GLuint id = glGetUniformLocation(program.programId(), name); 49 | glUniform1ui(id, value); 50 | program.release(); 51 | } 52 | -------------------------------------------------------------------------------- /tracker/OpenGL/ObjectRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "util/gl_wrapper.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | /// Superclass for any renderer 10 | class ObjectRenderer{ 11 | protected: 12 | QGLShaderProgram program; 13 | QOpenGLVertexArrayObject vao; 14 | 15 | public: 16 | GLuint program_id(){ return program.programId(); } 17 | void set_uniform(const char* name, const Eigen::Matrix4f& value); 18 | void set_uniform(const char* name, const Eigen::Matrix3f& value); 19 | void set_uniform(const char* name, float value); 20 | void set_texture(const char* name, int value /*GL_TEXTURE_?*/); 21 | void set_uniform_uint(const char* name, unsigned int value); 22 | 23 | public: 24 | virtual ~ObjectRenderer(){} ///< safe polymorphic destruct 25 | virtual void init(){} 26 | virtual void render()=0; 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /tracker/OpenGL/OffscreenRenderer.cpp: -------------------------------------------------------------------------------- 1 | #include "OffscreenRenderer.h" 2 | 3 | #include "util/tictoc.h" 4 | #include "util/gl_wrapper.h" 5 | #include "util/mylogger.h" 6 | #include "tracker/Data/Camera.h" 7 | #include "tracker/OpenGL/ConvolutionRenderer/ConvolutionRenderer.h" 8 | #include "tracker/OpenGL/CustomFrameBuffer.h" 9 | 10 | void OffscreenRenderer::init(Camera* camera, Model * model, std::string data_path, bool render_block_id) { 11 | this->camera = camera; 12 | this->model = model; 13 | 14 | if (render_block_id) { 15 | frame_buffer = new CustomFrameBuffer(camera->width(), camera->height(), render_block_id); 16 | convolution_renderer = new ConvolutionRenderer(model, ConvolutionRenderer::FRAMEBUFFER, camera->view_projection_matrix(), data_path); 17 | } 18 | else { // render_depth 19 | frame_buffer = new CustomFrameBuffer(camera->width(), camera->height(), render_block_id); 20 | convolution_renderer = new ConvolutionRenderer(model, ConvolutionRenderer::RASTORIZER, camera->view_projection_matrix(), data_path); 21 | } 22 | } 23 | 24 | OffscreenRenderer::~OffscreenRenderer() { 25 | delete frame_buffer; 26 | delete convolution_renderer; 27 | } 28 | 29 | void OffscreenRenderer::render_offscreen(bool last_iter, bool fingers_only, bool reinit) { 30 | 31 | glViewport(0, 0, camera->width(), camera->height()); 32 | glClearColor(1.0, 1.0, 1.0, 1.0); 33 | glDisable(GL_BLEND); ///< just in case 34 | glEnable(GL_DEPTH_TEST); 35 | 36 | //frame_buffer->display_color_attachment(); 37 | 38 | frame_buffer->bind(true); 39 | glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 40 | convolution_renderer->render_offscreen(fingers_only); 41 | frame_buffer->unbind(); 42 | 43 | if (last_iter) frame_buffer->fetch_color_attachment(model->silhouette_texture); 44 | 45 | glFinish(); 46 | } 47 | 48 | void OffscreenRenderer::rastorize_model(cv::Mat & rastorized_model) { 49 | 50 | glViewport(0, 0, camera->width(), camera->height()); 51 | glClearColor(1.0, 1.0, 1.0, 1.0); 52 | glDisable(GL_BLEND); ///< just in case 53 | glEnable(GL_DEPTH_TEST); 54 | 55 | frame_buffer->bind(false); 56 | glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 57 | convolution_renderer->render_offscreen(false); 58 | frame_buffer->unbind(); 59 | 60 | //frame_buffer->display_depth_attachment(); 61 | frame_buffer->fetch_depth_attachment(rastorized_model); 62 | cv::flip(rastorized_model, rastorized_model, 0); 63 | //frame_buffer->fetch_normals_attachment(rastorized_normals); 64 | //cv::flip(rastorized_normals, rastorized_normals, 0); 65 | 66 | glFinish(); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /tracker/OpenGL/OffscreenRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "tracker/ForwardDeclarations.h" 3 | #include "tracker/Types.h" 4 | 5 | class OffscreenRenderer{ 6 | protected: 7 | Camera* camera = NULL; 8 | Model * model; 9 | public: 10 | CustomFrameBuffer* frame_buffer = NULL; 11 | ConvolutionRenderer * convolution_renderer; 12 | 13 | void init(Camera *camera, Model * model, std::string data_path, bool render_block_id); 14 | void render_offscreen(bool last_iter, bool fingers_only, bool reinit=false); 15 | void rastorize_model(cv::Mat & rastorized_model); 16 | ~OffscreenRenderer(); 17 | }; 18 | 19 | -------------------------------------------------------------------------------- /tracker/OpenGL/QuadRenderer/QuadRenderer_color_fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform sampler2D tex; 3 | in vec2 uv; 4 | out vec4 color; 5 | 6 | void main() { 7 | // if(uv.x<.001 || uv.x>.99 || uv.y<.01 || uv.y>.99 ){ color = vec4(0,0,0,1); return; } 8 | color = vec4( texture(tex, uv).rgb, 1.0 ); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tracker/OpenGL/QuadRenderer/QuadRenderer_depth_fshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform usampler2D tex; 3 | uniform sampler1D colormap; 4 | in vec2 uv; 5 | out vec4 color; 6 | uniform uint znear; 7 | uniform uint zfar; 8 | 9 | uint dmin = znear; // 300U 10 | uint dmax = zfar; //1000U 11 | 12 | void main() { 13 | uint val = texture(tex, uv).x; 14 | float range = dmax-dmin; 15 | float w = (val-dmin)/range; 16 | color = vec4( texture(colormap, w).rgb, 1); 17 | if(valdmax) 18 | color = vec4(0,0,0,1); 19 | } 20 | -------------------------------------------------------------------------------- /tracker/OpenGL/QuadRenderer/QuadRenderer_vshader.glsl: -------------------------------------------------------------------------------- 1 | #version 330 2 | uniform mat4 model_view_projection; 3 | in vec3 vpoint; 4 | out vec2 uv; 5 | 6 | mat4 MVP = mat4(0); 7 | 8 | void main() 9 | { 10 | /// Map [0,1]^2 to [-1,1]^2 and flip matrix 11 | MVP[3][0] = -1; 12 | MVP[3][1] = +1; 13 | MVP[0][0] = +2.0; 14 | MVP[1][1] = -2.0; 15 | MVP[3][3] = 1; 16 | 17 | gl_Position = MVP*vec4(vpoint, 1.0); 18 | uv = vpoint.xy; 19 | } 20 | -------------------------------------------------------------------------------- /tracker/OpenGL/shaders.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | DebugRenderer/CloudRenderer_fshader.glsl 4 | DebugRenderer/CloudRenderer_vshader.glsl 5 | KinectDataRenderer/KinectDataRenderer_fshader.glsl 6 | KinectDataRenderer/KinectDataRenderer_vshader.glsl 7 | CylindersRenderer/Cylinders_FB_fshader.glsl 8 | CylindersRenderer/Cylinders_FB_vshader.glsl 9 | CylindersRenderer/Cylinders_fshader.glsl 10 | CylindersRenderer/Cylinders_vshader.glsl 11 | QuadRenderer/QuadRenderer_color_fshader.glsl 12 | QuadRenderer/QuadRenderer_depth_fshader.glsl 13 | QuadRenderer/QuadRenderer_vshader.glsl 14 | 15 | 16 | -------------------------------------------------------------------------------- /tracker/Sensor/Sensor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | 5 | #include "tracker/HandFinder/HandFinder.h" 6 | 7 | struct DataFrame; 8 | class Camera; 9 | 10 | class Sensor{ 11 | protected: 12 | bool initialized; 13 | bool real_color; 14 | const Camera * camera; 15 | public: 16 | HandFinder * handfinder; 17 | 18 | 19 | public: 20 | Sensor(Camera* camera): initialized(false), camera(camera) {} 21 | Sensor(Camera* camera, bool real_color) : initialized(false), camera(camera) {} 22 | virtual ~Sensor(){} 23 | virtual bool spin_wait_for_data(float timeout_seconds) = 0; 24 | virtual bool fetch_streams(DataFrame& frame) = 0; 25 | virtual bool concurrent_fetch_streams(DataFrame &frame, HandFinder & handfinder, cv::Mat & full_color) = 0; 26 | virtual void start() = 0; 27 | virtual void stop() = 0; 28 | private: 29 | virtual int initialize() = 0; 30 | }; 31 | 32 | class SensorOpenNI : public Sensor{ 33 | public: 34 | SensorOpenNI(Camera* camera); 35 | virtual ~SensorOpenNI(); 36 | bool spin_wait_for_data(float timeout_seconds); 37 | bool fetch_streams(DataFrame& frame); 38 | bool concurrent_fetch_streams(DataFrame &frame, HandFinder & handfinder, cv::Mat & full_color) { return 0; } 39 | void start(){} 40 | void stop(){} 41 | private: 42 | int initialize(); 43 | }; 44 | 45 | class SensorSoftKin : public Sensor{ 46 | public: 47 | SensorSoftKin(Camera* camera); 48 | virtual ~SensorSoftKin(); 49 | bool spin_wait_for_data(float timeout_seconds); 50 | bool fetch_streams(DataFrame& frame); 51 | bool concurrent_fetch_streams(DataFrame &frame, HandFinder & handfinder, cv::Mat & full_color) { return 0; } 52 | void start(); ///< calls initialize 53 | void stop(); 54 | private: 55 | int initialize(); 56 | }; 57 | 58 | class SensorRealSense : public Sensor { 59 | public: 60 | SensorRealSense(Camera* camera); 61 | SensorRealSense(Camera* camera, bool real_color); 62 | virtual ~SensorRealSense(); 63 | bool spin_wait_for_data(float timeout_seconds); 64 | bool fetch_streams(DataFrame& frame); 65 | bool concurrent_fetch_streams(DataFrame &frame, HandFinder & handfinder, cv::Mat & full_color); 66 | bool run(); 67 | void start(); ///< calls initialize 68 | void stop(); 69 | private: 70 | int initialize(); 71 | }; 72 | 73 | -------------------------------------------------------------------------------- /tracker/TwSettings.cpp: -------------------------------------------------------------------------------- 1 | #include "TwSettings.h" 2 | #include "util/gl_wrapper.h" 3 | #include "util/mylogger.h" 4 | #ifdef WITH_ANTTWEAKBAR 5 | #include "AntTweakBar.h" 6 | #endif 7 | 8 | ///@{ Definition of extern settings 9 | TwSettings _settings; 10 | TwSettings* tw_settings = &_settings; 11 | ///@} 12 | 13 | void TwSettings::tw_init(int width, int height){ 14 | #ifdef WITH_ANTTWEAKBAR 15 | // LOG(INFO) << "TwSettings::tw_init"; 16 | TwInit(TW_OPENGL_CORE, NULL); 17 | TwWindowSize(width, height); 18 | this->bar = TwNewBar("Settings"); 19 | #endif 20 | } 21 | 22 | void TwSettings::tw_cleanup(){ 23 | #ifdef WITH_ANTTWEAKBAR 24 | TwTerminate(); 25 | #endif 26 | } 27 | 28 | void TwSettings::tw_resz(int width, int height){ 29 | #ifdef WITH_ANTTWEAKBAR 30 | TwWindowSize(width, height); 31 | #endif 32 | } 33 | 34 | void TwSettings::tw_draw(){ 35 | #ifdef WITH_ANTTWEAKBAR 36 | glDisable(GL_DEPTH_TEST); 37 | TwDraw(); 38 | glEnable(GL_DEPTH_TEST); 39 | #endif 40 | } 41 | 42 | void TwSettings::tw_add(float& var, const char* name, const char* def){ 43 | if(bar==NULL) return; 44 | #ifdef WITH_ANTTWEAKBAR 45 | TwAddVarRW(bar, name, TW_TYPE_FLOAT, &var, def); 46 | #endif 47 | } 48 | 49 | void TwSettings::tw_add(bool& var, const char* name, const char* def){ 50 | if(bar==NULL) return; 51 | #ifdef WITH_ANTTWEAKBAR 52 | TwAddVarRW(bar, name, TW_TYPE_BOOLCPP, &var, def); 53 | #endif 54 | } 55 | 56 | void TwSettings::tw_add(int& var, const char* name, const char* def){ 57 | if(bar==NULL) return; 58 | #ifdef WITH_ANTTWEAKBAR 59 | TwAddVarRW(bar, name, TW_TYPE_INT32, &var, def); 60 | #endif 61 | } 62 | 63 | void TwSettings::tw_add_ro(float& var, const char* name, const char* def){ 64 | if(bar==NULL) return; 65 | #ifdef WITH_ANTTWEAKBAR 66 | TwAddVarRO(bar, name, TW_TYPE_FLOAT, &var, def); 67 | #endif 68 | } 69 | 70 | void TwSettings::tw_add_ro(bool& var, const char* name, const char* def){ 71 | if(bar==NULL) return; 72 | #ifdef WITH_ANTTWEAKBAR 73 | TwAddVarRO(bar, name, TW_TYPE_BOOLCPP, &var, def); 74 | #endif 75 | } 76 | -------------------------------------------------------------------------------- /tracker/TwSettings.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | typedef struct CTwBar TwBar; // structure CTwBar is not exposed. 3 | 4 | class TwSettings{ 5 | public: 6 | TwBar* anttweakbar(){ return bar; } 7 | void tw_init(int width, int height); 8 | void tw_cleanup(); 9 | void tw_resz(int width, int height); 10 | void tw_draw(); 11 | void tw_add_ro(float &var, const char *name, const char *def=""); 12 | void tw_add_ro(bool &var, const char *name, const char *def=""); 13 | void tw_add(float &var, const char *name, const char *def=""); 14 | void tw_add(bool &var, const char *name, const char *def=""); 15 | void tw_add(int &var, const char *name, const char *def=""); 16 | private: 17 | TwBar* bar = 0 /*NULL*/; 18 | }; 19 | 20 | /// --- Externally pre-instantiated settings 21 | extern TwSettings* tw_settings; 22 | 23 | -------------------------------------------------------------------------------- /tracker/Types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | typedef float Scalar; 10 | typedef Scalar Real; 11 | typedef std::string String; 12 | typedef unsigned int uint; 13 | typedef int Integer; 14 | typedef Eigen::Matrix4f Matrix4; 15 | typedef Eigen::Matrix3f Matrix3; 16 | typedef Eigen::Vector2f Vector2; 17 | typedef Eigen::Vector3f Vector3; 18 | typedef Eigen::Vector4f Vector4; 19 | typedef Eigen::VectorXf VectorN; 20 | 21 | const int d = 3; 22 | 23 | /// Parameters vector 24 | const int num_thetas = 29; 25 | const int num_thetas_ignore = 9; 26 | const int num_thetas_translation = 3; 27 | const int num_thetas_rotation = 26; 28 | const int num_thetas_rigid_motion = 6; 29 | const int num_thetas_latent = 2; 30 | const int num_thetas_thumb = 4; 31 | const int num_thetas_fingers = 16; 32 | const int num_thetas_pose = 20; 33 | const int num_fingers = 5; 34 | const int num_joints = 21; 35 | const int num_temporal = 37; 36 | const int num_phalanges = 17; 37 | 38 | const int upper_bound_num_sensor_points = 76800; 39 | const int upper_bound_num_rendered_outline_points = 5000; 40 | 41 | typedef Eigen::Matrix Thetas; 42 | 43 | /// More complex matrixes 44 | typedef Eigen::Matrix Matrix_2x3; 45 | typedef Eigen::Matrix Matrix_1xN; 46 | typedef Eigen::Matrix Matrix_2xN; 47 | typedef Eigen::Matrix Matrix_3xN; 48 | typedef Eigen::Matrix Matrix_Nx2; 49 | typedef Eigen::Matrix Matrix_MxN; 50 | 51 | typedef Eigen::Hyperplane Plane3; 52 | typedef Eigen::ParametrizedLine Ray3; 53 | typedef Eigen::AlignedBox3f BBox3; 54 | typedef Eigen::Vector2i Vector2i; 55 | typedef Eigen::AlignedBox2i BBox2i; 56 | typedef Eigen::Quaternion Quaternion; 57 | 58 | /// Nan for the default type 59 | inline Real nan(){ return std::numeric_limits::quiet_NaN(); } 60 | inline Real inf(){ return std::numeric_limits::max(); } 61 | 62 | /// Linear system lhs*x=rhs 63 | struct LinearSystem { 64 | Matrix_MxN lhs; // J^T*J 65 | VectorN rhs; // J^T*r 66 | LinearSystem() {} 67 | LinearSystem(int n) { 68 | lhs = Matrix_MxN::Zero(n,n); 69 | rhs = VectorN::Zero(n); 70 | } 71 | }; 72 | 73 | -------------------------------------------------------------------------------- /tracker/Worker.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "util/gl_wrapper.h" 3 | #include "tracker/ForwardDeclarations.h" 4 | #include "tracker/Types.h" 5 | #include "OpenGL/OffscreenRenderer.h" 6 | #include "Data/DataFrame.h" 7 | #include "Energy/JointLimits.h" 8 | #include "Energy/Damping.h" 9 | #include "Energy/Collision.h" 10 | #include "Energy/PoseSpace.h" 11 | #include "Energy/Fitting.h" 12 | #include "Energy/Fitting/TrackingMonitor.h" 13 | #include "Energy/Temporal.h" 14 | 15 | #include "opencv2/core/core.hpp" ///< cv::Mat 16 | #include "opencv2/highgui/highgui.hpp" ///< cv::imShow 17 | 18 | /// @note do not construct more than one instance of this class 19 | class Worker { 20 | 21 | public: 22 | struct Settings { 23 | int termination_max_iters = 6; 24 | int termination_max_rigid_iters = 1; 25 | } _settings; 26 | Settings*const settings = &_settings; 27 | 28 | public: 29 | QGLWidget* glarea = NULL; 30 | public: 31 | void bind_glwidget(QGLWidget* glarea) { this->glarea = glarea; } 32 | void updateGL(); 33 | 34 | public: 35 | bool test; 36 | bool benchmark; 37 | bool save_rastorized_model; 38 | int user_name; 39 | std::string data_path; 40 | 41 | Camera* camera = NULL; 42 | Model * model; 43 | DataFrame current_frame = DataFrame(-1); 44 | TrackingError tracking_error; 45 | //std::vector tracking_error_optimization; 46 | 47 | DepthTexture16UC1* sensor_depth_texture = NULL; 48 | ColorTexture8UC3* sensor_color_texture = NULL; 49 | 50 | energy::Fitting E_fitting; 51 | energy::Temporal E_temporal; 52 | energy::Damping E_damping; 53 | energy::JointLimits E_limits; 54 | energy::Collision E_collision; 55 | energy::PoseSpace E_pose; 56 | 57 | HandFinder* handfinder = NULL; 58 | TrivialDetector* trivial_detector = NULL; 59 | OffscreenRenderer offscreen_renderer; 60 | OffscreenRenderer rastorizer; 61 | TrackingMonitor monitor; 62 | 63 | public: 64 | Worker(Camera *camera, bool test, bool benchmark, bool save_rasotrized_model, int user_name, string data_path); 65 | ~Worker(); 66 | void init_graphic_resources(); ///< not in constructor as needs valid OpenGL context 67 | void cleanup_graphic_resources(); 68 | 69 | public: 70 | void track(int iter); 71 | bool track_till_convergence(); 72 | }; 73 | -------------------------------------------------------------------------------- /util/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | #--- Dummy target to see headers 3 | include_directories(.) 4 | file(GLOB_RECURSE UTIL_HEADERS "*.h") 5 | add_custom_target(util_headers SOURCES ${UTIL_HEADERS}) 6 | -------------------------------------------------------------------------------- /util/MathUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "MathUtils.h" 2 | 3 | #include 4 | #include "util/openmp_helpers.h" 5 | using namespace Eigen; 6 | 7 | //===========================================================================// 8 | 9 | Vec3f toEuler(const Mat3f &m, int e1, int e2, int e3) 10 | { 11 | return m.eulerAngles(e1,e2,e3); 12 | } 13 | 14 | //===========================================================================// 15 | 16 | Vec3f toEuler(const Mat4f &m, int e1, int e2, int e3) 17 | { 18 | Mat3f m_ = m.block(0,0,3,3); 19 | return toEuler(m_, e1, e2, e3); 20 | } 21 | 22 | //===========================================================================// 23 | 24 | Mat3f fromEuler(const Vec3f &v, int e1, int e2, int e3) 25 | { 26 | return Mat3f( 27 | AngleAxisf(v[0], Vec3f::Unit(e1)) * 28 | AngleAxisf(v[1], Vec3f::Unit(e2)) * 29 | AngleAxisf(v[2], Vec3f::Unit(e3)) ); 30 | } 31 | 32 | //===========================================================================// 33 | 34 | Mat3f fromEuler(float a, float b, float c, int e1, int e2, int e3) 35 | { 36 | return fromEuler(Vec3f(a, b, c), e1, e2, e3); 37 | } 38 | 39 | //===========================================================================// 40 | 41 | MatXf pinv(const MatXf &sym) 42 | { 43 | return sym.llt().solve(MatXf::Identity(sym.rows(), sym.rows())); 44 | } 45 | 46 | //===========================================================================// 47 | 48 | MatXf transp(const MatXf &m) 49 | { 50 | size_t r = m.rows(); 51 | size_t c = m.cols(); 52 | 53 | MatXf mT(c, r); 54 | 55 | openmp::setNumThreads(openmp::NUM_THREADS); 56 | // #pragma omp parallel for 57 | for(size_t i = 0; i < r; ++i) 58 | for(size_t j = 0; j < c; ++j) 59 | mT(j,i) = m(i,j); 60 | 61 | return mT; 62 | } 63 | 64 | //===========================================================================// 65 | 66 | MatXf addpar(const MatXf &a, const MatXf &b) 67 | { 68 | size_t r = a.rows(); 69 | size_t c = a.cols(); 70 | 71 | assert(b.rows() == r && b.cols() == c); 72 | 73 | MatXf m(r, c); 74 | 75 | openmp::setNumThreads(openmp::NUM_THREADS); 76 | #pragma omp parallel for collapse(2) 77 | for(size_t i = 0; i < r; ++i) 78 | for(size_t j = 0; j < c; ++j) 79 | m(i,j) = a(i,j) + b(i,j); 80 | 81 | return m; 82 | } 83 | 84 | //===========================================================================// 85 | 86 | MatXf maxvol(const MatXf &A) 87 | { 88 | std::vector_; 89 | return maxvol(A,_); 90 | } 91 | 92 | //===========================================================================// 93 | 94 | MatXf maxvol(const MatXf &A, std::vector &indices) 95 | { 96 | // matrix dimensions 97 | int n = A.rows(); 98 | int m = A.cols(); 99 | 100 | if(m >= n) 101 | { 102 | for(int i = 0; i < m; ++i) 103 | indices.push_back(i); 104 | 105 | return A; 106 | } 107 | 108 | // LU decomposition of A with pivoting 109 | // for initialization of submatrix Ap 110 | Eigen::FullPivLU lu(A); 111 | 112 | // initialize permuted A_ and B 113 | MatXf A_ = lu.permutationP() * A; 114 | MatXf Ap = A_.block(0,0,m,m); 115 | MatXf B = A_ * Ap.inverse(); 116 | 117 | // initialize index vector with permutation indices 118 | indices = std::vector( 119 | lu.permutationP().indices().data(), 120 | lu.permutationP().indices().data() + n); 121 | 122 | // iterative matrix re-ordering 123 | for(int i = m; i < n; ++i) 124 | { 125 | // find index j of maximum absolute coefficient in row i 126 | int j = i; 127 | float Bij = B.row(i).cwiseAbs().maxCoeff(&j); 128 | 129 | if(Bij <= 1.0f) 130 | break; 131 | 132 | // swap rows i and j in the current solution 133 | A_.row(i).swap(A_.row(j)); 134 | std::swap(indices[i], indices[j]); 135 | 136 | // update B 137 | const VecXf &ej = VecXf::Unit(n, j); 138 | const VecXf &ei = VecXf::Unit(n, i); 139 | const RowVectorXf &ejT = VecXf::Unit(m, j); 140 | 141 | B = B - (B.col(j) - ej + ei) * (B.row(i) - ejT) / Bij; 142 | } 143 | 144 | return A_.block(0,0,m,m); 145 | } 146 | 147 | //===========================================================================// 148 | 149 | -------------------------------------------------------------------------------- /util/MathUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | // 3d vector types 9 | typedef Eigen::Vector3f Vec3f; 10 | typedef Eigen::Vector3d Vec3d; 11 | 12 | // 4d vector types 13 | typedef Eigen::Vector4f Vec4f; 14 | typedef Eigen::Vector4d Vec4d; 15 | 16 | // dynamic vector types 17 | typedef Eigen::VectorXf VecXf; 18 | typedef Eigen::VectorXd VecXd; 19 | 20 | // 3x3 matrix types 21 | typedef Eigen::Matrix Mat3f; 22 | typedef Eigen::Matrix Mat3d; 23 | 24 | // 4x4 matrix types 25 | typedef Eigen::Matrix Mat4f; 26 | typedef Eigen::Matrix Mat4d; 27 | 28 | // dynamic matrix types 29 | typedef Eigen::Matrix MatXf; 30 | typedef Eigen::Matrix MatXd; 31 | 32 | // affine transformation types 33 | typedef Eigen::Transform Transform3f; 34 | typedef Eigen::Transform Transform3d; 35 | 36 | // aligned stl vector for eigen3 (substitute with c++11 typedef alias when gcc supports it) 37 | template 38 | struct aligned_vector { 39 | typedef std::vector > type; 40 | }; 41 | 42 | // aligned stl map for eigen3 (substitute with c++11 typedef alias when gcc supports it) 43 | template 44 | struct aligned_map { 45 | typedef std::map, 46 | Eigen::aligned_allocator > > type; 47 | }; 48 | 49 | // euler angle conversion functions 50 | Vec3f toEuler(const Mat3f &m, int e1, int e2, int e3); 51 | Vec3f toEuler(const Mat4f &m, int e1, int e2, int e3); 52 | Mat3f fromEuler(const Vec3f &v, int e1, int e2, int e3); 53 | Mat3f fromEuler(float a, float b, float c, int e1, int e2, int e3); 54 | 55 | // matrix functions 56 | MatXf pinv(const MatXf &sym); 57 | MatXf transp(const MatXf &m); 58 | MatXf addpar(const MatXf &a, const MatXf &b); 59 | MatXf maxvol(const MatXf &m); 60 | MatXf maxvol(const MatXf &m, std::vector &indices); 61 | 62 | -------------------------------------------------------------------------------- /util/OpenGL32Format.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | class OpenGL32Format : public QGLFormat { 4 | public: 5 | OpenGL32Format() { 6 | setVersion(3,2); 7 | setProfile(QGLFormat::CoreProfile); 8 | #if 0 9 | /// Enable Anti-Aliasing 10 | setSampleBuffers(true); 11 | setAlpha(true); 12 | #else 13 | setSampleBuffers(false); ///< no anti-aliasing 14 | setAlpha(false); 15 | #endif 16 | setSwapInterval(0); 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /util/Sleeper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | class Sleeper : public QThread{ 4 | public: 5 | static void usleep(unsigned long usecs){QThread::usleep(usecs);} 6 | static void msleep(unsigned long msecs){QThread::msleep(msecs);} 7 | static void sleep(unsigned long secs){QThread::sleep(secs);} 8 | }; 9 | -------------------------------------------------------------------------------- /util/check_error_gl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #ifdef __clang__ 6 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" ///< 'gluErrorString' is deprecated 7 | #endif 8 | 9 | //////////////////////////////////////////////////////////////////////////// 10 | //! Check for OpenGL error 11 | //! @return bool if no GL error has been encountered, otherwise 0 12 | //! @param file __FILE__ macro 13 | //! @param line __LINE__ macro 14 | //! @note The GL error is listed on stderr 15 | //! @note This function should be used via the CHECK_ERROR_GL() macro 16 | //////////////////////////////////////////////////////////////////////////// 17 | inline bool 18 | sdkCheckErrorGL(const char *file, const int line) 19 | { 20 | bool ret_val = true; 21 | 22 | // check for error 23 | GLenum gl_error = glGetError(); 24 | 25 | if (gl_error != GL_NO_ERROR) 26 | { 27 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 28 | char tmpStr[512]; 29 | // NOTE: "%s(%i) : " allows Visual Studio to directly jump to the file at the right line 30 | // when the user double clicks on the error line in the Output pane. Like any compile error. 31 | sprintf_s(tmpStr, 255, "\n%s(%i) : GL Error : %s\n\n", file, line, gluErrorString(gl_error)); 32 | fprintf(stderr, "%s", tmpStr); 33 | #endif 34 | fprintf(stderr, "GL Error in file '%s' in line %d :\n", file, line); 35 | fprintf(stderr, "%s\n", gluErrorString(gl_error)); 36 | ret_val = false; 37 | } 38 | 39 | return ret_val; 40 | } 41 | 42 | #define CHECK_ERROR_GL() \ 43 | if( false == sdkCheckErrorGL( __FILE__, __LINE__)) { \ 44 | exit(EXIT_FAILURE); \ 45 | } 46 | 47 | //#define CHECK_ERROR_GL() \ 48 | // if( false == sdkCheckErrorGL( __FILE__, __LINE__)) { \ 49 | // DEVICE_RESET \ 50 | // exit(EXIT_FAILURE); \ 51 | // } 52 | -------------------------------------------------------------------------------- /util/gl_wrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | /// fix windows.h problems 5 | #define NOMINMAX 6 | /// fix no storage class or type specifier gl.h 7 | #include 8 | #endif 9 | 10 | ///--- GLEW 11 | //#ifdef WITH_GLEW 12 | #include ///< must be before anything else gl'ish 13 | #include 14 | inline void initialize_glew(){ 15 | glewExperimental = true; 16 | if (glewInit() != GLEW_NO_ERROR){ 17 | 18 | fprintf(stderr, "Failed to initialize GLEW\n"); 19 | exit(EXIT_FAILURE); 20 | } 21 | } 22 | 23 | ///--- Linux needs extensions for framebuffers 24 | #if __unix__ 25 | #define GL_GLEXT_PROTOTYPES 1 26 | #include 27 | #include 28 | #endif 29 | 30 | #if _WIN32 31 | #include 32 | #endif 33 | 34 | #ifdef __APPLE__ 35 | #include "OpenGL/glu.h" 36 | #else 37 | #include "GL/glu.h" 38 | #endif 39 | 40 | #include "check_error_gl.h" 41 | -------------------------------------------------------------------------------- /util/mylogger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #ifdef __clang__ 5 | #pragma clang diagnostic ignored "-Wunused-function" 6 | #endif 7 | 8 | #ifdef WITH_LOGGER 9 | #include "easylogging++.h" 10 | #else 11 | #define INFO "[INFO]" 12 | #define FATAL ((void)0) 13 | #include 14 | #include "qDebug_helpers.h" 15 | inline void _foo(){} 16 | #define TIMED_BLOCK(x,y) _foo(); 17 | #define TIMED_SCOPE(x,y) _foo(); 18 | #define TIMED_FUNC(x) _foo(); 19 | #define LOG(x) qDebug() 20 | #define CHECK_BOUNDS(x,y,z) ((void)0) 21 | #define LOG_UNREACHABLE LOG(FATAL) ((void)0) 22 | #define CHECK(val) if(true) std::cout 23 | #define CHECK_NOTNULL(val) if(val==NULL){ std::cout << "!!!CHECK_NOTNULL: " << __FILE__ << " " << __LINE__ << std::endl; exit(0); } 24 | #endif 25 | 26 | static void setup_logger(){ 27 | #ifdef WITH_LOGGER 28 | #endif 29 | } 30 | -------------------------------------------------------------------------------- /util/opencv_wrapper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifdef WITH_OPENCV 3 | 4 | #define NOMINMAX 5 | #include 6 | #include 7 | 8 | #include "opencv2/core/core.hpp" ///< cv::Mat 9 | #include "opencv2/highgui/highgui.hpp" ///< cv::imShow 10 | #include "opencv2/contrib/contrib.hpp" ///< cvtConvert 11 | #include "opencv2/imgproc/types_c.h" ///< CV_BGRA2RGBA 12 | #endif 13 | 14 | namespace cv{ 15 | /// Gives a string representation for the cv::Mat type 16 | /// @example LOG(INFO) << cv::type2str(boundary_image.type()); 17 | inline std::string type2str(int type) { 18 | std::string r; 19 | 20 | uchar depth = type & CV_MAT_DEPTH_MASK; 21 | uchar chans = 1 + (type >> CV_CN_SHIFT); 22 | 23 | switch ( depth ) { 24 | case CV_8U: r = "8U"; break; 25 | case CV_8S: r = "8S"; break; 26 | case CV_16U: r = "16U"; break; 27 | case CV_16S: r = "16S"; break; 28 | case CV_32S: r = "32S"; break; 29 | case CV_32F: r = "32F"; break; 30 | case CV_64F: r = "64F"; break; 31 | default: r = "User"; break; 32 | } 33 | 34 | r += "C"; 35 | r += (chans+'0'); 36 | 37 | return r; 38 | } 39 | } ///< cv:: 40 | -------------------------------------------------------------------------------- /util/openmp_helpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifdef OPENMP 3 | #include "omp.h" 4 | #endif 5 | 6 | namespace openmp{ 7 | 8 | const int NUM_THREADS = 8; 9 | // set scheduler cpu affinity, number of omp threads, init parallel eigen3 10 | inline void setNumThreads(int n, bool out = false){ 11 | #ifdef OPENMP 12 | #if __unix__ 13 | cpu_set_t my_set; 14 | CPU_ZERO(&my_set); 15 | for(int i = 0; i < n; ++i) 16 | CPU_SET(i, &my_set); 17 | sched_setaffinity(0, sizeof(cpu_set_t), &my_set); 18 | #endif 19 | 20 | omp_set_num_threads(n); 21 | Eigen::initParallel(); 22 | 23 | if(out) 24 | { 25 | std::cout << " Number of processors available: " << omp_get_num_procs() 26 | << " MAX number of OpenMP threads: " << omp_get_max_threads() << std::endl; 27 | } 28 | #endif 29 | } 30 | 31 | } // openmp:: 32 | -------------------------------------------------------------------------------- /util/qDebug_helpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | //#include "tracker/Types.h" 6 | 7 | namespace Eigen{ 8 | inline QDebug operator<< (QDebug d, const Eigen::AlignedBox2i & box) { return d << "[" << box.min().x() << box.min().y() << box.min().z() << "]" << "[" << box.max().x() << box.max().y() << box.max().y() << "]"; } 9 | inline QDebug operator<< (QDebug d, const Eigen::AlignedBox3f & box) { return d << "[" << box.min().x() << box.min().y() << "]" << "[" << box.max().x() << box.max().y() << "]"; } 10 | 11 | // @note these two give problems, replaced with generic matrix 12 | // inline QDebug operator<< (QDebug d, const Vector2i vec) { return d << "["<< vec.x() << vec.y() << "]"; } 13 | // inline QDebug operator<< (QDebug d, const Vector3 vec) { return d << "["<< vec.x() << vec.y() << vec.z() << "]"; } 14 | 15 | template 16 | inline QDebug operator<< (QDebug d, const MatrixBase& m){ 17 | for(int i=0; i 2 | #include 3 | #include 4 | #include 5 | 6 | /// Computes the full file path of a file with a relative location given w.r.t. the EXE file 7 | inline std::string local_file_path(const std::string& local_path, bool exit_if_notfound=true){ 8 | QString exe_path = QCoreApplication::applicationDirPath(); 9 | QString qpath = QDir(exe_path).filePath(local_path.c_str()); 10 | bool exists = QDir(qpath).exists() || QFile(qpath).exists(); 11 | if(!exists){ 12 | if(exit_if_notfound){ 13 | //LOG(INFO) << "!!!FATAL: failed to find resource: " << qpath; 14 | exit(EXIT_FAILURE); 15 | } else { 16 | return ""; 17 | } 18 | } 19 | return qpath.toStdString(); 20 | } 21 | -------------------------------------------------------------------------------- /util/qt2eigen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | namespace Convert{ 3 | inline Vector2i tr(QPoint p1){ return Vector2i(p1.x(), p1.y()); } 4 | inline QPoint tr(Vector2i p1){ return QPoint(p1.x(), p1.y()); } 5 | inline BBox2i tr(QRect rect){ return BBox2i(tr(rect.topLeft()), tr(rect.bottomRight())); } 6 | inline QRect tr(BBox2i rect){ return QRect(tr(rect.corner(BBox2i::TopLeft)), tr(rect.corner(BBox2i::BottomRight))); } 7 | } -------------------------------------------------------------------------------- /util/singleton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef SINGLETON 3 | #define SINGLETON(ClassName)\ 4 | private: \ 5 | ClassName() {} \ 6 | ClassName(ClassName const&); \ 7 | void operator=(ClassName const&); \ 8 | public: \ 9 | static ClassName& instance(){ \ 10 | static ClassName _instance; \ 11 | return _instance; \ 12 | } 13 | #endif 14 | -------------------------------------------------------------------------------- /util/tictoc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #define tic(x) auto x = std::chrono::steady_clock::now() 7 | #define toc(x) std::chrono::duration (std::chrono::steady_clock::now() - x).count() 8 | 9 | /// Helper class for TICTOC_SCOPE and TICTOC_BLOCK 10 | class TicTocTimerObject{ 11 | private: 12 | std::chrono::time_point _start; 13 | std::string _str; 14 | public: 15 | int i=0; 16 | TicTocTimerObject(const std::string& str) : _str(str){ 17 | _start = std::chrono::system_clock::now(); 18 | } 19 | ~TicTocTimerObject(){ 20 | double t_ms = std::chrono::duration (std::chrono::system_clock::now() - _start).count(); 21 | std::cout << "[" << _str << "] " << t_ms << " ms" << std::endl; 22 | } 23 | }; 24 | 25 | /// Usage: 26 | /// 27 | /// { 28 | /// ///.... Code to be timed 29 | /// TICTOC_SCOPE(objname, "scope name"); 30 | /// } //< prints out [scope name] XXms 31 | /// 32 | #define TICTOC_SCOPE(objname, string) TicTocTimerObject objname(string) 33 | 34 | /// Usage (just a for loop!!): 35 | /// 36 | /// TIMED_BLOCK(objname, "output string") 37 | /// { 38 | /// // 39 | /// //... Code to be timed 40 | /// // 41 | /// } //< prints out [scope name] XXms 42 | /// 43 | #define TICTOC_BLOCK(obj, blockName) for (TicTocTimerObject obj(blockName); obj.i < 1; ++obj.i) 44 | --------------------------------------------------------------------------------