refs #896 Added CInterpolatorMulti to allow runtime switching between interpolator algorithms.

This commit is contained in:
Mathew Sutcliffe
2017-03-15 21:38:29 +00:00
parent 70520d44c3
commit b491a1432c
3 changed files with 244 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
/* Copyright (C) 2017
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_SIMULATION_INTERPOLATORDUMMY_H
#define BLACKMISC_SIMULATION_INTERPOLATORDUMMY_H
#include "blackmisc/aviation/aircraftparts.h"
#include "blackmisc/aviation/aircraftsituation.h"
#include "blackmisc/aviation/callsign.h"
#include "blackmisc/simulation/interpolationhints.h"
#include "blackmisc/simulation/interpolationlogger.h"
#include "blackmisc/simulation/interpolationrenderingsetup.h"
#include "blackmisc/simulation/interpolator.h"
namespace BlackMisc
{
namespace Simulation
{
/*!
* Dummy interpolator which does nothing.
*/
class BLACKMISC_EXPORT CInterpolatorDummy : public QObject
{
public:
//! Constructor
CInterpolatorDummy(const BlackMisc::Aviation::CCallsign &, QObject *parent) : QObject(parent) {}
//! \copydoc CInterpolator::getInterpolatedSituation
BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(
qint64, const CInterpolationAndRenderingSetup &, const CInterpolationHints &, CInterpolationStatus &) { return {}; }
//! \copydoc CInterpolator::getInterpolatedParts
BlackMisc::Aviation::CAircraftParts getInterpolatedParts(
qint64, const CInterpolationAndRenderingSetup &, CPartsStatus &, bool = false) { return {}; }
//! \copydoc CInterpolator::addAircraftSituation
void addAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &) {}
//! \copydoc CInterpolator::hasAircraftSituations
bool hasAircraftSituations() const { return false; }
//! \copydoc CInterpolator::addAircraftParts
void addAircraftParts(const BlackMisc::Aviation::CAircraftParts &) {}
//! \copydoc CInterpolator::hasAircraftParts
bool hasAircraftParts() const { return false; }
//! \copydoc CInterpolator::attachLogger
void attachLogger(CInterpolationLogger *) {}
};
}
}
#endif

View File

@@ -0,0 +1,102 @@
/* Copyright (C) 2017
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#include "blackmisc/simulation/interpolatormulti.h"
namespace BlackMisc
{
namespace Simulation
{
CInterpolatorMulti::CInterpolatorMulti(const BlackMisc::Aviation::CCallsign &callsign, QObject *parent) :
QObject(parent),
m_spline(callsign, this),
m_linear(callsign, this)
{}
BlackMisc::Aviation::CAircraftSituation CInterpolatorMulti::getInterpolatedSituation(
qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetup &setup, const CInterpolationHints &hints, CInterpolationStatus &status)
{
switch (m_mode)
{
case ModeLinear:
return m_linear.getInterpolatedSituation(currentTimeSinceEpoc, setup, hints, status);
case ModeSpline:
return m_spline.getInterpolatedSituation(currentTimeSinceEpoc, setup, hints, status);
}
return {};
}
BlackMisc::Aviation::CAircraftParts CInterpolatorMulti::getInterpolatedParts(
qint64 cutoffTime, const CInterpolationAndRenderingSetup &setup, CPartsStatus &partsStatus, bool log)
{
switch (m_mode)
{
case ModeLinear:
return m_linear.getInterpolatedParts(cutoffTime, setup, partsStatus, log);
case ModeSpline:
return m_spline.getInterpolatedParts(cutoffTime, setup, partsStatus, log);
}
return {};
}
void CInterpolatorMulti::addAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation)
{
m_linear.addAircraftSituation(situation);
m_spline.addAircraftSituation(situation);
}
bool CInterpolatorMulti::hasAircraftSituations() const
{
switch (m_mode)
{
case ModeLinear: return m_linear.hasAircraftSituations();
case ModeSpline: return m_spline.hasAircraftSituations();
}
return false;
}
void CInterpolatorMulti::addAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts)
{
m_linear.addAircraftParts(parts);
m_spline.addAircraftParts(parts);
}
bool CInterpolatorMulti::hasAircraftParts() const
{
switch (m_mode)
{
case ModeLinear: return m_linear.hasAircraftParts();
case ModeSpline: return m_spline.hasAircraftParts();
}
return false;
}
void CInterpolatorMulti::attachLogger(CInterpolationLogger *logger)
{
m_linear.attachLogger(logger);
m_spline.attachLogger(logger);
}
bool CInterpolatorMulti::setMode(Mode mode)
{
#ifdef QT_DEBUG
if (m_mode != mode)
{
m_mode = mode;
return true;
}
#else
Q_UNUSED(mode);
#endif
return false;
}
}
}

View File

@@ -0,0 +1,80 @@
/* Copyright (C) 2017
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_SIMULATION_INTERPOLATORMULTI_H
#define BLACKMISC_SIMULATION_INTERPOLATORMULTI_H
#include "blackmisc/simulation/interpolatorlinear.h"
#include "blackmisc/simulation/interpolatorspline.h"
#include "blackmisc/simulation/interpolatordummy.h"
namespace BlackMisc
{
namespace Simulation
{
/*!
* Multiplexed interpolator which allows switching between modes at runtime.
*/
class BLACKMISC_EXPORT CInterpolatorMulti : public QObject
{
public:
//! Constructor
CInterpolatorMulti(const BlackMisc::Aviation::CCallsign &callsign, QObject *parent = nullptr);
//! \copydoc CInterpolator::getInterpolatedSituation
BlackMisc::Aviation::CAircraftSituation getInterpolatedSituation(
qint64 currentTimeSinceEpoc, const CInterpolationAndRenderingSetup &setup, const CInterpolationHints &hints, CInterpolationStatus &status);
//! \copydoc CInterpolator::getInterpolatedParts
BlackMisc::Aviation::CAircraftParts getInterpolatedParts(
qint64 cutoffTime, const CInterpolationAndRenderingSetup &setup, CPartsStatus &partsStatus, bool log = false);
//! \copydoc CInterpolator::addAircraftSituation
void addAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation);
//! \copydoc CInterpolator::hasAircraftSituations
bool hasAircraftSituations() const;
//! \copydoc CInterpolator::addAircraftParts
void addAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts);
//! \copydoc CInterpolator::hasAircraftParts
bool hasAircraftParts() const;
//! \copydoc CInterpolator::attachLogger
void attachLogger(CInterpolationLogger *logger);
//! Supported interpolation modes.
enum Mode
{
ModeSpline, //!< spline interpolation mode
ModeLinear //!< linear interpolation mode
};
//! Set interpolation mode. Return true if mode was changed. Mode will not be changed in release build.
bool setMode(Mode mode);
//! Get active interpolation mode.
Mode getMode() const { return m_mode; }
private:
Mode m_mode = ModeSpline;
CInterpolatorSpline m_spline;
#ifdef QT_DEBUG
CInterpolatorLinear m_linear;
#else
CInterpolatorDummy m_linear;
#endif
};
}
}
#endif