Ref T778, added/improved removeElevationValues, cleanElevationValues

This commit is contained in:
Klaus Basan
2020-04-07 00:16:53 +02:00
committed by Mat Sutcliffe
parent 919b6e9515
commit 1821b6e6c5
2 changed files with 30 additions and 26 deletions

View File

@@ -515,54 +515,52 @@ namespace BlackMisc
m_elvFound = m_elvMissed = 0;
}
bool ISimulationEnvironmentProvider::cleanElevationValues(const CAircraftSituation &reference, const CLength &range, bool forced)
int ISimulationEnvironmentProvider::removeElevationValues(const CAircraftSituation &reference, const CLength &removeRange)
{
if (reference.isNull() || range.isNull()) { return false; }
const CLength r = minRange(range);
QWriteLocker l(&m_lockElvCoordinates);
const int r = m_elvCoordinatesGnd.removeInsideRange(reference, removeRange);
return r;
}
CCoordinateGeodeticList elvs;
CCoordinateGeodeticList cleanedElvs;
bool ISimulationEnvironmentProvider::cleanElevationValues(const CAircraftSituation &reference, const CLength &keptRange, bool forced)
{
if (reference.isNull() || keptRange.isNull()) { return false; }
const CLength r = minRange(keptRange);
CCoordinateGeodeticList cleanedKeptElvs;
bool maxReached = false;
bool cleaned = false;
{
QReadLocker l(&m_lockElvCoordinates);
elvs = m_elvCoordinates;
cleanedKeptElvs = m_elvCoordinates;
maxReached = m_elvCoordinates.size() >= m_maxElevations;
}
if (!elvs.isEmpty() && (forced || maxReached))
if (!cleanedKeptElvs.isEmpty() && (forced || maxReached))
{
for (const CAircraftSituation &s : elvs)
{
if (s.isWithinRange(reference, r)) { cleanedElvs.push_back(s); }
}
if (cleanedElvs.size() < elvs.size())
const int removed = cleanedKeptElvs.removeOutsideRange(reference, r);
if (removed > 0)
{
cleaned = true;
QWriteLocker l(&m_lockElvCoordinates);
m_elvCoordinates = cleanedElvs;
m_elvCoordinates = cleanedKeptElvs;
}
}
cleanedElvs.clear();
cleanedKeptElvs.clear();
{
QReadLocker l(&m_lockElvCoordinates);
elvs = m_elvCoordinatesGnd;
cleanedKeptElvs = m_elvCoordinatesGnd;
maxReached = m_elvCoordinatesGnd.size() >= m_maxElevationsGnd;
}
if (!elvs.isEmpty() && (forced || maxReached))
if (!cleanedKeptElvs.isEmpty() && (forced || maxReached))
{
for (const CAircraftSituation &s : elvs)
{
if (s.isWithinRange(reference, r)) { cleanedElvs.push_back(s); }
}
if (cleanedElvs.size() < elvs.size())
const int removed = cleanedKeptElvs.removeOutsideRange(reference, r);
if (removed > 0)
{
cleaned = true;
QWriteLocker l(&m_lockElvCoordinates);
m_elvCoordinatesGnd = cleanedElvs;
m_elvCoordinatesGnd = cleanedKeptElvs;
}
}

View File

@@ -146,9 +146,15 @@ namespace BlackMisc
//! \threadsafe
void resetSimulationEnvironmentStatistics();
//! Average elevation of "on ground" cached values
//! Remove cached elevations outside range,
//! "forced" cleans always, otherwise only if max.values are reached
//! \threadsafe
bool cleanElevationValues(const Aviation::CAircraftSituation &reference, const PhysicalQuantities::CLength &range, bool forced = false);
bool cleanElevationValues(const Aviation::CAircraftSituation &reference, const PhysicalQuantities::CLength &keptRange, bool forced = false);
//! Remove cached elevations inside range,
//! \remark this removes inside range, cleanElevationValues outside the range
//! \threadsafe
int removeElevationValues(const Aviation::CAircraftSituation &reference, const PhysicalQuantities::CLength &removeRange);
protected:
//! Ctor