Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed to allow compilation on macOS M1 #49

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# cmake version to be used
## cmake version to be used
cmake_minimum_required( VERSION 3.0 )

# project name
Expand All @@ -10,6 +10,7 @@ project(PIXSFM)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fPIC")

include(FindPythonPyEnv)
# Include helper macros and commands, and allow the included file to override
# the CMake policies in this file
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeHelper.cmake NO_POLICY_SCOPE)
Expand All @@ -18,7 +19,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeHelper.cmake NO_POLICY_SCOPE)
# Options
################################################################################
option(TESTS_ENABLED "Whether to build test binaries" ON)
option(AVX2_ENABLED "Whether to compile with AVX2 support" ON)
option(AVX2_ENABLED "Whether to compile with AVX2 support" OFF)

if(TESTS_ENABLED)
enable_testing()
Expand Down Expand Up @@ -192,4 +193,3 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeUninstall.cmake.in"
IMMEDIATE @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/CMakeUninstall.cmake)
set_target_properties(uninstall PROPERTIES FOLDER ${CMAKE_TARGETS_ROOT_FOLDER})

75 changes: 75 additions & 0 deletions cmake/FindPythonPyEnv.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Taken from https://github.com/pybind/pybind11/issues/3081#issuecomment-935902332
# Find informations about the current python environment.
# by melMass
#
# Finds the following:
#
# - PYTHON_EXECUTABLE
# - PYTHON_INCLUDE_DIR
# - PYTHON_LIBRARY
# - PYTHON_SITE
# - PYTHON_NUMPY_INCLUDE_DIR
#
# - PYTHONLIBS_VERSION_STRING (The full version id. ie "3.7.4")
# - PYTHON_VERSION_MAJOR
# - PYTHON_VERSION_MINOR
# - PYTHON_VERSION_PATCH
#
#

function(debug_message messages)
# message(STATUS "")
message(STATUS "🐍 ${messages}")
message(STATUS "\n")
endfunction()

if (NOT DEFINED PYTHON_EXECUTABLE)
execute_process(
COMMAND which python
OUTPUT_VARIABLE PYTHON_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()

execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "from __future__ import print_function; from distutils.sysconfig import get_python_inc; print(get_python_inc())"
OUTPUT_VARIABLE PYTHON_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
)

if (NOT EXISTS ${PYTHON_INCLUDE_DIR})
message(FATAL "Python include directory not found.")
endif()

execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "from __future__ import print_function; import os, numpy.distutils; print(os.pathsep.join(numpy.distutils.misc_util.get_numpy_include_dirs()))"
OUTPUT_VARIABLE PYTHON_NUMPY_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
)

execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "from __future__ import print_function; import distutils.sysconfig as sysconfig; print('-L' + sysconfig.get_config_var('LIBDIR') + '/' + sysconfig.get_config_var('LDLIBRARY'))"
OUTPUT_VARIABLE PYTHON_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
)

execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "from __future__ import print_function; import platform; print(platform.python_version())"
OUTPUT_VARIABLE PYTHONLIBS_VERSION_STRING OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
)

execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "from __future__ import print_function; from distutils.sysconfig import get_python_lib; print(get_python_lib())"
OUTPUT_VARIABLE PYTHON_SITE OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
)

set(PYTHON_VIRTUAL_ENV $ENV{VIRTUAL_ENV})
string(REPLACE "." ";" _VERSION_LIST ${PYTHONLIBS_VERSION_STRING})

list(GET _VERSION_LIST 0 PYTHON_VERSION_MAJOR)
list(GET _VERSION_LIST 1 PYTHON_VERSION_MINOR)
list(GET _VERSION_LIST 2 PYTHON_VERSION_PATCH)



debug_message("Found Python ${PYTHON_VERSION_MAJOR} (${PYTHONLIBS_VERSION_STRING})")
debug_message("PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}")
debug_message("PYTHON_INCLUDE_DIR: ${PYTHON_INCLUDE_DIR}")
debug_message("PYTHON_LIBRARY: ${PYTHON_LIBRARY}")
debug_message("PYTHON_NUMPY_INCLUDE_DIR: ${PYTHON_NUMPY_INCLUDE_DIR}")
28 changes: 17 additions & 11 deletions pixsfm/base/src/interpolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace py = pybind11;
#include <string>
#include <utility>
#include <vector>
#include <type_traits>

#include "base/src/cubic_hermite_spline_simd.h"

Expand Down Expand Up @@ -115,21 +116,15 @@ class Interpolator {
}
}

// The following two Evaluate overloads are needed for interfacing
// with automatic differentiation. The first is for when a scalar
// evaluation is done, and the second one is for when Jets are used.
void Evaluate(const double& r, const double& c, double* f) const {
return Evaluate(r, c, f, NULL, NULL);
}

void IEvaluate(double r, double c, double* f, double* dfdr,
double* dfdc) const {
return Evaluate(r, c, f, dfdr, dfdc);
}


template <typename JetT>
void Evaluate(const JetT& r, const JetT& c, JetT* f) const {
double frc[Grid::DATA_DIMENSION];
void Evaluate(const JetT& r, const JetT& c, JetT* f) const {
double frc[Grid::DATA_DIMENSION];
double dfdr[Grid::DATA_DIMENSION];
double dfdc[Grid::DATA_DIMENSION];
Evaluate(r.a, c.a, frc, dfdr, dfdc);
Expand All @@ -139,6 +134,17 @@ class Interpolator {
}
}


// The following two Evaluate overloads are needed for interfacing
// with automatic differentiation. The first is for when a scalar
// evaluation is done, and the second one is for when Jets are used.
template <>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explicit specialization in class scope is accepted by clang but not by GCC:

error: explicit specialization in non-namespace scope ‘class pixsfm::Interpolator’

This is part of the standard only since C++17 and still a bug in GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85282 Will look into this when I find the time.

void Evaluate(const double& r, const double& c, double* f) const {
return Evaluate(r, c, f, NULL, NULL);
//Without template specialization it does not work with Clang
}


virtual int OutputDimension() const { return Grid::DATA_DIMENSION; }

protected:
Expand Down Expand Up @@ -608,7 +614,7 @@ class NearestNeighborInterpolator : public Interpolator<Grid> {

template <typename Grid>
class PixelInterpolator : public Interpolator<Grid> {
// template <typename JetT> using Interpolator<Grid>::Evaluate<JetT>;
// template <typename JetT> using Interpolator<Grid>::Evaluate<JetT>;
using Interpolator<Grid>::grid_;

public:
Expand Down Expand Up @@ -735,4 +741,4 @@ class PixelInterpolator : public Interpolator<Grid> {
std::unique_ptr<Interpolator<Grid>> interpolator_;
};

} // namespace pixsfm
} // namespace pixsfm
1 change: 1 addition & 0 deletions pixsfm/bundle_adjustment/src/reference_extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ ReferenceExtractor::InitReferences(const std::vector<int>& problem_labels) {
return references;
}


template <int N_NODES>
OffsetMatrix3d<N_NODES> NodeOffsets3D(
const colmap::Image& image, const colmap::Camera& camera,
Expand Down
4 changes: 2 additions & 2 deletions pixsfm/util/src/memory.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "sys/sysinfo.h"
//#include "sys/sysinfo.h"
#include "sys/types.h"

#include <ceres/ceres.h>
Expand Down Expand Up @@ -80,4 +80,4 @@ inline std::string MemoryString(int bytes, std::string unit = "KB") {
return ss.str();
}

} // namespace pixsfm
} // namespace pixsfm
10 changes: 5 additions & 5 deletions third-party/progressbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class progressbar {
std::string skip_char;
std::string opening_bracket_char;
std::string closing_bracket_char;
std::chrono::time_point<std::chrono::high_resolution_clock> last_timepoint;
std::chrono::time_point<std::chrono::high_resolution_clock> init_timepoint;
std::chrono::time_point<std::chrono::system_clock> last_timepoint;
std::chrono::time_point<std::chrono::system_clock> init_timepoint;
};

#include <iostream>
Expand Down Expand Up @@ -163,7 +163,7 @@ void progressbar::reset() {
update_is_called = false;
last_perc = 0;
update();
last_timepoint = std::chrono::high_resolution_clock::now();
last_timepoint = std::chrono::system_clock::now();
return;
}

Expand Down Expand Up @@ -206,7 +206,7 @@ std::string progressbar::get_update_str() {
}

// if (perc < last_perc) return;
auto now = std::chrono::high_resolution_clock::now();
auto now = std::chrono::system_clock::now();
double gap = std::chrono::duration_cast<std::chrono::milliseconds>(now-last_timepoint).count() / 1000.0;
// update percentage each unit
if ((perc > last_perc) || (!update_is_called) || gap > max_gap_sec) {
Expand Down Expand Up @@ -267,4 +267,4 @@ std::string progressbar::get_update_str() {
return progressstream.str();
}

#endif
#endif