Commit a3810b34 authored by Philipp Schäfer's avatar Philipp Schäfer
Browse files

OutdoorAcoustics

- filled outdoor simulator interface with live and added factory
- art simulator now properly derived from interface and should work with factory
- worker thread now holds simulator
- updated configs
parent 2fdc7734
......@@ -10,9 +10,7 @@
//#include <type_traits>
// simulation scheduler includes
#include <ITA/SimulationScheduler/update_scene.h>
#include <ITA/SimulationScheduler/OutdoorAcoustics/outdoor_simulator_interface.h>
#include <ITA/SimulationScheduler/OutdoorAcoustics/outdoor_simulation_result.h>
// ART includes
#include <ITAGeo/Atmosphere/StratifiedAtmosphere.h>
......@@ -33,34 +31,47 @@ namespace ITA
* This Simulator uses a single Atmosphere::EigenraySearch::Engine instance.
* The simulation is run synchronous/blocking. Thus, only one simulation can be run at the same time.
*/
class ITA_SIMULATION_SCHEDULER_API CSimulator : public OutdoorAcoustics::ISimulatorInterface
class ITA_SIMULATION_SCHEDULER_API CARTSimulator : public OutdoorAcoustics::ISimulatorInterface
{
public:
//! \brief Raven status types
enum class SimulatorStatus
//! \brief Configuration class for a outdoor acoustics simulator.
struct ITA_SIMULATION_SCHEDULER_API ARTSimulatorConfig : public ISimulatorInterface::SimulatorConfig
{
uninitialized, ///< Simulator is uninitialized.
idle, ///< Raven instance is running but no geometry is loaded.
sceneLoaded, ///< Raven instance is running and a geometry is loaded.
filterEngineLoaded ///< Raven initialized the filter engine.
inline explicit ARTSimulatorConfig() {};
VistaPropertyList Store() const override;
void Load(const VistaPropertyList& oProperties) override;
std::string sJsonAtmosphere;
};
// //! \brief Raven status types
//enum class SimulatorStatus
//{
// uninitialized, ///< Simulator is uninitialized.
// idle, ///< Raven instance is running but no geometry is loaded.
// sceneLoaded, ///< Raven instance is running and a geometry is loaded.
// filterEngineLoaded ///< Raven initialized the filter engine.
//};
CSimulator ( );
CARTSimulator( const ARTSimulatorConfig& oConfig );
CSimulator(const CSimulator& other) = delete;
CSimulator(CSimulator&& other) = delete;
CSimulator& operator=(const CSimulator& other) = delete;
CSimulator& operator=(CSimulator&& other) = delete;
CARTSimulator(const CARTSimulator& other) = delete;
CARTSimulator(CARTSimulator&& other) = delete;
CARTSimulator& operator=(const CARTSimulator& other) = delete;
CARTSimulator& operator=(CARTSimulator&& other) = delete;
static std::unique_ptr<ISimulatorInterface> Create( const std::shared_ptr<ISimulatorInterface::SimulatorConfig>& );
//! \brief Reset the simulator.
void Reset ( ) override;
//! \brief Simulate the given task.
std::unique_ptr<COutdoorSimulationResult> Compute ( std::unique_ptr<CUpdateScene> pSceneUpdate ) override;
inline std::string GetType() override
static std::string GetType()
{
return "ARTSimulator";
};
......@@ -74,18 +85,18 @@ namespace ITA
std::unique_ptr<CUpdateScene> m_pSceneUpdate;
//! \brief Current status of the simulator.
SimulatorStatus m_eStatus;
// //! \brief Current status of the simulator.
//SimulatorStatus m_eStatus;
//! \brief Initialise the raven instance.
//! The simulator is idle afterwards.
void Init ( );
};
inline bool operator<(const CSimulator::SimulatorStatus& lhs, const CSimulator::SimulatorStatus& rhs)
{
return std::underlying_type_t<CSimulator::SimulatorStatus>(lhs) < std::underlying_type_t<CSimulator::SimulatorStatus>(rhs);
};
//inline bool operator<(const CARTSimulator::SimulatorStatus& lhs, const CARTSimulator::SimulatorStatus& rhs)
//{
// return std::underlying_type_t<CARTSimulator::SimulatorStatus>(lhs) < std::underlying_type_t<CARTSimulator::SimulatorStatus>(rhs);
//};
} // namespace ART
} // namespace OutdoorAcoustics
......
......@@ -7,8 +7,10 @@
// std includes
#include <string>
#include <memory>
#include <functional>
// simulation scheduler includes
#include <ITA/SimulationScheduler/config_interface.h>
#include <ITA/SimulationScheduler/update_scene.h>
#include <ITA/SimulationScheduler/OutdoorAcoustics/outdoor_simulation_result.h>
......@@ -26,14 +28,75 @@ namespace ITA
class ITA_SIMULATION_SCHEDULER_API ISimulatorInterface
{
public:
//! \brief Reset the simulator.
//! \brief Configuration class for a outdoor acoustics simulator.
struct ITA_SIMULATION_SCHEDULER_API SimulatorConfig : public IConfig
{
explicit SimulatorConfig();
explicit SimulatorConfig(const std::string& sType);
SimulatorConfig(const SimulatorConfig& other);
SimulatorConfig& operator=(const SimulatorConfig& other);
VistaPropertyList Store() const override;
void Load(const VistaPropertyList& oProperties) override;
const std::string& sSimulatorType;
private:
std::string m_sSimulatorType;
};
//! \brief Reset the outdoor acoustics simulator.
virtual void Reset() = 0;
//! \brief Simulate the given task.
virtual std::unique_ptr<COutdoorSimulationResult> Compute(std::unique_ptr<CUpdateScene> pSceneUpdate) = 0;
//! \brief Returns the type of the simulator
virtual std::string GetType() = 0;
//! Static methods to be implemented by derived simulators for factory purposes
//static std::unique_ptr<ISimulatorInterface> Create(const std::shared_ptr <ISimulatorInterface::SimulatorConfig>&);
//static std::string GetType();
};
///
/// \brief Factory class for outdoor acoustic simulators.
///
/// This class implements an extensible factory for outdoor acoustic simulators.
/// After a type of simulator is registered with its IWorkerInterface::createWorker, it can be created using this factory.
/// \todo Add a way to get the correct config from the type. The factory already knows of all possible workers.
///
class ITA_SIMULATION_SCHEDULER_API CSimulatorFactory
{
public:
//! \brief The function signature for a create function.
typedef std::function<std::unique_ptr<ISimulatorInterface>(const std::shared_ptr<ISimulatorInterface::SimulatorConfig>&)> CreateCallback;
//! \brief The function signature for a config create function.
typedef std::function<std::shared_ptr<ISimulatorInterface::SimulatorConfig>()> ConfigCreateCallback;
//! \brief Register a type of simulator to the factory.
static void RegisterSimulator(const std::string& type, CreateCallback createFunction, ConfigCreateCallback configCreateFunction);
//! \brief Unregister a type of simulator from the factory.
static void UnregisterSimulator(const std::string& type);
//! \brief Factory method for simulators.
//! \param pConfig the configuration for the worker.
//! \param pParent the parent scheduler.
//! \return a pointer to the created worker.
static std::unique_ptr<ISimulatorInterface> CreateSimulator(const std::shared_ptr<ISimulatorInterface::SimulatorConfig>& pConfig);
//! \brief Factory method for corresponding configs.
//! \param sType the configuration for the filter.
//! \return a pointer to the created filter config.
static std::shared_ptr<ISimulatorInterface::SimulatorConfig> CreateConfig(const std::string& sType);
private:
//! \brief Map containing all creation functions.
static std::map < std::string, std::pair<CreateCallback, ConfigCreateCallback> > m_mRegisteredSimulatorTypes;
};
} // namespace OutdoorAcoustics
......
......@@ -10,6 +10,7 @@
// simulation scheduler includes
#include <ITA/SimulationScheduler/worker_interface.h>
#include <ITA/SimulationScheduler/config_interface.h>
#include <ITA/SimulationScheduler/update_scene.h>
#include <ITA/SimulationScheduler/OutdoorAcoustics/outdoor_simulator_interface.h>
......@@ -35,7 +36,7 @@ namespace ITA
{
public:
//! \brief Configuration class for a raven thread worker.
//! \brief Configuration class for a outdoor acoustics thread worker.
struct ITA_SIMULATION_SCHEDULER_API WorkerThreadConfig : public IWorkerInterface::WorkerConfig
{
explicit WorkerThreadConfig();
......@@ -44,9 +45,7 @@ namespace ITA
VistaPropertyList Store() const override;
void Load(const VistaPropertyList& oProperties) override;
const std::string& sSimulatorType;
private:
std::string m_sSimulatorType;
std::shared_ptr<ISimulatorInterface::SimulatorConfig> pSimulatorConfig;
};
//! \brief Constructor for CWorkerThread.
......
......@@ -4,8 +4,10 @@
#include <ITA/SimulationScheduler/Profiler/profiler.h>
//#include <ITA/SimulationScheduler/Utils/utils.h>
#include "../../configuration_keys.h"
//#include "ITALog.h"
//ITAGeo
#include <ITAGeo/Utils/JSON/Atmosphere.h>
namespace ITA
{
......@@ -21,20 +23,42 @@ namespace ITA
//#define RAVENSIMULATOR_REQUIRE_FILTER_ENGINE { if( operator<(m_eStatus , SimulatorStatus::filterEngineLoaded) ) ITA_EXCEPT1( MODAL_EXCEPTION, "Loaded filter engine required for this method, probably an error in LoadScene() occured" ); };
const int g_iMaxNumSources = 1;
const int g_iMaxNumReceivers = 1;
CSimulator::CSimulator ( )
: m_eStatus ( SimulatorStatus::uninitialized )
VistaPropertyList CARTSimulator::ARTSimulatorConfig::Store() const
{
//m_pRavenMasterController = std::make_unique<R_MasterController> ( );
auto oProperties = ISimulatorInterface::SimulatorConfig::Store();
oProperties.SetValue(STRATIFIED_ATMOSPHERE_KEY, sJsonAtmosphere);
return oProperties;
}
void CARTSimulator::ARTSimulatorConfig::Load(const VistaPropertyList& oProperties)
{
ISimulatorInterface::SimulatorConfig::Load(oProperties);
oProperties.GetValue(STRATIFIED_ATMOSPHERE_KEY, sJsonAtmosphere);
}
//CARTSimulator::CARTSimulator ( )
// : m_eStatus ( SimulatorStatus::uninitialized )
//{
// //m_pRavenMasterController = std::make_unique<R_MasterController> ( );
//m_pRavenMasterController->m_currentConfig_General.applicationMode = NET_MODE;
// //m_pRavenMasterController->m_currentConfig_General.applicationMode = NET_MODE;
Init ( ); // Danach: IDLE
// Init ( ); // Danach: IDLE
//}
CARTSimulator::CARTSimulator(const ARTSimulatorConfig& oConfig)
{
ITAGeo::Utils::JSON::Decode(m_oAtmosphere, oConfig.sJsonAtmosphere);
Init(); // Danach: IDLE
}
std::unique_ptr<ISimulatorInterface> CARTSimulator::Create( const std::shared_ptr<ISimulatorInterface::SimulatorConfig>& pConfig )
{
return std::make_unique<CARTSimulator>( dynamic_cast< const ARTSimulatorConfig& > ( *pConfig ) );
}
void CSimulator::Reset ( )
void CARTSimulator::Reset ( )
{
PROFILER_EVENT_COUNT ( "Reset" );
Init ( );
......@@ -42,7 +66,7 @@ namespace ITA
std::unique_ptr<COutdoorSimulationResult> CSimulator::Compute ( std::unique_ptr<CUpdateScene> pUpdateScene )
std::unique_ptr<COutdoorSimulationResult> CARTSimulator::Compute ( std::unique_ptr<CUpdateScene> pUpdateScene )
{
PROFILER_FUNCTION ( );
......@@ -56,12 +80,12 @@ namespace ITA
return std::move(pResult);
}
void CSimulator::Init ( )
void CARTSimulator::Init ( )
{
PROFILER_FUNCTION ( );
//m_oEigenrayEngine; //TODO INIT
m_eStatus = SimulatorStatus::idle;
//m_eStatus = SimulatorStatus::idle;
}
} // namespace ART
} // namespace OutdoorAcoustics
......
......@@ -11,6 +11,7 @@ endif()
set( DirFiles
outdoor_simulation_result.cpp
outdoor_worker_thread.cpp
outdoor_simulator_interface.cpp
)
set( DirFiles_SourceGroup "${RelativeSourceGroup}" )
......
// Header include
#include <ITA/SimulationScheduler/OutdoorAcoustics/outdoor_simulator_interface.h>
// simulation scheduler includes
#include "../configuration_keys.h"
#ifdef WITH_ART
#include <ITA/SimulationScheduler/OutdoorAcoustics/ART/art_simulator.h>
#endif
namespace ITA
{
namespace SimulationScheduler
{
namespace OutdoorAcoustics
{
//-------CONFIG-------
//--------------------
#pragma region CONFIG
ISimulatorInterface::SimulatorConfig::SimulatorConfig() : SimulatorConfig("Unknown")
{}
ISimulatorInterface::SimulatorConfig::SimulatorConfig(const std::string & sType)
: m_sSimulatorType(sType)
, sSimulatorType(m_sSimulatorType)
{}
ISimulatorInterface::SimulatorConfig::SimulatorConfig(const SimulatorConfig & other)
: SimulatorConfig(sSimulatorType)
{}
ISimulatorInterface::SimulatorConfig& ISimulatorInterface::SimulatorConfig::operator=(const SimulatorConfig& other)
{
if (this == &other)
return *this;
IConfig::operator =(other);
m_sSimulatorType = other.m_sSimulatorType;
return *this;
}
VistaPropertyList ISimulatorInterface::SimulatorConfig::Store() const
{
VistaPropertyList oProperties;
oProperties.SetValue(SIMULATOR_TYPE_KEY, m_sSimulatorType);
return oProperties;
}
void ISimulatorInterface::SimulatorConfig::Load(const VistaPropertyList& oProperties)
{
oProperties.GetValue <std::string>(SIMULATOR_TYPE_KEY, m_sSimulatorType);
}
#pragma endregion
//-------FACTORY-------
//---------------------
#pragma region FACTORY
std::map<std::string, std::pair<CSimulatorFactory::CreateCallback, CSimulatorFactory::ConfigCreateCallback>> CSimulatorFactory::m_mRegisteredSimulatorTypes =
{
#ifdef WITH_ART
{ OutdoorAcoustics::ART::CARTSimulator::GetType(), { OutdoorAcoustics::ART::CARTSimulator::Create, std::make_shared<OutdoorAcoustics::ART::CARTSimulator::SimulatorConfig> } },
#endif
};
void CSimulatorFactory::RegisterSimulator(const std::string& sType, CreateCallback createFunction, ConfigCreateCallback configCreateFunction)
{
m_mRegisteredSimulatorTypes[sType] = { createFunction, configCreateFunction };
}
void CSimulatorFactory::UnregisterSimulator(const std::string& sType)
{
m_mRegisteredSimulatorTypes.erase(sType);
}
std::unique_ptr<ISimulatorInterface> CSimulatorFactory::CreateSimulator(const std::shared_ptr<ISimulatorInterface::SimulatorConfig>& pConfig)
{
auto it = m_mRegisteredSimulatorTypes.find(pConfig->sSimulatorType);
if (it != m_mRegisteredSimulatorTypes.end())
{
// call the creation callback to construct this derived type
return it->second.first(pConfig);
}
return nullptr;
}
std::shared_ptr<ISimulatorInterface::SimulatorConfig> CSimulatorFactory::CreateConfig(const std::string& sType)
{
auto it = m_mRegisteredSimulatorTypes.find(sType);
if (it != m_mRegisteredSimulatorTypes.end())
{
// call the creation callback to construct this derived type
return it->second.second();
}
return nullptr;
}
#pragma endregion
} // namespace OutdoorAcoustics
} // namespace SimulationScheduler
} // namespace ITA
\ No newline at end of file
......@@ -31,8 +31,6 @@ namespace ITA
CWorkerThread::WorkerThreadConfig::WorkerThreadConfig(const std::string& sType)
: WorkerConfig(GetType())
, m_sSimulatorType(sType)
, sSimulatorType(m_sSimulatorType)
{
}
......@@ -40,7 +38,8 @@ namespace ITA
{
auto oProperties = WorkerConfig::Store();
oProperties.SetValue(SIMULATOR_TYPE_KEY, sSimulatorType);
if (pSimulatorConfig)
oProperties.SetValue( WORKER_SIMULATOR_SECTION_NAME, pSimulatorConfig->Store() );
return oProperties;
}
......@@ -49,11 +48,25 @@ namespace ITA
{
WorkerConfig::Load(oProperties);
oProperties.GetValue(SIMULATOR_TYPE_KEY, m_sSimulatorType);
for (const auto& oProperty : oProperties)
{
if (oProperty.first.find( WORKER_SIMULATOR_SECTION_NAME ) != std::string::npos && oProperty.second.GetPropertyType() == VistaProperty::PROPT_PROPERTYLIST)
{
const VistaPropertyList configProperties = oProperty.second.GetPropertyListConstRef();
const auto sType = configProperties.GetValue<std::string>(SIMULATOR_TYPE_KEY);
pSimulatorConfig = CSimulatorFactory::CreateConfig(sType);
if (!pSimulatorConfig)
ITA_EXCEPT_INVALID_PARAMETER("Could not create simulation worker thread of type '" + sType + "'");
pSimulatorConfig->Load(configProperties);
}
}
}
CWorkerThread::CWorkerThread(const WorkerThreadConfig& oConfig, ISchedulerInterface* pParent) :
IWorkerInterface(pParent), m_evTriggerLoop(VistaThreadEvent::NON_WAITABLE_EVENT)
CWorkerThread::CWorkerThread(const WorkerThreadConfig& oConfig, ISchedulerInterface* pParent)
: IWorkerInterface(pParent), m_evTriggerLoop(VistaThreadEvent::NON_WAITABLE_EVENT)
{
//oConfig;
//m_oSimulator = std::make_unique<CSimulator> ( m_eFieldOfDuty, oConfig.sRavenProjectFilePath );
......
......@@ -37,7 +37,13 @@ namespace ITA
}
namespace OutdoorAcoustics
{
const std::string WORKER_SIMULATOR_SECTION_NAME = "Simulator";
const std::string SIMULATOR_TYPE_KEY = "@SimulatorType";
namespace ART
{
const std::string STRATIFIED_ATMOSPHERE_KEY = "@StratifiedAtmosphere";
}
}
namespace AudibilityFilter
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment