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

ART Simulator

- now checks for coordinate system type
- filled Compute() method with live
- kicked out unnecessary relicts from RAVEN Simulator
parent fcdb2d1b
......@@ -104,6 +104,7 @@ if( ITA_SIMULATION_SCHEDULER_ART_MODULE )
vista_use_package( ITAGeo REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAPropagationModels REQUIRED FIND_DEPENDENCIES )
vista_use_package( ITAPropagationPathSim REQUIRED FIND_DEPENDENCIES )
vista_use_package( libjson )
endif( )
......
......@@ -42,18 +42,10 @@ namespace ITA
VistaPropertyList Store() const override;
void Load(const VistaPropertyList& oProperties) override;
CoordinateSystem eClientCoordinateSystem = CoordinateSystem::Cartesian;
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.
//};
CARTSimulator( const ARTSimulatorConfig& oConfig );
......@@ -66,7 +58,7 @@ namespace ITA
static std::unique_ptr<ISimulatorInterface> Create( const std::shared_ptr<ISimulatorInterface::SimulatorConfig>& );
//! \brief Reset the simulator.
void Reset ( ) override;
inline void Reset() override { };
//! \brief Simulate the given task.
std::unique_ptr<COutdoorSimulationResult> Compute ( std::unique_ptr<CUpdateScene> pSceneUpdate ) override;
......@@ -77,27 +69,22 @@ namespace ITA
};
private:
//! \brief RT Eigenray-Engine instance.
static VistaVector3D OpenGLToCart(const VistaVector3D& v3In);
static VistaVector3D CartToOpenGL(const VistaVector3D& v3In);
private:
//! \brief Coordinate system used by client (e.g. VA)
CoordinateSystem m_eClientCoordinateSystem;
//! \brief ART Eigenray-Engine instance.
EigenraySearch::CEngine m_oEngine;
//! \brief Stratified atmosphere
CStratifiedAtmosphere m_oAtmosphere;
std::unique_ptr<CUpdateScene> m_pSceneUpdate;
// //! \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 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
} // namespace SimulationScheduler
......
......@@ -20,6 +20,12 @@ namespace ITA
const C3DObject* receiver;
} SourceReceiverPair;
enum class CoordinateSystem
{
Cartesian,
OpenGL
};
namespace RoomAcoustics
{
///
......
......@@ -2,13 +2,17 @@
#include <ITA/SimulationScheduler/OutdoorAcoustics/ART/art_simulator.h>
#include <ITA/SimulationScheduler/Profiler/profiler.h>
//#include <ITA/SimulationScheduler/Utils/utils.h>
#include <ITA/SimulationScheduler/Utils/data_type_utils.h>
#include "../../configuration_keys.h"
//ITAGeo
#include <ITAGeo/Utils/JSON/Atmosphere.h>
#include <ITAPropagationModels/Atmosphere/AirAttenuation.h>
using namespace ITAPropagationPathSim::AtmosphericRayTracing;
using namespace ITAPropagationModels::Atmosphere;
namespace ITA
{
namespace SimulationScheduler
......@@ -17,76 +21,107 @@ namespace ITA
{
namespace ART
{
//#define RAVENSIMULATOR_REQUIRE_UNINITIALISED { if( operator<(m_eStatus, SimulatorStatus::uninitialized) ) ITA_EXCEPT1( MODAL_EXCEPTION, "Uninitialized mode required for this method, use Reset() prior to this call" ); };
//#define RAVENSIMULATOR_REQUIRE_IDLE { if( operator<(m_eStatus , SimulatorStatus::idle) ) ITA_EXCEPT1( MODAL_EXCEPTION, "Idle mode required for this method, use Reset() and Init() prior to this call" ); };
//#define RAVENSIMULATOR_REQUIRE_SCENE { if( operator<(m_eStatus , SimulatorStatus::sceneLoaded) ) ITA_EXCEPT1( MODAL_EXCEPTION, "Loaded scene required for this method, use LoadScene() prior to this call" ); };
//#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" ); };
//------CONFIG------
#pragma region CONFIG
VistaPropertyList CARTSimulator::ARTSimulatorConfig::Store() const
{
auto oProperties = ISimulatorInterface::SimulatorConfig::Store();
oProperties.SetValue(CLIENT_COORDINATE_SYSTEM_KEY, AsInteger(eClientCoordinateSystem));
oProperties.SetValue(STRATIFIED_ATMOSPHERE_KEY, sJsonAtmosphere);
return oProperties;
}
void CARTSimulator::ARTSimulatorConfig::Load(const VistaPropertyList& oProperties)
{
ISimulatorInterface::SimulatorConfig::Load(oProperties);
eClientCoordinateSystem = static_cast<CoordinateSystem>(oProperties.GetValue <int>(CLIENT_COORDINATE_SYSTEM_KEY));
oProperties.GetValue(STRATIFIED_ATMOSPHERE_KEY, sJsonAtmosphere);
}
#pragma endregion
//CARTSimulator::CARTSimulator ( )
// : m_eStatus ( SimulatorStatus::uninitialized )
//{
// //m_pRavenMasterController = std::make_unique<R_MasterController> ( );
// //m_pRavenMasterController->m_currentConfig_General.applicationMode = NET_MODE;
// Init ( ); // Danach: IDLE
//}
//------SIMULATOR------
#pragma region SIMULATOR
CARTSimulator::CARTSimulator(const ARTSimulatorConfig& oConfig)
{
m_eClientCoordinateSystem = oConfig.eClientCoordinateSystem;
ITAGeo::Utils::JSON::Decode(m_oAtmosphere, oConfig.sJsonAtmosphere);
Init(); // Danach: IDLE
m_oEngine.eigenraySettings.rayTracing.maxReflectionOrder = 1; //Always expect exactly 2 eigenrays
}
std::unique_ptr<ISimulatorInterface> CARTSimulator::Create( const std::shared_ptr<ISimulatorInterface::SimulatorConfig>& pConfig )
{
return std::make_unique<CARTSimulator>( dynamic_cast< const ARTSimulatorConfig& > ( *pConfig ) );
}
void CARTSimulator::Reset ( )
{
PROFILER_EVENT_COUNT ( "Reset" );
Init ( );
}
std::unique_ptr<COutdoorSimulationResult> CARTSimulator::Compute ( std::unique_ptr<CUpdateScene> pUpdateScene )
{
PROFILER_FUNCTION ( );
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 ( "Adapt Scene" );
// Simulate
PROFILER_SECTION( "Finding Eigenrays" );
std::vector< std::shared_ptr< CRay > > vpEigenrays = m_oEngine.Run( m_oAtmosphere, v3SourcePos, v3ReceiverPos );
PROFILER_END_SECTION( );
PROFILER_END_SECTION ( );
if (vpEigenrays.size() != 2)
ITA_EXCEPT_INVALID_PARAMETER( std::string( "Expected 2 eigenrays but found " + std::to_string(vpEigenrays.size()) + ".") );
// Simulate
PROFILER_SECTION("Eigenrays to OutdoorSimulationResult");
auto pResult = std::make_unique< COutdoorSimulationResult>();
pResult->sourceReceiverPair = oSRPair;
pResult->iReferenceID = m_pSceneUpdate->GetReferenceID();
auto oIdentitySpectrum = ITABase::CThirdOctaveFactorMagnitudeSpectrum();
oIdentitySpectrum.SetIdentity();
for (int idx = 0; idx < vpEigenrays.size(); idx++)
{
pResult->voPathProperties.push_back( COutdoorSimulationResult::CPathProperty() );
pResult->voPathProperties[idx].dPropagationDelay = vpEigenrays[idx]->LastTimeStamp();
pResult->voPathProperties[idx].dSpreadingLoss = vpEigenrays[idx]->SpreadingLoss();
pResult->voPathProperties[idx].iReflectionOrder = vpEigenrays[idx]->ReflectionOrder();
pResult->voPathProperties[idx].iDiffractionOrder = 0; //No diffraction
pResult->voPathProperties[idx].oAirAttenuationSpectrum = ITAPropagationModels::Atmosphere::AirAttenuationSpectrum(*vpEigenrays[idx], m_oAtmosphere);
//pResult->voPathProperties[idx].oGeoAttenuationSpectrum = ...; //Default is identity. To be changed in future. Probably reading data from config.
pResult->voPathProperties[idx].v3SourceWaveFrontNormal = vpEigenrays[idx]->InitialDirection();
pResult->voPathProperties[idx].v3ReceiverWaveFrontNormal = vpEigenrays[idx]->LastWavefrontNormal();
if (m_eClientCoordinateSystem == CoordinateSystem::OpenGL)
{
pResult->voPathProperties[idx].v3SourceWaveFrontNormal = CartToOpenGL(pResult->voPathProperties[idx].v3SourceWaveFrontNormal);
pResult->voPathProperties[idx].v3ReceiverWaveFrontNormal = CartToOpenGL(pResult->voPathProperties[idx].v3ReceiverWaveFrontNormal);
}
}
PROFILER_END_SECTION();
return std::move(pResult);
}
void CARTSimulator::Init ( )
VistaVector3D CARTSimulator::OpenGLToCart(const VistaVector3D& v3In)
{
PROFILER_FUNCTION ( );
//m_oEigenrayEngine; //TODO INIT
//m_eStatus = SimulatorStatus::idle;
return VistaVector3D( v3In[Vista::X], -v3In[Vista::Z], v3In[Vista::Y] );
}
VistaVector3D CARTSimulator::CartToOpenGL(const VistaVector3D& v3In)
{
return VistaVector3D( v3In[Vista::X], v3In[Vista::Z], -v3In[Vista::Y] );
}
#pragma endregion
} // namespace ART
} // namespace OutdoorAcoustics
} // namespace SimulationScheduler
......
......@@ -65,7 +65,8 @@ int COutdoorSimulationResult::DeSerialize(IVistaDeSerializer& pDeserializer)
int iNumPaths;
returnVal += pDeserializer.ReadInt32(iNumPaths);
assert(iNumPaths >= 0, "Number of path properties must be >= 0.");
if (iNumPaths < 0)
ITA_EXCEPT_INVALID_PARAMETER("Number of path properties must be >= 0.");
voPathProperties.resize(iNumPaths);
for(CPathProperty& oPathProp : voPathProperties)
......
......@@ -43,6 +43,7 @@ namespace ITA
namespace ART
{
const std::string STRATIFIED_ATMOSPHERE_KEY = "@StratifiedAtmosphere";
const std::string CLIENT_COORDINATE_SYSTEM_KEY = "@ClientCoordinateSystem";
}
}
......
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