From 8da80f36f871e393b3a63abb5406266842cab445 Mon Sep 17 00:00:00 2001 From: Guillaume Pasero <guillaume.pasero@c-s.fr> Date: Fri, 1 Feb 2019 15:46:03 +0100 Subject: [PATCH] ENH: use tolerance on layer extent check --- Modules/IO/TestKernel/include/otbTestHelper.h | 4 ++- Modules/IO/TestKernel/src/otbTestHelper.cxx | 26 ++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Modules/IO/TestKernel/include/otbTestHelper.h b/Modules/IO/TestKernel/include/otbTestHelper.h index fe7c39636c..7cb7b0c308 100644 --- a/Modules/IO/TestKernel/include/otbTestHelper.h +++ b/Modules/IO/TestKernel/include/otbTestHelper.h @@ -161,7 +161,7 @@ private: void ogrReportOnLayer(OGRLayer * ref_poLayer, const char *ref_pszWHERE, OGRGeometry *ref_poSpatialFilter, OGRLayer * test_poLayer, const char *test_pszWHERE, OGRGeometry *test_poSpatialFilter, - int& nbdiff) const; + int& nbdiff, double epsilon) const; static void DumpOGRFeature(FILE* fileid, OGRFeature* feature, char** papszOptions = nullptr); static void DumpOGRGeometry(FILE* fileid, OGRGeometry* geometry, const char * pszPrefix, char** papszOptions = nullptr); @@ -175,6 +175,8 @@ private: void AddWhiteSpace(const std::string& strIn, std::string &strOut) const; + void CheckValueTolerance(const char *Comment, double ref, double test, int &count, bool report, double epsilon) const; + std::vector<std::pair<std::string, std::string> > m_SpecialTokens; }; } diff --git a/Modules/IO/TestKernel/src/otbTestHelper.cxx b/Modules/IO/TestKernel/src/otbTestHelper.cxx index 5f47f2f3c7..e44e24d1d0 100644 --- a/Modules/IO/TestKernel/src/otbTestHelper.cxx +++ b/Modules/IO/TestKernel/src/otbTestHelper.cxx @@ -92,6 +92,19 @@ namespace otb { +void TestHelper::CheckValueTolerance(const char *comment, double ref, double test, int &count, bool report, double epsilon) const +{ + double norm = (std::abs(ref) + std::abs(test))/2; + if (norm > m_EpsilonBoundaryChecking && (std::abs(ref-test) > epsilon * norm)) + { + count++; + if (report) + { + otbPrintDiff(comment, ref, test); + } + } +} + int TestHelper::RegressionTestAllImages(const StringList& baselineFilenamesImage, const StringList& testFilenamesImage) { @@ -1847,7 +1860,7 @@ int TestHelper::RegressionTestOgrFile(const char *testOgrFilename, const char *b } //Check Layer inforamtion - ogrReportOnLayer(ref_poLayer, nullptr, nullptr, test_poLayer, nullptr, nullptr, nbdiff); + ogrReportOnLayer(ref_poLayer, nullptr, nullptr, test_poLayer, nullptr, nullptr, nbdiff, toleranceDiffValue); //If no difference, check the feature if (nbdiff == 0) @@ -2534,7 +2547,8 @@ void TestHelper::ogrReportOnLayer(OGRLayer * ref_poLayer, OGRLayer * test_poLayer, const char *test_pszWHERE, OGRGeometry *test_poSpatialFilter, - int& nbdiff) const + int& nbdiff, + double epsilon) const { OGRFeatureDefn *ref_poDefn = ref_poLayer->GetLayerDefn(); @@ -2573,10 +2587,10 @@ void TestHelper::ogrReportOnLayer(OGRLayer * ref_poLayer, if (ref_poLayer->GetExtent(&ref_oExt, TRUE) == OGRERR_NONE) { - otbCheckValue("Extent: MinX", ref_oExt.MinX, test_oExt.MinX, nbdiff, m_ReportErrors); - otbCheckValue("Extent: MinY", ref_oExt.MinY, test_oExt.MinY, nbdiff, m_ReportErrors); - otbCheckValue("Extent: MaxX", ref_oExt.MaxX, test_oExt.MaxX, nbdiff, m_ReportErrors); - otbCheckValue("Extent: MaxY", ref_oExt.MaxY, test_oExt.MaxY, nbdiff, m_ReportErrors); + CheckValueTolerance("Extent: MinX", ref_oExt.MinX, test_oExt.MinX, nbdiff, m_ReportErrors, epsilon); + CheckValueTolerance("Extent: MinY", ref_oExt.MinY, test_oExt.MinY, nbdiff, m_ReportErrors, epsilon); + CheckValueTolerance("Extent: MaxX", ref_oExt.MaxX, test_oExt.MaxX, nbdiff, m_ReportErrors, epsilon); + CheckValueTolerance("Extent: MaxY", ref_oExt.MaxY, test_oExt.MaxY, nbdiff, m_ReportErrors, epsilon); } char *ref_pszWKT; -- GitLab