From 85dd16d9c0264452953bb01226108995066b49b5 Mon Sep 17 00:00:00 2001 From: Fabien Castan Date: Wed, 18 Aug 2021 10:25:44 +0200 Subject: [PATCH] [sfmDataIO] use integers for versions --- .../localization/LocalizationResult.cpp | 10 ++++++--- src/aliceVision/numeric/numeric.hpp | 5 ++++- src/aliceVision/sfmDataIO/jsonIO.cpp | 12 ++++++---- src/aliceVision/version.hpp | 22 ++++++++++++++----- 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/aliceVision/localization/LocalizationResult.cpp b/src/aliceVision/localization/LocalizationResult.cpp index b0491be695..f07cca70d8 100644 --- a/src/aliceVision/localization/LocalizationResult.cpp +++ b/src/aliceVision/localization/LocalizationResult.cpp @@ -160,7 +160,7 @@ void LocalizationResult::load(std::vector& localizationResul // empty output vector localizationResults.clear(); - Vec3 version; + Version version; // main tree bpt::ptree fileTree; @@ -169,7 +169,11 @@ void LocalizationResult::load(std::vector& localizationResul bpt::read_json(filename, fileTree); // version - sfmDataIO::loadMatrix("version", version, fileTree); + { + Vec3i v; + sfmDataIO::loadMatrix("version", v, fileTree); + version = v; + } if(fileTree.count("localizationResults")) { @@ -251,7 +255,7 @@ void LocalizationResult::save(const std::vector& localizatio { using namespace aliceVision::sfm; - const Vec3 version = {1, 0, 0}; + const Vec3i version = {1, 0, 0}; // main tree bpt::ptree fileTree; diff --git a/src/aliceVision/numeric/numeric.hpp b/src/aliceVision/numeric/numeric.hpp index 214805ad86..1475c13e95 100644 --- a/src/aliceVision/numeric/numeric.hpp +++ b/src/aliceVision/numeric/numeric.hpp @@ -69,9 +69,12 @@ using Eigen::Map; using EigenDoubleTraits = Eigen::NumTraits; using Vec3 = Eigen::Vector3d; +using Vec3i = Eigen::Vector3i; +using Vec3f = Eigen::Vector3f; + using Vec2i = Eigen::Vector2i; using Vec2f = Eigen::Vector2f; -using Vec3f = Eigen::Vector3f; + using Vec9 = Eigen::Matrix; using Quaternion = Eigen::Quaternion; diff --git a/src/aliceVision/sfmDataIO/jsonIO.cpp b/src/aliceVision/sfmDataIO/jsonIO.cpp index adebe20fa6..42a7a39d04 100644 --- a/src/aliceVision/sfmDataIO/jsonIO.cpp +++ b/src/aliceVision/sfmDataIO/jsonIO.cpp @@ -163,7 +163,7 @@ void loadIntrinsic(const Version & version, IndexT& intrinsicId, std::shared_ptr // Focal length Vec2 pxFocalLength; - if (version < Version(1,2,0)) // version < 1.2 + if (version < Version(1,2,0)) { pxFocalLength(0) = intrinsicTree.get("pxFocalLength", -1); // Only one focal value for X and Y in previous versions @@ -332,7 +332,7 @@ void loadLandmark(IndexT& landmarkId, sfmData::Landmark& landmark, bpt::ptree& l bool saveJSON(const sfmData::SfMData& sfmData, const std::string& filename, ESfMData partFlag) { - const Vec3 version = {ALICEVISION_SFMDATAIO_VERSION_MAJOR, ALICEVISION_SFMDATAIO_VERSION_MINOR, ALICEVISION_SFMDATAIO_VERSION_REVISION}; + const Vec3i version = {ALICEVISION_SFMDATAIO_VERSION_MAJOR, ALICEVISION_SFMDATAIO_VERSION_MINOR, ALICEVISION_SFMDATAIO_VERSION_REVISION}; // save flags const bool saveViews = (partFlag & VIEWS) == VIEWS; @@ -464,7 +464,7 @@ bool saveJSON(const sfmData::SfMData& sfmData, const std::string& filename, ESfM bool loadJSON(sfmData::SfMData& sfmData, const std::string& filename, ESfMData partFlag, bool incompleteViews, EViewIdMethod viewIdMethod, const std::string& viewIdRegex) { - Vec3 version; + Version version; // load flags const bool loadViews = (partFlag & VIEWS) == VIEWS; @@ -482,7 +482,11 @@ bool loadJSON(sfmData::SfMData& sfmData, const std::string& filename, ESfMData p bpt::read_json(filename, fileTree); // version - loadMatrix("version", version, fileTree); + { + Vec3i v; + loadMatrix("version", v, fileTree); + version = v; + } // folders if(fileTree.count("featuresFolders")) diff --git a/src/aliceVision/version.hpp b/src/aliceVision/version.hpp index df317bf9d0..509bcd0c14 100644 --- a/src/aliceVision/version.hpp +++ b/src/aliceVision/version.hpp @@ -26,17 +26,29 @@ namespace aliceVision { class Version { public: - Version(const Vec3 & v) : _v(v) + Version() + : _v(Vec3i::Zero()) + {} + + explicit Version(const Vec3i & v) + : _v(v) { } - - Version(int major, int minor, int micro) : _v(major, minor, micro) + + Version(int major, int minor, int micro) + : _v(major, minor, micro) + { + } + + Version& operator=(const Vec3i& other) { + _v = other; + return *this; } bool operator<(const Version& other) const { - for (Vec3::Index i = 0; i < 3; i++) + for (Vec3i::Index i = 0; i < 3; i++) { if (_v[i] < other._v[i]) { @@ -53,7 +65,7 @@ class Version } private: - Vec3 _v; + Vec3i _v; }; } \ No newline at end of file