231 lines
7.4 KiB
C++
Executable File
231 lines
7.4 KiB
C++
Executable File
|
|
|
|
|
|
#include "elevation_unit_test.h"
|
|
|
|
#include <ElevationMap/elevation_map_manager.h>
|
|
#include <LtsCoordTrans/lts_coord_trans.h>
|
|
|
|
#include <nglapplication/nglcoreapplication.h>
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
#include <QtTest/QTest>
|
|
|
|
|
|
Q_DECLARE_METATYPE(LtsUtils::QPoint3D);
|
|
Q_DECLARE_METATYPE(LtsElevation::LineOfSight);
|
|
|
|
#include <iostream>
|
|
|
|
static const int s_id{4711};
|
|
static LtsElevation::LtsElevationManager *s_eleMgr{nullptr};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
UnitTestElevation::UnitTestElevation()
|
|
: m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("UnitTestElevation"))
|
|
{}
|
|
|
|
|
|
void UnitTestElevation::initTestCase()
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
{
|
|
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");
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnitTestElevation::test_elevation_data()
|
|
{
|
|
QTest::addColumn<QPointF>("lonLat");
|
|
QTest::addColumn<double>("elevationRef");
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
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<double>::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<double>::max();
|
|
elevation = s_eleMgr->elevation(lonLat.x(), lonLat.y(), defaultValue);
|
|
QVERIFY2(qFuzzyCompare(elevation, defaultValue), " error on defaultValue");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnitTestElevation::test_lineOfSightCalculation_data()
|
|
{
|
|
QTest::addColumn<QPointF>("startGeo2D");
|
|
QTest::addColumn<double>("startObjH");
|
|
QTest::addColumn<QPointF>("endGeo2D");
|
|
QTest::addColumn<double>("endObjH");
|
|
QTest::addColumn<LtsElevation::LineOfSight>("expectedResult");
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
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;
|
|
|
|
|
|
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;
|
|
|
|
|
|
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");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
NGLCoreApplication app(argc, argv);
|
|
app.createLogger("UnitTestElevation", "log4cxxElevationUnitTest.props");
|
|
|
|
UnitTestElevation tc;
|
|
|
|
int ret = QTest::qExec(&tc, argc, argv);
|
|
|
|
|
|
if (s_eleMgr)
|
|
{
|
|
s_eleMgr->cleanupAll();
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
|