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

ART - Rays

- added < operator for RayElement
- added method to get data at certain timestamp using nearest neighbor
parent ad481632
......@@ -44,6 +44,8 @@ namespace ITAPropagationPathSim
RayElement() {}
RayElement(const VistaVector3D& r, const VistaVector3D& n, const double& time) : position(r), wavefrontNormal(n), timeStamp(time) {}
};
//! Comparison of timestamps
inline bool operator<(const RayElement& lhs, const RayElement& rhs) { return lhs.timeStamp < rhs.timeStamp; }
class ITA_PROPAGATION_PATH_SIM_API CRay : public std::vector<RayElement>
{
......@@ -71,6 +73,9 @@ namespace ITAPropagationPathSim
const VistaVector3D& LastWavefrontNormal() const { return back().wavefrontNormal; }
const double& LastTimeStamp() const { return back().timeStamp; }
//! Returns the ray element at a given time using nearest neighbor approach.
const RayElement& AtTime(const double& time);
unsigned int ReflectionOrder() const { return iReflectionIndices.size(); }
#pragma endregion
......
#include <ITAPropagationPathSim/AtmosphericRayTracing/Rays.h>
// ITA includes
#include <ITAException.h>
// STD
//#include <cmath>
#include <algorithm>
using namespace ITAPropagationPathSim::AtmosphericRayTracing;
......@@ -20,6 +22,26 @@ CRay::CRay(const VistaVector3D& v3SourcePos, const VistaVector3D& v3Direction)
Append(v3SourcePos, v3Direction.GetNormalized(), 0.0);
}
const RayElement& CRay::AtTime(const double& time)
{
if(time < 0.0)
ITA_EXCEPT_INVALID_PARAMETER("Only positive values for time are allowed.");
RayElement compare; compare.timeStamp = time;
CRay::iterator itAfterTime = std::lower_bound(begin(), end(), compare);
if (itAfterTime == end())
return back();
if (itAfterTime == begin())
return front();
CRay::iterator itBeforeTime = itAfterTime - 1;
if (std::abs(itBeforeTime->timeStamp - time) <= std::abs(itAfterTime->timeStamp - time))
return *itBeforeTime;
return *itAfterTime;
}
void CRay::Append(const VistaVector3D& position, const VistaVector3D& wavefrontNormal, const double& timeStamp)
{
push_back( RayElement(position, wavefrontNormal, timeStamp) );
......
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