Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
BUILD_DIR: make
CTEST_OUTPUT_ON_FAILURE: 1
VCPKG_FEATURE_FLAGS: manifests,binarycaching,registries
VCPKG_COMMIT: '37bb045f3c7a747d3e5d1c13b6fe6a0aec4b5d00'
VCPKG_COMMIT: '9eec002df1cd109f8f104cd966a763daf9751489' # 2026.10.16

defaults:
run:
Expand Down Expand Up @@ -214,6 +214,14 @@ jobs:
run: |
ctest --parallel 2 --build-config ${{ env.BUILD_CONFIG }}

- name: Package Test
run: |
# install OpenMVS and build a project using it through find_package(OpenMVS)
cmake --install ${{ env.BUILD_DIR }} --config ${{ env.BUILD_CONFIG }} --prefix install
# quoted shell variables: bash drops the backslashes of unquoted Windows paths
cmake -S build/PackageTest -B package_test -DCMAKE_BUILD_TYPE=${{ env.BUILD_CONFIG }} -DCMAKE_CONFIGURATION_TYPES=${{ env.BUILD_CONFIG }} -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_MANIFEST_MODE=OFF -DVCPKG_INSTALLED_DIR="$GITHUB_WORKSPACE/${{ env.BUILD_DIR }}/vcpkg_installed" -DVCPKG_TARGET_TRIPLET=${{ env.VCPKG_DEFAULT_TRIPLET }} -DCMAKE_PREFIX_PATH="$GITHUB_WORKSPACE/install" ${{ env.CMAKE_EXTRA_ARGS }}
cmake --build package_test --config ${{ env.BUILD_CONFIG }}

- name: Deploy release
uses: actions/upload-artifact@v4
with:
Expand Down
114 changes: 67 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ OPTION(OpenMVS_USE_FAST_FLOAT2INT "Use an optimized code to convert real numbers
OPTION(OpenMVS_USE_FAST_INVSQRT "Use an optimized code to compute the inverse square root (slower in fact on modern compilers)" OFF)
OPTION(OpenMVS_USE_FAST_CBRT "Use an optimized code to compute the cubic root" OFF)
OPTION(OpenMVS_USE_SSE "Enable SSE optimizations" ON)
OPTION(OpenMVS_MAX_CUDA_COMPATIBILITY "Build for maximum CUDA device compatibility" OFF)
OPTION(OpenMVS_ENABLE_IPO "Whether to enable interprocedural optimization" ON)
OPTION(OpenMVS_ENABLE_TESTS "Enable test code" ON)
OPTION(OpenMVS_HEADLESS_DEBUG "Print asserts to stderr and continue; do not redirect cout/cerr or pop modal dialogs (for CI / non-interactive debug runs)" OFF)
Expand Down Expand Up @@ -126,12 +125,9 @@ SET(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
# build/Utils.cmake was already included above (it must run before project()
# so the opencv4 overlay generator can append to VCPKG_OVERLAY_PORTS before
# the vcpkg toolchain consumes it). Among other things, it declares
# OPTION(BUILD_SHARED_LIBS ...), so the OPENMVS_SHARED / IPO logic that
# follows can rely on BUILD_SHARED_LIBS being defined here.
# Tell C++ code we are building shared libraries, so headers (e.g. Types.h) can
# pick the cross-DLL-friendly path for things like boost exception-unwinding.
# OPTION(BUILD_SHARED_LIBS ...), so the IPO logic that follows can rely on
# BUILD_SHARED_LIBS being defined here (the Common library defines OPENMVS_SHARED).
IF(BUILD_SHARED_LIBS)
ADD_COMPILE_DEFINITIONS(OPENMVS_SHARED)
# MSVC's /GL+/LTCG is catastrophic on shared builds: the linker tries to
# re-do whole-program optimization across each DLL's .obj graph, peaking at
# 30-40 GB RAM and many minutes per DLL link. Per-DLL native code is fine
Expand Down Expand Up @@ -198,7 +194,7 @@ if(OpenMVS_USE_OPENMP)
if(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(OpenMP_ROOT "/opt/homebrew/opt/libomp")
endif()
FIND_PACKAGE(OpenMP QUIET)
find_exported_dependency(OpenMP QUIET)
if(OPENMP_FOUND)
SET(_USE_OPENMP TRUE)
LIST(APPEND OpenMVS_EXTRA_LIBS OpenMP::OpenMP_CXX)
Expand All @@ -221,48 +217,56 @@ if(OpenMVS_USE_CUDA)
# Finding CUDA fails on some systems if paths to nvcc / cuda library are not set; ex. on linux:
# export PATH="/usr/local/cuda/bin:$PATH"
# export LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
# `native` (CMake >= 3.24) tells nvcc to detect and target the build
# host's GPU; the project's CMAKE_MINIMUM_REQUIRED guarantees support.
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES AND NOT DEFINED ENV{CUDAARCHS})
# `native` (CMake >= 3.24) tells nvcc to target only the build host's GPU,
# the fastest to compile; distributed binaries must instead list every
# targeted architecture, ex. -DCMAKE_CUDA_ARCHITECTURES=all-major
SET(CMAKE_CUDA_ARCHITECTURES "native")
endif()
SET(CMAKE_CUDA_FLAGS_INIT "${CMAKE_CUDA_FLAGS_INIT} -allow-unsupported-compiler")
ENABLE_LANGUAGE(CUDA)
SET(CUDA_FOUND TRUE)
SET(CMAKE_CUDA_STANDARD 17)
SET(CMAKE_CUDA_STANDARD_REQUIRED ON)
FIND_PACKAGE(CUDAToolkit REQUIRED)
if(OpenMVS_MAX_CUDA_COMPATIBILITY)
EXECUTE_PROCESS(COMMAND "${CMAKE_CUDA_COMPILER}" --list-gpu-arch
OUTPUT_VARIABLE LIST_GPU_ARCH
ERROR_QUIET)
if(NOT LIST_GPU_ARCH)
MESSAGE(WARNING "Cannot compile for max CUDA compatibility, nvcc does not support --list-gpu-arch")
SET(OpenMVS_MAX_CUDA_COMPATIBILITY OFF)
endif()
find_exported_dependency(CUDAToolkit REQUIRED)
# resolve the compute capabilities the CUDA code is compiled for, so that
# devices it cannot run on are skipped at runtime: native code (SASS) runs
# on the same major version, PTX is compiled by the driver for newer ones
if(CMAKE_CUDA_ARCHITECTURES STREQUAL "native")
SET(_CUDA_ARCHS "${CMAKE_CUDA_ARCHITECTURES_NATIVE}")
elseif(CMAKE_CUDA_ARCHITECTURES STREQUAL "all")
SET(_CUDA_ARCHS "${CMAKE_CUDA_ARCHITECTURES_ALL}")
elseif(CMAKE_CUDA_ARCHITECTURES STREQUAL "all-major")
SET(_CUDA_ARCHS "${CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR}")
else()
SET(_CUDA_ARCHS "${CMAKE_CUDA_ARCHITECTURES}")
endif()
if(OpenMVS_MAX_CUDA_COMPATIBILITY)
# Build for maximum compatibility
# https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
UNSET(CMAKE_CUDA_ARCHITECTURES)
# Extract list of arch and gencodes
STRING(REPLACE "\r" "" LIST_GPU_ARCH ${LIST_GPU_ARCH})
STRING(REPLACE "\n" ";" LIST_GPU_ARCH ${LIST_GPU_ARCH})
EXECUTE_PROCESS(COMMAND "${CMAKE_CUDA_COMPILER}" --list-gpu-code
OUTPUT_VARIABLE LIST_GPU_CODE
ERROR_QUIET)
STRING(REPLACE "\r" "" LIST_GPU_CODE ${LIST_GPU_CODE})
STRING(REPLACE "\n" ";" LIST_GPU_CODE ${LIST_GPU_CODE})
LIST(GET LIST_GPU_CODE 0 TARGET_GPU_CODE)
SET(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -arch=${TARGET_GPU_CODE}")
SET(IDX 0)
foreach(GPU_ARCH ${LIST_GPU_ARCH})
LIST(GET LIST_GPU_CODE ${IDX} GPU_CODE)
SET(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode=arch=${GPU_ARCH},code=${GPU_CODE}")
MATH(EXPR IDX "${IDX}+1")
endforeach()
MESSAGE(STATUS "Set CUDA flags: " ${CMAKE_CUDA_FLAGS})
SET(_CUDA_ARCHS_SASS "")
SET(_CUDA_ARCHS_SASS_EXACT "")
SET(_CUDA_ARCH_PTX 0)
foreach(CUDA_ARCH ${_CUDA_ARCHS})
if(NOT CUDA_ARCH MATCHES "^([0-9]+)([a-z]?)(-real|-virtual)?$")
MESSAGE(FATAL_ERROR "Unsupported CUDA architecture '${CUDA_ARCH}' in CMAKE_CUDA_ARCHITECTURES='${CMAKE_CUDA_ARCHITECTURES}'")
endif()
# architecture-specific code (ex. 90a) runs only on that exact architecture,
# family-specific code (ex. 100f) like the generic one on its major version
if(NOT CMAKE_MATCH_3 STREQUAL "-virtual")
if(CMAKE_MATCH_2 STREQUAL "a")
LIST(APPEND _CUDA_ARCHS_SASS_EXACT ${CMAKE_MATCH_1})
else()
LIST(APPEND _CUDA_ARCHS_SASS ${CMAKE_MATCH_1})
endif()
endif()
# architecture- and family-specific PTX is not forward compatible
if(NOT CMAKE_MATCH_3 STREQUAL "-real" AND NOT CMAKE_MATCH_2 AND (_CUDA_ARCH_PTX EQUAL 0 OR CMAKE_MATCH_1 LESS _CUDA_ARCH_PTX))
SET(_CUDA_ARCH_PTX ${CMAKE_MATCH_1})
endif()
endforeach()
if(NOT _CUDA_ARCHS_SASS AND NOT _CUDA_ARCHS_SASS_EXACT AND _CUDA_ARCH_PTX EQUAL 0)
MESSAGE(FATAL_ERROR "No CUDA architecture to compile for: set CMAKE_CUDA_ARCHITECTURES (ex. native or all-major)")
endif()
STRING(REPLACE ";" "," _CUDA_ARCHS_SASS "${_CUDA_ARCHS_SASS}")
STRING(REPLACE ";" "," _CUDA_ARCHS_SASS_EXACT "${_CUDA_ARCHS_SASS_EXACT}")
SET(CMAKE_CUDA_SEPARABLE_COMPILATION ON)
SET(CMAKE_CUDA_RESOLVE_DEVICE_SYMBOLS ON)
SET(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
Expand All @@ -274,7 +278,7 @@ if(OpenMVS_USE_CUDA)
INCLUDE_DIRECTORIES(${CUDAToolkit_INCLUDE_DIRS})
LIST(APPEND OpenMVS_EXTRA_LIBS ${CUDAToolkit_LIBRARIES} CUDA::cuda_driver CUDA::cudart CUDA::curand)
SET(_USE_CUDA TRUE)
MESSAGE(STATUS "Found CUDA: " ${CMAKE_CUDA_COMPILER_VERSION} " with GPU arch: " ${CMAKE_CUDA_ARCHITECTURES})
MESSAGE(STATUS "Found CUDA: ${CMAKE_CUDA_COMPILER_VERSION} with GPU arch: ${CMAKE_CUDA_ARCHITECTURES} (SASS ${_CUDA_ARCHS_SASS}; exact SASS ${_CUDA_ARCHS_SASS_EXACT}; PTX ${_CUDA_ARCH_PTX})")
else()
MESSAGE(STATUS "Can't find CUDA. Continuing without it.")
endif()
Expand Down Expand Up @@ -311,10 +315,17 @@ SET(OpenMVS_PYTHON_LIBS "")
if(OpenMVS_USE_PYTHON)
FIND_PACKAGE(Python3 COMPONENTS Interpreter Development.Module REQUIRED)
LIST(APPEND OpenMVS_PYTHON_LIBS Python3::Module)
# relative to the install prefix, laid out like a Python installation or virtual environment
if(WIN32)
SET(_PYTHON_INSTALL_PATH "Lib/site-packages")
else()
SET(_PYTHON_INSTALL_PATH "lib/python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}/site-packages")
endif()
SET(PYTHON_INSTALL_PATH "${_PYTHON_INSTALL_PATH}" CACHE PATH "Installation directory for the Python bindings")
MESSAGE(STATUS "Python ${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR} found (include: ${Python3_INCLUDE_DIRS})")
endif()

FIND_PACKAGE(Boost REQUIRED COMPONENTS iostreams program_options serialization exception)
find_exported_dependency(Boost REQUIRED COMPONENTS iostreams program_options serialization exception)
if(Boost_FOUND)
ADD_DEFINITIONS(${Boost_DEFINITIONS})
LIST(APPEND OpenMVS_EXTRA_LIBS ${Boost_LIBRARIES})
Expand Down Expand Up @@ -344,7 +355,7 @@ if(OpenMVS_USE_PYTHON)
endif()
endif()

FIND_PACKAGE(Eigen3 CONFIG REQUIRED)
find_exported_dependency(Eigen3 CONFIG REQUIRED)
if(Eigen3_FOUND)
if(Eigen3_VERSION VERSION_LESS "3.4")
MESSAGE(FATAL_ERROR "Eigen ${Eigen3_VERSION} found, but at least 3.4 is required")
Expand All @@ -354,7 +365,7 @@ if(Eigen3_FOUND)
MESSAGE(STATUS "Eigen ${Eigen3_VERSION} found")
endif()

FIND_PACKAGE(OpenCV REQUIRED)
find_exported_dependency(OpenCV REQUIRED)
if(OpenCV_FOUND)
ADD_DEFINITIONS(${OpenCV_DEFINITIONS})
LIST(APPEND OpenMVS_EXTRA_LIBS ${OpenCV_LIBS})
Expand All @@ -376,6 +387,12 @@ FIND_PACKAGE(gflags CONFIG QUIET)
if(TARGET gflags::gflags AND NOT TARGET gflags)
ADD_LIBRARY(gflags INTERFACE IMPORTED)
SET_TARGET_PROPERTIES(gflags PROPERTIES INTERFACE_LINK_LIBRARIES gflags::gflags)
# the projects using the installed OpenMVS link ceres through it too
SET_PROPERTY(GLOBAL APPEND PROPERTY OpenMVS_EXPORTED_DEPENDENCIES "find_dependency(gflags CONFIG)
if(NOT TARGET gflags)
add_library(gflags INTERFACE IMPORTED)
set_target_properties(gflags PROPERTIES INTERFACE_LINK_LIBRARIES gflags::gflags)
endif()")
endif()

LIST(REMOVE_DUPLICATES OpenMVS_EXTRA_LIBS)
Expand Down Expand Up @@ -467,11 +484,14 @@ INCLUDE(CMakePackageConfigHelpers)
write_basic_package_version_file("${PROJECT_BINARY_DIR}/OpenMVSConfigVersion.cmake"
VERSION ${OpenMVS_VERSION}
COMPATIBILITY AnyNewerVersion)
# Note: Include paths are handled via imported targets and target_include_directories
SET(INSTALL_CMAKE_DIR_IN ${INSTALL_CMAKE_DIR_PREFIX})
# the packages the exported targets link against, as found by find_exported_dependency()
GET_PROPERTY(OpenMVS_EXPORTED_DEPENDENCIES GLOBAL PROPERTY OpenMVS_EXPORTED_DEPENDENCIES)
LIST(REMOVE_DUPLICATES OpenMVS_EXPORTED_DEPENDENCIES)
STRING(REPLACE ";" "\n" OpenMVS_EXPORTED_DEPENDENCIES "${OpenMVS_EXPORTED_DEPENDENCIES}")
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/build/Templates/OpenMVSConfig.cmake.in"
"${PROJECT_BINARY_DIR}/OpenMVSConfig.cmake"
INSTALL_DESTINATION ${PROJECT_BINARY_DIR}
INSTALL_DESTINATION "${INSTALL_CMAKE_DIR}"
PATH_VARS INSTALL_INCLUDE_DIR
NO_SET_AND_CHECK_MACRO)
# Install the OpenMVSConfig.cmake and OpenMVSConfigVersion.cmake
INSTALL(FILES
Expand Down
2 changes: 1 addition & 1 deletion apps/InterfaceMVSNet/InterfaceMVSNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "../../libs/MVS/Common.h"
#include "../../libs/MVS/Scene.h"
#define JSON_NOEXCEPTION
#include "../../libs/IO/json.hpp"
#include <nlohmann/json.hpp>
#include <boost/program_options.hpp>

using namespace MVS;
Expand Down
2 changes: 1 addition & 1 deletion apps/InterfacePolycam/InterfacePolycam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "../../libs/MVS/Common.h"
#include "../../libs/MVS/Scene.h"
#define JSON_NOEXCEPTION
#include "../../libs/IO/json.hpp"
#include <nlohmann/json.hpp>
#include <boost/program_options.hpp>

using namespace MVS;
Expand Down
1 change: 0 additions & 1 deletion apps/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ cxx_executable_with_flags(Tests "Apps" "${cxx_default}" "SFM;MVS" ${LIBRARY_FILE

# Install
INSTALL(TARGETS Tests
EXPORT OpenMVSTargets
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin)
2 changes: 2 additions & 0 deletions apps/Tests/Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ int main(int argc, LPCTSTR* argv)
return false;
if (!MVS::SelectNeighborViewsScaleTest())
return false;
if (!MVS::DMapCacheKeepsRequestedImageTest())
return false;
}
return true;
}();
Expand Down
27 changes: 27 additions & 0 deletions apps/Tests/TestsMVS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include "../../libs/MVS.h"
#include "../../libs/MVS/SceneRefineCommon.h"
#include "../../libs/MVS/DMapCache.h"
#include "Tests.h"
#include "TestsMVS.h"
#include <halfmesh/RectPacking.h>
Expand Down Expand Up @@ -3467,4 +3468,30 @@ bool SelectNeighborViewsScaleTest()
}
/*----------------------------------------------------------------*/

bool DMapCacheKeepsRequestedImageTest()
{
// two depth-maps already in memory, each larger than the whole budget: UseImage() accounts
// them on first use and ejects to fit, as after loading them from disk
DepthDataArr arrDepthData(2);
for (DepthData& depthData: arrDepthData) {
depthData.images.emplace_back();
depthData.depthMap.create(4, 4);
depthData.depthMap.setTo(1.f);
}
DMapCache cache(arrDepthData, 0, 1);
cache.UseImage(0);
if (arrDepthData[0].IsEmpty()) {
VERBOSE("ERROR: DMapCacheKeepsRequestedImageTest ejected the depth-map it was asked for!");
return false;
}
cache.UseImage(1);
if (arrDepthData[1].IsEmpty() || !arrDepthData[0].IsEmpty()) {
VERBOSE("ERROR: DMapCacheKeepsRequestedImageTest kept depth-maps %d/%d loaded, expected only the second!",
!arrDepthData[0].IsEmpty(), !arrDepthData[1].IsEmpty());
return false;
}
return true;
}
/*----------------------------------------------------------------*/

} // namespace MVS
4 changes: 4 additions & 0 deletions apps/Tests/TestsMVS.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ bool MeshUnseenFacesTest();
// unit must change neither the scale nor the neighbors picked, and no neighbor the filter keeps
// may carry a scale outside its bounds (an image is resampled by it)
bool SelectNeighborViewsScaleTest();

// test that DMapCache::UseImage() keeps the depth-map it was asked for loaded even when it alone
// exceeds the memory budget, ejecting the least recently used other depth-maps instead
bool DMapCacheKeepsRequestedImageTest();
/*----------------------------------------------------------------*/

} // namespace MVS
4 changes: 2 additions & 2 deletions apps/Viewer/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Scene (top-level container)
```

### Precompiled Header Chain
`Common.h` → `MVS/Common.h` → `glad/glad.h` (with `GLAD_GL_IMPLEMENTATION`) → `GLFW/glfw3.h` → `OpenGLDebug.h`
`Common.h` → `MVS/Common.h` → `glad/gl.h` (GLAD 2, `_USE_GLAD2`) or `glad/glad.h` (GLAD 1) → `GLFW/glfw3.h` → `OpenGLDebug.h`; Common.h is the only place choosing the loader, so every Viewer file gets OpenGL by including it

### Coordinate System
`Common.h` defines `gs_convert` — a static 4x4 matrix converting from OpenGL default (Y-up) to camera coordinates (Y-down, Z-backward/NADIR). Helper functions `TransW2L(R,t)` and `TransL2W(R,t)` build world-to-local and local-to-world 4x4 Eigen matrices from rotation + translation.
Expand Down Expand Up @@ -241,7 +241,7 @@ Async MVS pipeline stages executable from the Viewer UI:

## Build & Dependencies

**Required packages** (all via vcpkg): GLAD, GLFW3, ImGui, portable-file-dialogs
**Required packages** (all via vcpkg): GLAD (GLAD 1 from vcpkg; a GLAD 2 CMake package with `glad_add_library` is preferred when found), GLFW3, ImGui, portable-file-dialogs
**Links against**: MVS library (which brings in Common, IO, Math, Eigen, OpenCV, etc.)

### Platform-Specific
Expand Down
2 changes: 1 addition & 1 deletion apps/Viewer/BufferObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#pragma once

#include <glad/glad.h>
#include "Common.h"

namespace VIEWER {

Expand Down
Loading
Loading