Skip to content

Commit d09c1a6

Browse files
authored
Merge pull request weigao95#5 from Algomorph/master
Add support for cilantro to optionally replace PCL requirement
2 parents 204aac8 + 3165a36 commit d09c1a6

26 files changed

+1138
-1006
lines changed

CMakeLists.txt

+89-28
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,114 @@ project(surfelwarp)
55
# Add cmake module path
66
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
77

8+
# Language options
9+
set(CMAKE_CXX_STANDARD 11)
10+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
11+
812
# Cuda
9-
find_package(CUDA 9 EXACT REQUIRED)
13+
find_package(CUDA 9 REQUIRED)
1014
include_directories(${CUDA_INCLUDE_DIRS})
11-
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_60")
12-
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_50,code=sm_50")
13-
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_60,code=sm_60")
14-
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_61,code=sm_61")
15-
16-
# The library built on windows platform
17-
if(WIN32)
18-
# Point cloud library and a series
19-
set(PCL_DIR "C:/Developer/ShareLib/PCL_GPU/cmake")
20-
21-
# OpenCV lib
22-
set(OpenCV_DIR "C:/Developer/ShareLib/opencv_gpu_world/")
23-
24-
# GLFW
25-
include("C:/Developer/ShareLib/GLFW/lib/cmake/glfw3/glfw3Config.cmake")
26-
include_directories("C:/Developer/ShareLib/GLFW/include")
27-
endif(WIN32)
15+
set(CUDA_ARCH "50 through 61" CACHE STRING "Architecture(s) for which to generate CUDA PTX code")
16+
if(CUDA_VERSION_MAJOR LESS 10)
17+
set_property(CACHE CUDA_ARCH PROPERTY STRINGS "50 through 61" "50" "60" "61")
18+
else()
19+
set_property(CACHE CUDA_ARCH PROPERTY STRINGS "50 through 61" "50" "60" "61" "70" "72" "75")
20+
endif()
21+
if(CUDA_ARCH STREQUAL "50 through 61")
22+
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_60")
23+
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_50,code=sm_50")
24+
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_60,code=sm_60")
25+
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_61,code=sm_61")
26+
else()
27+
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_${CUDA_ARCH}")
28+
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_${CUDA_ARCH},code=sm_${CUDA_ARCH}")
29+
endif()
2830

31+
# GLFW package
32+
find_package(glfw3 REQUIRED)
33+
34+
35+
# The library and compiler flags on Windows
36+
if(MSVC)
37+
option( MSVC_USE_STATIC_CRT "Use static C Runtime with MSVC, /MT instead of /MD" ON)
38+
39+
# Make sure there are no erroneous C Runtime flags
40+
list(APPEND FLAG_VARS
41+
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
42+
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
43+
)
44+
if(MSVC_USE_STATIC_CRT)
45+
foreach(FLAG_VAR ${FLAG_VARS})
46+
string(REGEX REPLACE "/MD" "/MT" NEW_FLAGS "${${FLAG_VAR}}")
47+
set(${FLAG_VAR} "${NEW_FLAGS}" CACHE STRING "" FORCE)
48+
endforeach()
49+
else()
50+
foreach(FLAG_VAR ${FLAG_VARS})
51+
string(REGEX REPLACE "/MT" "/MD" NEW_FLAGS "${${FLAG_VAR}}")
52+
set(${FLAG_VAR} "${NEW_FLAGS}" CACHE STRING "" FORCE)
53+
endforeach()
54+
endif()
55+
56+
# Provisions for typical Boost compiled on Windows
57+
# Most commonly, Boost libraries are compiled statically on windows (change as necesssary)
58+
set(Boost_USE_STATIC_LIBS TRUE)
59+
if(MSVC_USE_STATIC_CRT)
60+
set(Boost_USE_STATIC_RUNTIME ON)
61+
else()
62+
set(Boost_USE_STATIC_RUNTIME OFF)
63+
endif()
64+
set(Boost_USE_MULTITHREADED ON)
65+
set(Boost_USE_DEBUG_RUNTIME ON)
66+
set(Boost_USE_DEBUG_PYTHON OFF)
67+
endif(MSVC)
2968
# The library and compiler flags on Ubuntu
3069
if(UNIX)
31-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
70+
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
3271
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
3372
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -g -G")
34-
35-
# GLFW package
36-
find_package(GLFW REQUIRED)
37-
include_directories(${GLFW_INCLUDE_DIR})
3873
endif(UNIX)
3974

75+
# Append "d" to library versions with debugging symbols
76+
set(CMAKE_DEBUG_POSTFIX d)
77+
4078
# Do not use the system Eigen
4179
set(EIGEN_ROOT "${CMAKE_SOURCE_DIR}/external/eigen3.4")
4280
set(EIGEN_INCLUDE_DIR ${EIGEN_ROOT})
43-
include_directories(${EIGEN_INCLUDE_DIR})
4481

4582
# The cub package
4683
set(CUB_DIR "${CMAKE_SOURCE_DIR}/external/cub-1.8.0")
4784
include_directories(${CUB_DIR})
4885

49-
# Point cloud library and a series
50-
find_package(PCL REQUIRED)
51-
include_directories(${PCL_INCLUDE_DIRS})
86+
# Point cloud library and a series / cilantro
87+
88+
89+
set(VISUALIZATION_LIBRARY "PCL" CACHE STRING "Which library to use for visualization")
90+
set_property(CACHE VISUALIZATION_LIBRARY PROPERTY STRINGS "PCL" "cilantro")
91+
if(VISUALIZATION_LIBRARY STREQUAL "PCL")
92+
find_package(PCL REQUIRED)
93+
include_directories(${PCL_INCLUDE_DIRS})
94+
add_definitions(-DWITH_PCL)
95+
elseif(VISUALIZATION_LIBRARY STREQUAL "cilantro")
96+
find_package(cilantro REQUIRED)
97+
include_directories(${cilantro_INCLUDE_DIRS})
98+
add_definitions(-DWITH_CILANTRO)
99+
# workaround for https://github.com/kzampog/cilantro/issues/37
100+
find_package(Pangolin REQUIRED)
101+
list(APPEND cilantro_LIBRARIES ${Pangolin_LIBRARIES})
102+
# workaround for OpenMP flags not propagating from cilantro
103+
find_package(OpenMP)
104+
if(OPENMP_FOUND)
105+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
106+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
107+
endif()
108+
endif()
109+
52110

53111
# Check the CUDA version and resolve confliction with pcl
54112
if(${CUDA_VERSION_MAJOR} LESS 11)
55-
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
113+
if(VISUALIZATION_LIBRARY STREQUAL "PCL")
114+
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
115+
endif()
56116
get_directory_property(dir_defs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
57117
set(vtk_flags)
58118
foreach(it ${dir_defs})
@@ -71,6 +131,7 @@ find_package(OpenCV REQUIRED)
71131
include_directories(${OpenCV_INCLUDE_DIR})
72132

73133
# The boost library is contained in pcl
134+
find_package(Boost REQUIRED COMPONENTS system filesystem)
74135
include_directories(${Boost_INCLUDE_DIRS})
75136

76137
# The project directory shall also be included

README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@ SurfelWarp is a dynamic reconstruction system similar to [DynamicFusion](https:/
1010

1111
Wei Gao and Russ Tedrake, "SurfelWarp: Efficient Non-Volumetic Single View Dynamic Reconstruction", Robotics: Science and Systems (RSS) 2018 [[Project]](<https://sites.google.com/view/surfelwarp/home>)[[Paper]](https://arxiv.org/abs/1904.13073)[[Presentation]](https://www.youtube.com/watch?v=fexYm61VGMA)
1212

13-
### Build Instruction
13+
### Build Instructions
1414

15-
The code is developed on Visual Studio 2015 with `CUDA 9` . Note that `CUDA 10` and higher versions are not compatible with `pcl 1.8` and don't work. The code also works with Ubuntu 16.04, but for unknown reason it runs much slower on ubuntu (seems to be problem with GPU driver that only permits Debug mode). You might need to update [these lines](https://github.com/weigao95/surfelwarp/blob/4dd7a99b4cf92ebc168a592616554a54eee98a7b/CMakeLists.txt#L11) of the build script according to your GPU (the default is for Nvidia Titan Xp).
15+
The code was originally developed on Visual Studio 2015 with `CUDA 9` and `PCL 1.8` and successfully tested on Ubuntu 16.04. Note that `CUDA 10` and higher versions are not compatible with `PCL 1.8`. However, you can now chose to use the `cilantro` library instead of `PCL`, making the code compatible with any version of `CUDA` starting with `CUDA 9` and above. The code was also successfuly tested with the `cilantro` option on Ubuntu 18.04 with gcc 7.4 and Windows 10 with Visual Studio 2017. Also note that, for some unknown reason, the code runs much slower on Ubuntu (seems to be problem with GPU driver that only permits Debug mode).
1616

17-
In addition to `cuda`, the code depends on `pcl` , `opencv` and `glfw`. On Ubuntu, these dependencies can be installed with `apt`, while they need to be built from source on windows. For Ubuntu 16.04, you can run the following command to install the dependency
17+
To switch to `cilantro` and effectively remove the `PCL` dependency, pass `-DVISUALIZATION_LIBRARY=cilantro` and `-Dcilantro_DIR=<path_to_cilantro_install_directory>` when you run `cmake` or fill in the corresponding `cmake-gui` options. You will have to build `cilantro` and its dependency, `Pangolin`, from scratch, which should be relatively easy and is explained further.
18+
19+
To choose the CUDA architecture [compatible](https://en.wikipedia.org/wiki/CUDA#GPUs_supported) with your `CUDA` version and graphics card, thereby also reducing compile time, pass `-DCUDA_ARCH=<arg>` to CMake, where `<arg>` is a two-digit compile compatibility version, e.g. "61", or choose this number from the corresponding drop-down in `cmake-gui`.
20+
21+
In addition to `CUDA` and `PCL`/`cilantro`, the code depends on `OpenCV` and `GLFW`. On Ubuntu, these dependencies can be installed with `apt`, while they need to be built from source on windows. On Ubuntu, you can run the following command to install the dependencies:
1822

1923
```shell
2024
sudo apt-get install libpcl-dev libopencv-dev libglfw3 libglfw3-dev
2125
```
2226

23-
Now you are ready to build
27+
Now you are ready to build (add cmake arguments as nescessary):
2428

2529
```shell
2630
git clone https://github.com/weigao95/surfelwarp
@@ -29,10 +33,12 @@ mkdir build && cd build
2933
cmake ..
3034
make
3135
```
36+
#### Building _cilantro_ and _Pangolin_
37+
For instructions on building cilantro and Pangolin via Linux terminal, please refer to [this document](https://github.com/weigao95/surfelwarp/blob/master/doc/cilantro_build.md).
38+
#### Building on Windows
39+
For instructions on building SurfelWarp and its dependencies on Windows, please refer to [this document](https://github.com/weigao95/surfelwarp/blob/master/doc/windows%20build.md). We also provide a [pre-built binary](https://github.com/weigao95/surfelwarp/tree/master/test_data/binary) for the windows platform (The `-arch` flag for this executable is `sm_60`).
3240

33-
For build on windows please refer to [this document](https://github.com/weigao95/surfelwarp/blob/master/doc/windows%20build.md). We also provide a [pre-built binary](https://github.com/weigao95/surfelwarp/tree/master/test_data/binary) for the windows platform (The `arch` flag for this executable is `sm_60`).
34-
35-
### Run Instruction
41+
### Run Instructions
3642

3743
We use the [VolumeDeform dataset](https://www.lgdv.tf.fau.de/publicationen/volumedeform-real-time-volumetric-non-rigid-reconstruction/) to illustrate how to run the code. An example configuration file is provided [here](https://github.com/weigao95/surfelwarp/blob/master/test_data/boxing_config.json) for the "boxing" sequence. First, you need to download the boxing sequence from the VolumeDeform dataset and extract it to `data_root`, your file structure should look like
3844

apps/surfelwarp_app/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
file(GLOB SURFELWARP_APP_SRC *.h *.hpp *.cpp *.cu)
22
cuda_add_executable(surfelwarp_app ${SURFELWARP_APP_SRC})
3+
#if(MSVC)
4+
# set(CUDA_LIBRARY_DIR "${CUDA_TOOLKIT_ROOT_DIR}/lib/x64")
5+
# target_link_libraries(surfelwarp_app PUBLIC ${CUDA_LIBRARY_DIR}) #${Boost_LIBRARY_DIRS})
6+
#endif()
37
target_link_libraries(surfelwarp_app common_lib)
48
target_link_libraries(surfelwarp_app math_lib)
59
target_link_libraries(surfelwarp_app imgproc_lib)

apps/surfelwarp_app/main.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ int main(int argc, char** argv) {
3030
//auto context = initCudaContext();
3131

3232
//Save offline
33-
bool offline_rendering = true;
33+
bool offline_rendering = false;
3434

3535
//The processing loop
36-
SurfelWarpSerial::Ptr fusion = std::make_shared<SurfelWarpSerial>();
37-
fusion->ProcessFirstFrame();
36+
SurfelWarpSerial fusion;
37+
38+
fusion.ProcessFirstFrame();
3839
for(auto i = 0; i < config.num_frames(); i++){
3940
LOG(INFO) << "The " << i << "th Frame";
40-
fusion->ProcessNextFrameWithReinit(offline_rendering);
41+
fusion.ProcessNextFrameWithReinit(offline_rendering);
4142
}
4243

4344
//destroyCudaContext(context);

0 commit comments

Comments
 (0)