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
81 changes: 17 additions & 64 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,80 +33,33 @@ message("OpenSplat Version: ${DAPP_VERSION}")
add_compile_options("-DAPP_VERSION=\"${DAPP_VERSION}\"")
add_compile_options("-DAPP_REVISION=\"${DAPP_REVISION}\"")

# Don't complain about the override from NANOFLANN_BUILD_EXAMPLES
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
# Use time-of-extraction for FetchContent'ed files modification time
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
# Suppress warning #20012-D (nvcc and glm)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -diag-suppress=20012)
if(OPENSPLAT_USE_FAST_MATH)
message(STATUS "Fast math optimizations enabled for CUDA")
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --use_fast_math)
endif()

# Fetch/find additional dependencies
include(FetchContent)

set(NANOFLANN_BUILD_EXAMPLES OFF)
set(NANOFLANN_BUILD_TESTS OFF)
set(ZLIB_BUILD_TESTING OFF)
set(ZLIB_BUILD_SHARED OFF)
set(ZLIB_INSTALL OFF)

find_package(nlohmann_json QUIET)
if(NOT nlohmann_json_FOUND)
message(STATUS "nlohmann_json not found, fetching it")
FetchContent_Declare(nlohmann_json
URL https://github.com/nlohmann/json/archive/refs/tags/v3.11.3.zip
)
FetchContent_MakeAvailable(nlohmann_json)
endif()
# Vendor deps
add_library(nlohmann_json INTERFACE)
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)
target_include_directories(nlohmann_json INTERFACE ${PROJECT_SOURCE_DIR}/vendor)

find_package(nanoflann QUIET)
if(NOT nanoflann_FOUND)
message(STATUS "nanoflann not found, fetching it")
FetchContent_Declare(nanoflann
URL https://github.com/jlblancoc/nanoflann/archive/refs/tags/v1.5.5.zip
)
FetchContent_MakeAvailable(nanoflann)
endif()
add_library(nanoflann INTERFACE)
add_library(nanoflann::nanoflann ALIAS nanoflann)
target_include_directories(nanoflann INTERFACE ${PROJECT_SOURCE_DIR}/vendor/nanoflann)

find_package(cxxopts QUIET)
if(NOT cxxopts_FOUND)
message(STATUS "cxxopts not found, fetching it")
FetchContent_Declare(cxxopts
URL https://github.com/jarro2783/cxxopts/archive/refs/tags/v3.2.0.zip
)
FetchContent_MakeAvailable(cxxopts)
endif()
add_library(cxxopts INTERFACE)
add_library(cxxopts::cxxopts ALIAS cxxopts)
target_include_directories(cxxopts INTERFACE ${PROJECT_SOURCE_DIR}/vendor/cxxopts)

find_package(ZLIB QUIET)
if(ZLIB_FOUND)
set(ZLIB_LIB ZLIB::ZLIB)
else()
message(STATUS "ZLIB not found, fetching it")
FetchContent_Declare(zlib
URL https://github.com/pierotofy/OpenSplat/releases/download/v1.1.4/zlib-1.3.2.tar.gz
)
FetchContent_MakeAvailable(zlib)
set(ZLIB_LIB zlibstatic)
endif()
add_library(tinyglm INTERFACE)
target_include_directories(tinyglm INTERFACE ${PROJECT_SOURCE_DIR}/vendor/tinyglm)

add_subdirectory(vendor/miniz)
add_subdirectory(vendor/zstd)
add_subdirectory(vendor/spz)

if((GPU_RUNTIME STREQUAL "CUDA") OR (GPU_RUNTIME STREQUAL "HIP"))
find_package(glm QUIET)
if(NOT glm_FOUND)
message(STATUS "glm not found, fetching it")
FetchContent_Declare(glm
URL https://github.com/g-truc/glm/archive/refs/tags/1.0.1.zip
)
FetchContent_MakeAvailable(glm)
endif()
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
Expand Down Expand Up @@ -261,7 +214,7 @@ if((GPU_RUNTIME STREQUAL "CUDA") OR (GPU_RUNTIME STREQUAL "HIP"))
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
${TORCH_INCLUDE_DIRS}
)
target_link_libraries(gsplat PUBLIC glm::glm-header-only)
target_link_libraries(gsplat PUBLIC tinyglm)
set_target_properties(gsplat PROPERTIES LINKER_LANGUAGE CXX)
elseif(GPU_RUNTIME STREQUAL "MPS")
add_library(gsplat rasterizer/gsplat-metal/gsplat_metal.mm)
Expand Down Expand Up @@ -296,7 +249,7 @@ target_include_directories(gsplat_cpu PRIVATE ${TORCH_INCLUDE_DIRS})
set(OPENSPLAT_SRC_FILES opensplat.cpp point_io.cpp nerfstudio.cpp model.cpp
kdtree_tensor.cpp spherical_harmonics.cpp cv_utils.cpp utils.cpp project_gaussians.cpp
rasterize_gaussians.cpp ssim.cpp optim_scheduler.cpp colmap.cpp opensfm.cpp openmvg.cpp input_data.cpp
tensor_math.cpp rad.cpp)
tensor_math.cpp rad.cpp zip_utils.cpp)

if (OPENSPLAT_BUILD_VISUALIZER)
if (Pangolin_FOUND)
Expand Down Expand Up @@ -333,7 +286,7 @@ target_link_libraries(opensplat PRIVATE
nlohmann_json::nlohmann_json
cxxopts::cxxopts
nanoflann::nanoflann
${ZLIB_LIB}
miniz
spz::spz
)
if (NOT WIN32)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.5
1.1.6
10 changes: 8 additions & 2 deletions input_data.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <filesystem>
#include <mutex>
#include <nlohmann/json.hpp>
#include "input_data.hpp"
#include "cv_utils.hpp"
Expand Down Expand Up @@ -42,8 +43,13 @@ void Camera::loadImage(float downscaleFactor){
// Caution: this function has destructive behaviors
// and should be called only once
if (image.numel()) std::runtime_error("loadImage already called");
std::cout << "Loading " << filePath << std::endl;


{
static std::mutex logMutex;
std::lock_guard<std::mutex> lock(logMutex);
std::cout << "Loading " << fs::path(filePath).filename().string() << std::endl;
}

cv::Mat cImg = imreadRGB(filePath);

float rescaleF = 1.0f;
Expand Down
7 changes: 5 additions & 2 deletions opensplat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "utils.hpp"
#include "cv_utils.hpp"
#include "constants.hpp"
#include "zip_utils.hpp"
#include <cxxopts.hpp>

#ifdef USE_VISUALIZATION
Expand Down Expand Up @@ -48,7 +49,7 @@ int main(int argc, char *argv[]){
("version", "Print version")
;
options.parse_positional({ "input" });
options.positional_help("[colmap/nerfstudio/opensfm/odx/openmvg project path]");
options.positional_help("[colmap/nerfstudio/opensfm/odx/openmvg project path or .zip archive]");
cxxopts::ParseResult result;
try {
result = options.parse(argc, argv);
Expand Down Expand Up @@ -117,7 +118,9 @@ int main(int argc, char *argv[]){
#endif

try{
InputData inputData = inputDataFromX(projectRoot);
std::string projectPath = projectRoot;
if (isZipArchive(projectRoot)) projectPath = extractZipToCache(projectRoot);
InputData inputData = inputDataFromX(projectPath);

parallel_for(inputData.cameras.begin(), inputData.cameras.end(), [&downScaleFactor](Camera &cam){
cam.loadImage(downScaleFactor);
Expand Down
24 changes: 12 additions & 12 deletions rad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <unordered_map>
#include <vector>

#include <zlib.h>
#include <miniz.h>
#include <nlohmann/json.hpp>

namespace rad {
Expand Down Expand Up @@ -1479,27 +1479,27 @@ bool runPipeline(const SplatData &data, GsplatArray &splats, PipelineResult &res
return true;
}

// Deflate via zlib: raw stream (no zlib header, windowBits -15), level 6
// Raw deflate stream (no zlib header, windowBits -15), level 6

std::vector<uint8_t> compressToVec(const std::vector<uint8_t> &data){
z_stream strm;
mz_stream strm;
std::memset(&strm, 0, sizeof(strm));
if (deflateInit2(&strm, 6, Z_DEFLATED, -15, 8, Z_DEFAULT_STRATEGY) != Z_OK){
if (mz_deflateInit2(&strm, 6, MZ_DEFLATED, -MZ_DEFAULT_WINDOW_BITS, 8, MZ_DEFAULT_STRATEGY) != MZ_OK){
throw std::runtime_error("saveRad: deflateInit2 failed");
}
uLong bound = deflateBound(&strm, static_cast<uLong>(data.size()));
mz_ulong bound = mz_deflateBound(&strm, static_cast<mz_ulong>(data.size()));
std::vector<uint8_t> out(bound);
strm.next_in = const_cast<Bytef *>(data.data());
strm.avail_in = static_cast<uInt>(data.size());
strm.next_in = data.data();
strm.avail_in = static_cast<unsigned int>(data.size());
strm.next_out = out.data();
strm.avail_out = static_cast<uInt>(bound);
int ret = deflate(&strm, Z_FINISH);
if (ret != Z_STREAM_END){
deflateEnd(&strm);
strm.avail_out = static_cast<unsigned int>(bound);
int ret = mz_deflate(&strm, MZ_FINISH);
if (ret != MZ_STREAM_END){
mz_deflateEnd(&strm);
throw std::runtime_error("saveRad: deflate failed");
}
out.resize(strm.total_out);
deflateEnd(&strm);
mz_deflateEnd(&strm);
return out;
}

Expand Down
3 changes: 1 addition & 2 deletions rasterizer/gsplat/helpers.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#include <cuda_runtime.h>
#endif

#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <tinyglm.hpp>
#include <iostream>

inline __device__ float ndc2pix(const float x, const float W, const float cx) {
Expand Down
19 changes: 19 additions & 0 deletions vendor/cxxopts/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2014 Jarryd Beck

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Loading
Loading