diff --git a/include/helper.h b/include/helper.h index 9634afdc7feff94ddb7ce587904353bcda05987d..bed375d9525f0d19116de1942d17d9eac4fd9799 100644 --- a/include/helper.h +++ b/include/helper.h @@ -292,6 +292,8 @@ inline clock_t getElapsedTime() lastTime = clock(); return diffTime; } +bool lessThanVersion(const QString &q1, const QString &q2); + /** * Computes the median of the values in a given vector. diff --git a/src/helper.cpp b/src/helper.cpp index eaccacfd50ff2b0de8c23f533dab2d96acaf62fb..cbaeb0f90baeabba932a3d8475212162247e119f 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -186,3 +186,56 @@ cv::Mat getRoi(cv::Mat &img, const QRect &roi, cv::Rect &rect, bool evenPixelNum return img(rect); } +#include <iostream> +#include <vector> +/** + * @brief Compares two PeTrack version strings and returns if the first version string is newer than the second one + * + * @param q1: first PeTrack version string + * @param q2: second PeTrack version string + * @throws std::invalid_argument Thrown if one of the input strings is not in the right format + * @return boolean, whether the first version is higher than the second one + */ +bool lessThanVersion(const QString &q1, const QString &q2) +{ + QStringList version1 = q1.split(QLatin1Char('.')); + QStringList version2 = q2.split(QLatin1Char('.')); + std::vector<int> version1_digits; + std::vector<int> version2_digits; + + for(int i = 0; i < version1.length(); ++i) + { + if(version1[i].length() == 1 && version1[i][0].isDigit()) + { + version1_digits.push_back(version1[i].toInt()); + } + else + { + throw std::invalid_argument("Invalid Input String!"); + } + } + for(int i = 0; i < version2.length(); ++i) + { + if(version2[i].length() == 1 && version2[i][0].isDigit()) + { + version2_digits.push_back(version2[i].toInt()); + } + else + { + throw std::invalid_argument("Invalid Input String!"); + } + } + int length = std::min(version1_digits.size(), version2_digits.size()); + for(int i = 0; i < length; ++i) + { + if(version1_digits[i] > version2_digits[i]) + { + return true; + } + else if(version1_digits[i] < version2_digits[i]) + { + return false; + } + } + return version1_digits.size() > version2_digits.size(); +} diff --git a/src/petrack.cpp b/src/petrack.cpp index 603f70e090009e4b25003307670ce84f1fb7a347..169a7e6aae89e9437c352b226e9f2a2157df157f 100644 --- a/src/petrack.cpp +++ b/src/petrack.cpp @@ -34,6 +34,7 @@ #include "colorRangeWidget.h" #include "control.h" #include "gridItem.h" +#include "helper.h" #include "imageItem.h" #include "logoItem.h" #include "moCapItem.h" @@ -652,16 +653,16 @@ void Petrack::openProject(QString fileName, bool openSeq) // default fileName="" openXml(doc, openSeq); mLastTrackerExport = mTrcFileName; - if(mControlWidget->getCalibS1Value() == 0 && mControlWidget->getCalibS2Value() == 0 && - mControlWidget->getCalibS3Value() == 0 && mControlWidget->getCalibS4Value() == 0 && - mControlWidget->getCalibTAUXValue() == 0 && mControlWidget->getCalibTAUYValue() == 0) + if(!lessThanVersion(root.attribute("VERSION"), QString("0.9.0"))) { PWarning( this, tr("PeTrack"), - tr("You are using an old project! Therefore the old intr. calibration model is set the default")); + tr("You are using a project version lower than 0.9: Therefore, the extended intrinsic calibration " + "model is disabled.")); mControlWidget->setNewModelChecked(false); } + updateWindowTitle(); } } diff --git a/tests/unit_test/CMakeLists.txt b/tests/unit_test/CMakeLists.txt index 558dec9661301f10cfd5eb60c4cc716d515e6c3f..30e66a31d636551286b9ab48362e9b81372891f9 100644 --- a/tests/unit_test/CMakeLists.txt +++ b/tests/unit_test/CMakeLists.txt @@ -9,5 +9,6 @@ target_sources(petrack_tests PRIVATE tst_moCapController.cpp tst_recognition.cpp tst_codeMarkerWidget.cpp + tst_helper.cpp tst_petrack.cpp ) diff --git a/tests/unit_test/tst_helper.cpp b/tests/unit_test/tst_helper.cpp new file mode 100644 index 0000000000000000000000000000000000000000..83d2d6afafb0046fb9ad668b70327ca373b0d189 --- /dev/null +++ b/tests/unit_test/tst_helper.cpp @@ -0,0 +1,49 @@ +/* + * PeTrack - Software for tracking pedestrians movement in videos + * Copyright (C) 2010-2021 Forschungszentrum Jülich GmbH, + * Maik Boltes, Juliane Adrian, Ricardo Martin Brualla, Arne Graf, Paul Häger, Daniel Hillebrand, + * Deniz Kilic, Paul Lieberenz, Daniel Salden, Tobias Schrödter, Ann Katrin Seemann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#include "helper.h" + +#include <catch2/catch.hpp> + + +TEST_CASE("Petrack version strings are compared", "[lessThanVersion]") +{ + CHECK(lessThanVersion(QString("0.9.1"), QString("0.9.0"))); + CHECK(lessThanVersion(QString("0.9.0"), QString("0.8.0"))); + CHECK(lessThanVersion(QString("1.8.0"), QString("0.9.0"))); + CHECK(lessThanVersion(QString("0.9.1.1"), QString("0.9.0"))); + CHECK(lessThanVersion(QString("0.9.0.0"), QString("0.9.0"))); + + CHECK_FALSE(lessThanVersion(QString("0.9.0"), QString("0.9.1"))); + CHECK_FALSE(lessThanVersion(QString("0.8.0"), QString("0.9.0"))); + CHECK_FALSE(lessThanVersion(QString("0.9.0"), QString("1.9.0"))); + CHECK_FALSE(lessThanVersion(QString("0.9.0"), QString("0.9.1.1"))); + CHECK_FALSE(lessThanVersion(QString("0.9.0.1"), QString("0.9.1"))); + CHECK_FALSE(lessThanVersion(QString("0.9.0"), QString("0.9.0.0"))); + CHECK_FALSE(lessThanVersion(QString("0.9.0"), QString("0.9.0"))); + + CHECK_THROWS(lessThanVersion(QString("0.8.k"), QString("0.9.0"))); + CHECK_THROWS(lessThanVersion(QString("0.8.9"), QString("0.9.k"))); + CHECK_THROWS(lessThanVersion(QString("0.k.9"), QString("0.9.0"))); + CHECK_THROWS(lessThanVersion(QString("0.8.9"), QString("0.k.9"))); + CHECK_THROWS(lessThanVersion(QString("k.8.9"), QString("0.9.0"))); + CHECK_THROWS(lessThanVersion(QString("0.8.9"), QString("k.9.0"))); + CHECK_THROWS(lessThanVersion(QString("0.8.9"), QString("k.9.0"))); +}