Skip to content

Commit

Permalink
[sfmDataIO] use integers for versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiencastan committed Aug 18, 2021
1 parent 42048fb commit 85dd16d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
10 changes: 7 additions & 3 deletions src/aliceVision/localization/LocalizationResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void LocalizationResult::load(std::vector<LocalizationResult>& localizationResul
// empty output vector
localizationResults.clear();

Vec3 version;
Version version;

// main tree
bpt::ptree fileTree;
Expand All @@ -169,7 +169,11 @@ void LocalizationResult::load(std::vector<LocalizationResult>& 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"))
{
Expand Down Expand Up @@ -251,7 +255,7 @@ void LocalizationResult::save(const std::vector<LocalizationResult>& localizatio
{
using namespace aliceVision::sfm;

const Vec3 version = {1, 0, 0};
const Vec3i version = {1, 0, 0};

// main tree
bpt::ptree fileTree;
Expand Down
5 changes: 4 additions & 1 deletion src/aliceVision/numeric/numeric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ using Eigen::Map;
using EigenDoubleTraits = Eigen::NumTraits<double>;

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<double, 9, 1>;

using Quaternion = Eigen::Quaternion<double>;
Expand Down
12 changes: 8 additions & 4 deletions src/aliceVision/sfmDataIO/jsonIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>("pxFocalLength", -1);
// Only one focal value for X and Y in previous versions
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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"))
Expand Down
22 changes: 17 additions & 5 deletions src/aliceVision/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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])
{
Expand All @@ -53,7 +65,7 @@ class Version
}

private:
Vec3 _v;
Vec3i _v;
};

}

0 comments on commit 85dd16d

Please sign in to comment.