audibility_filter_interface.cpp 4.34 KB
Newer Older
1
2
#include <ITA/simulation_scheduler/audibility_filter/audibility_filter_interface.h>

3
4
// simulation scheduler includes
#include <ITA/simulation_scheduler/update_scene.h>
5
#include "../configuration_keys.h"
Pascal Palenda's avatar
Pascal Palenda committed
6
7
8
9
10
#include <ITA/simulation_scheduler/audibility_filter/rate_filter.h>
#include <ITA/simulation_scheduler/audibility_filter/reverberation_radius_filter.h>
#include <ITA/simulation_scheduler/audibility_filter/rotation_filter.h>
#include <ITA/simulation_scheduler/audibility_filter/translation_filter.h>
#include <ITA/simulation_scheduler/audibility_filter/zone_filter.h>
11

12
13
14
15
16
// ITA includes
#include <ITAException.h>
#include <ITAStringUtils.h>

#include "../utils.h"
17

18
19
20
21
22
23
namespace ITA
{
	namespace simulation_scheduler
	{
		namespace audibility_filter
		{
Pascal Palenda's avatar
Pascal Palenda committed
24
25
26
27
28
29
			std::map<std::string, CAudibilityFilterFactory::CreateCallback> CAudibilityFilterFactory::m_mFilters = {
				{CRateFilter::getType ( ), CRateFilter::createFilter},
				{CReverberationRadiusFilter::getType ( ), CReverberationRadiusFilter::createFilter},
				{CRotationFilter::getType ( ), CRotationFilter::createFilter},
				{CTranslationFilter::getType ( ), CTranslationFilter::createFilter},
				{CZoneFilter::getType ( ), CZoneFilter::createFilter} };
30

31

32
33
34
35
			IAudibilityFilter::AudibilityFilterConfig::AudibilityFilterConfig ( ) : sFilterType ( m_sFilterType )
			{
				m_sFilterType = "Unknown";
			}
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
			IAudibilityFilter::AudibilityFilterConfig::AudibilityFilterConfig ( std::string sType ) : sFilterType ( m_sFilterType )
			{
				m_sFilterType = sType;
			}

			IAudibilityFilter::AudibilityFilterConfig::AudibilityFilterConfig ( const AudibilityFilterConfig& other ) :
				IConfig ( other ),
				sFilterName ( other.sFilterName ),
				sFilterType ( m_sFilterType ),
				sNextFilter ( other.sNextFilter ),
				eUsageMode ( other.eUsageMode ),
				bInvertCondition ( other.bInvertCondition ),
				m_sFilterType ( other.m_sFilterType )
			{ }

			IAudibilityFilter::AudibilityFilterConfig& IAudibilityFilter::AudibilityFilterConfig::operator=(
				const AudibilityFilterConfig& other )
			{
				if ( this == &other )
					return *this;
				IConfig::operator =( other );
				sFilterName = other.sFilterName;
				sNextFilter = other.sNextFilter;
				eUsageMode = other.eUsageMode;
				bInvertCondition = other.bInvertCondition;
				m_sFilterType = other.m_sFilterType;
				return *this;
			}

66
67
68
			VistaPropertyList IAudibilityFilter::AudibilityFilterConfig::store ( ) const
			{
				VistaPropertyList properties;
Pascal Palenda's avatar
Pascal Palenda committed
69
70
71
72
73
				properties.SetValue ( audibilityFilterNameKey, sFilterName );
				properties.SetValue ( audibilityFilterNextFilterKey, sNextFilter );
				properties.SetValue ( audibilityFilterTypeKey, m_sFilterType );
				properties.SetValue ( audibilityFilterUsageModeKey, as_integer ( eUsageMode ) );
				properties.SetValue ( audibilityFilterInvertConditionKey, bInvertCondition );
74
75
76
77
78
				return properties;
			}

			void IAudibilityFilter::AudibilityFilterConfig::load ( const VistaPropertyList& oProperties )
			{
Pascal Palenda's avatar
Pascal Palenda committed
79
80
81
82
83
				oProperties.GetValue ( audibilityFilterNameKey, sFilterName );
				oProperties.GetValue ( audibilityFilterNextFilterKey, sNextFilter );
				oProperties.GetValue <std::string> ( audibilityFilterTypeKey, m_sFilterType );
				eUsageMode = static_cast< UsageMode >( oProperties.GetValue <int> ( audibilityFilterUsageModeKey ) );
				oProperties.GetValue ( audibilityFilterInvertConditionKey, bInvertCondition );
84
85
86
			}

			void IAudibilityFilter::checkUpdateTimestamp ( const CUpdateScene& previousState, const CUpdateScene& newUpdate )
87
			{
Pascal Palenda's avatar
Pascal Palenda committed
88
89
				if ( previousState.getTimeStamp ( ) > newUpdate.getTimeStamp ( ) )
					ITA_EXCEPT_INVALID_PARAMETER ( "The previous state happend before the new update" );
90
91
92
93
94
95
96
97
98
99
100
101
			}

			void CAudibilityFilterFactory::registerFilter ( const std::string& type, CreateCallback createFunction )
			{
				m_mFilters [type] = createFunction;
			}

			void CAudibilityFilterFactory::unregisterFilter ( const std::string& type )
			{
				m_mFilters.erase ( type );
			}

102
			std::unique_ptr<IAudibilityFilter> CAudibilityFilterFactory::createFilter ( const std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig>& pConfig )
103
			{
104
				auto it = m_mFilters.find ( pConfig->sFilterType );
105
106
107
108
109
110
111
112
113
114
				if ( it != m_mFilters.end ( ) )
				{
					// call the creation callback to construct this derived type
					return it->second ( pConfig );
				}
				return nullptr;
			}
		} // namespace audibility_filter
	} // namespace simulation_scheduler
} // namespace ITA