audibility_filter_interface.cpp 5.4 KB
Newer Older
Pascal Palenda's avatar
Pascal Palenda committed
1
#include <ITA/SimulationScheduler/AudibilityFilter/audibility_filter_interface.h>
2

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

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

#include "../utils.h"
18

19
20
namespace ITA
{
21
	namespace SimulationScheduler
22
	{
23
		namespace AudibilityFilter
24
		{
Pascal Palenda's avatar
Pascal Palenda committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
			std::map<std::string, std::pair<CAudibilityFilterFactory::CreateCallback, CAudibilityFilterFactory::ConfigCreateCallback>>
				CAudibilityFilterFactory::m_mFilters = {
					{CRateFilter::GetType ( ),
						{ CRateFilter::CreateFilter, std::make_shared<CRateFilter::RateFilterConfig> } },
					{CReverberationRadiusFilter::GetType ( ),
						{ CReverberationRadiusFilter::CreateFilter, std::make_shared<CReverberationRadiusFilter::ReverberationRadiusFilterConfig> } },
					{CRotationFilter::GetType ( ),
						{ CRotationFilter::CreateFilter, std::make_shared<CRotationFilter::RotationFilterConfig> } },
					{CTranslationFilter::GetType ( ),
						{ CTranslationFilter::CreateFilter, std::make_shared<CTranslationFilter::TranslationFilterConfig> } },
					{CZoneFilter::GetType ( ),
						{ CZoneFilter::CreateFilter, std::make_shared<CZoneFilter::ZoneFilterConfig> } },
					{CPerceptiveRotationFilter::GetType ( ),
						{ CPerceptiveRotationFilter::CreateFilter, std::make_shared<CPerceptiveRotationFilter::PerceptiveRotationFilterConfig> } }
				};
40

41

42
43
44
45
			IAudibilityFilter::AudibilityFilterConfig::AudibilityFilterConfig ( ) : sFilterType ( m_sFilterType )
			{
				m_sFilterType = "Unknown";
			}
46

47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
			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;
			}

76
			VistaPropertyList IAudibilityFilter::AudibilityFilterConfig::Store ( ) const
77
78
			{
				VistaPropertyList properties;
Pascal Palenda's avatar
Pascal Palenda committed
79
80
81
				properties.SetValue ( audibilityFilterNameKey, sFilterName );
				properties.SetValue ( audibilityFilterNextFilterKey, sNextFilter );
				properties.SetValue ( audibilityFilterTypeKey, m_sFilterType );
82
				properties.SetValue ( audibilityFilterUsageModeKey, AsInteger ( eUsageMode ) );
Pascal Palenda's avatar
Pascal Palenda committed
83
				properties.SetValue ( audibilityFilterInvertConditionKey, bInvertCondition );
84
85
86
				return properties;
			}

87
			void IAudibilityFilter::AudibilityFilterConfig::Load ( const VistaPropertyList& oProperties )
88
			{
Pascal Palenda's avatar
Pascal Palenda committed
89
90
91
92
93
				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 );
94
95
			}

96
			void IAudibilityFilter::CheckUpdateTimestamp ( const CUpdateScene& previousState, const CUpdateScene& newUpdate )
97
			{
98
				if ( previousState.GetTimeStamp ( ) > newUpdate.GetTimeStamp ( ) )
Pascal Palenda's avatar
Pascal Palenda committed
99
					ITA_EXCEPT_INVALID_PARAMETER ( "The previous state happend before the new update" );
100
101
			}

Pascal Palenda's avatar
Pascal Palenda committed
102
			void CAudibilityFilterFactory::RegisterFilter ( const std::string& type, CreateCallback createFunction, ConfigCreateCallback configCreateFunction )
103
			{
Pascal Palenda's avatar
Pascal Palenda committed
104
				m_mFilters [type] = { createFunction, configCreateFunction };
105
106
			}

107
			void CAudibilityFilterFactory::UnregisterFilter ( const std::string& type )
108
109
110
111
			{
				m_mFilters.erase ( type );
			}

112
			std::unique_ptr<IAudibilityFilter> CAudibilityFilterFactory::CreateFilter ( const std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig>& pConfig )
113
			{
114
				auto it = m_mFilters.find ( pConfig->sFilterType );
115
116
117
				if ( it != m_mFilters.end ( ) )
				{
					// call the creation callback to construct this derived type
Pascal Palenda's avatar
Pascal Palenda committed
118
119
120
121
122
123
124
125
126
127
128
129
130
					return it->second.first ( pConfig );
				}
				return nullptr;
			}

			std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig> CAudibilityFilterFactory::CreateConfig (
				const std::string& sType )
			{
				auto it = m_mFilters.find ( sType );
				if ( it != m_mFilters.end ( ) )
				{
					// call the creation callback to construct this derived type
					return it->second.second ( );
131
132
133
				}
				return nullptr;
			}
134
135
		} // namespace AudibilityFilter
	} // namespace SimulationScheduler
136
} // namespace ITA