Commit 487daf57 authored by Dipl.-Ing. Jonas Stienen's avatar Dipl.-Ing. Jonas Stienen
Browse files

Adding urban simulator structure, no implementation yet

parent 515a8524
......@@ -4,14 +4,7 @@ set( SubDirs
)
set( DirFiles
urban_worker_thread.h
#raven_scene.h
#raven_simulation_result.h
#simulation_task.h
#simulator.h
#raven_worker_interface.h
#worker_thread.h
#simulator_interface.h
urban_simulator.h
)
set( DirFiles_SourceGroup "${RelativeSourceGroup}" )
......
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_OUTDOOR_ACOUSTICS_URBAN_SIMULATOR
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_OUTDOOR_ACOUSTICS_URBAN_SIMULATOR
// API includes
#include <ITA/SimulationScheduler/definitions.h>
// std includes
#include <string>
#include <memory>
//#include <type_traits>
// simulation scheduler includes
#include <ITA/SimulationScheduler/OutdoorAcoustics/outdoor_simulator_interface.h>
// Urban includes
namespace ITA
{
namespace SimulationScheduler
{
namespace OutdoorAcoustics
{
namespace Urban
{
//! \brief Simulator using the Atmospheric Ray Tracing framework from ITAGeometricalAcoustics.
/**
* 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 CUrbanSimulator : public OutdoorAcoustics::ISimulatorInterface
{
public:
//! \brief Configuration class for a outdoor acoustics simulator.
struct ITA_SIMULATION_SCHEDULER_API UrbanSimulatorConfig : public ISimulatorInterface::SimulatorConfig
{
inline explicit UrbanSimulatorConfig() {};
VistaPropertyList Store() const override;
void Load( const VistaPropertyList& oProperties ) override;
CoordinateSystem eClientCoordinateSystem = CoordinateSystem::Cartesian; //!< 0 = Cartesian, 1 = OpenGL
};
CUrbanSimulator( const UrbanSimulatorConfig& oConfig );
CUrbanSimulator( const CUrbanSimulator& other ) = delete;
CUrbanSimulator( CUrbanSimulator&& other ) = delete;
CUrbanSimulator& operator=( const CUrbanSimulator& other ) = delete;
CUrbanSimulator& operator=( CUrbanSimulator&& other ) = delete;
static std::unique_ptr< ISimulatorInterface > Create( std::shared_ptr< const ISimulatorInterface::SimulatorConfig > );
//! \brief Reset the simulator.
inline void Reset() override { };
//! \brief Simulate the given task.
std::unique_ptr< COutdoorSimulationResult > Compute( std::unique_ptr< CUpdateScene > pSceneUpdate ) override;
inline static std::string GetType()
{
return "UrbanSimulator";
};
private:
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;
std::unique_ptr< CUpdateScene > m_pSceneUpdate;
};
} // namespace Urban
} // namespace OutdoorAcoustics
} // namespace SimulationScheduler
} // namespace ITA
#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_OUTDOOR_ACOUSTICS_URBAN_SIMULATOR
\ No newline at end of file
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_OUTDOOR_ACOUSTICS_URBAN_WORKER_THREAD
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_OUTDOOR_ACOUSTICS_URBAN_WORKER_THREAD
// std include
#include <string>
#include <memory>
// API includes
#include <ITA/SimulationScheduler/definitions.h>
// simulation scheduler includes
#include <ITA/SimulationScheduler/RoomAcoustics/raven/raven_worker_interface.h>
#include <ITA/SimulationScheduler/RoomAcoustics/raven/simulator_interface.h>
#include <ITA/SimulationScheduler/update_scene.h>
// Vista includes
#include <VistaInterProcComm/Concurrency/VistaThreadLoop.h>
#include <VistaInterProcComm/Concurrency/VistaThreadEvent.h>
#include <ITAAtomicPrimitives.h>
namespace ITA
{
namespace SimulationScheduler
{
namespace OutdoorAcoustics
{
namespace Urban
{
struct CRavenConfig;
///
/// \brief Raven worker utilizing a thread to run the actual simulation.
///
class ITA_SIMULATION_SCHEDULER_API CWorkerThread : public IRavenWorkerInterface, VistaThreadLoop
{
public:
///
/// \brief Configuration class for a raven thread worker.
///
struct ITA_SIMULATION_SCHEDULER_API WorkerThreadConfig : public IRavenWorkerInterface::RavenWorkerConfig
{
explicit WorkerThreadConfig ( );
std::string sRavenProjectFilePath = "path/to/raven/project/file.rpf";
VistaPropertyList Store ( ) const override;
void Load ( const VistaPropertyList& oProperties ) override;
};
///
/// \brief Constructor for CWorkerThread.
/// \param oConfig the WorkerConfig used to configure the CWorkerThread.
/// \param pParent the parent scheduler of the worker.
///
CWorkerThread ( const WorkerThreadConfig& oConfig, ISchedulerInterface* pParent );
///
/// \brief Destructor of CWorkerThread.
///
/// This waits till the simulation is finished and stops the thread loop gently.
///
~CWorkerThread ( );
///
/// \copydoc IWorkerInterface::IsBusy
///
bool IsBusy ( ) override;
///
/// \copydoc IWorkerInterface::PushUpdate
///
void PushUpdate ( std::unique_ptr<CUpdateScene> pUpdate ) override;
///
/// \copydoc IWorkerInterface::Reset
/// \detail With the reset, the simulator get reset.
///
void Reset ( ) override;
///
/// \copydoc IWorkerInterface::Shutdown
///
void Shutdown() override;
///
/// \brief Factory function for CWorkerThread.
/// \param pConfig the WorkerConfig used to configure the CWorkerThread.
/// \param pParent the parent scheduler of the worker.
///
static std::unique_ptr<IWorkerInterface> CreateWorker ( const std::shared_ptr<IWorkerInterface::WorkerConfig>& pConfig, ISchedulerInterface* pParent );
///
/// \brief Return a unique type identifying string.
/// \return a unique type identifying string.
///
static std::string GetType ( );
protected:
///
/// \brief Loop body for the CWorkerThread.
///
/// The following steps are done in the loop:
/// - Check if the scene is loaded, and load it if not.
/// - Simulate the Task.
/// - Forward the result to the scheduler.
/// \return true if VistaThreadLoop::ThreadBody() shall call VistaThread::YieldThread() before the next loop, false else
///
virtual bool LoopBody ( ) override;
///
/// \brief Pre loop function.
///
/// This function is called once before the thread starts.
/// \note This is primarily used to set the thread name while profiling.
///
void PreLoop ( ) override;
///
/// \brief Set the simulator of the worker.
/// \param pSimulator the new simulator.
/// \note This function is primarily for testing.
/// However, it could also be useful in the long run.
///
void SetSimulator ( std::unique_ptr<ISimulatorInterface> pSimulator );
private:
///
/// \brief The actual raven simulator
///
std::unique_ptr<ISimulatorInterface> m_pSimulator;
///
/// \brief True if a scene is loaded.
///
ITAAtomicBool m_bSceneLoaded;
///
/// \brief Trigger for starting a thread loop.
///
VistaThreadEvent m_evTriggerLoop;
///
/// \brief The task that is currently being simulated.
///
/// We need this to later reference the task when creating the result.
///
ITAAtomicPtr<CSimulationTask> m_pCurrentTask = nullptr;
///
/// \{
/// \brief Bools for handling the stop of the loop.
///
/// As these will be accessed by two threads, they have to be atomic.
///
ITAAtomicBool m_bStopIndicated = false;
ITAAtomicBool m_bResetIndicated = false;
/// \}
#ifdef WITH_PROFILER
static std::size_t iWorkerMaxID;
#endif
};
} // namespace Urban
} // namespace OutdoorAcoustics
} // namespace SimulationScheduler
} // namespace ITA
#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_OUTDOOR_ACOUSTICS_URBAN_WORKER_THREAD
\ No newline at end of file
......@@ -4,12 +4,7 @@ set( SubDirs
)
set( DirFiles
#raven_scene.cpp
#simulation_task.cpp
#simulator.cpp
#raven_worker_interface.cpp
#worker_thread.cpp
#_SourceFiles.cmake
urban_simulator.cpp
)
set( DirFiles_SourceGroup "${RelativeSourceGroup}" )
......
// Header include
#include <ITA/SimulationScheduler/OutdoorAcoustics/Urban/urban_simulator.h>
#include <ITA/SimulationScheduler/Profiler/profiler.h>
#include <ITA/SimulationScheduler/Utils/data_type_utils.h>
#include "../../configuration_keys.h"
// ITAGeo
// ITA Base
#include <ITAFileSystemUtils.h>
#include <ITAException.h>
// STD
#include <ostream>
#include <memory>
//------CONFIG------
#pragma region CONFIG
VistaPropertyList ITA::SimulationScheduler::OutdoorAcoustics::Urban::CUrbanSimulator::UrbanSimulatorConfig::Store() const
{
auto oProperties = ISimulatorInterface::SimulatorConfig::Store();
//oProperties.SetValue(CLIENT_COORDINATE_SYSTEM_KEY, AsInteger(eClientCoordinateSystem));
//oProperties.SetValue(STRATIFIED_ATMOSPHERE_KEY, sJsonAtmosphere);
return oProperties;
}
void ITA::SimulationScheduler::OutdoorAcoustics::Urban::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 = "";
*/
}
#pragma endregion
namespace ITA
{
namespace SimulationScheduler
{
namespace OutdoorAcoustics
{
namespace Urban
{
//------SIMULATOR------
#pragma region SIMULATOR
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
} // namespace Urban
} // namespace OutdoorAcoustics
} // namespace SimulationScheduler
} // namespace ITA
\ No newline at end of file
......@@ -8,6 +8,9 @@
#ifdef WITH_ART
#include <ITA/SimulationScheduler/OutdoorAcoustics/ART/art_simulator.h>
#endif
#ifdef WITH_URBAN
#include <ITA/SimulationScheduler/OutdoorAcoustics/Urban/urban_simulator.h>
#endif
namespace ITA
......@@ -65,7 +68,7 @@ namespace ITA
{ OutdoorAcoustics::ART::CARTSimulator::GetType(), { OutdoorAcoustics::ART::CARTSimulator::Create, std::make_shared<OutdoorAcoustics::ART::CARTSimulator::ARTSimulatorConfig> } },
#endif
#ifdef WITH_URBAN
{ OutdoorAcoustics::Urban::CARTSimulator::GetType(), { OutdoorAcoustics::ART::CUrbanSimulator::Create, std::make_shared<OutdoorAcoustics::Urban::CUrbanSimulator::SimulatorConfig> } },
{ OutdoorAcoustics::Urban::CUrbanSimulator::GetType(), { OutdoorAcoustics::Urban::CUrbanSimulator::Create, std::make_shared<OutdoorAcoustics::Urban::CUrbanSimulator::SimulatorConfig> } },
#endif
};
......
Supports Markdown
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