/** * @RDE_HEADER@ * Unittest * $Id$ * $HeadURL$ * $Author$ */ #include "elevation_unit_test.h" #include #include #include #include #include Q_DECLARE_METATYPE(LtsUtils::QPoint3D); Q_DECLARE_METATYPE(LtsElevation::LineOfSight); #include static const int s_id{4711}; static LtsElevation::LtsElevationManager *s_eleMgr{nullptr}; //------------------------------------------------------------------------------ // class MyLtsElevationManagerBootStrap //------------------------------------------------------------------------------ // hack: do not use dtcs. // Use this class to get access to ElevationMapManager::init(); class MyLtsElevationManagerBootstrap : public LtsElevation::LtsElevationManager { using BaseClass = LtsElevation::LtsElevationManager; public: static LtsElevationManager *createInstanceUnitTest(int id, const QStringList &filePaths_rough_to_fine) { return BaseClass::createInstanceUnitTest(id, filePaths_rough_to_fine); } }; //------------------------------------------------------------------------------ // class UnitTestElevation //------------------------------------------------------------------------------ UnitTestElevation::UnitTestElevation() : m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTestElevation")) {} void UnitTestElevation::initTestCase() { // ll /usr/share/arcgis/resources/elevation/ QString filePath(QStringLiteral("/usr/share/arcgis/resources/elevation/Altmark_dt1.tif")); s_eleMgr = MyLtsElevationManagerBootstrap::createInstanceUnitTest(s_id, {filePath}); const bool bIsValid = s_eleMgr->isValid(); std::cerr << "myBootstrapMgr->isValid() 1 = " << bIsValid << std::endl; // we have to wait for loading to be finished: { s_eleMgr->waitForInitialization(); const bool bIsValid = s_eleMgr->isValid(); std::cerr << "myBootstrapMgr->isValid() 2 = " << bIsValid << std::endl; } } void UnitTestElevation::init() { QVERIFY2(s_eleMgr , "static LtsElevationManager does not exist"); } // Elevation // Elevation // Elevation void UnitTestElevation::test_elevation_data() { QTest::addColumn("lonLat"); QTest::addColumn("elevationRef"); // Altmark_dt1.tif: QTest::newRow("elevation 1 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 70000 10000")).geographic() << 75.0; QTest::newRow("elevation 2 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 72000 13000")).geographic() << 80.0; // 32U PD 77000 19000 is in the city of schnoeggersburg. // Altmark_dt1.tif: // 2022-08-02_Schnoeggersburg_3D-18-A317_DGM_EPSG4326_float32.tif should have different data: QTest::newRow("elevation 3 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 76925 18625")).geographic() << 92.0; } void UnitTestElevation::test_elevation() { QFETCH(QPointF, lonLat); QFETCH(double, elevationRef); double elevation = s_eleMgr->elevation(lonLat.x(), lonLat.y()); QVERIFY2(qFuzzyCompare(elevationRef, elevation), " got wrong elevation result"); } void UnitTestElevation::test_elevation_isCovered() { const QPointF &lonLat1 = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 70000 10000")).geographic(); const QPointF &lonLat2 = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U MD 60000 10000")).geographic(); const double defaultElevationValue = -123; { bool bIsCovered = false; s_eleMgr->elevation(lonLat1.x(), lonLat1.y(), defaultElevationValue, &bIsCovered); QVERIFY2(bIsCovered, " error on bIsCovered"); } { bool bIsCovered = true; s_eleMgr->elevation(lonLat2.x(), lonLat2.y(), defaultElevationValue, &bIsCovered); QVERIFY2(!bIsCovered, " error on bIsCovered"); } } void UnitTestElevation::test_elevation_defaultValue() { const QPointF &lonLat = LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 60000 10000")).geographic(); double elevation = s_eleMgr->elevation(lonLat.x(), lonLat.y()); QVERIFY2(qFuzzyCompare(elevation, std::numeric_limits::min()), " error on defaultValue"); { const double defaultValue = 100; elevation = s_eleMgr->elevation(lonLat.x(), lonLat.y(), defaultValue); QVERIFY2(qFuzzyCompare(elevation, defaultValue), " error on defaultValue"); } { const double defaultValue = std::numeric_limits::max(); elevation = s_eleMgr->elevation(lonLat.x(), lonLat.y(), defaultValue); QVERIFY2(qFuzzyCompare(elevation, defaultValue), " error on defaultValue"); } } // LineOfSight // LineOfSight // LineOfSight void UnitTestElevation::test_lineOfSightCalculation_data() { QTest::addColumn("startGeo2D"); QTest::addColumn("startObjH"); QTest::addColumn("endGeo2D"); QTest::addColumn("endObjH"); QTest::addColumn("expectedResult"); // LineOfSight::LOS_VISIBLE // 32U PD 60000 10000 not covered by Altmark_dt1.tif: QTest::newRow("losDataset 1 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 60000 10000")).geographic() << 1.0 << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 60000 60000")).geographic() << 1.0 << LtsElevation::LineOfSight::LOS_ERROR; // there is a hill between both coordinates, and startObjH, endObjH are very small -> LOS_INVISIBLE QTest::newRow("losDataset 2 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 1.0 << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 1.0 << LtsElevation::LineOfSight::LOS_INVISIBLE; // there is a hill between both coordinates, and startObjH, endObjH are rel high -> LOS_VISIBLE QTest::newRow("losDataset 3 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 20.0 << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 20.0 << LtsElevation::LineOfSight::LOS_VISIBLE; // check same coordinates, but different z values: QTest::newRow("losDataset 4 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << -1.0 << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 1.0 << LtsElevation::LineOfSight::LOS_ERROR; QTest::newRow("losDataset 5 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 1.0 << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << -1.0 << LtsElevation::LineOfSight::LOS_ERROR; QTest::newRow("losDataset 6 ") << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77200 17600")).geographic() << 0.0 << LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32U PD 77600 17600")).geographic() << 0.0 << LtsElevation::LineOfSight::LOS_INVISIBLE; } void UnitTestElevation::test_lineOfSightCalculation() { QFETCH(QPointF, startGeo2D); QFETCH(double, startObjH); QFETCH(QPointF, endGeo2D); QFETCH(double, endObjH); QFETCH(LtsElevation::LineOfSight, expectedResult); LtsUtils::QPoint3D start3D = LtsUtils::QPoint3D::fromQPointF(startGeo2D); start3D.rz() = startObjH; start3D.rz() += s_eleMgr->elevation(start3D.x(), start3D.y()); LtsUtils::QPoint3D end3D = LtsUtils::QPoint3D::fromQPointF(endGeo2D); end3D.rz() = endObjH; end3D.rz() += s_eleMgr->elevation(end3D.x(), end3D.y()); LtsElevation::LineOfSight los = s_eleMgr->lineOfSightCalculation(start3D, end3D); NOTICE_LOG(m_logger) << "los = " << los; { LtsElevation::LineOfSight los2 = s_eleMgr->lineOfSightCalculation(startGeo2D, startObjH, endGeo2D, endObjH); QVERIFY2(los == los2, " got different lineOfSightCalculation result"); } QVERIFY2(los == expectedResult, " got lineOfSightCalculation result"); } // main // main // main int main(int argc, char *argv[]) { NGLCoreApplication app(argc, argv); app.createLogger("UnitTestElevation", "log4cxxElevationUnitTest.props"); UnitTestElevation tc; int ret = QTest::qExec(&tc, argc, argv); // cleanup: if (s_eleMgr) { s_eleMgr->cleanupAll(); } return ret; }