From 26cbdcd00a412f134fcd4f3822c0907ffedde74a Mon Sep 17 00:00:00 2001 From: Mihai Bujanca Date: Sat, 9 Sep 2017 12:10:28 +0100 Subject: [PATCH] More directory restructuring, getting CUDA through opencv rather than explicit --- modules/dynamicfusion/CMakeLists.txt | 71 +++----- .../cmake/Modules/FindOpenNI.cmake | 78 --------- modules/dynamicfusion/cmake/Targets.cmake | 57 +++---- .../include/opencv2/dynamicfusion.hpp | 6 +- .../opencv2/dynamicfusion}/cuda/device.hpp | 9 +- .../cuda/device_array.hpp | 81 +-------- .../cuda/device_memory.hpp | 85 ++++++---- .../opencv2/dynamicfusion/cuda/imgproc.hpp | 38 +++++ .../opencv2/dynamicfusion/cuda}/internal.hpp | 2 +- .../cuda/kernel_containers.hpp | 0 .../opencv2/dynamicfusion/cuda}/precomp.hpp | 10 +- .../cuda/projective_icp.hpp | 2 +- .../opencv2/dynamicfusion/cuda}/safe_call.hpp | 0 .../dynamicfusion}/cuda/temp_utils.hpp | 2 +- .../dynamicfusion}/cuda/texture_binder.hpp | 4 +- .../cuda/tsdf_volume.hpp | 6 +- .../include/opencv2/dynamicfusion/kinfu.hpp | 113 +++++++++++++ .../optimisation.hpp | 2 +- .../{kfusion => dynamicfusion}/types.hpp | 10 +- .../utils/dual_quaternion.hpp | 2 +- .../utils/knn_point_cloud.hpp | 2 +- .../{ => dynamicfusion}/utils/quaternion.hpp | 2 +- .../{kfusion => dynamicfusion}/warp_field.hpp | 8 +- .../include/opencv2/io/capture.hpp | 43 ----- .../include/opencv2/kfusion/cuda/imgproc.hpp | 38 ----- .../include/opencv2/kfusion/exports.hpp | 7 - .../include/opencv2/kfusion/kinfu.hpp | 113 ------------- modules/dynamicfusion/samples/demo.cpp | 2 +- modules/dynamicfusion/src/core.cpp | 4 +- modules/dynamicfusion/src/device_array.cpp | 155 ++++++++++++++++++ modules/dynamicfusion/src/device_memory.cpp | 4 +- modules/dynamicfusion/src/imgproc.cpp | 4 +- .../dynamicfusion/src/{cuda => }/imgproc.cu | 2 +- modules/dynamicfusion/src/kinfu.cpp | 28 ++-- modules/dynamicfusion/src/precomp.cpp | 4 +- .../dynamicfusion/src/{cuda => }/proj_icp.cu | 4 +- modules/dynamicfusion/src/projective_icp.cpp | 2 +- modules/dynamicfusion/src/tsdf_volume.cpp | 8 +- .../src/{cuda => }/tsdf_volume.cu | 6 +- modules/dynamicfusion/src/warp_field.cpp | 14 +- 40 files changed, 475 insertions(+), 553 deletions(-) delete mode 100644 modules/dynamicfusion/cmake/Modules/FindOpenNI.cmake rename modules/dynamicfusion/{src => include/opencv2/dynamicfusion}/cuda/device.hpp (99%) rename modules/dynamicfusion/include/opencv2/{kfusion => dynamicfusion}/cuda/device_array.hpp (60%) rename modules/dynamicfusion/include/opencv2/{kfusion => dynamicfusion}/cuda/device_memory.hpp (87%) create mode 100644 modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/imgproc.hpp rename modules/dynamicfusion/{src => include/opencv2/dynamicfusion/cuda}/internal.hpp (99%) rename modules/dynamicfusion/include/opencv2/{kfusion => dynamicfusion}/cuda/kernel_containers.hpp (100%) rename modules/dynamicfusion/{src => include/opencv2/dynamicfusion/cuda}/precomp.hpp (75%) rename modules/dynamicfusion/include/opencv2/{kfusion => dynamicfusion}/cuda/projective_icp.hpp (97%) rename modules/dynamicfusion/{src => include/opencv2/dynamicfusion/cuda}/safe_call.hpp (100%) rename modules/dynamicfusion/{src => include/opencv2/dynamicfusion}/cuda/temp_utils.hpp (99%) rename modules/dynamicfusion/{src => include/opencv2/dynamicfusion}/cuda/texture_binder.hpp (96%) rename modules/dynamicfusion/include/opencv2/{kfusion => dynamicfusion}/cuda/tsdf_volume.hpp (96%) create mode 100644 modules/dynamicfusion/include/opencv2/dynamicfusion/kinfu.hpp rename modules/dynamicfusion/include/opencv2/{kfusion => dynamicfusion}/optimisation.hpp (99%) rename modules/dynamicfusion/include/opencv2/{kfusion => dynamicfusion}/types.hpp (90%) rename modules/dynamicfusion/include/opencv2/{ => dynamicfusion}/utils/dual_quaternion.hpp (99%) rename modules/dynamicfusion/include/opencv2/{ => dynamicfusion}/utils/knn_point_cloud.hpp (98%) rename modules/dynamicfusion/include/opencv2/{ => dynamicfusion}/utils/quaternion.hpp (99%) rename modules/dynamicfusion/include/opencv2/{kfusion => dynamicfusion}/warp_field.hpp (94%) delete mode 100644 modules/dynamicfusion/include/opencv2/io/capture.hpp delete mode 100644 modules/dynamicfusion/include/opencv2/kfusion/cuda/imgproc.hpp delete mode 100644 modules/dynamicfusion/include/opencv2/kfusion/exports.hpp delete mode 100644 modules/dynamicfusion/include/opencv2/kfusion/kinfu.hpp create mode 100644 modules/dynamicfusion/src/device_array.cpp rename modules/dynamicfusion/src/{cuda => }/imgproc.cu (99%) rename modules/dynamicfusion/src/{cuda => }/proj_icp.cu (99%) rename modules/dynamicfusion/src/{cuda => }/tsdf_volume.cu (99%) diff --git a/modules/dynamicfusion/CMakeLists.txt b/modules/dynamicfusion/CMakeLists.txt index a901d87dfd8..80950f3b660 100644 --- a/modules/dynamicfusion/CMakeLists.txt +++ b/modules/dynamicfusion/CMakeLists.txt @@ -1,58 +1,10 @@ set(the_description "Non-rigid 3D reconstruction") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DFORCE_INLINERS -D_MWAITXINTRIN_H_INCLUDED") -# -## ---[ Solution name -# -## ---[ utility -list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/") include(cmake/Utils.cmake) -#include(cmake/Targets.cmake) -# -## ---[ find dependencies -find_package(CUDA REQUIRED) -#find_package(OpenNI) -find_package(Ceres REQUIRED) -include_directories(${CERES_INCLUDE_DIRS} ${Boost_INCLUDE_DIR} ${CUDA_INCLUDE_DIRS} ${OPENNI_INCLUDE_DIR} "kfusion/src/utils" "kfusion/include/nanoflann") -#if(OPENNI_FOUND) -# message("FOUND OPENNI AT: ${OPENNI_INCLUDE_DIR}") -#endif() -## ---[ misc settings -#if(USE_PROJECT_FOLDERS) -# set_property(GLOBAL PROPERTY USE_FOLDERS ON) -# set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakeTargets") -#endif() -# -## ---[ cuda settings -#set(HAVE_CUDA 1) -#list(APPEND CUDA_NVCC_FLAGS "-gencode;arch=compute_20,code=sm_20;-gencode;arch=compute_20,code=sm_21;-gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_61,code=sm_61") -# -#if(UNIX OR APPLE) -# list(APPEND CUDA_NVCC_FLAGS "-Xcompiler;-fPIC;") -#endif() -# -#warnings_disable(CMAKE_CXX_FLAGS /wd4985) -# -#set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "--ftz=true;--prec-div=false;--prec-sqrt=false") -#add_module_library(kfusion) -#if(OPENNI_FOUND) -# target_compile_definitions(kfusion PRIVATE OPENNI_FOUND=1) -#endif() -#target_link_libraries(kfusion ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY} ${OPENNI_LIBRARY} ${CERES_LIBRARIES}) -#add_subdirectory(apps) -# -#if(BUILD_TESTS) -# find_package(GTest REQUIRED) -# if( GTEST_FOUND ) -# message( "Found Gtest at ${GTEST_ROOT}") -# message( "GTest Libs: ${GTEST_BOTH_LIBRARIES}") -# message( "GTest Include: ${GTEST_INCLUDE_DIRS}") -# include_directories(${GTEST_INCLUDE_DIRS}) -# add_subdirectory(tests) -# endif() -#endif() -find_package(Boost REQUIRED COMPONENTS system filesystem program_options) -ocv_define_module(dynamicfusion opencv_core opencv_calib3d opencv_viz opencv_highgui) +include(cmake/Targets.cmake) + +ocv_define_module(dynamicfusion opencv_core opencv_viz opencv_imgproc) ocv_warnings_disable(CMAKE_CXX_FLAGS -Wundef @@ -63,3 +15,20 @@ ocv_warnings_disable(CMAKE_CXX_FLAGS -Wunused-parameter -Wunused-function ) + +find_package(Ceres QUIET) + +if (NOT Ceres_FOUND) + message(STATUS "${the_module} has been disabled because Ceres library has not been found") + ocv_module_disable(${the_module}) +else() + include_directories(${CERES_INCLUDE_DIRS}) + ocv_target_link_libraries(${the_module} ${CERES_LIBRARIES}) +endif() +if(NOT HAVE_CUDA) + message(STATUS "${the_module} currently requires CUDA to run") + ocv_module_disable(${the_module}) +else() + include_directories(${CUDA_INCLUDE_DIRS}) + ocv_target_link_libraries(${the_module} ${CUDA_LIBRARIES} ${CUDA_CUDA_LIBRARY}) +endif() diff --git a/modules/dynamicfusion/cmake/Modules/FindOpenNI.cmake b/modules/dynamicfusion/cmake/Modules/FindOpenNI.cmake deleted file mode 100644 index a8e6f51f915..00000000000 --- a/modules/dynamicfusion/cmake/Modules/FindOpenNI.cmake +++ /dev/null @@ -1,78 +0,0 @@ -############################################################################### -# Find OpenNI -# -# This sets the following variables: -# OPENNI_FOUND - True if OPENNI was found. -# OPENNI_INCLUDE_DIRS - Directories containing the OPENNI include files. -# OPENNI_LIBRARIES - Libraries needed to use OPENNI. -# OPENNI_DEFINITIONS - Compiler flags for OPENNI. -# -# For libusb-1.0, add USB_10_ROOT if not found - -find_package(PkgConfig QUIET) - -# Find LibUSB -if(NOT WIN32) - pkg_check_modules(PC_USB_10 libusb-1.0) - find_path(USB_10_INCLUDE_DIR libusb-1.0/libusb.h - HINTS ${PC_USB_10_INCLUDEDIR} ${PC_USB_10_INCLUDE_DIRS} "${USB_10_ROOT}" "$ENV{USB_10_ROOT}" - PATH_SUFFIXES libusb-1.0) - - find_library(USB_10_LIBRARY - NAMES usb-1.0 - HINTS ${PC_USB_10_LIBDIR} ${PC_USB_10_LIBRARY_DIRS} "${USB_10_ROOT}" "$ENV{USB_10_ROOT}" - PATH_SUFFIXES lib) - - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(USB_10 DEFAULT_MSG USB_10_LIBRARY USB_10_INCLUDE_DIR) - - if(NOT USB_10_FOUND) - message(STATUS "OpenNI disabled because libusb-1.0 not found.") - return() - else() - include_directories(SYSTEM ${USB_10_INCLUDE_DIR}) - endif() -endif(NOT WIN32) - -if(${CMAKE_VERSION} VERSION_LESS 2.8.2) - pkg_check_modules(PC_OPENNI openni-dev) -else() - pkg_check_modules(PC_OPENNI QUIET openni-dev) -endif() - -set(OPENNI_DEFINITIONS ${PC_OPENNI_CFLAGS_OTHER}) - -set(OPENNI_SUFFIX) -if(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8) - set(OPENNI_SUFFIX 64) -endif(WIN32 AND CMAKE_SIZEOF_VOID_P EQUAL 8) - -#add a hint so that it can find it without the pkg-config -find_path(OPENNI_INCLUDE_DIR XnStatus.h - HINTS ${PC_OPENNI_INCLUDEDIR} ${PC_OPENNI_INCLUDE_DIRS} /usr/include/openni /usr/include/ni "${OPENNI_ROOT}" "$ENV{OPENNI_ROOT}" - PATHS "$ENV{OPEN_NI_INSTALL_PATH${OPENNI_SUFFIX}}/Include" - PATH_SUFFIXES openni include Include) -#add a hint so that it can find it without the pkg-config -find_library(OPENNI_LIBRARY - NAMES OpenNI${OPENNI_SUFFIX} - HINTS ${PC_OPENNI_LIBDIR} ${PC_OPENNI_LIBRARY_DIRS} /usr/lib "${OPENNI_ROOT}" "$ENV{OPENNI_ROOT}" - PATHS "$ENV{OPEN_NI_LIB${OPENNI_SUFFIX}}" - PATH_SUFFIXES lib Lib Lib64) - -if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - set(OPENNI_LIBRARIES ${OPENNI_LIBRARY} ${LIBUSB_1_LIBRARIES}) -else() - set(OPENNI_LIBRARIES ${OPENNI_LIBRARY}) -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(OpenNI DEFAULT_MSG OPENNI_LIBRARY OPENNI_INCLUDE_DIR) - -mark_as_advanced(OPENNI_LIBRARY OPENNI_INCLUDE_DIR) - -if(OPENNI_FOUND) - # Add the include directories - set(OPENNI_INCLUDE_DIRS ${OPENNI_INCLUDE_DIR}) - message(STATUS "OpenNI found (include: ${OPENNI_INCLUDE_DIRS}, lib: ${OPENNI_LIBRARY})") -endif(OPENNI_FOUND) - diff --git a/modules/dynamicfusion/cmake/Targets.cmake b/modules/dynamicfusion/cmake/Targets.cmake index 2c66ece1969..3ad696e96e0 100644 --- a/modules/dynamicfusion/cmake/Targets.cmake +++ b/modules/dynamicfusion/cmake/Targets.cmake @@ -2,8 +2,8 @@ # short command to setup source group function(kf_source_group group) cmake_parse_arguments(VW_SOURCE_GROUP "" "" "GLOB" ${ARGN}) - file(GLOB srcs ${VW_SOURCE_GROUP_GLOB}) - #list(LENGTH ${srcs} ___size) + file(GLOB srcs ${VW_SOURCE_GROUP_GLOB}) + #list(LENGTH ${srcs} ___size) #if (___size GREATER 0) source_group(${group} FILES ${srcs}) #endif() @@ -12,7 +12,7 @@ endfunction() ################################################################################################ # short command getting sources from standard directores -macro(pickup_std_sources) +macro(pickup_std_sources) kf_source_group("Include" GLOB "include/${module_name}/*.h*") kf_source_group("Include\\cuda" GLOB "include/${module_name}/cuda/*.h*") kf_source_group("Source" GLOB "src/*.cpp" "src/*.h*") @@ -25,13 +25,13 @@ endmacro() ################################################################################################ # short command for declaring includes from other modules macro(declare_deps_includes) - foreach(__arg ${ARGN}) + foreach(__arg ${ARGN}) get_filename_component(___path "${CMAKE_SOURCE_DIR}/modules/${__arg}/include" ABSOLUTE) - if (EXISTS ${___path}) + if (EXISTS ${___path}) include_directories(${___path}) endif() endforeach() - + unset(___path) unset(__arg) endmacro() @@ -40,21 +40,21 @@ endmacro() ################################################################################################ # short command for setting defeault target properties function(default_properties target) - set_target_properties(${target} PROPERTIES + set_target_properties(${target} PROPERTIES DEBUG_POSTFIX "d" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") - + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + if (NOT ${target} MATCHES "^test_") install(TARGETS ${the_target} RUNTIME DESTINATION ".") endif() endfunction() function(test_props target) - #os_project_label(${target} "[test]") + #os_project_label(${target} "[test]") if(USE_PROJECT_FOLDERS) set_target_properties(${target} PROPERTIES FOLDER "Tests") - endif() + endif() endfunction() function(app_props target) @@ -68,11 +68,11 @@ endfunction() ################################################################################################ # short command for setting defeault target properties function(default_properties target) - set_target_properties(${target} PROPERTIES + set_target_properties(${target} PROPERTIES DEBUG_POSTFIX "d" ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") - + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + if (NOT ${target} MATCHES "^test_") install(TARGETS ${the_target} RUNTIME DESTINATION ".") endif() @@ -82,32 +82,32 @@ endfunction() ################################################################################################ # short command for adding library module macro(add_module_library name) - set(module_name ${name}) + set(module_name ${name}) pickup_std_sources() include_directories(include src src/cuda src/utils) - + set(__has_cuda OFF) - check_cuda(__has_cuda) - + check_cuda(__has_cuda) + set(__lib_type STATIC) if (${ARGV1} MATCHES "SHARED|STATIC") set(__lib_type ${ARGV1}) endif() - if (__has_cuda) + if (__has_cuda) cuda_add_library(${module_name} ${__lib_type} ${sources}) else() add_library(${module_name} ${__lib_type} ${sources}) endif() - + if(MSVC) set_target_properties(${module_name} PROPERTIES DEFINE_SYMBOL KFUSION_API_EXPORTS) else() add_definitions(-DKFUSION_API_EXPORTS) - endif() - + endif() + default_properties(${module_name}) - + if(USE_PROJECT_FOLDERS) set_target_properties(${module_name} PROPERTIES FOLDER "Libraries") endif() @@ -125,16 +125,7 @@ endmacro() ################################################################################################ # short command for adding application module macro(add_application target sources) - add_executable(${target} ${sources}) + add_executable(${target} ${sources}) default_properties(${target}) app_props(${target}) endmacro() - - -################################################################################################ -# short command for adding test target -macro(add_test the_target) - add_executable(${the_target} ${ARGN}) - default_properties(${the_target}) - test_props(${the_target}) -endmacro() diff --git a/modules/dynamicfusion/include/opencv2/dynamicfusion.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion.hpp index 72b7cbd6dce..eb9867a571d 100644 --- a/modules/dynamicfusion/include/opencv2/dynamicfusion.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion.hpp @@ -1,5 +1,7 @@ #ifndef OPENCV_DYNAMICFUSION_HPP #define OPENCV_DYNAMICFUSION_HPP -#include -#include +#include +#include +#include +#include #endif //OPENCV_DYNAMICFUSION_HPP diff --git a/modules/dynamicfusion/src/cuda/device.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/device.hpp similarity index 99% rename from modules/dynamicfusion/src/cuda/device.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/device.hpp index 497c8f84cf8..ee5948ff8da 100644 --- a/modules/dynamicfusion/src/cuda/device.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/device.hpp @@ -13,7 +13,8 @@ //__kf_device__ //kfusion::device::TsdfVolume::TsdfVolume(const TsdfVolume& other) // : data(other.data), dims(other.dims), voxel_size(other.voxel_size), trunc_dist(other.trunc_dist), max_weight(other.max_weight) {} - +namespace cv +{ __kf_device__ kfusion::device::TsdfVolume::elem_type* kfusion::device::TsdfVolume::operator()(int x, int y, int z) { return data + x + y*dims.x + z*dims.y*dims.x; } @@ -120,8 +121,4 @@ namespace kfusion template<> __kf_device__ void kfusion::device::gmem::StCs(const ushort2& val, ushort2* ptr) { *ptr = val; } #endif - - - - - +} \ No newline at end of file diff --git a/modules/dynamicfusion/include/opencv2/kfusion/cuda/device_array.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/device_array.hpp similarity index 60% rename from modules/dynamicfusion/include/opencv2/kfusion/cuda/device_array.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/device_array.hpp index 83b7b6788fc..a39e295bb09 100644 --- a/modules/dynamicfusion/include/opencv2/kfusion/cuda/device_array.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/device_array.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include "device_memory.hpp" #include @@ -19,7 +19,7 @@ namespace cv * \author Anatoly Baksheev */ template - class KF_EXPORTS DeviceArray : public DeviceMemory + class DeviceArray : public DeviceMemory { public: /** \brief Element type. */ @@ -116,7 +116,7 @@ namespace cv * \author Anatoly Baksheev */ template - class KF_EXPORTS DeviceArray2D : public DeviceMemory2D + class DeviceArray2D : public DeviceMemory2D { public: /** \brief Element type. */ @@ -231,76 +231,3 @@ namespace device } } } - -///////////////////// Inline implementations of DeviceArray //////////////////////////////////////////// - -template inline cv::kfusion::cuda::DeviceArray::DeviceArray() {} -template inline cv::kfusion::cuda::DeviceArray::DeviceArray(size_t size) : DeviceMemory(size * elem_size) {} -template inline cv::kfusion::cuda::DeviceArray::DeviceArray(T *ptr, size_t size) : DeviceMemory(ptr, size * elem_size) {} -template inline cv::kfusion::cuda::DeviceArray::DeviceArray(const DeviceArray& other) : DeviceMemory(other) {} -template inline cv::kfusion::cuda::DeviceArray& cv::kfusion::cuda::DeviceArray::operator=(const DeviceArray& other) -{ DeviceMemory::operator=(other); return *this; } - -template inline void cv::kfusion::cuda::DeviceArray::create(size_t size) -{ DeviceMemory::create(size * elem_size); } -template inline void cv::kfusion::cuda::DeviceArray::release() -{ DeviceMemory::release(); } - -template inline void cv::kfusion::cuda::DeviceArray::copyTo(DeviceArray& other) const -{ DeviceMemory::copyTo(other); } -template inline void cv::kfusion::cuda::DeviceArray::upload(const T *host_ptr, size_t size) -{ DeviceMemory::upload(host_ptr, size * elem_size); } -template inline void cv::kfusion::cuda::DeviceArray::download(T *host_ptr) const -{ DeviceMemory::download( host_ptr ); } - -template void cv::kfusion::cuda::DeviceArray::swap(DeviceArray& other_arg) { DeviceMemory::swap(other_arg); } - -template inline cv::kfusion::cuda::DeviceArray::operator T*() { return ptr(); } -template inline cv::kfusion::cuda::DeviceArray::operator const T*() const { return ptr(); } -template inline size_t cv::kfusion::cuda::DeviceArray::size() const { return sizeBytes() / elem_size; } - -template inline T* cv::kfusion::cuda::DeviceArray::ptr() { return DeviceMemory::ptr(); } -template inline const T* cv::kfusion::cuda::DeviceArray::ptr() const { return DeviceMemory::ptr(); } - -template template inline void cv::kfusion::cuda::DeviceArray::upload(const std::vector& data) { upload(&data[0], data.size()); } -template template inline void cv::kfusion::cuda::DeviceArray::download(std::vector& data) const { data.resize(size()); if (!data.empty()) download(&data[0]); } - -///////////////////// Inline implementations of DeviceArray2D //////////////////////////////////////////// - -template inline cv::kfusion::cuda::DeviceArray2D::DeviceArray2D() {} -template inline cv::kfusion::cuda::DeviceArray2D::DeviceArray2D(int rows, int cols) : DeviceMemory2D(rows, cols * elem_size) {} -template inline cv::kfusion::cuda::DeviceArray2D::DeviceArray2D(int rows, int cols, void *data, size_t stepBytes) : DeviceMemory2D(rows, cols * elem_size, data, stepBytes) {} -template inline cv::kfusion::cuda::DeviceArray2D::DeviceArray2D(const DeviceArray2D& other) : DeviceMemory2D(other) {} -template inline cv::kfusion::cuda::DeviceArray2D& cv::kfusion::cuda::DeviceArray2D::operator=(const DeviceArray2D& other) -{ DeviceMemory2D::operator=(other); return *this; } - -template inline void cv::kfusion::cuda::DeviceArray2D::create(int rows, int cols) -{ DeviceMemory2D::create(rows, cols * elem_size); } -template inline void cv::kfusion::cuda::DeviceArray2D::release() -{ DeviceMemory2D::release(); } - -template inline void cv::kfusion::cuda::DeviceArray2D::copyTo(DeviceArray2D& other) const -{ DeviceMemory2D::copyTo(other); } -template inline void cv::kfusion::cuda::DeviceArray2D::upload(const void *host_ptr, size_t host_step, int rows, int cols) -{ DeviceMemory2D::upload(host_ptr, host_step, rows, cols * elem_size); } -template inline void cv::kfusion::cuda::DeviceArray2D::download(void *host_ptr, size_t host_step) const -{ DeviceMemory2D::download( host_ptr, host_step ); } - -template template inline void cv::kfusion::cuda::DeviceArray2D::upload(const std::vector& data, int cols) -{ upload(&data[0], cols * elem_size, data.size()/cols, cols); } - -template template inline void cv::kfusion::cuda::DeviceArray2D::download(std::vector& data, int& elem_step) const -{ elem_step = cols(); data.resize(cols() * rows()); if (!data.empty()) download(&data[0], colsBytes()); } - -template void cv::kfusion::cuda::DeviceArray2D::swap(DeviceArray2D& other_arg) { DeviceMemory2D::swap(other_arg); } - -template inline T* cv::kfusion::cuda::DeviceArray2D::ptr(int y) { return DeviceMemory2D::ptr(y); } -template inline const T* cv::kfusion::cuda::DeviceArray2D::ptr(int y) const { return DeviceMemory2D::ptr(y); } - -template inline cv::kfusion::cuda::DeviceArray2D::operator T*() { return ptr(); } -template inline cv::kfusion::cuda::DeviceArray2D::operator const T*() const { return ptr(); } - -template inline int cv::kfusion::cuda::DeviceArray2D::cols() const { return DeviceMemory2D::colsBytes()/elem_size; } -template inline int cv::kfusion::cuda::DeviceArray2D::rows() const { return DeviceMemory2D::rows(); } - -template inline size_t cv::kfusion::cuda::DeviceArray2D::elem_step() const { return DeviceMemory2D::step()/elem_size; } diff --git a/modules/dynamicfusion/include/opencv2/kfusion/cuda/device_memory.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/device_memory.hpp similarity index 87% rename from modules/dynamicfusion/include/opencv2/kfusion/cuda/device_memory.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/device_memory.hpp index c7dde9ac190..7c7fdff6280 100644 --- a/modules/dynamicfusion/include/opencv2/kfusion/cuda/device_memory.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/device_memory.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include "kernel_containers.hpp" namespace cv { @@ -10,7 +10,7 @@ namespace cv namespace cuda { /** \brief Error handler. All GPU functions from this subsystem call the function to report an error. For internal use only */ - KF_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func = ""); + void error(const char *error_string, const char *file, const int line, const char *func = ""); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /** \brief @b DeviceMemory class @@ -20,7 +20,7 @@ namespace cv * \author Anatoly Baksheev */ - class KF_EXPORTS DeviceMemory + class DeviceMemory { public: /** \brief Empty constructor. */ @@ -108,7 +108,7 @@ namespace cv * \author Anatoly Baksheev */ - class KF_EXPORTS DeviceMemory2D + class DeviceMemory2D { public: /** \brief Empty constructor. */ @@ -224,37 +224,54 @@ namespace cv } } ///////////////////// Inline implementations of DeviceMemory //////////////////////////////////////////// - -template inline T* cv::kfusion::cuda::DeviceMemory::ptr() { return ( T*)data_; } -template inline const T* cv::kfusion::cuda::DeviceMemory::ptr() const { return (const T*)data_; } - -template inline cv::kfusion::cuda::DeviceMemory::operator cv::kfusion::cuda::PtrSz() const +namespace cv { - PtrSz result; - result.data = (U*)ptr(); - result.size = sizeBytes_/sizeof(U); - return result; -} + namespace kfusion + { + namespace cuda + { -///////////////////// Inline implementations of DeviceMemory2D //////////////////////////////////////////// + template + inline T *DeviceMemory::ptr() { return (T *) data_; } -template T* cv::kfusion::cuda::DeviceMemory2D::ptr(int y_arg) { return ( T*)(( char*)data_ + y_arg * step_); } -template const T* cv::kfusion::cuda::DeviceMemory2D::ptr(int y_arg) const { return (const T*)((const char*)data_ + y_arg * step_); } + template + inline const T *DeviceMemory::ptr() const { return (const T *) data_; } -template cv::kfusion::cuda::DeviceMemory2D::operator cv::kfusion::cuda::PtrStep() const -{ - PtrStep result; - result.data = (U*)ptr(); - result.step = step_; - return result; -} + template + inline DeviceMemory::operator PtrSz() const { + PtrSz result; + result.data = (U *) ptr(); + result.size = sizeBytes_ / sizeof(U); + return result; + } -template cv::kfusion::cuda::DeviceMemory2D::operator cv::kfusion::cuda::PtrStepSz() const -{ - PtrStepSz result; - result.data = (U*)ptr(); - result.step = step_; - result.cols = colsBytes_/sizeof(U); - result.rows = rows_; - return result; -} +///////////////////// Inline implementations of DeviceMemory2D //////////////////////////////////////////// + + template + T *DeviceMemory2D::ptr(int y_arg) { return (T *) ((char *) data_ + y_arg * step_); } + + template + const T *DeviceMemory2D::ptr(int y_arg) const { + return (const T *) ((const char *) data_ + y_arg * step_); + } + + template + DeviceMemory2D::operator PtrStep() const { + PtrStep result; + result.data = (U *) ptr(); + result.step = step_; + return result; + } + + template + DeviceMemory2D::operator PtrStepSz() const { + PtrStepSz result; + result.data = (U *) ptr(); + result.step = step_; + result.cols = colsBytes_ / sizeof(U); + result.rows = rows_; + return result; + } + } + } +} \ No newline at end of file diff --git a/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/imgproc.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/imgproc.hpp new file mode 100644 index 00000000000..b809b9655a2 --- /dev/null +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/imgproc.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include + +namespace cv +{ + namespace kfusion + { + namespace cuda + { + void depthBilateralFilter(const Depth& in, Depth& out, int ksz, float sigma_spatial, float sigma_depth); + + void depthTruncation(Depth& depth, float threshold); + + void depthBuildPyramid(const Depth& depth, Depth& pyramid, float sigma_depth); + + void computeNormalsAndMaskDepth(const Intr& intr, Depth& depth, Normals& normals); + + void computePointNormals(const Intr& intr, const Depth& depth, Cloud& points, Normals& normals); + + void computeDists(const Depth& depth, Dists& dists, const Intr& intr); + + void cloudToDepth(const Cloud& cloud, Depth& depth); + + void resizeDepthNormals(const Depth& depth, const Normals& normals, Depth& depth_out, Normals& normals_out); + + void resizePointsNormals(const Cloud& points, const Normals& normals, Cloud& points_out, Normals& normals_out); + + void waitAllDefaultStream(); + + void renderTangentColors(const Normals& normals, Image& image); + + void renderImage(const Depth& depth, const Normals& normals, const Intr& intr, const Vec3f& light_pose, Image& image); + + void renderImage(const Cloud& points, const Normals& normals, const Intr& intr, const Vec3f& light_pose, Image& image); + } + } +} diff --git a/modules/dynamicfusion/src/internal.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/internal.hpp similarity index 99% rename from modules/dynamicfusion/src/internal.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/internal.hpp index f964ea8e6a5..b1bb2f81658 100644 --- a/modules/dynamicfusion/src/internal.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/internal.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "device_array.hpp" #include "safe_call.hpp" //#define USE_DEPTH namespace cv { diff --git a/modules/dynamicfusion/include/opencv2/kfusion/cuda/kernel_containers.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/kernel_containers.hpp similarity index 100% rename from modules/dynamicfusion/include/opencv2/kfusion/cuda/kernel_containers.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/kernel_containers.hpp diff --git a/modules/dynamicfusion/src/precomp.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/precomp.hpp similarity index 75% rename from modules/dynamicfusion/src/precomp.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/precomp.hpp index b2c485e3f4c..4fd760f19c8 100644 --- a/modules/dynamicfusion/src/precomp.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/precomp.hpp @@ -1,10 +1,10 @@ #pragma once -#include -#include -#include -#include -#include +#include +#include +#include "tsdf_volume.hpp" +#include "imgproc.hpp" +#include "projective_icp.hpp" #include "internal.hpp" #include #include "vector_functions.h" diff --git a/modules/dynamicfusion/include/opencv2/kfusion/cuda/projective_icp.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/projective_icp.hpp similarity index 97% rename from modules/dynamicfusion/include/opencv2/kfusion/cuda/projective_icp.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/projective_icp.hpp index 33854a5238f..b9b209ee482 100644 --- a/modules/dynamicfusion/include/opencv2/kfusion/cuda/projective_icp.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/projective_icp.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace cv { diff --git a/modules/dynamicfusion/src/safe_call.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/safe_call.hpp similarity index 100% rename from modules/dynamicfusion/src/safe_call.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/safe_call.hpp diff --git a/modules/dynamicfusion/src/cuda/temp_utils.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/temp_utils.hpp similarity index 99% rename from modules/dynamicfusion/src/cuda/temp_utils.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/temp_utils.hpp index 3709b658e7f..bbf633b80cf 100644 --- a/modules/dynamicfusion/src/cuda/temp_utils.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/temp_utils.hpp @@ -1,7 +1,7 @@ #pragma once #include "cuda.h" -#include +#include "kernel_containers.hpp" namespace kfusion { diff --git a/modules/dynamicfusion/src/cuda/texture_binder.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/texture_binder.hpp similarity index 96% rename from modules/dynamicfusion/src/cuda/texture_binder.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/texture_binder.hpp index 0d3702199ef..1f438b02407 100644 --- a/modules/dynamicfusion/src/cuda/texture_binder.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/texture_binder.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include "device_array.hpp" +#include "safe_call.hpp" namespace kfusion { diff --git a/modules/dynamicfusion/include/opencv2/kfusion/cuda/tsdf_volume.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/tsdf_volume.hpp similarity index 96% rename from modules/dynamicfusion/include/opencv2/kfusion/cuda/tsdf_volume.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/tsdf_volume.hpp index 8a415c2a2ed..473cb2adb60 100644 --- a/modules/dynamicfusion/include/opencv2/kfusion/cuda/tsdf_volume.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/cuda/tsdf_volume.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include +#include +#include namespace cv { @@ -10,7 +10,7 @@ namespace cv class WarpField; namespace cuda { - class KF_EXPORTS TsdfVolume + class TsdfVolume { public: TsdfVolume(const cv::Vec3i& dims); diff --git a/modules/dynamicfusion/include/opencv2/dynamicfusion/kinfu.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/kinfu.hpp new file mode 100644 index 00000000000..3394ef486a5 --- /dev/null +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/kinfu.hpp @@ -0,0 +1,113 @@ +#ifndef DYNAMIC_FUSION_KINFU_HPP +#define DYNAMIC_FUSION_KINFU_HPP +//#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace cv +{ + namespace kfusion + { + namespace cuda + { + int getCudaEnabledDeviceCount(); + void setDevice(int device); + std::string getDeviceName(int device); + bool checkIfPreFermiGPU(int device); + void printCudaDeviceInfo(int device); + void printShortCudaDeviceInfo(int device); + } + + struct KinFuParams + { + static KinFuParams default_params(); + static KinFuParams default_params_dynamicfusion(); + + int cols; //pixels + int rows; //pixels + + Intr intr; //Camera parameters + + Vec3i volume_dims; //number of voxels + Vec3f volume_size; //meters + Affine3f volume_pose; //meters, inital pose + + float bilateral_sigma_depth; //meters + float bilateral_sigma_spatial; //pixels + int bilateral_kernel_size; //pixels + + float icp_truncate_depth_dist; //meters + float icp_dist_thres; //meters + float icp_angle_thres; //radians + std::vector icp_iter_num; //iterations for level index 0,1,..,3 + + float tsdf_min_camera_movement; //meters, integrate only if exceedes + float tsdf_trunc_dist; //meters; + int tsdf_max_weight; //frames + + float raycast_step_factor; // in voxel sizes + float gradient_delta_factor; // in voxel sizes + + Vec3f light_pose; //meters + + }; + + class KinFu + { + public: + typedef cv::Ptr Ptr; + + KinFu(const KinFuParams& params); + + const KinFuParams& params() const; + KinFuParams& params(); + + const cuda::TsdfVolume& tsdf() const; + cuda::TsdfVolume& tsdf(); + + const cuda::ProjectiveICP& icp() const; + cuda::ProjectiveICP& icp(); + + const WarpField& getWarp() const; + WarpField& getWarp(); + + void reset(); + + bool operator()(const cuda::Depth& depth, const cuda::Image& image = cuda::Image()); + + void renderImage(cuda::Image& image, int flags = 0); + void dynamicfusion(cuda::Depth& depth, cuda::Cloud current_frame, cuda::Normals current_normals); + void renderImage(cuda::Image& image, const Affine3f& pose, int flags = 0); + void reprojectToDepth(); + + Affine3f getCameraPose (int time = -1) const; + private: + void allocate_buffers(); + + int frame_counter_; + KinFuParams params_; + + std::vector poses_; + + cuda::Dists dists_; + cuda::Frame curr_, prev_, first_; + + cuda::Cloud points_; + cuda::Normals normals_; + cuda::Depth depths_; + + cv::Ptr volume_; + cv::Ptr icp_; + cv::Ptr warp_; + std::vector, utils::DualQuaternion>> edges; + }; + } +} +#endif \ No newline at end of file diff --git a/modules/dynamicfusion/include/opencv2/kfusion/optimisation.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/optimisation.hpp similarity index 99% rename from modules/dynamicfusion/include/opencv2/kfusion/optimisation.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/optimisation.hpp index 5877dc14e0d..749aa46eb85 100644 --- a/modules/dynamicfusion/include/opencv2/kfusion/optimisation.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/optimisation.hpp @@ -2,7 +2,7 @@ #define KFUSION_OPTIMISATION_H #include "ceres/ceres.h" #include "ceres/rotation.h" -#include +#include namespace cv { diff --git a/modules/dynamicfusion/include/opencv2/kfusion/types.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/types.hpp similarity index 90% rename from modules/dynamicfusion/include/opencv2/kfusion/types.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/types.hpp index 07b6a12093a..915710619c6 100644 --- a/modules/dynamicfusion/include/opencv2/kfusion/types.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/types.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -17,7 +17,7 @@ namespace cv typedef cv::Vec3i Vec3i; typedef cv::Affine3f Affine3f; - struct KF_EXPORTS Intr + struct Intr { float fx, fy, cx, cy; @@ -26,7 +26,7 @@ namespace cv Intr operator()(int level_index) const; }; - KF_EXPORTS std::ostream& operator << (std::ostream& os, const Intr& intr); + std::ostream& operator << (std::ostream& os, const Intr& intr); struct Point { @@ -74,7 +74,7 @@ namespace cv inline float deg2rad (float alpha) { return alpha * 0.017453293f; } - struct KF_EXPORTS ScopeTime + struct ScopeTime { const char* name; double start; @@ -82,7 +82,7 @@ namespace cv ~ScopeTime(); }; - struct KF_EXPORTS SampledScopeTime + struct SampledScopeTime { public: enum { EACH = 33 }; diff --git a/modules/dynamicfusion/include/opencv2/utils/dual_quaternion.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/utils/dual_quaternion.hpp similarity index 99% rename from modules/dynamicfusion/include/opencv2/utils/dual_quaternion.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/utils/dual_quaternion.hpp index 83ed53c413a..96cc3ed7223 100644 --- a/modules/dynamicfusion/include/opencv2/utils/dual_quaternion.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/utils/dual_quaternion.hpp @@ -1,7 +1,7 @@ #ifndef DYNAMIC_FUSION_DUAL_QUATERNION_HPP #define DYNAMIC_FUSION_DUAL_QUATERNION_HPP #include -#include +#include //Adapted from https://github.com/Poofjunior/QPose /** diff --git a/modules/dynamicfusion/include/opencv2/utils/knn_point_cloud.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/utils/knn_point_cloud.hpp similarity index 98% rename from modules/dynamicfusion/include/opencv2/utils/knn_point_cloud.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/utils/knn_point_cloud.hpp index b72c51943b8..6bb3da24799 100644 --- a/modules/dynamicfusion/include/opencv2/utils/knn_point_cloud.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/utils/knn_point_cloud.hpp @@ -1,7 +1,7 @@ #ifndef KFUSION_KNN_POINfloat_CLOUD_HPP #define KFUSION_KNN_POINfloat_CLOUD_HPP -#include +#include namespace cv { namespace kfusion diff --git a/modules/dynamicfusion/include/opencv2/utils/quaternion.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/utils/quaternion.hpp similarity index 99% rename from modules/dynamicfusion/include/opencv2/utils/quaternion.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/utils/quaternion.hpp index 75784454ed1..8cf00a8b734 100644 --- a/modules/dynamicfusion/include/opencv2/utils/quaternion.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/utils/quaternion.hpp @@ -2,7 +2,7 @@ #define DYNAMIC_FUSION_QUATERNION_HPP #pragma once #include -#include +#include //Adapted from https://github.com/Poofjunior/QPose namespace cv { diff --git a/modules/dynamicfusion/include/opencv2/kfusion/warp_field.hpp b/modules/dynamicfusion/include/opencv2/dynamicfusion/warp_field.hpp similarity index 94% rename from modules/dynamicfusion/include/opencv2/kfusion/warp_field.hpp rename to modules/dynamicfusion/include/opencv2/dynamicfusion/warp_field.hpp index 0779953c93f..2218948056b 100644 --- a/modules/dynamicfusion/include/opencv2/kfusion/warp_field.hpp +++ b/modules/dynamicfusion/include/opencv2/dynamicfusion/warp_field.hpp @@ -5,11 +5,11 @@ * \brief * \details */ -#include -#include +#include +#include #include -#include -#include +#include +#include #define KNN_NEIGHBOURS 8 namespace cv diff --git a/modules/dynamicfusion/include/opencv2/io/capture.hpp b/modules/dynamicfusion/include/opencv2/io/capture.hpp deleted file mode 100644 index 4e6d6b5f8c2..00000000000 --- a/modules/dynamicfusion/include/opencv2/io/capture.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include -#include - -namespace cv -{ - namespace kfusion - { - class KF_EXPORTS OpenNISource - { - public: - typedef kfusion::PixelRGB RGB24; - - enum { PROP_OPENNI_REGISTRATION_ON = 104 }; - - OpenNISource(); - OpenNISource(int device); - OpenNISource(const std::string& oni_filename, bool repeat = false); - - void open(int device); - void open(const std::string& oni_filename, bool repeat = false); - void release(); - - ~OpenNISource(); - - bool grab(cv::Mat &depth, cv::Mat &image); - - //parameters taken from camera/oni - int shadow_value, no_sample_value; - float depth_focal_length_VGA; - float baseline; // mm - double pixelSize; // mm - unsigned short max_depth; // mm - - bool setRegistration (bool value = false); - private: - struct Impl; - cv::Ptr impl_; - void getParams (); - }; - } -} diff --git a/modules/dynamicfusion/include/opencv2/kfusion/cuda/imgproc.hpp b/modules/dynamicfusion/include/opencv2/kfusion/cuda/imgproc.hpp deleted file mode 100644 index 7b2f5535ca6..00000000000 --- a/modules/dynamicfusion/include/opencv2/kfusion/cuda/imgproc.hpp +++ /dev/null @@ -1,38 +0,0 @@ -#pragma once - -#include - -namespace cv -{ - namespace kfusion - { - namespace cuda - { - KF_EXPORTS void depthBilateralFilter(const Depth& in, Depth& out, int ksz, float sigma_spatial, float sigma_depth); - - KF_EXPORTS void depthTruncation(Depth& depth, float threshold); - - KF_EXPORTS void depthBuildPyramid(const Depth& depth, Depth& pyramid, float sigma_depth); - - KF_EXPORTS void computeNormalsAndMaskDepth(const Intr& intr, Depth& depth, Normals& normals); - - KF_EXPORTS void computePointNormals(const Intr& intr, const Depth& depth, Cloud& points, Normals& normals); - - KF_EXPORTS void computeDists(const Depth& depth, Dists& dists, const Intr& intr); - - KF_EXPORTS void cloudToDepth(const Cloud& cloud, Depth& depth); - - KF_EXPORTS void resizeDepthNormals(const Depth& depth, const Normals& normals, Depth& depth_out, Normals& normals_out); - - KF_EXPORTS void resizePointsNormals(const Cloud& points, const Normals& normals, Cloud& points_out, Normals& normals_out); - - KF_EXPORTS void waitAllDefaultStream(); - - KF_EXPORTS void renderTangentColors(const Normals& normals, Image& image); - - KF_EXPORTS void renderImage(const Depth& depth, const Normals& normals, const Intr& intr, const Vec3f& light_pose, Image& image); - - KF_EXPORTS void renderImage(const Cloud& points, const Normals& normals, const Intr& intr, const Vec3f& light_pose, Image& image); - } - } -} diff --git a/modules/dynamicfusion/include/opencv2/kfusion/exports.hpp b/modules/dynamicfusion/include/opencv2/kfusion/exports.hpp deleted file mode 100644 index 43fdf142d90..00000000000 --- a/modules/dynamicfusion/include/opencv2/kfusion/exports.hpp +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#if (defined WIN32 || defined _WIN32 || defined WINCE) && defined KFUSION_API_EXPORTS - #define KF_EXPORTS __declspec(dllexport) -#else - #define KF_EXPORTS -#endif diff --git a/modules/dynamicfusion/include/opencv2/kfusion/kinfu.hpp b/modules/dynamicfusion/include/opencv2/kfusion/kinfu.hpp deleted file mode 100644 index bf3cda7438a..00000000000 --- a/modules/dynamicfusion/include/opencv2/kfusion/kinfu.hpp +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef DYNAMIC_FUSION_KINFU_HPP -#define DYNAMIC_FUSION_KINFU_HPP -//#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace cv -{ - namespace kfusion - { - namespace cuda - { - KF_EXPORTS int getCudaEnabledDeviceCount(); - KF_EXPORTS void setDevice(int device); - KF_EXPORTS std::string getDeviceName(int device); - KF_EXPORTS bool checkIfPreFermiGPU(int device); - KF_EXPORTS void printCudaDeviceInfo(int device); - KF_EXPORTS void printShortCudaDeviceInfo(int device); - } - - struct KF_EXPORTS KinFuParams - { - static KinFuParams default_params(); - static KinFuParams default_params_dynamicfusion(); - - int cols; //pixels - int rows; //pixels - - Intr intr; //Camera parameters - - Vec3i volume_dims; //number of voxels - Vec3f volume_size; //meters - Affine3f volume_pose; //meters, inital pose - - float bilateral_sigma_depth; //meters - float bilateral_sigma_spatial; //pixels - int bilateral_kernel_size; //pixels - - float icp_truncate_depth_dist; //meters - float icp_dist_thres; //meters - float icp_angle_thres; //radians - std::vector icp_iter_num; //iterations for level index 0,1,..,3 - - float tsdf_min_camera_movement; //meters, integrate only if exceedes - float tsdf_trunc_dist; //meters; - int tsdf_max_weight; //frames - - float raycast_step_factor; // in voxel sizes - float gradient_delta_factor; // in voxel sizes - - Vec3f light_pose; //meters - - }; - - class KF_EXPORTS KinFu - { - public: - typedef cv::Ptr Ptr; - - KinFu(const KinFuParams& params); - - const KinFuParams& params() const; - KinFuParams& params(); - - const cuda::TsdfVolume& tsdf() const; - cuda::TsdfVolume& tsdf(); - - const cuda::ProjectiveICP& icp() const; - cuda::ProjectiveICP& icp(); - - const WarpField& getWarp() const; - WarpField& getWarp(); - - void reset(); - - bool operator()(const cuda::Depth& depth, const cuda::Image& image = cuda::Image()); - - void renderImage(cuda::Image& image, int flags = 0); - void dynamicfusion(cuda::Depth& depth, cuda::Cloud current_frame, cuda::Normals current_normals); - void renderImage(cuda::Image& image, const Affine3f& pose, int flags = 0); - void reprojectToDepth(); - - Affine3f getCameraPose (int time = -1) const; - private: - void allocate_buffers(); - - int frame_counter_; - KinFuParams params_; - - std::vector poses_; - - cuda::Dists dists_; - cuda::Frame curr_, prev_, first_; - - cuda::Cloud points_; - cuda::Normals normals_; - cuda::Depth depths_; - - cv::Ptr volume_; - cv::Ptr icp_; - cv::Ptr warp_; - std::vector, utils::DualQuaternion>> edges; - }; - } -} -#endif \ No newline at end of file diff --git a/modules/dynamicfusion/samples/demo.cpp b/modules/dynamicfusion/samples/demo.cpp index 30b21d53bb2..4d8ab6cc0ba 100644 --- a/modules/dynamicfusion/samples/demo.cpp +++ b/modules/dynamicfusion/samples/demo.cpp @@ -2,7 +2,7 @@ #include #include #include - +#include using namespace cv; struct DynamicFusionApp { diff --git a/modules/dynamicfusion/src/core.cpp b/modules/dynamicfusion/src/core.cpp index 5a1a568cd22..7fefc23f212 100644 --- a/modules/dynamicfusion/src/core.cpp +++ b/modules/dynamicfusion/src/core.cpp @@ -1,5 +1,5 @@ -#include -#include "safe_call.hpp" +#include +#include #include #include diff --git a/modules/dynamicfusion/src/device_array.cpp b/modules/dynamicfusion/src/device_array.cpp new file mode 100644 index 00000000000..538fb9c56c3 --- /dev/null +++ b/modules/dynamicfusion/src/device_array.cpp @@ -0,0 +1,155 @@ +#include +///////////////////// implementations of DeviceArray //////////////////////////////////////////// +namespace cv +{ + namespace kfusion + { + namespace cuda + { + + + template + DeviceArray::DeviceArray() {} + + template + DeviceArray::DeviceArray(size_t size) : DeviceMemory(size * elem_size) {} + + template + DeviceArray::DeviceArray(T *ptr, size_t size) : DeviceMemory(ptr, size * elem_size) {} + + template + DeviceArray::DeviceArray(const DeviceArray &other) : DeviceMemory(other) {} + + template + DeviceArray &DeviceArray::operator=(const DeviceArray &other) { + DeviceMemory::operator=(other); + return *this; + } + + template + void DeviceArray::create(size_t size) { DeviceMemory::create(size * elem_size); } + + template + void DeviceArray::release() { DeviceMemory::release(); } + + template + void DeviceArray::copyTo(DeviceArray &other) const { DeviceMemory::copyTo(other); } + + template + void DeviceArray::upload(const T *host_ptr, size_t size) { DeviceMemory::upload(host_ptr, size * elem_size); } + + template + void DeviceArray::download(T *host_ptr) const { DeviceMemory::download(host_ptr); } + + template + void DeviceArray::swap(DeviceArray &other_arg) { DeviceMemory::swap(other_arg); } + + template + DeviceArray::operator T *() { return ptr(); } + + template + DeviceArray::operator const T *() const { return ptr(); } + + template + size_t DeviceArray::size() const { return sizeBytes() / elem_size; } + + template + T *DeviceArray::ptr() { return DeviceMemory::ptr(); } + + template + const T *DeviceArray::ptr() const { return DeviceMemory::ptr(); } + + template + template + void DeviceArray::upload(const std::vector &data) { upload(&data[0], data.size()); } + + template + template + void DeviceArray::download(std::vector &data) const { + data.resize(size()); + if (!data.empty()) download(&data[0]); + } + +///////////////////// implementations of DeviceArray2D //////////////////////////////////////////// + + template + DeviceArray2D::DeviceArray2D() {} + + template + DeviceArray2D::DeviceArray2D(int rows, int cols) : DeviceMemory2D(rows, cols * elem_size) {} + + template + DeviceArray2D::DeviceArray2D(int rows, int cols, void *data, size_t stepBytes) : DeviceMemory2D(rows, cols * + elem_size, + data, + stepBytes) {} + + template + DeviceArray2D::DeviceArray2D(const DeviceArray2D &other) : DeviceMemory2D(other) {} + + template + DeviceArray2D &DeviceArray2D::operator=(const DeviceArray2D &other) { + DeviceMemory2D::operator=(other); + return *this; + } + + template + void DeviceArray2D::create(int rows, int cols) { DeviceMemory2D::create(rows, cols * elem_size); } + + template + void DeviceArray2D::release() { DeviceMemory2D::release(); } + + template + void DeviceArray2D::copyTo(DeviceArray2D &other) const { DeviceMemory2D::copyTo(other); } + + template + void DeviceArray2D::upload(const void *host_ptr, size_t host_step, int rows, int cols) { + DeviceMemory2D::upload(host_ptr, host_step, rows, cols * elem_size); + } + + template + void DeviceArray2D::download(void *host_ptr, size_t host_step) const { + DeviceMemory2D::download(host_ptr, host_step); + } + + template + template + void DeviceArray2D::upload(const std::vector &data, int cols) { + upload(&data[0], cols * elem_size, data.size() / cols, cols); + } + + template + template + void DeviceArray2D::download(std::vector &data, int &elem_step) const { + elem_step = cols(); + data.resize(cols() * rows()); + if (!data.empty()) download(&data[0], colsBytes()); + } + + template + void DeviceArray2D::swap(DeviceArray2D &other_arg) { DeviceMemory2D::swap(other_arg); } + + template + T *DeviceArray2D::ptr(int y) { return DeviceMemory2D::ptr(y); } + + template + const T *DeviceArray2D::ptr(int y) const { return DeviceMemory2D::ptr(y); } + + template + DeviceArray2D::operator T *() { return ptr(); } + + template + DeviceArray2D::operator const T *() const { return ptr(); } + + template + int DeviceArray2D::cols() const { return DeviceMemory2D::colsBytes() / elem_size; } + + template + int DeviceArray2D::rows() const { return DeviceMemory2D::rows(); } + + template + size_t DeviceArray2D::elem_step() const { return DeviceMemory2D::step() / elem_size; } + + } + } +} \ No newline at end of file diff --git a/modules/dynamicfusion/src/device_memory.cpp b/modules/dynamicfusion/src/device_memory.cpp index 84e30fb3f91..abbed7465e1 100644 --- a/modules/dynamicfusion/src/device_memory.cpp +++ b/modules/dynamicfusion/src/device_memory.cpp @@ -1,5 +1,5 @@ -#include -#include "safe_call.hpp" +#include +#include #include #include #include diff --git a/modules/dynamicfusion/src/imgproc.cpp b/modules/dynamicfusion/src/imgproc.cpp index d5fedb60aa0..37867ff7575 100644 --- a/modules/dynamicfusion/src/imgproc.cpp +++ b/modules/dynamicfusion/src/imgproc.cpp @@ -1,5 +1,5 @@ -#include "precomp.hpp" -#include +#include +#include using namespace cv; /** * diff --git a/modules/dynamicfusion/src/cuda/imgproc.cu b/modules/dynamicfusion/src/imgproc.cu similarity index 99% rename from modules/dynamicfusion/src/cuda/imgproc.cu rename to modules/dynamicfusion/src/imgproc.cu index 511b629f09b..f512f3559ea 100644 --- a/modules/dynamicfusion/src/cuda/imgproc.cu +++ b/modules/dynamicfusion/src/imgproc.cu @@ -1,5 +1,5 @@ #include -#include "device.hpp" +#include //////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Depth bilateral filter diff --git a/modules/dynamicfusion/src/kinfu.cpp b/modules/dynamicfusion/src/kinfu.cpp index 82491d9d3d0..3d44c6755bb 100644 --- a/modules/dynamicfusion/src/kinfu.cpp +++ b/modules/dynamicfusion/src/kinfu.cpp @@ -1,16 +1,13 @@ -#include "precomp.hpp" -#include "internal.hpp" +#include +#include #include -#include +#include #include -#include -#include -#include -#include -#include - -using namespace std; -using namespace cv; +#include +#include +#include +#include +#include static inline float deg2rad (float alpha) { return alpha * 0.017453293f; } /** @@ -194,7 +191,7 @@ void cv::kfusion::KinFu::allocate_buffers() void cv::kfusion::KinFu::reset() { if (frame_counter_) - cout << "Reset" << endl; + std::cout << "Reset" << std::endl; frame_counter_ = 0; poses_.clear(); @@ -393,13 +390,8 @@ void cv::kfusion::KinFu::dynamicfusion(cv::kfusion::cuda::Depth& depth, cv::kfus // getWarp().warp(warped, warped_normals); // //ScopeTime time("fusion"); - tsdf().surface_fusion(getWarp(), warped, canonical_visible, depth, camera_pose, params_.intr); + tsdf().surface_fusion(*warp_, warped, canonical_visible, depth, camera_pose, params_.intr); - cv::Mat depth_cloud(depth.rows(),depth.cols(), CV_16U); - depth.download(depth_cloud.ptr(), depth_cloud.step); - cv::Mat display; - depth_cloud.convertTo(display, CV_8U, 255.0/4000); - cv::viz::imshow("Depth diff", display); volume_->compute_points(); volume_->compute_normals(); } diff --git a/modules/dynamicfusion/src/precomp.cpp b/modules/dynamicfusion/src/precomp.cpp index 05703fecf4a..5b351f05825 100644 --- a/modules/dynamicfusion/src/precomp.cpp +++ b/modules/dynamicfusion/src/precomp.cpp @@ -1,5 +1,5 @@ -#include "precomp.hpp" -#include "internal.hpp" +#include +#include using namespace cv; //////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// Kinfu/types implementation diff --git a/modules/dynamicfusion/src/cuda/proj_icp.cu b/modules/dynamicfusion/src/proj_icp.cu similarity index 99% rename from modules/dynamicfusion/src/cuda/proj_icp.cu rename to modules/dynamicfusion/src/proj_icp.cu index 159ab4e3b04..a07f7e0a277 100644 --- a/modules/dynamicfusion/src/cuda/proj_icp.cu +++ b/modules/dynamicfusion/src/proj_icp.cu @@ -1,5 +1,5 @@ -#include "device.hpp" -#include "texture_binder.hpp" +#include +#include namespace kfusion diff --git a/modules/dynamicfusion/src/projective_icp.cpp b/modules/dynamicfusion/src/projective_icp.cpp index 0e1e4f8f18c..0411133486e 100644 --- a/modules/dynamicfusion/src/projective_icp.cpp +++ b/modules/dynamicfusion/src/projective_icp.cpp @@ -1,4 +1,4 @@ -#include "precomp.hpp" +#include using namespace cv::kfusion; diff --git a/modules/dynamicfusion/src/tsdf_volume.cpp b/modules/dynamicfusion/src/tsdf_volume.cpp index eb0bac2f31d..a4e93de1faa 100644 --- a/modules/dynamicfusion/src/tsdf_volume.cpp +++ b/modules/dynamicfusion/src/tsdf_volume.cpp @@ -1,9 +1,9 @@ -#include -#include -#include +#include +#include +#include #include #include -#include "precomp.hpp" +#include #include using namespace cv::kfusion; using namespace cv::kfusion::cuda; diff --git a/modules/dynamicfusion/src/cuda/tsdf_volume.cu b/modules/dynamicfusion/src/tsdf_volume.cu similarity index 99% rename from modules/dynamicfusion/src/cuda/tsdf_volume.cu rename to modules/dynamicfusion/src/tsdf_volume.cu index bf41284a78d..a3cee59091c 100644 --- a/modules/dynamicfusion/src/cuda/tsdf_volume.cu +++ b/modules/dynamicfusion/src/tsdf_volume.cu @@ -1,7 +1,7 @@ #include -#include "device.hpp" -#include "texture_binder.hpp" -#include "../internal.hpp" +#include +#include +#include #include "math_constants.h" using namespace kfusion::device; diff --git a/modules/dynamicfusion/src/warp_field.cpp b/modules/dynamicfusion/src/warp_field.cpp index 7e388bae620..cf217dad449 100644 --- a/modules/dynamicfusion/src/warp_field.cpp +++ b/modules/dynamicfusion/src/warp_field.cpp @@ -1,11 +1,11 @@ -#include -#include -#include #include -#include -#include "internal.hpp" -#include "precomp.hpp" -#include +#include +#include +#include +#include +#include +#include +#include using namespace cv::kfusion; using namespace cv;