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

ART - EigenraySearch->Worker

- moved all definitions to cpp
parent 7ba298c5
......@@ -10,12 +10,155 @@
// STD
float ITAPropagationPathSim::AtmosphericRayTracing::EigenraySearch::DistanceToReceiver( const VistaVector3D& point, const VistaVector3D& receiverPos, const unsigned int& reflectionOrder )
using namespace ITAPropagationPathSim::AtmosphericRayTracing;
#pragma region FUNCTIONS
VistaVector3D EigenraySearch::VirtualReceiverPosition(const VistaVector3D& receiverPos, const int reflectionOrder) {
VistaVector3D out = receiverPos;
if (reflectionOrder % 2 != 0) //On uneven reflection order
out[Vista::Z] = -out[Vista::Z];
return out;
}
float EigenraySearch::DistanceToVirtualReceiver( const VistaVector3D& point, const VistaVector3D& receiverPos, const int reflectionOrder )
{
return VectorToVirtualReceiver( point, receiverPos, reflectionOrder ).GetLength();
}
VistaVector3D EigenraySearch::VectorToVirtualReceiver( const VistaVector3D& point, const VistaVector3D& receiverPos, const int reflectionOrder )
{
return VirtualReceiverPosition( receiverPos, reflectionOrder ) - point;
}
#pragma endregion
#pragma region INITIAL WORKER
bool EigenraySearch::CInitialWorker::AbortRequested(const RayPtr& pRay) {
if (pRay->LastTimeStamp() >= rayTracingAbortSettings.maxTime)
return true;
if (pRay->ReflectionOrder() > rayTracingAbortSettings.maxReflectionOrder)
return true;
UpdateMinimumReceiverDistance(pRay);
return false;
}
EigenraySearch::CInitialWorker::CInitialWorker(const VistaVector3D& sourcePosition, const VistaVector3D& receiverPosition, const Simulation::Settings& simSettings, const RayTracingAbortSettings& abortSettings)
: v3SourcePosition(sourcePosition), v3ReceiverPosition(receiverPosition), rayTracingAbortSettings(abortSettings)
{
simulationEngine.settings = simSettings;
}
std::vector<CRayGrid> EigenraySearch::CInitialWorker::Run(const ITAGeo::CStratifiedAtmosphere& atmosphere)
{
CRayGrid rayGrid = InitRayGrid(atmosphere);
simulationEngine.Run(atmosphere, rayGrid.Rays());
return FinalizeResult(rayGrid);
}
bool EigenraySearch::CInitialWorker::UpdateMinimumReceiverDistance(const RayPtr& pRay)
{
const int reflectionOrder = pRay->ReflectionOrder();
float receiverDistance = DistanceToVirtualReceiver(pRay->LastPoint(), v3ReceiverPosition, reflectionOrder);
if (reflectionOrder < vfMinDistances.size())
{
if (vfMinDistances[reflectionOrder] <= receiverDistance)
return false;
vfMinDistances[reflectionOrder] = receiverDistance;
vpMinDistanceRays[reflectionOrder] = pRay;
return true;
}
vfMinDistances.push_back(receiverDistance);
vpMinDistanceRays.push_back(pRay);
return true;
}
CRayGrid EigenraySearch::CInitialWorker::InitRayGrid(const ITAGeo::CStratifiedAtmosphere& atmosphere)
{
return CEquiangularRayDistribution(v3SourcePosition, 7, 10);
}
std::vector<CRayGrid> EigenraySearch::CInitialWorker::FinalizeResult(const CRayGrid& initialRayGrid)
{
std::vector<CRayGrid> rayGridsOfReflectionOrder;
for each (RayPtr pRay in vpMinDistanceRays)
rayGridsOfReflectionOrder.push_back(initialRayGrid.GetSurroundingGrid(pRay).CopyWithNewRays());
return rayGridsOfReflectionOrder;
}
#pragma endregion
#pragma region ADAPTIVE WORKER
bool EigenraySearch::CAdaptiveWorker::AbortRequested(const RayPtr& pRay) {
if (pRay->LastTimeStamp() >= rayTracingAbortSettings.maxTime)
return true;
if (pRay->ReflectionOrder() > rayTracingAbortSettings.maxReflectionOrder)
return true;
UpdateMinimumReceiverDistance(pRay);
return false;
}
EigenraySearch::CAdaptiveWorker::CAdaptiveWorker(const CRayGrid& rayGrid, const VistaVector3D& receiverPosition, const Simulation::Settings& simSettings, const Settings& eigenraySettings, const int activeReflectionOrder)
: rayResolutionAdapter(rayGrid), v3ReceiverPosition(receiverPosition), iActiveReflexionOrder(activeReflectionOrder), rayAdaptationSettings(eigenraySettings.rayAdaptation), rayTracingAbortSettings(eigenraySettings.rayTracing)
{
simulationEngine.settings = simSettings;
const float sourceReceiverDistance = DistanceToVirtualReceiver(rayGrid.SourcePosition(), v3ReceiverPosition, iActiveReflexionOrder);
fReceiverRadius = tan(rayAdaptationSettings.accuracy.maxSourceReceiverAngle) * sourceReceiverDistance;
fReceiverRadius = fmin(rayAdaptationSettings.accuracy.maxReceiverRadius, fReceiverRadius);
}
EigenraySearch::RayPtr EigenraySearch::CAdaptiveWorker::Run(const ITAGeo::CStratifiedAtmosphere& atmosphere)
{
return VectorToReceiver( point, receiverPos, reflectionOrder ).GetLength();
simulationEngine.Run(atmosphere, rayResolutionAdapter.Rays());
while (!EigenrayAccuracyReached())
{
rayResolutionAdapter.ZoomIntoRay(pMinDistanceRay);
simulationEngine.Run(atmosphere, rayResolutionAdapter.NewRaysOfLastAdaptation());
nAdaptations++;
}
return pMinDistanceRay;
}
VistaVector3D ITAPropagationPathSim::AtmosphericRayTracing::EigenraySearch::VectorToReceiver( const VistaVector3D& point, const VistaVector3D& receiverPos, const unsigned int& reflectionOrder )
bool EigenraySearch::CAdaptiveWorker::UpdateMinimumReceiverDistance(const RayPtr& pRay)
{
return VirtualReceiverPosition2( receiverPos, reflectionOrder ) - point;
const VistaVector3D deltaVec = VectorToVirtualReceiver(pRay->LastPoint(), v3ReceiverPosition, iActiveReflexionOrder);
const float receiverDistance = deltaVec.GetLength();
if (fMinReceiverDistance <= receiverDistance)
return false;
fMinReceiverDistance = receiverDistance;
v3MinReceiverVector = deltaVec;
iMinReceiverDistanceIdx = pRay->NumPoints() - 1;
pMinDistanceRay = pRay;
}
bool EigenraySearch::CAdaptiveWorker::EigenrayAccuracyReached()
{
if (fMinReceiverDistance <= fReceiverRadius)
return true;
bool abort = nAdaptations > rayAdaptationSettings.abort.maxNAdaptations; //TODO: also check delta angle of RayResolutionAdapter?
if (abort)
{
//TODO: Warning: Abort criterion reached!
}
return abort;
}
#pragma endregion
\ No newline at end of file
......@@ -48,67 +48,9 @@ namespace ITAPropagationPathSim
typedef std::shared_ptr<CRay> RayPtr;
typedef std::vector< RayPtr > RayVector;
//class CMinReceiverDistanceResult : public CRayGrid
//{
//private:
// RayPtr pMinDistanceRay;
// int iMinDistanceIndex;
//public:
// CMinReceiverDistanceResult(const CRayGrid& minDistRayGrid, const RayPtr& minDistRay, const int& idxMinDist)
// : CRayGrid(minDistRayGrid), pMinDistanceRay(minDistRay), iMinDistanceIndex(idxMinDist)
// {
// if (IsEmpty() || NTheta() > 3 || NPhi() > 3)
// return; //TODO: Throw exception
// }
//};
inline VistaVector3D VirtualReceiverPosition2(const VistaVector3D& receiverPos, const unsigned int& reflectionOrder) {
VistaVector3D out = receiverPos;
if (reflectionOrder % 2 != 0) //On uneven reflection order
out[Vista::Z] = -out[Vista::Z];
return out;
}
VistaVector3D VectorToReceiver( const VistaVector3D& point, const VistaVector3D& receiverPos, const unsigned int& reflectionOrder );
float DistanceToReceiver( const VistaVector3D& point, const VistaVector3D& receiverPos, const unsigned int& reflectionOrder );
class CWorkerBase : public Simulation::IAbortCriterion
{
protected:
Simulation::CEngine simulationEngine;
RayTracingAbortSettings rayTracingAbortSettings;
VistaVector3D v3ReceiverPosition;
public:
virtual bool AbortRequested(const RayPtr& pRay) {
if (pRay->LastTimeStamp() >= rayTracingAbortSettings.maxTime)
return true;
if (pRay->ReflectionOrder() > rayTracingAbortSettings.maxReflectionOrder)
return true;
UpdateMinimumReceiverDistance(pRay);
return false;
}
public:
CWorkerBase(const VistaVector3D& receiverPosition, const Simulation::Settings& simSettings, const RayTracingAbortSettings& rtSettings)
: v3ReceiverPosition(receiverPosition), rayTracingAbortSettings(rtSettings) {
simulationEngine.settings = simSettings;
}
protected:
virtual bool UpdateMinimumReceiverDistance(const RayPtr& pRay) = 0;
VistaVector3D ReceiverDistanceVector(const unsigned int& reflectionOrder, const VistaVector3D& rayPoint) { return VirtualReceiverPosition(reflectionOrder) - rayPoint; }
float ReceiverDistance(const unsigned int& reflectionOrder, const VistaVector3D& rayPoint) { return ReceiverDistanceVector(reflectionOrder, rayPoint).GetLength(); }
VistaVector3D VirtualReceiverPosition(const unsigned int& reflectionOrder) {
VistaVector3D out = v3ReceiverPosition;
if (reflectionOrder % 2 != 0) //On uneven reflection order
out[Vista::Z] = -out[Vista::Z];
return out;
}
};
VistaVector3D VirtualReceiverPosition( const VistaVector3D& receiverPos, const int reflectionOrder );
VistaVector3D VectorToVirtualReceiver( const VistaVector3D& point, const VistaVector3D& receiverPos, const int reflectionOrder );
float DistanceToVirtualReceiver( const VistaVector3D& point, const VistaVector3D& receiverPos, const int reflectionOrder );
class CInitialWorker : public Simulation::IAbortCriterion
......@@ -123,69 +65,27 @@ namespace ITAPropagationPathSim
std::vector<float> vfMinDistances; //< Current minimum distance to receiver for each reflection order
public:
virtual bool AbortRequested(const RayPtr& pRay) {
if (pRay->LastTimeStamp() >= rayTracingAbortSettings.maxTime)
return true;
if (pRay->ReflectionOrder() > rayTracingAbortSettings.maxReflectionOrder)
return true;
//! Interface function to receive data from Simulation::Engine and abort the ray tracer
virtual bool AbortRequested(const RayPtr& pRay);
public:
CInitialWorker(const VistaVector3D& sourcePosition, const VistaVector3D& receiverPosition, const Simulation::Settings& simSettings, const RayTracingAbortSettings& abortSettings);
UpdateMinimumReceiverDistance(pRay);
return false;
}
std::vector<CRayGrid> Run(const ITAGeo::CStratifiedAtmosphere& atmosphere);
private:
virtual bool UpdateMinimumReceiverDistance(const RayPtr& pRay)
{
const int reflectionOrder = pRay->ReflectionOrder();
float receiverDistance = DistanceToReceiver(pRay->LastPoint(), v3ReceiverPosition, reflectionOrder);
if (reflectionOrder < vfMinDistances.size())
{
if (vfMinDistances[reflectionOrder] <= receiverDistance)
return false;
bool UpdateMinimumReceiverDistance(const RayPtr& pRay);
vfMinDistances[reflectionOrder] = receiverDistance;
vpMinDistanceRays[reflectionOrder] = pRay;
return true;
}
vfMinDistances.push_back(receiverDistance);
vpMinDistanceRays.push_back(pRay);
return true;
}
CRayGrid InitRayGrid(const ITAGeo::CStratifiedAtmosphere& atmosphere)
{
return CEquiangularRayDistribution(v3SourcePosition, 7, 10);
}
std::vector<CRayGrid> FinalizeResult(const CRayGrid& initialRayGrid)
{
std::vector<CRayGrid> rayGridsOfReflectionOrder;
for each (RayPtr pRay in vpMinDistanceRays)
rayGridsOfReflectionOrder.push_back(initialRayGrid.GetSurroundingGrid(pRay).CopyWithNewRays());
return rayGridsOfReflectionOrder;
}
public:
CInitialWorker(const VistaVector3D& sourcePosition, const VistaVector3D& receiverPosition, const Simulation::Settings& simSettings, const RayTracingAbortSettings& abortSettings)
: v3SourcePosition(sourcePosition), v3ReceiverPosition(receiverPosition), rayTracingAbortSettings(abortSettings)
{
simulationEngine.settings = simSettings;
}
std::vector<CRayGrid> Run(const ITAGeo::CStratifiedAtmosphere& atmosphere)
{
CRayGrid rayGrid = InitRayGrid(atmosphere);
simulationEngine.Run(atmosphere, rayGrid.Rays());
return FinalizeResult(rayGrid);
}
CRayGrid InitRayGrid(const ITAGeo::CStratifiedAtmosphere& atmosphere);
std::vector<CRayGrid> FinalizeResult(const CRayGrid& initialRayGrid);
};
class CAdaptiveWorker : public CWorkerBase
class CAdaptiveWorker : public Simulation::IAbortCriterion
{
private:
Simulation::CEngine simulationEngine;
RayTracingAbortSettings rayTracingAbortSettings;
CRayResolutionAdapter rayResolutionAdapter;
VistaVector3D v3ReceiverPosition;
unsigned int iActiveReflexionOrder;
RayAdaptationSettings rayAdaptationSettings;
......@@ -198,67 +98,15 @@ namespace ITAPropagationPathSim
float fReceiverRadius;
public:
//virtual bool AbortRequested(const RayPtr pRay) {
// if (pRay->LastTimeStamp() >= eigenraySettings.maxTime)
// return true;
// if (pRay->ReflectionOrder() > eigenraySettings.maxReflectionOrder)
// return true;
// UpdateMinimumReceiverDistance(pRay);
// return false;
//}
protected:
bool UpdateMinimumReceiverDistance(const RayPtr& pRay)
{
const VistaVector3D deltaVec = ReceiverDistanceVector(iActiveReflexionOrder, pRay->LastPoint());
const float receiverDistance = deltaVec.GetLength();
if (fMinReceiverDistance <= receiverDistance)
return false;
fMinReceiverDistance = receiverDistance;
v3MinReceiverVector = deltaVec;
iMinReceiverDistanceIdx = pRay->NumPoints() - 1;
pMinDistanceRay = pRay;
}
private:
bool EigenrayAccuracyReached()
{
if (fMinReceiverDistance <= fReceiverRadius)
return true;
bool abort = nAdaptations > rayAdaptationSettings.abort.maxNAdaptations; //TODO: also check delta angle of RayResolutionAdapter?
if (abort)
{
//TODO: Warning: Abort criterion reached!
}
return abort;
}
//! Interface function to receive data from Simulation::Engine and abort the ray tracer
virtual bool AbortRequested(const RayPtr& pRay);
public:
CAdaptiveWorker(const CRayGrid& rayGrid, const VistaVector3D& receiverPosition, const Simulation::Settings& simSettings, const Settings& eigenraySettings, const int& activeReflectionOrder)
: CWorkerBase(receiverPosition, simSettings, eigenraySettings.rayTracing),
rayResolutionAdapter(rayGrid), iActiveReflexionOrder(activeReflectionOrder), rayAdaptationSettings(eigenraySettings.rayAdaptation)
{
const float sourceReceiverDistance = ReceiverDistance(iActiveReflexionOrder, rayGrid.SourcePosition());
fReceiverRadius = tan(rayAdaptationSettings.accuracy.maxSourceReceiverAngle) * sourceReceiverDistance;
fReceiverRadius = fmin(rayAdaptationSettings.accuracy.maxReceiverRadius, fReceiverRadius);
}
CAdaptiveWorker(const CRayGrid& rayGrid, const VistaVector3D& receiverPosition, const Simulation::Settings& simSettings, const Settings& eigenraySettings, const int activeReflectionOrder);
public:
RayPtr Run(const ITAGeo::CStratifiedAtmosphere& atmosphere)
{
simulationEngine.Run(atmosphere, rayResolutionAdapter.Rays());
while (!EigenrayAccuracyReached())
{
rayResolutionAdapter.ZoomIntoRay(pMinDistanceRay);
simulationEngine.Run(atmosphere, rayResolutionAdapter.NewRaysOfLastAdaptation());
nAdaptations++;
}
return pMinDistanceRay;
}
RayPtr Run(const ITAGeo::CStratifiedAtmosphere& atmosphere);
private:
bool UpdateMinimumReceiverDistance(const RayPtr& pRay);
bool EigenrayAccuracyReached();
};
}
}
......
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