Skip to content

Commit

Permalink
support compile without xrprimer
Browse files Browse the repository at this point in the history
  • Loading branch information
oneLOH committed Nov 21, 2023
1 parent 27e8317 commit f7d745a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 45 deletions.
53 changes: 25 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.16)

project(xrsfm)

option(XRPRIMER_ENABLED "Buinding based on XRPRIMER, if available" ON)
option(CUDA_ENABLED "Whether to enable CUDA, if available" ON)
set(CUDA_ARCHS "Auto" CACHE STRING "List of CUDA architectures for which to \
generate code, e.g., Auto, All, Maxwell, Pascal, ...")
Expand All @@ -11,17 +12,22 @@ generate code, e.g., Auto, All, Maxwell, Pascal, ...")
# Find packages
################################################################################

set(XRPrimer_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../xrprimer/install/lib/cmake")
find_package(XRPrimer REQUIRED)
if(XRPRIMER_ENABLED)
set(XRPrimer_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../xrprimer/install/lib/cmake")
find_package(XRPrimer REQUIRED)
else ()
find_package(Ceres REQUIRED)
find_package(OpenCV REQUIRED)
if(Ceres_VERSION VERSION_GREATER 2.1)
message(FATAL_ERROR "Ceres version ${Ceres_VERSION} is not supported. Please install a version less than 2.2.")
endif()
endif ()

# for sift gpu & view
set(OpenGL_GL_PREFERENCE "LEGACY")#for const
find_package(OpenGL REQUIRED)

find_package(GLEW REQUIRED)

# find_package(Pangolin REQUIRED)

if (CUDA_ENABLED)
find_package(CUDA ${CUDA_MIN_VERSION} QUIET)
message(STATUS "found")
Expand Down Expand Up @@ -53,12 +59,12 @@ if (CUDA_FOUND)
CUDA_SELECT_NVCC_ARCH_FLAGS(CUDA_ARCH_FLAGS ${CUDA_ARCHS})

set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ${CUDA_ARCH_FLAGS}")

# Fix for some combinations of CUDA and GCC (e.g. under Ubuntu 16.04).
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -D_FORCE_INLINES")
# Do not show warnings if the architectures are deprecated.
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Wno-deprecated-gpu-targets")
# set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} --std=c++11")#need add
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} --use_fast_math")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} --default-stream per-thread")

add_definitions("-D_MWAITXINTRIN_H_INCLUDED")

message(STATUS "Enabling CUDA support (version: ${CUDA_VERSION_STRING},"
" archs: ${CUDA_ARCH_FLAGS_readable})")
Expand Down Expand Up @@ -88,18 +94,6 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
add_subdirectory(3rdparty/SiftGPU)
add_subdirectory(3rdparty/apriltag)

if (CUDA_ENABLED)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} --use_fast_math")

# Use a separate stream per thread to allow for concurrent kernel execution
# between multiple threads on the same device.
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} --default-stream per-thread")

# Fix for Ubuntu 16.04.
add_definitions("-D_MWAITXINTRIN_H_INCLUDED")
endif ()


add_library(xrsfm
src/base/map.cc

Expand Down Expand Up @@ -129,12 +123,7 @@ add_library(xrsfm
src/geometry/colmap/optim/support_measurement.cc

src/optimization/ba_solver.cc

src/mapper/incremental_mapper.cc

# src/utility/view.cc
# src/utility/viewer_handler.cc
# src/utility/viewer.cc
src/utility/io_ecim.cc
)

Expand All @@ -148,14 +137,22 @@ target_include_directories(xrsfm
${EIGEN3_INCLUDE_DIRS}
)

target_link_libraries(xrsfm
if(XRPRIMER_ENABLED)
target_link_libraries(xrsfm
stdc++fs
XRPrimer::xrprimer
${OpenCV_LIBS}
${GTEST_LIBRARIES}
# ${Pangolin_LIBRARIES}
sift_gpu
)
else ()
target_link_libraries(xrsfm
stdc++fs
${OpenCV_LIBS}
${CERES_LIBRARIES}
sift_gpu
)
endif()

add_executable(run_matching src/run_matching.cc)
target_link_libraries(run_matching xrsfm)
Expand Down
31 changes: 21 additions & 10 deletions docs/en/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,47 @@ Dependencies from the default Ubuntu repositories:
libgoogle-glog-dev
```

Update if the version of cmake < 3.16
If the version of CMake is less than 3.16, update it.
```shell
wget https://cmake.org/files/v3.21/cmake-3.21.0-linux-x86_64.tar.gz
tar -xf cmake-3.21.0-linux-x86_64.tar.gz
cp -r cmake-3.21.0-linux-x86_64 /usr/share/
ln -sf /usr/share/cmake-3.21.0-linux-x86_64/bin/cmake /usr/bin/cmake
```

Install [XRPRimer](https://github.com/openxrlab/xrprimer)
Install [xrprimer](https://github.com/openxrlab/xrprimer)
```shell
git clone [email protected]:openxrlab/xrprimer.git
cd xrprimer
cmake -S . -Bbuild -DBUILD_EXTERNAL=ON -DCMAKE_BUILD_TYPE=Release
git checkout xrslam-opencv3.4.7
cmake -S. -Bbuild -DBUILD_EXTERNAL=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_PRECOMPILED_HEADERS=OFF
cmake --build build --target install -j4
```

Install [Pangolin]([email protected]:stevenlovegrove/Pangolin.git)
```shell
git clone [email protected]:stevenlovegrove/Pangolin.git
cd Pangolin && cmake -B build && cmake --build build -j4
cd build
sudo make install
Ensure that the root directories of xrsfm and xrprimer remain the same.

```
xrprimer
├──
...
xrsfm
├── docs
├── scripts
├── src
...
```

Compile XRSfM::
Compile xrsfm
```shell
git clone [email protected]:openxrlab/xrsfm.git
cd xrsfm && cmake -B build && cmake --build build -j4
```

Note: If you encounter difficulties during the compilation of xrprimer, you can try installing xrsfm without xrprimer. This requires OpenCV and Ceres-Solver. Then you can install xrsfm using the following command:
```shell
cd xrsfm && cmake -B build -DXRPRIMER_ENABLED=OFF && cmake --build build -j4
```

### Dockerfile

We provide a [Dockerfile](../../Dockerfile) to build an image. Ensure that you are using [docker version](https://docs.docker.com/engine/install/) >=19.03 and `"default-runtime": "nvidia"` in daemon.json.
Expand Down
25 changes: 18 additions & 7 deletions docs/zh/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,35 @@ ln -sf /usr/share/cmake-3.21.0-linux-x86_64/bin/cmake /usr/bin/cmake
```shell
git clone [email protected]:openxrlab/xrprimer.git
cd xrprimer
cmake -S . -Bbuild -DBUILD_EXTERNAL=ON -DCMAKE_BUILD_TYPE=Release
git checkout xrslam-opencv3.4.7
cmake -S. -Bbuild -DBUILD_EXTERNAL=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_PRECOMPILED_HEADERS=OFF
cmake --build build --target install -j4
```

安装 [Pangolin](https://github.com/stevenlovegrove/Pangolin)
```shell
git clone [email protected]:stevenlovegrove/Pangolin.git
cd Pangolin && cmake -B build && cmake --build build -j4
cd build
sudo make install
确保xrsfm和xrprimer的根目录保持一致。
```
xrprimer
├──
...
xrsfm
├── docs
├── scripts
├── src
...
```


编译 XRSfM
```shell
git clone [email protected]:openxrlab/xrsfm.git
cd xrsfm && cmake -B build && cmake --build build -j4
```

注意:如果您在编译xrprimer时遇到困难,可以尝试在没有xrprimer的情况下安装xrsfm。这需要OpenCV和Ceres-Solver。然后,您可以使用以下命令安装xrsfm:
```shell
cd xrsfm && cmake -B build -DXRPRIMER_ENABLED=OFF && cmake --build build -j4
```

### 通过Docker镜像运行

We provide a [Dockerfile](../../Dockerfile) to build an image. Ensure that you are using [docker version](https://docs.docker.com/engine/install/) >=19.03 and `"default-runtime": "nvidia"` in daemon.json.
Expand Down

0 comments on commit f7d745a

Please sign in to comment.