Skip to content

Commit

Permalink
adding fmt dependency (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
strasdat authored Jul 21, 2019
1 parent 1e2f110 commit 6374f17
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 201 deletions.
36 changes: 36 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
branches:
only:
- master
- dev

os: Visual Studio 2017

clone_folder: c:\projects\sophus

platform: x64
configuration: Debug

build:
project: c:\projects\sophus\build\Sophus.sln

install:
- ps: wget http://bitbucket.org/eigen/eigen/get/3.3.4.zip -outfile eigen3.zip
- cmd: 7z x eigen3.zip -o"C:\projects" -y > nul
- git clone https://github.com/fmtlib/fmt.git
- cd fmt
- git checkout 5.3.0
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE=Debug -G "Visual Studio 15 2017 Win64" ..
- cmake --build .
- cmake --build . --target install
- cd ../..

before_build:
- cd c:\projects\sophus
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE=Debug -G "Visual Studio 15 2017 Win64" -D EIGEN3_INCLUDE_DIR=C:\projects\eigen-eigen-5a0156e40feb ..

after_build:
- ctest
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ deploy:
branches:
only:
- master
- dev
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)

# Set compiler specific settings (FixMe: Should not cmake do this for us automatically?)
IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
Expand All @@ -20,7 +20,7 @@ IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -std=c++11 -Wno-deprecated-declarations -ftemplate-backtrace-limit=0")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -std=c++14 -Wno-deprecated-declarations -ftemplate-backtrace-limit=0")
SET(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_DEBUG} --coverage -fno-inline -fno-inline-small-functions -fno-default-inline")
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE "${CMAKE_EXE_LINKER_FLAGS_DEBUG} --coverage")
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} --coverage")
Expand All @@ -34,6 +34,8 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules")
# Find Eigen 3 (dependency)
find_package(Eigen3 3.3.0 REQUIRED)

find_package(fmt REQUIRED)

# Define interface library target
add_library(sophus INTERFACE)

Expand Down Expand Up @@ -70,7 +72,7 @@ endif (MSVC)

# Add Eigen interface dependency, depending on available cmake info
if(TARGET Eigen3::Eigen)
target_link_libraries(sophus INTERFACE Eigen3::Eigen)
target_link_libraries(sophus INTERFACE Eigen3::Eigen fmt::fmt)
set(Eigen3_DEPENDENCY "find_dependency (Eigen3 ${Eigen3_VERSION})")
else(TARGET Eigen3::Eigen)
target_include_directories (sophus SYSTEM INTERFACE ${EIGEN3_INCLUDE_DIR})
Expand All @@ -82,7 +84,7 @@ target_include_directories(sophus INTERFACE
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
)

# Declare all used C++11 features
# Declare all used C++14 features
target_compile_features (sophus INTERFACE
cxx_auto_type
cxx_decltype
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ the ones which are used in the Continuous Integration (CI): See TravisCI_ and
AppVeyor_ for details.

However, it should work (with no to minor modification) on many other
modern configurations as long they support c++11, CMake, and Eigen 3.X.
modern configurations as long they support c++14, CMake, Eigen 3.X and fmt.

.. |TravisCI| image:: https://travis-ci.org/strasdat/Sophus.svg?branch=master
.. _TravisCI: https://travis-ci.org/strasdat/Sophus
Expand Down
26 changes: 0 additions & 26 deletions appveyor.yml

This file was deleted.

13 changes: 13 additions & 0 deletions scripts/install_linux_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ mkdir build-eigen
cd build-eigen
cmake ../eigen-eigen-5a0156e40feb -DEIGEN_DEFAULT_TO_ROW_MAJOR=$ROW_MAJOR_DEFAULT
sudo make install
cd ..

git clone https://ceres-solver.googlesource.com/ceres-solver ceres-solver
cd ceres-solver
git reset --hard afe93546b67cee0ad205fe8044325646ed5deea9
Expand All @@ -23,3 +25,14 @@ ccache -s
cmake -DCXX11=On -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DOPENMP=Off ..
make -j3
sudo make install
cd ../..

git clone https://github.com/fmtlib/fmt.git
cd fmt
git checkout 5.3.0
mkdir build
cd build
cmake ..
make -j3
sudo make install
cd ../..
1 change: 1 addition & 0 deletions scripts/install_osx_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ brew install eigen
brew install glog
brew install suite-sparse
brew install ccache
brew install fmt
export PATH="/usr/local/opt/ccache/libexec:$PATH"
whereis ccache
git clone https://ceres-solver.googlesource.com/ceres-solver ceres-solver
Expand Down
108 changes: 18 additions & 90 deletions sophus/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

#include <Eigen/Core>

#define FMT_STRING_ALIAS 1
#include <fmt/core.h>
#include <fmt/format.h>
#include <fmt/ostream.h>

// following boost's assert.hpp
#undef SOPHUS_ENSURE

Expand All @@ -36,68 +41,6 @@

#define SOPHUS_FUNC EIGEN_DEVICE_FUNC

namespace Sophus {
namespace details {

// Following: http://stackoverflow.com/a/22759544
template <class T>
class IsStreamable {
private:
template <class TT>
static auto test(int)
-> decltype(std::declval<std::stringstream&>() << std::declval<TT>(),
std::true_type());

template <class>
static auto test(...) -> std::false_type;

public:
static bool const value = decltype(test<T>(0))::value;
};

template <class T>
class ArgToStream {
public:
static void impl(std::stringstream& stream, T&& arg) {
stream << std::forward<T>(arg);
}
};

inline void FormatStream(std::stringstream& stream, char const* text) {
stream << text;
return;
}

// Following: http://en.cppreference.com/w/cpp/language/parameter_pack
template <class T, typename... Args>
void FormatStream(std::stringstream& stream, char const* text, T&& arg,
Args&&... args) {
static_assert(IsStreamable<T>::value,
"One of the args has no ostream overload!");
for (; *text != '\0'; ++text) {
if (*text == '%') {
ArgToStream<T&&>::impl(stream, std::forward<T>(arg));
FormatStream(stream, text + 1, std::forward<Args>(args)...);
return;
}
stream << *text;
}
stream << "\nFormat-Warning: There are " << sizeof...(Args) + 1
<< " args unused.";
return;
}

template <class... Args>
std::string FormatString(char const* text, Args&&... args) {
std::stringstream stream;
FormatStream(stream, text, std::forward<Args>(args)...);
return stream.str();
}

inline std::string FormatString() { return std::string(); }
} // namespace details
} // namespace Sophus

#if defined(SOPHUS_DISABLE_ENSURES)

#define SOPHUS_ENSURE(expr, ...) ((void)0)
Expand All @@ -109,35 +52,20 @@ void ensureFailed(char const* function, char const* file, int line,
char const* description);
}

#define SOPHUS_ENSURE(expr, ...) \
((expr) ? ((void)0) \
: ::Sophus::ensureFailed( \
SOPHUS_FUNCTION, __FILE__, __LINE__, \
Sophus::details::FormatString(__VA_ARGS__).c_str()))
#define SOPHUS_ENSURE(expr, desc, ...) \
((expr) \
? ((void)0) \
: ::Sophus::ensureFailed(SOPHUS_FUNCTION, __FILE__, __LINE__, \
fmt::format(fmt(desc), __VA_ARGS__).c_str()))
#else
// LCOV_EXCL_START

namespace Sophus {
template <class... Args>
SOPHUS_FUNC void defaultEnsure(char const* function, char const* file, int line,
char const* description, Args&&... args) {
std::printf("Sophus ensure failed in function '%s', file '%s', line %d.\n",
function, file, line);
#ifdef __CUDACC__
std::printf("%s", description);
#else
std::cout << details::FormatString(description, std::forward<Args>(args)...)
<< std::endl;
std::abort();
#endif
}
} // namespace Sophus

// LCOV_EXCL_STOP
#define SOPHUS_ENSURE(expr, ...) \
((expr) ? ((void)0) \
: Sophus::defaultEnsure(SOPHUS_FUNCTION, __FILE__, __LINE__, \
##__VA_ARGS__))
#define SOPHUS_ENSURE(expr, desc, ...) \
if (!(expr)) { \
std::printf( \
"Sophus assertion failed in function '%s', file '%s', line %d.\n", \
SOPHUS_FUNCTION, __FILE__, __LINE__); \
std::cout << fmt::format(fmt(desc), ##__VA_ARGS__) << std::endl; \
std::abort(); \
}
#endif

namespace Sophus {
Expand Down
12 changes: 6 additions & 6 deletions sophus/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Vector2<T> normalFromSO2(SO2<T> const& R_foo_line) {
///
template <class T>
SO2<T> SO2FromNormal(Vector2<T> normal_foo) {
SOPHUS_ENSURE(normal_foo.squaredNorm() > Constants<T>::epsilon(), "%",
SOPHUS_ENSURE(normal_foo.squaredNorm() > Constants<T>::epsilon(), "{}",
normal_foo.transpose());
normal_foo.normalize();
return SO2<T>(normal_foo.y(), -normal_foo.x());
Expand Down Expand Up @@ -61,18 +61,18 @@ Matrix3<T> rotationFromNormal(Vector3<T> const& normal_foo,
Vector3<T> yDirHint_foo = Vector3<T>(T(0), T(1),
T(0))) {
SOPHUS_ENSURE(xDirHint_foo.dot(yDirHint_foo) < Constants<T>::epsilon(),
"xDirHint (%) and yDirHint (%) must be perpendicular.",
"xDirHint ({}) and yDirHint ({}) must be perpendicular.",
xDirHint_foo.transpose(), yDirHint_foo.transpose());
using std::abs;
using std::sqrt;
T const xDirHint_foo_sqr_length = xDirHint_foo.squaredNorm();
T const yDirHint_foo_sqr_length = yDirHint_foo.squaredNorm();
T const normal_foo_sqr_length = normal_foo.squaredNorm();
SOPHUS_ENSURE(xDirHint_foo_sqr_length > Constants<T>::epsilon(), "%",
SOPHUS_ENSURE(xDirHint_foo_sqr_length > Constants<T>::epsilon(), "{}",
xDirHint_foo.transpose());
SOPHUS_ENSURE(yDirHint_foo_sqr_length > Constants<T>::epsilon(), "%",
SOPHUS_ENSURE(yDirHint_foo_sqr_length > Constants<T>::epsilon(), "{}",
yDirHint_foo.transpose());
SOPHUS_ENSURE(normal_foo_sqr_length > Constants<T>::epsilon(), "%",
SOPHUS_ENSURE(normal_foo_sqr_length > Constants<T>::epsilon(), "{}",
normal_foo.transpose());

Matrix3<T> basis_foo;
Expand Down Expand Up @@ -102,7 +102,7 @@ Matrix3<T> rotationFromNormal(Vector3<T> const& normal_foo,
T det = basis_foo.determinant();
// sanity check
SOPHUS_ENSURE(abs(det - T(1)) < Constants<T>::epsilon(),
"Determinant of basis is not 1, but %. Basis is \n%\n", det,
"Determinant of basis is not 1, but {}. Basis is \n{}\n", det,
basis_foo);
return basis_foo;
}
Expand Down
2 changes: 1 addition & 1 deletion sophus/interpolate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enable_if_t<interp_details::Traits<G>::supported, G> interpolate(
using Scalar = typename G::Scalar;
Scalar inter_p(p);
SOPHUS_ENSURE(inter_p >= Scalar(0) && inter_p <= Scalar(1),
"p (%) must in [0, 1].");
"p ({}) must in [0, 1].", inter_p);
return foo_T_bar * G::exp(inter_p * (foo_T_bar.inverse() * foo_T_baz).log());
}

Expand Down
4 changes: 2 additions & 2 deletions sophus/rxso2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class RxSO2Base {
///
SOPHUS_FUNC void setScaledRotationMatrix(Transformation const& sR) {
SOPHUS_ENSURE(isScaledOrthogonalAndPositive(sR),
"sR must be scaled orthogonal:\n %", sR);
"sR must be scaled orthogonal:\n {}", sR);
complex_nonconst() = sR.col(0);
}

Expand Down Expand Up @@ -433,7 +433,7 @@ class RxSO2 : public RxSO2Base<RxSO2<Scalar_, Options>> {
SOPHUS_FUNC explicit RxSO2(Vector2<Scalar> const& z) : complex_(z) {
SOPHUS_ENSURE(complex_.squaredNorm() >= Constants<Scalar>::epsilon() *
Constants<Scalar>::epsilon(),
"Scale factor must be greater-equal epsilon: % vs %",
"Scale factor must be greater-equal epsilon: {} vs {}",
complex_.squaredNorm(),
Constants<Scalar>::epsilon() * Constants<Scalar>::epsilon());
}
Expand Down
6 changes: 3 additions & 3 deletions sophus/se2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ class SE2Base {
/// Precondition: ``R`` must be orthogonal and ``det(R)=1``.
///
SOPHUS_FUNC void setRotationMatrix(Matrix<Scalar, 2, 2> const& R) {
SOPHUS_ENSURE(isOrthogonal(R), "R is not orthogonal:\n %", R);
SOPHUS_ENSURE(R.determinant() > Scalar(0), "det(R) is not positive: %",
SOPHUS_ENSURE(isOrthogonal(R), "R is not orthogonal:\n {}", R);
SOPHUS_ENSURE(R.determinant() > Scalar(0), "det(R) is not positive: {}",
R.determinant());
typename SO2Type::ComplexT const complex(Scalar(0.5) * (R(0, 0) + R(1, 1)),
Scalar(0.5) * (R(1, 0) - R(0, 1)));
Expand Down Expand Up @@ -713,7 +713,7 @@ class SE2 : public SE2Base<SE2<Scalar_, Options>> {
SOPHUS_FUNC static Tangent vee(Transformation const& Omega) {
SOPHUS_ENSURE(
Omega.row(2).template lpNorm<1>() < Constants<Scalar>::epsilon(),
"Omega: \n%", Omega);
"Omega: \n{}", Omega);
Tangent upsilon_omega;
upsilon_omega.template head<2>() = Omega.col(2).template head<2>();
upsilon_omega[2] = SO2<Scalar>::vee(Omega.template topLeftCorner<2, 2>());
Expand Down
6 changes: 3 additions & 3 deletions sophus/se3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,8 @@ class SE3Base {
/// Precondition: ``R`` must be orthogonal and ``det(R)=1``.
///
SOPHUS_FUNC void setRotationMatrix(Matrix3<Scalar> const& R) {
SOPHUS_ENSURE(isOrthogonal(R), "R is not orthogonal:\n %", R);
SOPHUS_ENSURE(R.determinant() > Scalar(0), "det(R) is not positive: %",
SOPHUS_ENSURE(isOrthogonal(R), "R is not orthogonal:\n {}", R);
SOPHUS_ENSURE(R.determinant() > Scalar(0), "det(R) is not positive: {}",
R.determinant());
so3().setQuaternion(Eigen::Quaternion<Scalar>(R));
}
Expand Down Expand Up @@ -502,7 +502,7 @@ class SE3 : public SE3Base<SE3<Scalar_, Options>> {
SOPHUS_ENSURE((T.row(3) - Matrix<Scalar, 1, 4>(Scalar(0), Scalar(0),
Scalar(0), Scalar(1)))
.squaredNorm() < Constants<Scalar>::epsilon(),
"Last row is not (0,0,0,1), but (%).", T.row(3));
"Last row is not (0,0,0,1), but ({}).", T.row(3));
}

/// This provides unsafe read/write access to internal data. SO(3) is
Expand Down
Loading

0 comments on commit 6374f17

Please sign in to comment.