Commit 8ac69315 authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Prepare configs for filter network implementation - WIP

parent c1676750
......@@ -20,6 +20,7 @@ set( DirFiles
scheduler_interface.h
scheduler.h
worker_interface.h
config_interface.h
#_SourceFiles.cmake
)
......
......@@ -4,12 +4,13 @@
// API includes
#include <ITA/simulation_scheduler/definitions.h>
// simulation scheduler includes
#include <ITA/simulation_scheduler/config_interface.h>
// std includes
#include <memory>
#include <functional>
// Vista includes
#include <VistaAspects/VistaPropertyList.h>
#include <vector>
namespace ITA
{
......@@ -37,11 +38,32 @@ namespace ITA
class ITA_SIMULATION_SCHEDULER_API IAudibilityFilter
{
public:
enum class UsageMode
{
filter,
condition
};
///
/// \brief Configuration class for an audibility filter.
///
struct ITA_SIMULATION_SCHEDULER_API AudibilityFilterConfig : public VistaPropertyList
struct ITA_SIMULATION_SCHEDULER_API AudibilityFilterConfig : public IConfig
{
explicit AudibilityFilterConfig ( std::string sType );
std::string sFilterName = "Unknown";
const std::string sFilterType;
std::vector<std::string> sNextFilter;
UsageMode eUsageMode = UsageMode::filter;
bool bInvert = false;
VistaPropertyList store() const override;
void load(const VistaPropertyList& oProperties) override;
};
///
......@@ -66,7 +88,7 @@ namespace ITA
/// \param previousState CUpdateScene of the previous state.
/// \param newUpdate new CUpdateScene.
///
void checkUpdateTimestamp ( const CUpdateScene& previousState, const CUpdateScene& newUpdate );
static void checkUpdateTimestamp ( const CUpdateScene& previousState, const CUpdateScene& newUpdate );
};
///
......
......@@ -35,15 +35,13 @@ namespace ITA
///
struct ITA_SIMULATION_SCHEDULER_API RateFilterConfig : public IAudibilityFilter::AudibilityFilterConfig
{
void setRate ( double dRate );
double getRate ( ) const;
explicit RateFilterConfig ( );
///
/// \brief Returns the default Configuration for a CRateFilter.
/// \return the default config for a CRateFilter.
///
static RateFilterConfig getDefaultRateFilterConfig ( );
double dRate = 1.0;
VistaPropertyList store ( ) const override;
void load ( const VistaPropertyList& oProperties ) override;
};
CRateFilter ( ) = delete;
......@@ -68,6 +66,12 @@ namespace ITA
///
virtual bool changeIsAudible ( const CUpdateScene& previousState, const CUpdateScene& newUpdate ) override;
///
/// \brief Return a unique type identifying string.
/// \return a unique type identifying string.
///
static std::string getType();
///
/// \brief Factory function for a filter.
/// \remark This function should to be static.
......
......@@ -32,15 +32,13 @@ namespace ITA
///
struct ITA_SIMULATION_SCHEDULER_API ReverberationRadiusFilterConfig : public IAudibilityFilter::AudibilityFilterConfig
{
void setReverberationRadius ( double dReverberationRadius );
explicit ReverberationRadiusFilterConfig ( );
double dReverberationRadius = 5.0;
double getReverberationRadius ( ) const;
VistaPropertyList store ( ) const override;
///
/// \brief Returns the default Configuration for a CRateFilter.
/// \return the default config for a CRateFilter.
///
static ReverberationRadiusFilterConfig getDefaultReverberationRadiusFilterConfig ( );
void load ( const VistaPropertyList& oProperties ) override;
};
CReverberationRadiusFilter ( ) = delete;
......@@ -65,6 +63,12 @@ namespace ITA
///
virtual bool changeIsAudible ( const CUpdateScene& previousState, const CUpdateScene& newUpdate ) override;
///
/// \brief Return a unique type identifying string.
/// \return a unique type identifying string.
///
static std::string getType ( );
///
/// \brief Factory function for a filter.
/// \remark This function should to be static.
......
......@@ -46,23 +46,17 @@ namespace ITA
///
struct ITA_SIMULATION_SCHEDULER_API RotationFilterConfig : public IAudibilityFilter::AudibilityFilterConfig
{
void setSourceThreshold ( double dThreshold );
explicit RotationFilterConfig ( );
double dSourceThreshold = 2.5;
double getSourceThreshold ( ) const;
double dReceiverThreshold = 2.5;
void setReceiverThreshold ( double dThreshold );
RotationModes eMode = RotationModes::absolute;
double getReceiverThreshold ( ) const;
VistaPropertyList store ( ) const override;
void setRotationMode ( RotationModes eMode );
RotationModes getRotationMode ( ) const;
///
/// \brief Returns the default Configuration for a CRotationFilter.
/// \return the default config for a CRotationFilter.
///
static RotationFilterConfig getDefaultRotationFilterConfig ( );
void load ( const VistaPropertyList& oProperties ) override;
};
CRotationFilter ( ) = delete;
......@@ -87,6 +81,12 @@ namespace ITA
///
virtual bool changeIsAudible ( const CUpdateScene& previousState, const CUpdateScene& newUpdate ) override;
///
/// \brief Return a unique type identifying string.
/// \return a unique type identifying string.
///
static std::string getType ( );
///
/// \brief Factory function for a filter.
/// \remark This function should to be static.
......
......@@ -29,15 +29,13 @@ namespace ITA
///
struct ITA_SIMULATION_SCHEDULER_API TranslationFilterConfig : public IAudibilityFilter::AudibilityFilterConfig
{
void setMinimumTranslation ( double dMinimumTranslation );
explicit TranslationFilterConfig ( );
double getMinimumTranslation ( ) const;
///
/// \brief Returns the default Configuration for a CTranslationFilter.
/// \return the default config for a CTranslationFilter.
///
static TranslationFilterConfig getDefaultTranslationFilterConfig ( );
double dMinimumTranslation = 5.0;
VistaPropertyList store ( ) const override;
void load ( const VistaPropertyList& oProperties ) override;
};
CTranslationFilter ( ) = delete;
......@@ -62,6 +60,12 @@ namespace ITA
///
virtual bool changeIsAudible ( const CUpdateScene& previousState, const CUpdateScene& newUpdate ) override;
///
/// \brief Return a unique type identifying string.
/// \return a unique type identifying string.
///
static std::string getType ( );
///
/// \brief Factory function for a filter.
/// \remark This function should to be static.
......
......@@ -35,23 +35,18 @@ namespace ITA
///
struct ITA_SIMULATION_SCHEDULER_API ZoneFilterConfig : AudibilityFilterConfig
{
explicit ZoneFilterConfig ( );
///
/// \brief Set the zones for the config.
/// \brief The zones for the config.
///
/// Zones are cuboids defined by two points in 3D space.
/// As such, the definition is represented by a pair of VistaVector3D%s.
/// \param vpZones vector of definitions of the zones.
///
void setZones ( const std::vector<std::pair<VistaVector3D, VistaVector3D>>& vpZones );
std::vector<std::pair<VistaVector3D, VistaVector3D>> vpZones;
///
/// \brief Get the zones form the config.
///
/// Zones are cuboids defined by two points in 3D space.
/// As such, the definition is represented by a pair of VistaVector3D%s.
/// \return a vector of zone definitions.
///
std::vector<std::pair<VistaVector3D, VistaVector3D>> getZones ( ) const;
VistaPropertyList store ( ) const override;
void load ( const VistaPropertyList& oProperties ) override;
};
CZoneFilter ( ) = delete;
......@@ -70,6 +65,12 @@ namespace ITA
/// \return true, source or receiver of \p newUpdate lie inside any of the defined zones.
///
bool changeIsAudible(const CUpdateScene& previousState, const CUpdateScene& newUpdate) override;
///
/// \brief Return a unique type identifying string.
/// \return a unique type identifying string.
///
static std::string getType ( );
///
/// \brief Factory function for CZoneFilter.
......
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_CONFIG_INTERFACE
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_CONFIG_INTERFACE
// API includes
#include <ITA/simulation_scheduler/definitions.h>
// Vista includes
#include <VistaAspects/VistaPropertyList.h>
namespace ITA
{
namespace simulation_scheduler
{
///
/// \brief Interface for a configuration.
///
class ITA_SIMULATION_SCHEDULER_API IConfig
{
public:
///
/// \brief Store the config as a VistaPropertyList.
/// \return a VistaPropertyList with the config properties.
///
virtual VistaPropertyList store ( ) const = 0;
///
/// \brief Load the config from a VistaPropertyList.
/// \param oProperties a VistaPropertyList fro which to load the config properties.
///
virtual void load ( const VistaPropertyList& oProperties ) = 0;
};
} // namespace simulation_scheduler
} // namespace ITA
#endif // INCLUDE_WATINCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_CONFIG_INTERFACECHER_ITA_SIMULATION_SCHEDULER_TYPES
......@@ -4,7 +4,11 @@
#include <ITA/simulation_scheduler/update_scene.h>
#include "../configuration_keys.h"
#include "ITAException.h"
// ITA includes
#include <ITAException.h>
#include <ITAStringUtils.h>
#include "../utils.h"
namespace ITA
{
......@@ -14,11 +18,35 @@ namespace ITA
{
std::map<std::string, CAudibilityFilterFactory::CreateCallback> CAudibilityFilterFactory::m_mFilters;
IAudibilityFilter::AudibilityFilterConfig::AudibilityFilterConfig ( std::string sType ) :sFilterType ( sType )
{ }
VistaPropertyList IAudibilityFilter::AudibilityFilterConfig::store ( ) const
{
VistaPropertyList properties;
properties.SetValue ( audibilityFilterName, sFilterName );
properties.SetValue ( audibilityFilterNextFilter, sNextFilter );
properties.SetValue ( audibilityFilterType, sFilterType );
properties.SetValue ( audibilityFilterUsageMode, as_integer ( eUsageMode ) );
properties.SetValue ( audibilityFilterInvert, bInvert );
return properties;
}
void IAudibilityFilter::AudibilityFilterConfig::load ( const VistaPropertyList& oProperties )
{
oProperties.GetValue ( audibilityFilterName, sFilterName );
oProperties.GetValue ( audibilityFilterNextFilter, sNextFilter );
oProperties.GetValue ( audibilityFilterType, sFilterType );
eUsageMode = static_cast< UsageMode >( oProperties.GetValue <int> ( audibilityFilterUsageMode ) );
oProperties.GetValue ( audibilityFilterInvert, bInvert );
}
// Definition of the pure virtual destructor.
IAudibilityFilter::~IAudibilityFilter ( )
{ }
void IAudibilityFilter::checkUpdateTimestamp(const CUpdateScene& previousState, const CUpdateScene& newUpdate)
void IAudibilityFilter::checkUpdateTimestamp ( const CUpdateScene& previousState, const CUpdateScene& newUpdate )
{
if ( previousState.getTimeStamp ( ) > newUpdate.getTimeStamp ( ) )
ITA_EXCEPT_INVALID_PARAMETER ( "The previous state happend before the new update" );
......@@ -36,7 +64,7 @@ namespace ITA
std::unique_ptr<IAudibilityFilter> CAudibilityFilterFactory::createFilter ( const IAudibilityFilter::AudibilityFilterConfig& pConfig )
{
auto it = m_mFilters.find ( pConfig.begin ( )->first );
auto it = m_mFilters.find ( pConfig.sFilterType );
if ( it != m_mFilters.end ( ) )
{
// call the creation callback to construct this derived type
......
......@@ -13,29 +13,28 @@ namespace ITA
{
namespace audibility_filter
{
void CRateFilter::RateFilterConfig::setRate(double dRate)
{
SetValueInSubList ( rateFilterRateKey, rateFilterConfigSectionName, dRate );
}
CRateFilter::RateFilterConfig::RateFilterConfig ( ) : AudibilityFilterConfig ( getType ( ) )
{ }
double CRateFilter::RateFilterConfig::getRate() const
VistaPropertyList CRateFilter::RateFilterConfig::store ( ) const
{
return GetValueInSubList <double> ( rateFilterRateKey, rateFilterConfigSectionName );
auto oProperties = AudibilityFilterConfig::store ( );
oProperties.SetValue ( rateFilterRateKey, dRate );
return oProperties;
}
CRateFilter::RateFilterConfig CRateFilter::RateFilterConfig::getDefaultRateFilterConfig ( )
void CRateFilter::RateFilterConfig::load ( const VistaPropertyList& oProperties )
{
auto oConfig = RateFilterConfig ( );
oConfig.SetValueInSubList ( rateFilterRateKey, rateFilterConfigSectionName, 1.0 );
return oConfig;
AudibilityFilterConfig::load ( oProperties );
oProperties.GetValue ( rateFilterRateKey, dRate );
}
CRateFilter::CRateFilter ( const RateFilterConfig& oConfig )
{
if ( !oConfig.HasSubList ( rateFilterConfigSectionName ) )
ITA_EXCEPT_INVALID_PARAMETER ( "Config is not a valid rate filter config." );
m_dRate = oConfig.GetValueInSubListOrDefault ( rateFilterRateKey, rateFilterConfigSectionName, 1.0 );
m_dRate = oConfig.dRate;
}
bool CRateFilter::changeIsAudible ( const CUpdateScene& previousState, const CUpdateScene& newUpdate )
......@@ -43,11 +42,16 @@ namespace ITA
checkUpdateTimestamp ( previousState, newUpdate );
const auto dDeltaTime = newUpdate.getTimeStamp ( ) - previousState.getTimeStamp ( );
assert ( abs(dDeltaTime) > std::numeric_limits<double>::epsilon ( ) );
assert ( abs ( dDeltaTime ) > std::numeric_limits<double>::epsilon ( ) );
const auto dCurrentRate = 1 / dDeltaTime;
return dCurrentRate < m_dRate;
}
std::string CRateFilter::getType ( )
{
return "RateFilter";
}
std::unique_ptr<IAudibilityFilter> CRateFilter::createFilter (
const IAudibilityFilter::AudibilityFilterConfig& oConfig )
{
......
......@@ -13,27 +13,28 @@ namespace ITA
{
namespace audibility_filter
{
void CReverberationRadiusFilter::ReverberationRadiusFilterConfig::setReverberationRadius ( double dReverberationRadius )
{
SetValueInSubList ( reverberationRadiusFilterReverberationRadiusKey, reverberationRadiusFilterConfigSectionName, dReverberationRadius );
}
CReverberationRadiusFilter::ReverberationRadiusFilterConfig::ReverberationRadiusFilterConfig ( ) : AudibilityFilterConfig ( getType ( ) )
{ }
double CReverberationRadiusFilter::ReverberationRadiusFilterConfig::getReverberationRadius ( ) const
VistaPropertyList CReverberationRadiusFilter::ReverberationRadiusFilterConfig::store ( ) const
{
return GetValueInSubList <double> ( reverberationRadiusFilterReverberationRadiusKey, reverberationRadiusFilterConfigSectionName );
auto oProperties = AudibilityFilterConfig::store ( );
oProperties.SetValue ( reverberationRadiusFilterReverberationRadiusKey, dReverberationRadius );
return oProperties;
}
CReverberationRadiusFilter::ReverberationRadiusFilterConfig CReverberationRadiusFilter::
ReverberationRadiusFilterConfig::getDefaultReverberationRadiusFilterConfig ( )
void CReverberationRadiusFilter::ReverberationRadiusFilterConfig::load ( const VistaPropertyList& oProperties )
{
auto oConfig = ReverberationRadiusFilterConfig ( );
oConfig.setReverberationRadius ( 5.0 );
return oConfig;
AudibilityFilterConfig::load ( oProperties );
oProperties.GetValue ( reverberationRadiusFilterReverberationRadiusKey, dReverberationRadius );
}
CReverberationRadiusFilter::CReverberationRadiusFilter ( const ReverberationRadiusFilterConfig& oConfig )
{
m_dReverberationRadius = oConfig.getReverberationRadius ( );
m_dReverberationRadius = oConfig.dReverberationRadius;
}
bool CReverberationRadiusFilter::changeIsAudible ( const CUpdateScene& previousState,
......@@ -48,6 +49,11 @@ namespace ITA
return distance.GetLength ( ) < m_dReverberationRadius;
}
std::string CReverberationRadiusFilter::getType ( )
{
return "ReverberationRadiusFilter";
}
std::unique_ptr<IAudibilityFilter> CReverberationRadiusFilter::createFilter (
const IAudibilityFilter::AudibilityFilterConfig& oConfig )
{
......
......@@ -15,51 +15,34 @@ namespace ITA
{
namespace audibility_filter
{
void CRotationFilter::RotationFilterConfig::setSourceThreshold ( double dThreshold )
{
SetValueInSubList ( rotationFilterSourceThresholdKey, rotationFilterConfigSectionName, dThreshold );
}
CRotationFilter::RotationFilterConfig::RotationFilterConfig ( ) : AudibilityFilterConfig ( getType ( ) )
{ }
double CRotationFilter::RotationFilterConfig::getSourceThreshold ( ) const
VistaPropertyList CRotationFilter::RotationFilterConfig::store ( ) const
{
return GetValueInSubList <double> ( rotationFilterSourceThresholdKey, rotationFilterConfigSectionName );
}
auto oProperties = AudibilityFilterConfig::store ( );
void CRotationFilter::RotationFilterConfig::setReceiverThreshold ( double dThreshold )
{
SetValueInSubList ( rotationFilterReceiverThresholdKey, rotationFilterConfigSectionName, dThreshold );
}
double CRotationFilter::RotationFilterConfig::getReceiverThreshold ( ) const
{
return GetValueInSubList <double> ( rotationFilterReceiverThresholdKey, rotationFilterConfigSectionName );
}
oProperties.SetValue ( rotationFilterSourceThresholdKey, dSourceThreshold );
oProperties.SetValue ( rotationFilterReceiverThresholdKey, dReceiverThreshold );
oProperties.SetValue ( rotationFilterRotationModeKey, as_integer ( eMode ) );
void CRotationFilter::RotationFilterConfig::setRotationMode ( RotationModes eMode )
{
SetValueInSubList ( rotationFilterRotationModeKey, rotationFilterConfigSectionName, as_integer ( eMode ) );
return oProperties;
}
CRotationFilter::RotationModes CRotationFilter::RotationFilterConfig::getRotationMode ( ) const
void CRotationFilter::RotationFilterConfig::load ( const VistaPropertyList& oProperties )
{
return static_cast< RotationModes >( GetValueInSubList<int> ( rotationFilterRotationModeKey, rotationFilterConfigSectionName ) );
}
AudibilityFilterConfig::load ( oProperties );
CRotationFilter::RotationFilterConfig CRotationFilter::RotationFilterConfig::
getDefaultRotationFilterConfig ( )
{
auto oConfig = RotationFilterConfig ( );
oConfig.setSourceThreshold ( 2.5 );
oConfig.setReceiverThreshold ( 2.5 );
oConfig.setRotationMode ( RotationModes::absolute );
return oConfig;
oProperties.GetValue ( rotationFilterSourceThresholdKey, dSourceThreshold );
oProperties.GetValue ( rotationFilterReceiverThresholdKey, dReceiverThreshold );
eMode = static_cast< RotationModes >( oProperties.GetValue <int> ( rotationFilterRotationModeKey ) );
}
CRotationFilter::CRotationFilter ( const RotationFilterConfig& oConfig )
{
m_dSourceThreshold = oConfig.getSourceThreshold ( );
m_dReceiverThreshold = oConfig.getReceiverThreshold ( );
m_eRotationMode = oConfig.getRotationMode ( );
m_dSourceThreshold = oConfig.dSourceThreshold;
m_dReceiverThreshold = oConfig.dReceiverThreshold;
m_eRotationMode = oConfig.eMode;
}
bool CRotationFilter::changeIsAudible ( const CUpdateScene& previousState, const CUpdateScene& newUpdate )
......@@ -75,6 +58,11 @@ namespace ITA
return true;
}
std::string CRotationFilter::getType ( )
{
return "RotationFilter";
}
std::unique_ptr<IAudibilityFilter> CRotationFilter::createFilter (
const IAudibilityFilter::AudibilityFilterConfig& oConfig )
{
......@@ -145,7 +133,7 @@ namespace ITA
const auto sourceDelta = abs ( previousSourceAnglesRad - newSourceAnglesRad ) * 180.f / ITAConstants::PI_F;
const auto receiverDelta = abs ( previousReceiverAnglesRad - newReceiverAnglesRad ) * 180.f / ITAConstants::PI_F;
const auto audible = ( sourceDelta > float ( m_dSourceThreshold ) ).max() || ( receiverDelta > float ( m_dReceiverThreshold ) ).max ( );
const auto audible = ( sourceDelta > float ( m_dSourceThreshold ) ).max ( ) || ( receiverDelta > float ( m_dReceiverThreshold ) ).max ( );
return audible;
}
......
......@@ -12,42 +12,48 @@ namespace ITA
{
namespace audibility_filter
{
void CTranslationFilter::TranslationFilterConfig::setMinimumTranslation ( double dMinimumTranslation )
{
SetValueInSubList ( translationFilterMinimumTranslationKey, translationFilterConfigSectionName, dMinimumTranslation );
}
CTranslationFilter::TranslationFilterConfig::TranslationFilterConfig ( ) : AudibilityFilterConfig ( getType ( ) )
{ }
double CTranslationFilter::TranslationFilterConfig::getMinimumTranslation ( ) const
VistaPropertyList CTranslationFilter::TranslationFilterConfig::store ( ) const
{
return GetValueInSubList <double> ( translationFilterMinimumTranslationKey, translationFilterConfigSectionName );
auto oProperties = AudibilityFilterConfig::store ( );