audibility_filter_interface.cpp 5.43 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
#include <ITA/SimulationScheduler/Utils/utils.h>
13

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

18
19
namespace ITA
{
20
	namespace SimulationScheduler
21
	{
22
		namespace AudibilityFilter
23
		{
Pascal Palenda's avatar
Pascal Palenda committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
			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> } }
				};
39

40

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

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
			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;
			}

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

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

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

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

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

111
			std::unique_ptr<IAudibilityFilter> CAudibilityFilterFactory::CreateFilter ( const std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig>& pConfig )
112
			{
113
				auto it = m_mFilters.find ( pConfig->sFilterType );
114
115
116
				if ( it != m_mFilters.end ( ) )
				{
					// call the creation callback to construct this derived type
Pascal Palenda's avatar
Pascal Palenda committed
117
118
119
120
121
122
123
124
125
126
127
128
129
					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 ( );
130
131
132
				}
				return nullptr;
			}
133
134
		} // namespace AudibilityFilter
	} // namespace SimulationScheduler
135
} // namespace ITA