filter_network.h 5.75 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_AUDIBILITY_FILTER_FILTER_NETWORK
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_AUDIBILITY_FILTER_FILTER_NETWORK

// API includes
#include <ITA/simulation_scheduler/definitions.h>

// simulation scheduler includes
#include <ITA/simulation_scheduler/audibility_filter/audibility_filter_interface.h>
#include <ITA/simulation_scheduler/config_interface.h>

// std includes
#include <unordered_map>
13
#include <memory>
14
15
16
17
#include <vector>

namespace ITA
{
18
	namespace SimulationScheduler
19
20
21
	{
		class CUpdateScene;

22
		namespace AudibilityFilter
23
		{
Pascal Palenda's avatar
Pascal Palenda committed
24
25
26
27
28
29
30
31
			///
			/// \brief This class models a network of audibility filters.
			///
			/// It enables a easy building an evaluation of the configured network.
			/// The actual network is modeled as a tree.
			/// Even though in trees paths can not merge, a tree enables an easy way to model the network.
			/// However, merging paths can still be modeled this way. 
			/// 
32
33
34
			class ITA_SIMULATION_SCHEDULER_API CFilterNetwork
			{
			public:
Pascal Palenda's avatar
Pascal Palenda committed
35
36
37
				///
				/// \brief Configuration class for CFilterNetwork.
				/// 
38
39
40
41
42
43
				struct ITA_SIMULATION_SCHEDULER_API FilterNetworkConfig : public IConfig
				{
					std::vector<std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig>> vpFilterConfigs;

					std::string sStartFilter;

44
					VistaPropertyList Store ( ) const override;
45

46
					void Load ( const VistaPropertyList& oProperties ) override;
47
48
49
50
51
52
53
54
				};

				CFilterNetwork ( ) = delete;

				CFilterNetwork ( const CFilterNetwork& ) = delete;

				CFilterNetwork& operator=( const CFilterNetwork& ) = delete;

Pascal Palenda's avatar
Pascal Palenda committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
				///
				/// \brief Constructor for CFilterNetwork.
				/// \param oConfig the FilterNetworkConfig to configure the CFilterNetwork.
				/// 
				explicit CFilterNetwork ( const FilterNetworkConfig& oConfig );

				///
				/// \brief Evaluate the CFilterNetwork.
				///
				/// This method goes through the configured network and checks weather the \p newUpdate is audible.
				/// \param previousState the previous state of the scene to check against.
				/// \param newUpdate the CUpdateScene to check.
				/// \return true if the change between \p previousState and \p newUpdate is audible, else false.
				/// 
69
				bool EvaluateNetwork ( const CUpdateScene& previousState, const CUpdateScene& newUpdate ) const;
70
71

			private:
Pascal Palenda's avatar
Pascal Palenda committed
72
73
74
				///
				/// \brief Tree node used to model the actual network.
				/// 
75
76
77
				class NetworkTreeNode
				{
				public:
Pascal Palenda's avatar
Pascal Palenda committed
78
79
80
					///
					/// \brief Default constructor for NetworkTreeNode. 
					/// 
81
82
					NetworkTreeNode ( ) = default;

Pascal Palenda's avatar
Pascal Palenda committed
83
84
85
86
87
88
					///
					/// \brief Constructor for NetworkTreeNode.
					///
					/// This constructor set the filter to be executed for the tree node and how it should be used.
					/// \p bInvertCondition is only used if the UsageMode is set to be a condition.
					/// \param pFilter the filter to be executed for the tree node.
Pascal Palenda's avatar
Pascal Palenda committed
89
					/// \param sFilterName name of the filter.
Pascal Palenda's avatar
Pascal Palenda committed
90
91
92
					/// \param eUsageMode the UsageMode for the filter.
					/// \param bInvertCondition true, if the condition should be inverted.
					/// 
Pascal Palenda's avatar
Pascal Palenda committed
93
					NetworkTreeNode ( const IAudibilityFilter* pFilter, std::string sFilterName, IAudibilityFilter::UsageMode eUsageMode, bool bInvertCondition );
94

Pascal Palenda's avatar
Pascal Palenda committed
95
96
97
98
99
100
101
102
103
					///
					/// \brief Evaluate the tree nodes filter and its children.
					///
					/// This method first evaluates the filter or condition for this node.
					/// Depending on the result, the children of this node are evaluated next.
					/// \param previousState the previous state of the scene to check against.
					/// \param newUpdate the CUpdateScene to check.
					/// \return true if the change between \p previousState and \p newUpdate is audible, else false.
					/// 
104
					bool Evaluate ( const CUpdateScene& previousState, const CUpdateScene& newUpdate );
105

Pascal Palenda's avatar
Pascal Palenda committed
106
107
108
					///
					/// \brief Children of the node.
					/// 
109
110
111
					std::vector<NetworkTreeNode > vChildren;

				private:
Pascal Palenda's avatar
Pascal Palenda committed
112
113
114
					///
					/// \brief The audibility filter of the tree node.
					/// 
115
116
					const IAudibilityFilter* m_pFilter;

Pascal Palenda's avatar
Pascal Palenda committed
117
118
119
					///
					/// \brief The usage mode for the filter.
					/// 
120
121
					IAudibilityFilter::UsageMode m_eUsageMode;

Pascal Palenda's avatar
Pascal Palenda committed
122
123
124
					///
					/// \brief True, if the condition should be inverted.
					/// 
125
					bool m_bInvertCondition;
Pascal Palenda's avatar
Pascal Palenda committed
126
127
128
129
130
131

					///
					/// \brief Name of the filter of the tree node.
					/// \note This is primarily used for profiling.
					/// 
					std::string m_sFilterName;
132
133
				};

Pascal Palenda's avatar
Pascal Palenda committed
134
135
136
137
				///
				/// \brief Create all the actual filter instances that were configured.
				/// \param vpFilterConfigs vector of all filters that should be created.
				/// 
138
				void CreateFilters ( const std::vector<std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig>>& vpFilterConfigs );
139

Pascal Palenda's avatar
Pascal Palenda committed
140
141
142
143
				///
				/// \brief Build the network tree.
				/// \param oConfig configuration from which to build the tree.
				/// 
144
				void BuildNetwork ( const FilterNetworkConfig& oConfig );
145

Pascal Palenda's avatar
Pascal Palenda committed
146
147
148
149
150
151
				///
				/// \brief Recursive helper method for building the network tree. 
				/// \param mConfigMap map relating the filter name to its config. 
				/// \param oRoot the root from which to build the tree.
				/// \param oRootConfig 
				/// 
152
				void NetworkBuilderHelper ( const std::map<std::string, std::shared_ptr<IAudibilityFilter::AudibilityFilterConfig>>& mConfigMap,
153
154
155
											NetworkTreeNode& oRoot,
											const IAudibilityFilter::AudibilityFilterConfig& oRootConfig );

Pascal Palenda's avatar
Pascal Palenda committed
156
157
158
				///
				/// \brief Map containing all configured filters, keyed by their names.
				/// 
159
160
				std::unordered_map<std::string, std::unique_ptr<IAudibilityFilter>> m_mAudibilityFilters;

Pascal Palenda's avatar
Pascal Palenda committed
161
162
163
				///
				/// \brief The actual network tree of the CFilterNetwork.
				/// 
164
				std::unique_ptr<NetworkTreeNode> m_pNetworkTree;
165
			};
166
167
		} // namespace AudibilityFilter
	} // namespace SimulationScheduler
168
169
170
} // namespace ITA

#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_AUDIBILITY_FILTER_FILTER_NETWORK