Commit 11bda799 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Adding implementation for outdoor worker, first version making noise

parent cade34b0
......@@ -12,6 +12,8 @@
// simulation scheduler includes
#include <ITA/SimulationScheduler/OutdoorAcoustics/outdoor_simulator_interface.h>
#include <ITAPropagationPathSim/CombinedModel/PropagationEngine.h>
// Urban includes
namespace ITA
......@@ -39,6 +41,11 @@ namespace ITA
void Load( const VistaPropertyList& oProperties ) override;
CoordinateSystem eClientCoordinateSystem = CoordinateSystem::Cartesian; //!< 0 = Cartesian, 1 = OpenGL
std::string sJSONGeometryFilePath;
double dSpeedOfSound;
int iMaxReflectionOrder;
int iMaxDiffractionOrder;
};
......@@ -70,8 +77,14 @@ namespace ITA
private:
//! \brief Coordinate system used by client (e.g. VA)
CoordinateSystem m_eClientCoordinateSystem;
std::shared_ptr< ITAPropagationPathSim::CombinedModel::CPathEngine > m_pPathEngine;
std::shared_ptr< ITAGeo::CSensor > m_pSensor;
std::shared_ptr< ITAGeo::CEmitter > m_pEmitter;
std::unique_ptr< CUpdateScene > m_pSceneUpdate;
UrbanSimulatorConfig m_oInitialConfig;
};
} // namespace Urban
......
......@@ -7,116 +7,172 @@
#include "../../configuration_keys.h"
// ITAGeo
#include <ITAGeo/Halfedge/MeshModel.h>
// ITA Base
#include <ITAFileSystemUtils.h>
#include <ITAException.h>
#include <ITAConstants.h>
// STD
#include <ostream>
#include <memory>
//------CONFIG------
using namespace ITA;
using namespace SimulationScheduler;
using namespace OutdoorAcoustics;
using namespace Urban;
using namespace ITAGeo;
using namespace ITAPropagationPathSim;
#pragma region CONFIG
VistaPropertyList ITA::SimulationScheduler::OutdoorAcoustics::Urban::CUrbanSimulator::UrbanSimulatorConfig::Store() const
VistaPropertyList CUrbanSimulator::UrbanSimulatorConfig::Store() const
{
auto oProperties = ISimulatorInterface::SimulatorConfig::Store();
//oProperties.SetValue(CLIENT_COORDINATE_SYSTEM_KEY, AsInteger(eClientCoordinateSystem));
//oProperties.SetValue(STRATIFIED_ATMOSPHERE_KEY, sJsonAtmosphere);
oProperties.SetValue( GEOMETRY_FILE_PATH, sJSONGeometryFilePath );
return oProperties;
}
void ITA::SimulationScheduler::OutdoorAcoustics::Urban::CUrbanSimulator::UrbanSimulatorConfig::Load( const VistaPropertyList& oProperties )
void CUrbanSimulator::UrbanSimulatorConfig::Load( const VistaPropertyList& oProperties )
{
ISimulatorInterface::SimulatorConfig::Load( oProperties );
/*
eClientCoordinateSystem = static_cast<CoordinateSystem>(oProperties.GetValue <int>(CLIENT_COORDINATE_SYSTEM_KEY));
if (oProperties.HasProperty(STRATIFIED_ATMOSPHERE_KEY))
oProperties.GetValue(STRATIFIED_ATMOSPHERE_KEY, sJsonAtmosphere);
else
sJsonAtmosphere = "";
*/
//eClientCoordinateSystem = static_cast<CoordinateSystem>(oProperties.GetValue <int>(CLIENT_COORDINATE_SYSTEM_KEY));
if( !oProperties.HasProperty( GEOMETRY_FILE_PATH ) )
ITA_EXCEPT_INVALID_PARAMETER( "Urban simulator configuration is missing a geometry file path" );
oProperties.GetValue( GEOMETRY_FILE_PATH, sJSONGeometryFilePath );
oProperties.GetValueOrDefault( SPEED_OF_SOUND, dSpeedOfSound, ITAConstants::DEFAULT_SPEED_OF_SOUND_D );
oProperties.GetValueOrDefault( MAX_DIFFRACTION_ORDER , iMaxDiffractionOrder, 1 );
oProperties.GetValueOrDefault( MAX_REFLECTION_ORDER, iMaxReflectionOrder, 1 );
}
#pragma endregion
namespace ITA
#pragma region SIMULATOR
CUrbanSimulator::CUrbanSimulator( const UrbanSimulatorConfig& oConfig )
: m_oInitialConfig( oConfig )
{
namespace SimulationScheduler
m_eClientCoordinateSystem = oConfig.eClientCoordinateSystem;
try
{
namespace OutdoorAcoustics
{
namespace Urban
{
auto pMeshModelList = make_shared< Halfedge::CMeshModelList >();
if( !pMeshModelList->Load( oConfig.sJSONGeometryFilePath ) )
ITA_EXCEPT_INVALID_PARAMETER( "Could not load mes model froom file path " + oConfig.sJSONGeometryFilePath );
//------SIMULATOR------
#pragma region SIMULATOR
m_pSensor = make_shared< ITAGeo::CSensor >();
m_pEmitter = make_shared< ITAGeo::CEmitter >();
CUrbanSimulator::CUrbanSimulator( const UrbanSimulatorConfig& oConfig )
{
m_eClientCoordinateSystem = oConfig.eClientCoordinateSystem;
try
{
ITA_EXCEPT_NOT_IMPLEMENTED;
}
catch( const ITAException& err )
{
throw err;
}
catch( ... )
{
ITA_EXCEPT_INVALID_PARAMETER( "Urban Simulator: Unhandled error while loading configuration." );
}
}
std::unique_ptr< ISimulatorInterface > CUrbanSimulator::Create( std::shared_ptr< const ISimulatorInterface::SimulatorConfig > pConfig )
{
std::shared_ptr< const UrbanSimulatorConfig > pConfigGenericShared = std::dynamic_pointer_cast< const UrbanSimulatorConfig >( pConfig );
if( !pConfigGenericShared )
ITA_EXCEPT_INVALID_PARAMETER( "Pointer to oinvalid config given." );
const UrbanSimulatorConfig& oConf( *pConfigGenericShared );
return std::make_unique<CUrbanSimulator>( oConf );
}
std::unique_ptr< COutdoorSimulationResult > CUrbanSimulator::Compute( std::unique_ptr <CUpdateScene > pUpdateScene )
{
PROFILER_FUNCTION();
m_pSceneUpdate = std::move( pUpdateScene );
const SourceReceiverPair oSRPair = m_pSceneUpdate->GetSourceReceiverPair();
VistaVector3D v3SourcePos = oSRPair.source->GetPosition();
VistaVector3D v3ReceiverPos = oSRPair.receiver->GetPosition();
if( m_eClientCoordinateSystem == CoordinateSystem::OpenGL )
{
v3SourcePos = OpenGLToCart( v3SourcePos );
v3ReceiverPos = OpenGLToCart( v3ReceiverPos );
}
PROFILER_SECTION( "Simulation" );
// @todo
PROFILER_END_SECTION();
PROFILER_SECTION( "Propagation model" );
// @todo
PROFILER_END_SECTION();
auto pResult = std::make_unique< COutdoorSimulationResult >();
return std::move( pResult );
}
VistaVector3D CUrbanSimulator::OpenGLToCart( const VistaVector3D& v3In )
{
return VistaVector3D( v3In[ Vista::X ], -v3In[ Vista::Z ], v3In[ Vista::Y ] );
}
VistaVector3D CUrbanSimulator::CartToOpenGL( const VistaVector3D& v3In )
{
return VistaVector3D( v3In[ Vista::X ], v3In[ Vista::Z ], -v3In[ Vista::Y ] );
}
#pragma endregion
// Configuration
CombinedModel::CPathEngine::CSimulationConfig oConf;
oConf.bFilterIlluminatedRegionDiffraction = true;
CombinedModel::CPathEngine::CAbortionCriteria oAbort;
oAbort.iMaxDiffractionOrder = oConfig.iMaxDiffractionOrder;
oAbort.iMaxReflectionOrder = oConfig.iMaxReflectionOrder;
m_pPathEngine = make_shared< CombinedModel::CPathEngine >();
m_pPathEngine->SetSimulationConfiguration( oConf );
m_pPathEngine->SetAbortionCriteria( oAbort );
m_pPathEngine->InitializePathEnvironment( pMeshModelList );
}
catch( const ITAException& err )
{
throw err;
}
catch( ... )
{
ITA_EXCEPT_INVALID_PARAMETER( "Urban Simulator: Unhandled error while loading configuration." );
}
}
std::unique_ptr< ISimulatorInterface > CUrbanSimulator::Create( std::shared_ptr< const ISimulatorInterface::SimulatorConfig > pConfig )
{
std::shared_ptr< const UrbanSimulatorConfig > pConfigGenericShared = std::dynamic_pointer_cast< const UrbanSimulatorConfig >( pConfig );
if( !pConfigGenericShared )
ITA_EXCEPT_INVALID_PARAMETER( "Pointer to invalid config given." );
const UrbanSimulatorConfig& oConf( *pConfigGenericShared );
return std::make_unique< CUrbanSimulator >( oConf );
}
std::unique_ptr< COutdoorSimulationResult > CUrbanSimulator::Compute( std::unique_ptr< CUpdateScene > pUpdateScene )
{
PROFILER_FUNCTION();
m_pSceneUpdate = std::move( pUpdateScene );
} // namespace Urban
} // namespace OutdoorAcoustics
} // namespace SimulationScheduler
} // namespace ITA
\ No newline at end of file
PROFILER_SECTION( "SceneAdaption" );
// Don't change order of sensor and emitter update calls
auto v3SensorPos = m_pSceneUpdate->GetSourceReceiverPair().receiver->GetPosition();
m_pSensor->v3InteractionPoint = v3SensorPos;
m_pSensor->sName = "id" + std::to_string( m_pSceneUpdate->GetSourceReceiverPair().receiver->GetId() );
m_pPathEngine->UpdateTargetEntity( m_pSensor );
auto v3EmitterPos = m_pSceneUpdate->GetSourceReceiverPair().source->GetPosition();
m_pEmitter->v3InteractionPoint = v3EmitterPos;
m_pEmitter->sName = "id" + std::to_string( m_pSceneUpdate->GetSourceReceiverPair().source->GetId() );
m_pPathEngine->UpdateOriginEntity( m_pEmitter );
// old
//m_pPathEngine->SetEntities( m_pEmitter, m_pSensor );
PROFILER_END_SECTION();
PROFILER_SECTION( "Simulation" );
CPropagationPathList oPathList;
m_pPathEngine->ConstructPropagationPaths( oPathList );
ITAGeoUtils::AddIdentifier( oPathList );
PROFILER_END_SECTION();
auto pResult = std::make_unique< COutdoorSimulationResult >();
pResult->sourceReceiverPair = m_pSceneUpdate->GetSourceReceiverPair();
pResult->dTimeStamp = m_pSceneUpdate->GetTimeStamp();
PROFILER_SECTION( "Modelling" );
pResult->voPathProperties.resize( oPathList.size() );
for( size_t i = 0; i < oPathList.size(); i++ )
{
const CPropagationPath& oSimulationPath( oPathList[ i ] );
auto& oPathProp( pResult->voPathProperties[ i ] );
if( oSimulationPath.size() < 2 )
ITA_EXCEPT_INVALID_PARAMETER( "Result propagation path must have at least two propagation anchors, but received less, id = " + oSimulationPath.sIdentifier );
if( oSimulationPath.GetLength() <= 0.0f )
ITA_EXCEPT_INVALID_PARAMETER( "Result propagation path length was equal or less tan zero, id = " + oSimulationPath.sIdentifier );
// Static properties
oPathProp.sID = oSimulationPath.sIdentifier;
oPathProp.iDiffractionOrder = oSimulationPath.GetNumDiffractions();
oPathProp.iReflectionOrder = oSimulationPath.GetNumReflections();
// @todo move to a function that applies propagation models
oPathProp.dPropagationDelay = oSimulationPath.GetLength() / m_oInitialConfig.dSpeedOfSound;
oPathProp.dSpreadingLoss = 1 / oSimulationPath.GetLength();
oPathProp.oAirAttenuationSpectrum.SetIdentity();
oPathProp.oGeoAttenuationSpectrum.SetIdentity();
oPathProp.v3ReceiverWaveFrontNormal = oSimulationPath.GetReceiverWaveFrontNormal();
oPathProp.v3SourceWaveFrontNormal = oSimulationPath.GetSourceWaveFrontNormal();
}
PROFILER_END_SECTION();
return std::move( pResult );
}
#pragma endregion
......@@ -23,19 +23,23 @@ namespace ITA
//--------------------
#pragma region CONFIG
ISimulatorInterface::SimulatorConfig::SimulatorConfig() : SimulatorConfig( "Unknown" )
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::SimulatorConfig( const std::string & sType )
: m_sSimulatorType( sType )
, sSimulatorType( m_sSimulatorType )
{
}
ISimulatorInterface::SimulatorConfig::SimulatorConfig( const SimulatorConfig & oOther )
: SimulatorConfig( oOther.sSimulatorType )
{
}
ISimulatorInterface::SimulatorConfig& ISimulatorInterface::SimulatorConfig::operator=(const SimulatorConfig& other)
ISimulatorInterface::SimulatorConfig& ISimulatorInterface::SimulatorConfig::operator=( const SimulatorConfig& other )
{
if (this == &other)
return *this;
......@@ -50,6 +54,7 @@ namespace ITA
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);
......@@ -64,11 +69,11 @@ namespace ITA
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::ARTSimulatorConfig> } },
#endif
#ifdef WITH_ART
{ OutdoorAcoustics::ART::CARTSimulator::GetType(), { OutdoorAcoustics::ART::CARTSimulator::Create, std::make_shared< OutdoorAcoustics::ART::CARTSimulator::ARTSimulatorConfig > } },
#endif
#ifdef WITH_URBAN
{ OutdoorAcoustics::Urban::CUrbanSimulator::GetType(), { OutdoorAcoustics::Urban::CUrbanSimulator::Create, std::make_shared<OutdoorAcoustics::Urban::CUrbanSimulator::SimulatorConfig> } },
{ OutdoorAcoustics::Urban::CUrbanSimulator::GetType(), { OutdoorAcoustics::Urban::CUrbanSimulator::Create, std::make_shared< OutdoorAcoustics::Urban::CUrbanSimulator::UrbanSimulatorConfig > } },
#endif
};
......@@ -77,10 +82,12 @@ namespace ITA
{
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)
{
if (!pConfig)
......@@ -90,11 +97,12 @@ namespace ITA
if (it != m_mRegisteredSimulatorTypes.end())
{
// call the creation callback to construct this derived type
std::unique_ptr< ISimulatorInterface > pSimGeneric( it->second.first( pConfig ) );
std::unique_ptr< ISimulatorInterface > pSimGeneric( it->second.first( pConfig ) );
return pSimGeneric;
}
return nullptr;
}
std::shared_ptr<ISimulatorInterface::SimulatorConfig> CSimulatorFactory::CreateConfig(const std::string& sType)
{
auto it = m_mRegisteredSimulatorTypes.find(sType);
......@@ -109,4 +117,4 @@ namespace ITA
#pragma endregion
} // namespace OutdoorAcoustics
} // namespace SimulationScheduler
} // namespace ITA
\ No newline at end of file
} // namespace ITA
......@@ -57,7 +57,7 @@ namespace ITA
pSimulatorConfig = CSimulatorFactory::CreateConfig(sType);
if (!pSimulatorConfig)
if( !pSimulatorConfig ) // || pSimulatorConfig->sSimulatorType.compare( sType ) != 0
ITA_EXCEPT_INVALID_PARAMETER("Could not create simulation worker thread of type '" + sType + "'");
pSimulatorConfig->Load(configProperties);
......@@ -135,10 +135,9 @@ namespace ITA
StopGently(true);
}
std::unique_ptr<IWorkerInterface> CWorkerThread::CreateWorker(
const std::shared_ptr<IWorkerInterface::WorkerConfig>& pConfig, ISchedulerInterface* pParent)
std::unique_ptr< IWorkerInterface > CWorkerThread::CreateWorker( const std::shared_ptr< IWorkerInterface::WorkerConfig >& pConfig, ISchedulerInterface* pParent )
{
return std::make_unique<CWorkerThread>(dynamic_cast<const WorkerThreadConfig&>(*pConfig), pParent);
return std::make_unique< CWorkerThread >( dynamic_cast< const WorkerThreadConfig& >( *pConfig ), pParent );
}
void CWorkerThread::SetSimulator ( std::unique_ptr<ISimulatorInterface> pSimulator )
......@@ -175,10 +174,10 @@ namespace ITA
try
{
// Simulate (blocking)
DEBUG_PRINTF("[ART Thread Worker]\t Simulation Started\n");
pResult = m_pSimulator->Compute(std::move(m_pUpdate));
DEBUG_PRINTF( "[Outdoor Thread Worker]\t Simulation Started\n" );
pResult = m_pSimulator->Compute( std::move( m_pUpdate ) );
m_pUpdate = nullptr;
DEBUG_PRINTF("[ART Thread Worker]\t Simulation Finished\n");
DEBUG_PRINTF( "[Outdoor Thread Worker]\t Simulation Finished\n" );
}
catch (ITAException & e)
{
......
......@@ -35,6 +35,7 @@ namespace ITA
const std::string workerFieldOfDuty = "@FieldOfDuty";
}
namespace OutdoorAcoustics
{
const std::string WORKER_SIMULATOR_SECTION_NAME = "Simulator";
......@@ -45,6 +46,16 @@ namespace ITA
const std::string STRATIFIED_ATMOSPHERE_KEY = "@StratifiedAtmosphere";
const std::string CLIENT_COORDINATE_SYSTEM_KEY = "@ClientCoordinateSystem";
}
namespace Urban
{
const std::string GEOMETRY_FILE_PATH = "@GeometryFilePath";
const std::string CLIENT_COORDINATE_SYSTEM_KEY = "@ClientCoordinateSystem";
const std::string SPEED_OF_SOUND = "@SpeedOfSound";
const std::string MAX_REFLECTION_ORDER = "@MaxReflectionOrder";
const std::string MAX_DIFFRACTION_ORDER = "@MaxDiffractionOrder";
}
}
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