Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
No files matched your search
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
NGL_ADD_LIBRARY2(WS SV HLA LtsElevation SHARED
|
||||
lts_elevation_manager.cpp
|
||||
lts_elevation_manager.h
|
||||
logger.cpp
|
||||
logger.h
|
||||
)
|
||||
NGL_TARGET_INCLUDE_DIRECTORIES(LtsElevation
|
||||
INTERFACE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../
|
||||
)
|
||||
NGL_TARGET_LINK_LIBRARIES(LtsElevation
|
||||
PRIVATE
|
||||
NGLLogger
|
||||
## LtsSessionDataDds
|
||||
AsmDataPluginInterface
|
||||
ExmDataPluginInterface
|
||||
situationMapCommon
|
||||
situationMapElevationMap
|
||||
PUBLIC
|
||||
LtsUtilsCoreHeaderOnly
|
||||
Qt5::Core
|
||||
)
|
||||
|
||||
ADD_SUBDIRECTORY(UnitTest_Elevation)
|
||||
@@ -0,0 +1,29 @@
|
||||
#
|
||||
# @RDE_HEADER@
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
#
|
||||
|
||||
SET(UnitTestSources
|
||||
elevation_unit_test.cpp
|
||||
elevation_unit_test.h
|
||||
)
|
||||
|
||||
IF(BUILD_TESTING)
|
||||
ADD_EXECUTABLE(commenUnitTestElevation ${LinkedSources} ${UnitTestSources} )
|
||||
|
||||
TARGET_LINK_LIBRARIES(commenUnitTestElevation
|
||||
NGLLogger
|
||||
nglcoreapplication
|
||||
LtsElevation
|
||||
LtsCoordTrans
|
||||
situationMapCommon
|
||||
situationMapElevationMap
|
||||
Qt5::Core
|
||||
Qt5::Gui
|
||||
Qt5::Test)
|
||||
|
||||
ADD_TEST(NAME commenUnitTestElevation COMMAND $<TARGET_FILE:commenUnitTestElevation>)
|
||||
|
||||
ENDIF()
|
||||
@@ -0,0 +1,230 @@
|
||||
|
||||
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LtsElevation/lts_elevation_manager.h>
|
||||
|
||||
#include <ElevationMap/elevation_map_manager.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QtTest/QTest>
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
|
||||
using LOGGER_T = NGL::INGLLogger&;
|
||||
|
||||
|
||||
|
||||
|
||||
class UnitTestElevation : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
UnitTestElevation();
|
||||
|
||||
|
||||
private Q_SLOTS:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void initTestCase();
|
||||
|
||||
void init();
|
||||
|
||||
|
||||
|
||||
|
||||
void test_elevation_data();
|
||||
void test_elevation();
|
||||
|
||||
void test_elevation_isCovered();
|
||||
void test_elevation_defaultValue();
|
||||
|
||||
void test_lineOfSightCalculation_data();
|
||||
void test_lineOfSightCalculation();
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
namespace LtsElevation
|
||||
{
|
||||
|
||||
LOGGER_T getLogger(const char *name)
|
||||
{
|
||||
static const char ns[] = "Lts.Elevation.";
|
||||
std::string loggerName;
|
||||
const size_t len = strlen(name);
|
||||
loggerName.reserve(sizeof(ns) + len);
|
||||
loggerName.append(ns, sizeof(ns) - 1);
|
||||
loggerName.append(name, len);
|
||||
|
||||
try
|
||||
{
|
||||
return NGL::NGLLoggerBootstrap::getNGLRootLogger().
|
||||
getNGLLogger(loggerName);
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
fprintf(stderr, "Error retrieving logger: %s", ex.what());
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <NGLLogger/INGLLogger.h>
|
||||
|
||||
namespace LtsElevation
|
||||
{
|
||||
typedef NGL::INGLLogger &LOGGER_T;
|
||||
|
||||
LOGGER_T getLogger(const char *name);
|
||||
inline LOGGER_T getLogger(const QString &loggerName)
|
||||
{
|
||||
return getLogger(loggerName.toUtf8().constData());
|
||||
}
|
||||
}
|
||||
+510
@@ -0,0 +1,510 @@
|
||||
|
||||
|
||||
|
||||
#include "lts_elevation_manager.h"
|
||||
#include <Plugins/ExerciseManagement/exm_data_plugin_interface.h>
|
||||
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
|
||||
|
||||
#include <Viewer/SituationMap/ElevationMap/elevation_map_manager.h>
|
||||
#include <Viewer/SituationMap/Common/resource_path.h>
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include <QDir>
|
||||
#include <QUrl>
|
||||
#include <QHash>
|
||||
|
||||
|
||||
|
||||
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_UNDEFINED == (int)LtsElevation::LineOfSight::LOS_UNDEFINED, "LineOfSight mismatch");
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_ERROR == (int)LtsElevation::LineOfSight::LOS_ERROR, "LineOfSight mismatch");
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_VISIBLE == (int)LtsElevation::LineOfSight::LOS_VISIBLE, "LineOfSight mismatch");
|
||||
static_assert((int)SituationMap::ElevationMapManager::LineOfSight::LOS_INVISIBLE == (int)LtsElevation::LineOfSight::LOS_INVISIBLE, "LineOfSight mismatch");
|
||||
|
||||
namespace LtsElevation
|
||||
{
|
||||
class LtsElevationManager;
|
||||
|
||||
|
||||
|
||||
using LtsElevatioMgrMapTrainingAreaId = QMap<int, LTS_ELEVATION_MANAGER_TYPE>;
|
||||
|
||||
|
||||
static LtsElevatioMgrMapTrainingAreaId <sElevatioMgrMapTrainingAreaId()
|
||||
{
|
||||
static LtsElevatioMgrMapTrainingAreaId s_ltsElevatioMgrMapTrainingAreaId;
|
||||
return s_ltsElevatioMgrMapTrainingAreaId;
|
||||
}
|
||||
|
||||
static void cleanupLtsElevatioMgrMapTrainingAreaId()
|
||||
{
|
||||
qDeleteAll(ltsElevatioMgrMapTrainingAreaId());
|
||||
ltsElevatioMgrMapTrainingAreaId().clear();
|
||||
}
|
||||
|
||||
LtsElevatioMgrMapTrainingAreaId &getLtsElevationMgrMapTrainingAreaId()
|
||||
{
|
||||
if (ltsElevatioMgrMapTrainingAreaId().isEmpty())
|
||||
qAddPostRoutine(cleanupLtsElevatioMgrMapTrainingAreaId);
|
||||
|
||||
return ltsElevatioMgrMapTrainingAreaId();
|
||||
}
|
||||
|
||||
static long s_counter{0};
|
||||
|
||||
|
||||
|
||||
|
||||
class LtsElevationManager::Private
|
||||
{
|
||||
public:
|
||||
Private() = default;
|
||||
~Private()
|
||||
{
|
||||
delete m_elevationManager;
|
||||
}
|
||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> m_exmDtc;
|
||||
std::shared_ptr<AssetManagement::Interface::Dtc> m_asmDtc;
|
||||
|
||||
QStringList m_filePaths_rough_to_fine;
|
||||
SituationMap::ElevationMapManager *m_elevationManager{nullptr};
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
LtsElevationManager::LtsElevationManager()
|
||||
: QObject(nullptr)
|
||||
, d(new Private)
|
||||
, m_logger(getLogger("LtsElevationManager"))
|
||||
{
|
||||
++s_counter;
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START, s_counter=" << s_counter << " this=" << this;
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END, s_counter=" << s_counter << " this=" << this;
|
||||
}
|
||||
|
||||
LtsElevationManager::~LtsElevationManager()
|
||||
{
|
||||
--s_counter;
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START, s_counter=" << s_counter << " this=" << this;
|
||||
delete d;
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END, s_counter=" << s_counter << " this=" << this;
|
||||
}
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstance(int exerciseId,
|
||||
const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc)
|
||||
{
|
||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||
TRACE_LOG(logger) << LOGFUNCTION << " START, exerciseId=" << exerciseId;
|
||||
|
||||
if (exerciseId < 0)
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " exerciseId invalid, exerciseId=" << exerciseId;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int trainingAreaId = -1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static QHash<int,int> s_exIdToTaIdStore;
|
||||
|
||||
const auto exTaIt = s_exIdToTaIdStore.find(exerciseId);
|
||||
if (exTaIt != s_exIdToTaIdStore.end())
|
||||
{
|
||||
|
||||
|
||||
trainingAreaId = *exTaIt;
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
|
||||
if (!exmDtc || !asmDtc)
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " no dtcs for exerciseId=" << exerciseId
|
||||
<< ", asmDtc=" << asmDtc
|
||||
<< ", exmDtc=" << exmDtc;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
trainingAreaId = exerciseIdToTrainingAreaId(exerciseId, exmDtc);
|
||||
if (trainingAreaId <= 0)
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " Error getting trainingAreaId"
|
||||
<< ", exerciseId=" << exerciseId
|
||||
<< ", trainingAreaId=" << trainingAreaId;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
s_exIdToTaIdStore[exerciseId] = trainingAreaId;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE temp = createInstanceForTrainingAreaId(trainingAreaId, asmDtc);
|
||||
if (!temp)
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " Error on createInstanceForTrainingAreaId"
|
||||
<< ", exerciseId=" << exerciseId
|
||||
<< ", trainingAreaId=" << trainingAreaId;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
temp->initDDS(exmDtc, asmDtc);
|
||||
|
||||
TRACE_LOG(logger) << LOGFUNCTION << " END, exerciseId=" << exerciseId;
|
||||
return temp;
|
||||
}
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::getInstance(int exerciseId)
|
||||
{
|
||||
return LtsElevationManager::createInstance(exerciseId);
|
||||
}
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceForTrainingAreaId(int trainingAreaId,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc)
|
||||
{
|
||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||
TRACE_LOG(logger) << LOGFUNCTION << " START, trainingAreaId=" << trainingAreaId;
|
||||
|
||||
if (trainingAreaId < 0)
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " trainingAreaId invalid, trainingAreaId=" << trainingAreaId;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
LtsElevatioMgrMapTrainingAreaId &map = getLtsElevationMgrMapTrainingAreaId();
|
||||
QMap<int, LTS_ELEVATION_MANAGER_TYPE>::iterator it = map.find(trainingAreaId);
|
||||
|
||||
|
||||
if (it != map.end())
|
||||
{
|
||||
DEBUG_LOG(logger) << " LtsElevationMgrMap contains instances: " << map.size();
|
||||
return it.value();
|
||||
}
|
||||
|
||||
|
||||
if (!asmDtc)
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " no dtcs for trainingAreaId=" << trainingAreaId
|
||||
<< ", asmDtc=" << asmDtc;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE temp = new LtsElevationManager();
|
||||
|
||||
|
||||
temp->initDDS(nullptr, asmDtc);
|
||||
|
||||
const QStringList &filenames = temp->getFilenamesForTrainingArea(trainingAreaId);
|
||||
if (filenames.isEmpty())
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " no filenames for trainingAreaId=" << trainingAreaId;
|
||||
delete temp;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
bool bInitFilenames = temp->init(filenames);
|
||||
if (!bInitFilenames)
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " bInitFilenames failed for trainingAreaId=" << trainingAreaId;
|
||||
delete temp;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
map.insert(trainingAreaId, temp);
|
||||
|
||||
DEBUG_LOG(logger) << " LtsElevationMgrMap contains instances now: " << map.size();
|
||||
|
||||
TRACE_LOG(logger) << LOGFUNCTION << " END, trainingAreaId=" << trainingAreaId;
|
||||
return map[trainingAreaId];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE LtsElevationManager::createInstanceUnitTest(int id, const QStringList &filePaths_rough_to_fine)
|
||||
{
|
||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||
|
||||
LtsElevatioMgrMapTrainingAreaId &map = getLtsElevationMgrMapTrainingAreaId();
|
||||
QMap<int, LTS_ELEVATION_MANAGER_TYPE>::iterator it = map.find(id);
|
||||
|
||||
|
||||
if (it != map.end())
|
||||
{
|
||||
DEBUG_LOG(logger) << " LtsElevationMgrMap contains instances: " << map.size();
|
||||
return it.value();
|
||||
}
|
||||
|
||||
|
||||
LTS_ELEVATION_MANAGER_TYPE temp = new LtsElevationManager();
|
||||
|
||||
|
||||
bool bInitFilenames = temp->init(filePaths_rough_to_fine);
|
||||
if (!bInitFilenames)
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " bInitFilenames failed for id=" << id;
|
||||
delete temp;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
map.insert(id, temp);
|
||||
|
||||
DEBUG_LOG(logger) << " LtsElevationMgrMap contains instances now: " << map.size();
|
||||
|
||||
TRACE_LOG(logger) << LOGFUNCTION << " END, trainingAreaId=" << id;
|
||||
return map[id];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void LtsElevationManager::cleanupAll()
|
||||
{
|
||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||
TRACE_LOG(logger) << LOGFUNCTION << " START";
|
||||
cleanupLtsElevatioMgrMapTrainingAreaId();
|
||||
TRACE_LOG(logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
void LtsElevationManager::initDDS(const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc, const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
|
||||
d->m_exmDtc = exmDtc;
|
||||
if (d->m_exmDtc)
|
||||
d->m_exmDtc->waitForHistoricalDataExercise(1000);
|
||||
|
||||
d->m_asmDtc = asmDtc;
|
||||
if (d->m_asmDtc)
|
||||
d->m_asmDtc->waitForHistoricalDataTrainingArea(1000);
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
QStringList LtsElevationManager::getFilenamesForExercise(int exerciseId)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
|
||||
if (!d->m_exmDtc || !d->m_asmDtc)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " no dtcs"
|
||||
<< ", exerciseId=" << exerciseId;
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
int trainingAreaId = exerciseIdToTrainingAreaId(exerciseId, d->m_exmDtc);
|
||||
if (trainingAreaId <= 0)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " Error getting trainingAreaId"
|
||||
<< ", exerciseId=" << exerciseId
|
||||
<< ", trainingAreaId=" << trainingAreaId;
|
||||
return {};
|
||||
}
|
||||
|
||||
QStringList filePaths_rough_to_fine = getFilenamesForTrainingArea(trainingAreaId);
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END, filePaths_rough_to_fine=" << filePaths_rough_to_fine.join(QStringLiteral(";"));
|
||||
return filePaths_rough_to_fine;
|
||||
}
|
||||
|
||||
QStringList LtsElevationManager::getFilenamesForTrainingArea(int trainingAreaId)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
|
||||
if (!d->m_asmDtc)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " no dtcs"
|
||||
<< ", trainingAreaId=" << trainingAreaId;
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
QStringList filePaths_rough_to_fine;
|
||||
{
|
||||
d->m_asmDtc->waitForHistoricalDataTrainingArea(1000);
|
||||
const AssetManagement::TrainingArea &ta = d->m_asmDtc->trainingArea(trainingAreaId);
|
||||
if (ta.id() != trainingAreaId)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " Error on s_asmDtc->trainingArea"
|
||||
<< ", trainingAreaId=" << trainingAreaId;
|
||||
return {};
|
||||
}
|
||||
const std::vector<AssetManagement::MapDescription> &mdVec = ta.elevation();
|
||||
filePaths_rough_to_fine.reserve(mdVec.size());
|
||||
|
||||
for (const AssetManagement::MapDescription &md : qAsConst(mdVec))
|
||||
{
|
||||
|
||||
QUrl url(QString::fromStdString(md.url()));
|
||||
QString filePathAbs = url.toLocalFile();
|
||||
if (QDir::isRelativePath(filePathAbs))
|
||||
filePathAbs = SituationMap::getResourcePath() + QStringLiteral("/elevation/") + filePathAbs;
|
||||
|
||||
filePaths_rough_to_fine.append(filePathAbs);
|
||||
}
|
||||
}
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END, filePaths_rough_to_fine=" << filePaths_rough_to_fine.join(QStringLiteral(";"));
|
||||
return filePaths_rough_to_fine;
|
||||
}
|
||||
|
||||
bool LtsElevationManager::init(const QStringList &filePaths_rough_to_fine)
|
||||
{
|
||||
delete d->m_elevationManager;
|
||||
|
||||
d->m_elevationManager = new SituationMap::ElevationMapManager();
|
||||
int cnt = d->m_elevationManager->init(filePaths_rough_to_fine);
|
||||
|
||||
if (cnt != filePaths_rough_to_fine.size())
|
||||
{
|
||||
FATAL_LOG(m_logger) << LOGFUNCTION << " ERROR, not all files could be loaded !!!";
|
||||
FATAL_LOG(m_logger) << LOGFUNCTION << " ERROR, not all files could be loaded !!!";
|
||||
FATAL_LOG(m_logger) << LOGFUNCTION << " ERROR, not all files could be loaded !!!";
|
||||
FATAL_LOG(m_logger) << LOGFUNCTION << " ERROR, not all files could be loaded !!!";
|
||||
FATAL_LOG(m_logger) << LOGFUNCTION << " ERROR, not all files could be loaded !!!";
|
||||
FATAL_LOG(m_logger) << LOGFUNCTION << " ERROR, not all files could be loaded !!!";
|
||||
FATAL_LOG(m_logger) << LOGFUNCTION << " ERROR, not all files could be loaded !!!";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int LtsElevationManager::exerciseIdToTrainingAreaId(int exerciseId, const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc)
|
||||
{
|
||||
LOGGER_T logger = getLogger("LtsElevationManager");
|
||||
|
||||
if (!exmDtc)
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " no dtcs"
|
||||
<< ", exerciseId=" << exerciseId;
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
int trainingAreaId = -1;
|
||||
{
|
||||
exmDtc->waitForHistoricalDataExercise(1000);
|
||||
|
||||
const ExerciseManagement::Exercise &exm = exmDtc->exercise(exerciseId);
|
||||
if (exm.id() != exerciseId)
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " Error on m_exmDtc->exercise"
|
||||
<< ", exerciseId=" << exerciseId;
|
||||
return {};
|
||||
}
|
||||
trainingAreaId = exm.trainingAreaId();
|
||||
|
||||
if (trainingAreaId <= 0)
|
||||
{
|
||||
ERROR_LOG(logger) << LOGFUNCTION << " Error getting trainingAreaId"
|
||||
<< ", exerciseId=" << exerciseId
|
||||
<< ", trainingAreaId=" << trainingAreaId;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return trainingAreaId;
|
||||
}
|
||||
|
||||
bool LtsElevationManager::waitForInitialization()
|
||||
{
|
||||
if (!d->m_elevationManager)
|
||||
return false;
|
||||
return d->m_elevationManager->waitForInitialization();
|
||||
}
|
||||
|
||||
bool LtsElevationManager::isValid() const
|
||||
{
|
||||
if (!d->m_elevationManager)
|
||||
return false;
|
||||
return d->m_elevationManager->isValid();
|
||||
}
|
||||
|
||||
double LtsElevationManager::elevation(double lon_rad, double lat_rad, double defaultValue, bool *bIsCovered) const
|
||||
{
|
||||
if (!d->m_elevationManager)
|
||||
return defaultValue;
|
||||
return d->m_elevationManager->elevation(lon_rad, lat_rad, defaultValue, bIsCovered);
|
||||
}
|
||||
|
||||
LineOfSight LtsElevationManager::lineOfSightCalculation(const LtsUtils::QPoint3D &startPointGeo_absZ,
|
||||
const LtsUtils::QPoint3D &endPointGeo_absZ)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START" << ", startPointGeo_absZ = " << startPointGeo_absZ << ", endPointGeo_absZ = " << endPointGeo_absZ;
|
||||
|
||||
if (!isValid())
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " Error, LtsElevationManager not valid";
|
||||
return LineOfSight::LOS_ERROR;
|
||||
}
|
||||
|
||||
|
||||
SituationMap::ElevationMapManager::LineOfSight eleMapMgrResult = d->m_elevationManager->lineOfSightCalculation(startPointGeo_absZ,endPointGeo_absZ);
|
||||
|
||||
|
||||
LtsElevation::LineOfSight result = static_cast<LtsElevation::LineOfSight>(eleMapMgrResult);
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END" << ", startPointGeo = " << startPointGeo_absZ << ", endPointGeo = " << endPointGeo_absZ
|
||||
<< " -> LineOfSight " << result;
|
||||
return result;
|
||||
}
|
||||
|
||||
LineOfSight LtsElevationManager::lineOfSightCalculation(const QPointF &startPointGeo, double startHat, const QPointF &endPointGeo, double endHat)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START"
|
||||
<< ", startPointGeo = " << startPointGeo << ", startHat = " << startHat
|
||||
<< ", endPointGeo = " << endPointGeo << ", endHat = " << endHat;
|
||||
|
||||
|
||||
SituationMap::ElevationMapManager::LineOfSight eleMapMgrResult = d->m_elevationManager->lineOfSightCalculation(startPointGeo, startHat,
|
||||
endPointGeo, endHat);
|
||||
|
||||
|
||||
LtsElevation::LineOfSight result = static_cast<LtsElevation::LineOfSight>(eleMapMgrResult);
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END"
|
||||
<< ", startPointGeo = " << startPointGeo << ", startHat = " << startHat
|
||||
<< ", endPointGeo = " << endPointGeo << ", endHat = " << endHat
|
||||
<< " -> LineOfSight " << static_cast<int>(eleMapMgrResult);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
const QString toString(const LineOfSight &value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case LineOfSight::LOS_UNDEFINED:
|
||||
return QStringLiteral("LOS_UNDEFINED");
|
||||
case LineOfSight::LOS_ERROR:
|
||||
return QStringLiteral("LOS_ERROR");
|
||||
case LineOfSight::LOS_VISIBLE:
|
||||
return QStringLiteral("LOS_VISIBLE");
|
||||
case LineOfSight::LOS_INVISIBLE:
|
||||
return QStringLiteral("LOS_INVISIBLE");
|
||||
}
|
||||
Q_ASSERT(false);
|
||||
return QStringLiteral("LineOfSightERROR");
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const LineOfSight value)
|
||||
{
|
||||
stream << toString(value).toStdString();
|
||||
return stream;
|
||||
}
|
||||
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "logger.h"
|
||||
#include <LtsElevation/ltselevation_export.h>
|
||||
#include <LtsUtilsCore/qpoint3d.h>
|
||||
|
||||
|
||||
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#include <QStringList>
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include <memory>
|
||||
#include <iosfwd>
|
||||
|
||||
|
||||
|
||||
namespace LtsSession
|
||||
{
|
||||
class LtsSessionDataDds;
|
||||
}
|
||||
|
||||
namespace ExerciseManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
|
||||
namespace AssetManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace LtsElevation
|
||||
{
|
||||
|
||||
enum class LineOfSight { LOS_UNDEFINED,
|
||||
LOS_ERROR,
|
||||
LOS_VISIBLE,
|
||||
LOS_INVISIBLE };
|
||||
|
||||
class LtsElevationManager;
|
||||
using LTS_ELEVATION_MANAGER_TYPE = QPointer<LtsElevationManager>;
|
||||
|
||||
|
||||
|
||||
|
||||
class LTSELEVATION_EXPORT LtsElevationManager : public QObject
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static LTS_ELEVATION_MANAGER_TYPE createInstance(int exerciseId,
|
||||
const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc = {},
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc = {});
|
||||
|
||||
static LTS_ELEVATION_MANAGER_TYPE getInstance(int exerciseId);
|
||||
|
||||
|
||||
static LTS_ELEVATION_MANAGER_TYPE createInstanceForTrainingAreaId(int trainingAreaId,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc = nullptr);
|
||||
|
||||
|
||||
|
||||
|
||||
static void cleanupAll();
|
||||
virtual ~LtsElevationManager();
|
||||
|
||||
|
||||
bool waitForInitialization();
|
||||
bool isValid() const;
|
||||
|
||||
double elevation(double lon_rad, double lat_rad, double defaultValue = std::numeric_limits<double>::min(), bool *bIsCovered = nullptr) const;
|
||||
|
||||
LineOfSight lineOfSightCalculation(const LtsUtils::QPoint3D &startPointGeo_absZ,
|
||||
const LtsUtils::QPoint3D &endPointGeo_absZ);
|
||||
|
||||
LineOfSight lineOfSightCalculation(const QPointF &startPointGeo, double startHat,
|
||||
const QPointF &endPointGeo, double endHat);
|
||||
|
||||
protected:
|
||||
explicit LtsElevationManager();
|
||||
|
||||
|
||||
|
||||
void initDDS(const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc,
|
||||
const std::shared_ptr<AssetManagement::Interface::Dtc> &asmDtc);
|
||||
bool init(const QStringList &filePaths_rough_to_fine);
|
||||
static int exerciseIdToTrainingAreaId(int exerciseId, const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc);
|
||||
|
||||
|
||||
QStringList getFilenamesForExercise(int exerciseId);
|
||||
QStringList getFilenamesForTrainingArea(int trainingAreaId);
|
||||
|
||||
|
||||
|
||||
|
||||
static LTS_ELEVATION_MANAGER_TYPE createInstanceUnitTest(int id, const QStringList &filePaths_rough_to_fine);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
class Private;
|
||||
|
||||
Private *d;
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
|
||||
LTSELEVATION_EXPORT const QString toString(const LtsElevation::LineOfSight &value);
|
||||
|
||||
LTSELEVATION_EXPORT std::ostream &operator<< (std::ostream &stream,
|
||||
const LtsElevation::LineOfSight value);
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user