From df6eb400c4b427dc6e992ba8d66bebda00d124f3 Mon Sep 17 00:00:00 2001 From: Jesse Mapel <jmapel@usgs.gov> Date: Fri, 10 Apr 2020 10:38:17 -0700 Subject: [PATCH] Added Eigen and Json. Moved headers in build to match install (#347) * Moved ale headers * Made eigen and json optionally included --- .gitmodules | 8 +++++++- CMakeLists.txt | 28 ++++++++++++++++++++++------ eigen | 1 + include/{ => ale}/Distortion.h | 0 include/{ => ale}/InterpUtils.h | 2 +- include/{ => ale}/Isd.h | 9 ++++----- include/{ => ale}/Load.h | 0 include/{ => ale}/Orientations.h | 22 +++++++++++----------- include/{ => ale}/Rotation.h | 4 ++-- include/{ => ale}/States.h | 4 ++-- include/{ => ale}/Util.h | 10 +++++----- include/{ => ale}/Vectors.h | 0 json | 1 + src/InterpUtils.cpp | 2 +- src/Isd.cpp | 4 ++-- src/Load.cpp | 2 +- src/Orientations.cpp | 22 +++++++++++----------- src/Rotation.cpp | 4 ++-- src/States.cpp | 2 +- src/Util.cpp | 2 +- tests/ctests/IsdTests.cpp | 6 +++--- tests/ctests/LoadTests.cpp | 2 +- tests/ctests/OrientationsTests.cpp | 2 +- tests/ctests/RotationTests.cpp | 2 +- tests/ctests/StatesTests.cpp | 4 ++-- tests/ctests/TestInterpUtils.cpp | 2 +- 26 files changed, 84 insertions(+), 61 deletions(-) create mode 160000 eigen rename include/{ => ale}/Distortion.h (100%) rename include/{ => ale}/InterpUtils.h (99%) rename include/{ => ale}/Isd.h (92%) rename include/{ => ale}/Load.h (100%) rename include/{ => ale}/Orientations.h (86%) rename include/{ => ale}/Rotation.h (98%) rename include/{ => ale}/States.h (98%) rename include/{ => ale}/Util.h (94%) rename include/{ => ale}/Vectors.h (100%) create mode 160000 json diff --git a/.gitmodules b/.gitmodules index 947d17a..dec1e67 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,10 @@ [submodule "googletest"] path = googletest url = https://github.com/abseil/googletest.git - branch = release-1.8.1 \ No newline at end of file + branch = release-1.8.1 +[submodule "json"] + path = json + url = https://github.com/nlohmann/json.git +[submodule "eigen"] + path = eigen + url = https://gitlab.com/libeigen/eigen.git diff --git a/CMakeLists.txt b/CMakeLists.txt index ef9f7c6..7afb739 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,11 +14,26 @@ include(GNUInstallDirs) set(CMAKE_CXX_STANDARD 11) -set(ALE_BUILD_LOAD ON CACHE BOOL "If the C++ Python load interface should be built.") +option(ALE_BUILD_LOAD "If the C++ Python load interface should be built." ON) +option(ALE_USE_EXTERNAL_JSON "If an external nlohmann JSON library should be used" OFF) +option(ALE_USE_EXTERNAL_EIGEN "If an external EIGEN library should be used" OFF) # Third Party Dependencies -find_package(Eigen3 3.3 REQUIRED NO_MODULE) -find_package(nlohmann_json REQUIRED) +if(ALE_USE_EXTERNAL_JSON) + find_package(nlohmann_json REQUIRED) +else() + set(JSON_BuildTests OFF CACHE INTERNAL "") + add_subdirectory(json) +endif() + +if(ALE_USE_EXTERNAL_EIGEN) + find_package(Eigen3 3.3 REQUIRED NO_MODULE) +else() + add_library (eigen INTERFACE) + add_library (Eigen3::Eigen ALIAS eigen) + target_include_directories (eigen INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/eigen) +endif() if(ALE_BUILD_LOAD) # If there is an Anaconda environment activated, search that for Python first @@ -31,7 +46,7 @@ if(ALE_BUILD_LOAD) endif() # Library setup -set(ALE_BUILD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/") +set(ALE_BUILD_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/ale") set(ALE_INSTALL_INCLUDE_DIR "include/ale") set(ALE_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/InterpUtils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/Rotation.cpp @@ -62,8 +77,9 @@ set_target_properties(ale PROPERTIES # Use generator expressions so that downstream projects can use this target target_include_directories(ale PUBLIC - $<BUILD_INTERFACE:${ALE_BUILD_INCLUDE_DIR}> - $<INSTALL_INTERFACE:include>) + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> + $<INSTALL_INTERFACE:include> + PRIVATE) target_link_libraries(ale PRIVATE ${ALE_PRIVATE_LINKS} PUBLIC ${ALE_PUBLIC_LINKS}) diff --git a/eigen b/eigen new file mode 160000 index 0000000..3914290 --- /dev/null +++ b/eigen @@ -0,0 +1 @@ +Subproject commit 39142904cc2301628931481e8b331cc2d567e22f diff --git a/include/Distortion.h b/include/ale/Distortion.h similarity index 100% rename from include/Distortion.h rename to include/ale/Distortion.h diff --git a/include/InterpUtils.h b/include/ale/InterpUtils.h similarity index 99% rename from include/InterpUtils.h rename to include/ale/InterpUtils.h index b7a2bed..3bb0e84 100644 --- a/include/InterpUtils.h +++ b/include/ale/InterpUtils.h @@ -3,7 +3,7 @@ #include <vector> -#include "Vectors.h" +#include "ale/Vectors.h" namespace ale { diff --git a/include/Isd.h b/include/ale/Isd.h similarity index 92% rename from include/Isd.h rename to include/ale/Isd.h index d4ce223..d1126e7 100644 --- a/include/Isd.h +++ b/include/ale/Isd.h @@ -7,11 +7,10 @@ #include <nlohmann/json.hpp> -#include "Distortion.h" - -#include "Rotation.h" -#include "States.h" -#include "Orientations.h" +#include "ale/Distortion.h" +#include "ale/Rotation.h" +#include "ale/States.h" +#include "ale/Orientations.h" namespace ale { diff --git a/include/Load.h b/include/ale/Load.h similarity index 100% rename from include/Load.h rename to include/ale/Load.h diff --git a/include/Orientations.h b/include/ale/Orientations.h similarity index 86% rename from include/Orientations.h rename to include/ale/Orientations.h index cf193de..5f437db 100644 --- a/include/Orientations.h +++ b/include/ale/Orientations.h @@ -3,7 +3,7 @@ #include <vector> -#include "Rotation.h" +#include "ale/Rotation.h" namespace ale { class Orientations { @@ -12,7 +12,7 @@ namespace ale { * Construct a default empty orientation object */ Orientations() {}; - + /** * Construct an orientation object give a set of rotations * and optionally angular velocities at specific times. @@ -21,10 +21,10 @@ namespace ale { const std::vector<Rotation> &rotations, const std::vector<double> ×, const std::vector<Vec3d> &avs = std::vector<ale::Vec3d>(), - const int refFrame = 1, + const int refFrame = 1, const Rotation &constRot = Rotation(1, 0, 0, 0), - const std::vector<int> const_frames = std::vector<int>(), - const std::vector<int> time_dependent_frames = std::vector<int>() + const std::vector<int> const_frames = std::vector<int>(), + const std::vector<int> time_dependent_frames = std::vector<int>() ); /** @@ -38,10 +38,10 @@ namespace ale { std::vector<Rotation> getRotations() const; std::vector<ale::Vec3d> getAngularVelocities() const; std::vector<double> getTimes() const; - std::vector<int> getConstantFrames() const; + std::vector<int> getConstantFrames() const; std::vector<int> getTimeDependentFrames() const; int getReferenceFrame() const; - Rotation getConstantRotation() const; + Rotation getConstantRotation() const; /** * Get the interpolated rotation at a specific time. @@ -50,7 +50,7 @@ namespace ale { double time, RotationInterpolation interpType=SLERP ) const; - + /** * Get the interpolated angular velocity at a specific time */ @@ -86,10 +86,10 @@ namespace ale { std::vector<Rotation> m_rotations; std::vector<ale::Vec3d> m_avs; std::vector<double> m_times; - std::vector<int> m_timeDepFrames; - std::vector<int> m_constFrames; + std::vector<int> m_timeDepFrames; + std::vector<int> m_constFrames; Rotation m_constRotation; - int m_refFrame; + int m_refFrame; }; } diff --git a/include/Rotation.h b/include/ale/Rotation.h similarity index 98% rename from include/Rotation.h rename to include/ale/Rotation.h index f3f056c..3e64cc0 100644 --- a/include/Rotation.h +++ b/include/ale/Rotation.h @@ -4,8 +4,8 @@ #include <memory> #include <vector> -#include "States.h" -#include "Vectors.h" +#include "ale/States.h" +#include "ale/Vectors.h" namespace ale { diff --git a/include/States.h b/include/ale/States.h similarity index 98% rename from include/States.h rename to include/ale/States.h index 37de4e4..c4e5e81 100644 --- a/include/States.h +++ b/include/ale/States.h @@ -5,8 +5,8 @@ #include <stdexcept> -#include "Vectors.h" -#include "InterpUtils.h" +#include "ale/Vectors.h" +#include "ale/InterpUtils.h" namespace ale { /** A state vector with position and velocity*/ diff --git a/include/Util.h b/include/ale/Util.h similarity index 94% rename from include/Util.h rename to include/ale/Util.h index 7150a37..d27244f 100644 --- a/include/Util.h +++ b/include/ale/Util.h @@ -4,11 +4,11 @@ #include <string> #include <nlohmann/json.hpp> -#include "InterpUtils.h" -#include "Distortion.h" -#include "States.h" -#include "Orientations.h" -#include "Vectors.h" +#include "ale/InterpUtils.h" +#include "ale/Distortion.h" +#include "ale/States.h" +#include "ale/Orientations.h" +#include "ale/Vectors.h" namespace ale { diff --git a/include/Vectors.h b/include/ale/Vectors.h similarity index 100% rename from include/Vectors.h rename to include/ale/Vectors.h diff --git a/json b/json new file mode 160000 index 0000000..c6b2987 --- /dev/null +++ b/json @@ -0,0 +1 @@ +Subproject commit c6b298799aca23f2b35fc52c1df393afede20c15 diff --git a/src/InterpUtils.cpp b/src/InterpUtils.cpp index 75fbe15..741a709 100644 --- a/src/InterpUtils.cpp +++ b/src/InterpUtils.cpp @@ -1,4 +1,4 @@ -#include "InterpUtils.h" +#include "ale/InterpUtils.h" #include <exception> #include <stdexcept> diff --git a/src/Isd.cpp b/src/Isd.cpp index 8cb674b..e3b2876 100644 --- a/src/Isd.cpp +++ b/src/Isd.cpp @@ -1,6 +1,6 @@ -#include "Isd.h" -#include "Util.h" +#include "ale/Isd.h" +#include "ale/Util.h" using json = nlohmann::json; diff --git a/src/Load.cpp b/src/Load.cpp index 676dd6d..ed15a01 100644 --- a/src/Load.cpp +++ b/src/Load.cpp @@ -1,4 +1,4 @@ -#include "Load.h" +#include "ale/Load.h" #include <nlohmann/json.hpp> diff --git a/src/Orientations.cpp b/src/Orientations.cpp index 811d100..c2d0200 100644 --- a/src/Orientations.cpp +++ b/src/Orientations.cpp @@ -1,6 +1,6 @@ -#include "Orientations.h" +#include "ale/Orientations.h" -#include "InterpUtils.h" +#include "ale/InterpUtils.h" namespace ale { @@ -8,9 +8,9 @@ namespace ale { const std::vector<Rotation> &rotations, const std::vector<double> ×, const std::vector<Vec3d> &avs, - const int refFrame, - const Rotation &const_rot, - const std::vector<int> const_frames, + const int refFrame, + const Rotation &const_rot, + const std::vector<int> const_frames, const std::vector<int> time_dependent_frames ) : m_rotations(rotations), m_avs(avs), m_times(times), m_refFrame(refFrame), m_timeDepFrames(time_dependent_frames), m_constFrames(const_frames), m_constRotation(const_rot) { @@ -39,21 +39,21 @@ namespace ale { std::vector<double> Orientations::getTimes() const { return m_times; } - + std::vector<int> Orientations::getTimeDependentFrames() const { - return m_timeDepFrames; + return m_timeDepFrames; } std::vector<int> Orientations::getConstantFrames() const { - return m_constFrames; + return m_constFrames; } - + int Orientations::getReferenceFrame() const { - return m_refFrame; + return m_refFrame; } Rotation Orientations::getConstantRotation() const { - return m_constRotation; + return m_constRotation; } Rotation Orientations::interpolate( diff --git a/src/Rotation.cpp b/src/Rotation.cpp index 3778a03..031726c 100644 --- a/src/Rotation.cpp +++ b/src/Rotation.cpp @@ -1,10 +1,10 @@ -#include "Rotation.h" +#include "ale/Rotation.h" #include <exception> #include <Eigen/Geometry> -#include "InterpUtils.h" +#include "ale/InterpUtils.h" namespace ale { diff --git a/src/States.cpp b/src/States.cpp index ad38d10..a059780 100644 --- a/src/States.cpp +++ b/src/States.cpp @@ -1,4 +1,4 @@ -#include "States.h" +#include "ale/States.h" #include <iostream> #include <algorithm> diff --git a/src/Util.cpp b/src/Util.cpp index 103ecee..15776d4 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -2,7 +2,7 @@ #include <algorithm> #include <iostream> -#include "Util.h" +#include "ale/Util.h" using json = nlohmann::json; diff --git a/tests/ctests/IsdTests.cpp b/tests/ctests/IsdTests.cpp index 242e97d..b0dee7b 100644 --- a/tests/ctests/IsdTests.cpp +++ b/tests/ctests/IsdTests.cpp @@ -4,9 +4,9 @@ #include "gtest/gtest.h" -#include "Isd.h" -#include "Util.h" -#include "Vectors.h" +#include "ale/Isd.h" +#include "ale/Util.h" +#include "ale/Vectors.h" void ASSERT_DOUBLE_VECTOR_EQ(std::vector<double> v1, std::vector<double> v2) { ASSERT_EQ(v1.size(), v2.size()) << "The two input vectors are different in size"; diff --git a/tests/ctests/LoadTests.cpp b/tests/ctests/LoadTests.cpp index 78c4383..a5f0c69 100644 --- a/tests/ctests/LoadTests.cpp +++ b/tests/ctests/LoadTests.cpp @@ -1,6 +1,6 @@ #include "gtest/gtest.h" -#include "Load.h" +#include "ale/Load.h" #include <stdexcept> diff --git a/tests/ctests/OrientationsTests.cpp b/tests/ctests/OrientationsTests.cpp index 3c39252..6eb56fc 100644 --- a/tests/ctests/OrientationsTests.cpp +++ b/tests/ctests/OrientationsTests.cpp @@ -1,6 +1,6 @@ #include "gtest/gtest.h" -#include "Orientations.h" +#include "ale/Orientations.h" #include <cmath> #include <exception> diff --git a/tests/ctests/RotationTests.cpp b/tests/ctests/RotationTests.cpp index 37636fd..f143070 100644 --- a/tests/ctests/RotationTests.cpp +++ b/tests/ctests/RotationTests.cpp @@ -1,6 +1,6 @@ #include "gtest/gtest.h" -#include "Rotation.h" +#include "ale/Rotation.h" #include <cmath> #include <exception> diff --git a/tests/ctests/StatesTests.cpp b/tests/ctests/StatesTests.cpp index d4ccdf3..25ca539 100644 --- a/tests/ctests/StatesTests.cpp +++ b/tests/ctests/StatesTests.cpp @@ -3,8 +3,8 @@ #include <cmath> #include <exception> -#include "States.h" -#include "Vectors.h" +#include "ale/States.h" +#include "ale/Vectors.h" using namespace std; using namespace ale; diff --git a/tests/ctests/TestInterpUtils.cpp b/tests/ctests/TestInterpUtils.cpp index c1f8453..457a70c 100644 --- a/tests/ctests/TestInterpUtils.cpp +++ b/tests/ctests/TestInterpUtils.cpp @@ -1,6 +1,6 @@ #include "gmock/gmock.h" -#include "InterpUtils.h" +#include "ale/InterpUtils.h" #include <cmath> #include <exception> -- GitLab