FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
math::Path Class Reference

Represents a path with coordinates and allows for various interpolation methods. More...

#include "path.h"

Public Types

enum class  InterpType { INTERP_STATIC , INTERP_LINEAR , INTERP_CUBIC }
 Types of interpolation supported by the Path class. More...
 

Public Member Functions

 Path (const InterpType type=InterpType::INTERP_STATIC) noexcept
 Constructs a Path object with a specified interpolation type.
 
 ~Path ()=default
 
 Path (const Path &)=delete
 
 Path (Path &&)=delete
 
Pathoperator= (const Path &)=delete
 
Pathoperator= (Path &&)=delete
 
void addCoord (const Coord &coord) noexcept
 Adds a coordinate to the path.
 
void finalize ()
 Finalizes the path, preparing it for interpolation.
 
InterpType getType () const noexcept
 Retrieves the current interpolation type of the path.
 
const std::vector< Coord > & getCoords () const noexcept
 Gets the list of coordinates in the path.
 
Vec3 getPosition (RealType t) const
 Retrieves the position at a given time along the path.
 
Vec3 getVelocity (RealType t) const
 Retrieves the velocity at a given time along the path.
 
void setInterp (InterpType settype) noexcept
 Changes the interpolation type.
 

Detailed Description

Represents a path with coordinates and allows for various interpolation methods.

Definition at line 29 of file path.h.

Member Enumeration Documentation

◆ InterpType

enum class math::Path::InterpType
strong

Types of interpolation supported by the Path class.

Enumerator
INTERP_STATIC 
INTERP_LINEAR 
INTERP_CUBIC 

Definition at line 35 of file path.h.

Constructor & Destructor Documentation

◆ Path() [1/3]

math::Path::Path ( const InterpType  type = InterpType::INTERP_STATIC)
explicitnoexcept

Constructs a Path object with a specified interpolation type.

Parameters
typeThe interpolation type (default is INTERP_STATIC).

Definition at line 47 of file path.h.

47: _type(type) {}

◆ ~Path()

math::Path::~Path ( )
default

◆ Path() [2/3]

math::Path::Path ( const Path )
delete

◆ Path() [3/3]

math::Path::Path ( Path &&  )
delete

Member Function Documentation

◆ addCoord()

void math::Path::addCoord ( const Coord coord)
noexcept

Adds a coordinate to the path.

Parameters
coordThe coordinate to be added.

Definition at line 27 of file path.cpp.

28 {
29 auto comp = [](const Coord& a, const Coord& b) { return a.t < b.t; };
30
31 const auto iter = std::ranges::lower_bound(_coords, coord, comp);
32 _coords.insert(iter, coord);
33 _final = false;
34 }

References math::Coord::t.

Referenced by fers_get_interpolated_motion_path(), math::from_json(), and serial::xml_parser_utils::parseMotionPath().

+ Here is the caller graph for this function:

◆ finalize()

void math::Path::finalize ( )

Finalizes the path, preparing it for interpolation.

Definition at line 147 of file path.cpp.

148 {
149 if (!_final)
150 {
151 switch (_type)
152 {
155 break;
157 finalizeCubic<Coord>(_coords, _dd);
158 break;
159 }
160 _final = true;
161 }
162 }

References INTERP_CUBIC, INTERP_LINEAR, and INTERP_STATIC.

Referenced by fers_get_interpolated_motion_path(), math::from_json(), and serial::xml_parser_utils::parseMotionPath().

+ Here is the caller graph for this function:

◆ getCoords()

const std::vector< Coord > & math::Path::getCoords ( ) const
noexcept

Gets the list of coordinates in the path.

Returns
A constant reference to the vector of coordinates.

Definition at line 83 of file path.h.

83{ return _coords; }

Referenced by serial::kml_generator_utils::generateAntennaKml(), serial::kml_generator_utils::generateDirectionalAntennaKml(), serial::kml_generator_utils::generateDynamicPathKml(), serial::kml_generator_utils::generateStaticPlacemarkKml(), serial::kml_generator_utils::generateTrackEndpointsKml(), serial::kml_generator_utils::processPlatform(), and serial::xml_serializer_utils::serializeMotionPath().

+ Here is the caller graph for this function:

◆ getPosition()

Vec3 math::Path::getPosition ( RealType  t) const

Retrieves the position at a given time along the path.

Parameters
tThe time parameter at which to get the position.
Returns
The interpolated position as a Vec3 object.
Exceptions
PathExceptionIf finalize() has not been called before this method.

Definition at line 36 of file path.cpp.

37 {
38 if (!_final)
39 {
40 LOG(Level::FATAL, "Finalize not called before GetPosition");
41 throw PathException("Finalize not called before GetPosition");
42 }
43
44 Coord coord{};
45 switch (_type)
46 {
48 getPositionStatic(coord, _coords);
49 break;
51 getPositionLinear(t, coord, _coords);
52 break;
54 getPositionCubic(t, coord, _coords, _dd);
55 break;
56 }
57 return coord.pos;
58 }
#define LOG(level,...)
Definition logging.h:19
void getPositionLinear(RealType t, T &coord, const std::vector< T > &coords)
Performs linear interpolation between coordinate points.
Definition path_utils.h:90
void getPositionStatic(T &coord, const std::vector< T > &coords)
Interpolates a static position from a list of coordinates.
Definition path_utils.h:71
void getPositionCubic(RealType t, T &coord, const std::vector< T > &coords, const std::vector< T > &dd)
Performs cubic spline interpolation between coordinate points.
Definition path_utils.h:134

References getPositionCubic(), getPositionLinear(), getPositionStatic(), INTERP_CUBIC, INTERP_LINEAR, INTERP_STATIC, and LOG.

Referenced by fers_get_interpolated_motion_path(), and serial::kml_generator_utils::generateDynamicPathKml().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getType()

InterpType math::Path::getType ( ) const
noexcept

Retrieves the current interpolation type of the path.

Returns
The interpolation type of the path.

Definition at line 76 of file path.h.

76{ return _type; }

Referenced by serial::kml_generator_utils::generatePlatformPathKml(), and serial::xml_serializer_utils::serializeMotionPath().

+ Here is the caller graph for this function:

◆ getVelocity()

Vec3 math::Path::getVelocity ( RealType  t) const

Retrieves the velocity at a given time along the path.

Parameters
tThe time parameter at which to get the velocity.
Returns
The interpolated velocity as a Vec3 object.
Exceptions
PathExceptionIf finalize() has not been called before this method.

Definition at line 60 of file path.cpp.

61 {
62 if (!_final)
63 {
64 LOG(Level::FATAL, "Finalize not called before GetVelocity");
65 throw PathException("Finalize not called before GetVelocity");
66 }
67
68 if (_coords.empty())
69 {
70 return {0, 0, 0};
71 }
72
73 switch (_type)
74 {
76 return {0, 0, 0};
77
79 {
80 auto xrp = std::ranges::upper_bound(_coords, t, {}, &Coord::t);
81 auto idx = std::distance(_coords.begin(), xrp);
82
83 // Clamp to valid segments
84 if (idx <= 0)
85 idx = 1;
86 if (static_cast<std::size_t>(idx) >= _coords.size())
87 idx = static_cast<decltype(idx)>(_coords.size() - 1);
88
89 if (idx < 1 || static_cast<std::size_t>(idx) >= _coords.size())
90 return {0, 0, 0}; // Should not happen if size >= 1 and clamp works
91
92 const auto right_idx = static_cast<std::size_t>(idx);
93 const auto left_idx = right_idx - 1;
94
95 const auto& p1 = _coords[left_idx];
96 const auto& p2 = _coords[right_idx];
97 const RealType dt = p2.t - p1.t;
98
99 if (dt <= EPSILON)
100 return {0, 0, 0};
101
102 return (p2.pos - p1.pos) / dt;
103 }
104
106 {
107 auto xrp = std::ranges::upper_bound(_coords, t, {}, &Coord::t);
108 std::ptrdiff_t xri;
109 if (xrp == _coords.begin())
110 xri = 1;
111 else if (xrp == _coords.end())
112 xri = static_cast<std::ptrdiff_t>(_coords.size() - 1);
113 else
114 xri = std::distance(_coords.begin(), xrp);
115
116 if (xri < 1 || static_cast<std::size_t>(xri) >= _coords.size())
117 return {0, 0, 0};
118
119 const auto right_idx = static_cast<std::size_t>(xri);
120 const auto left_idx = right_idx - 1;
121
122 const RealType h = _coords[right_idx].t - _coords[left_idx].t;
123 if (h <= EPSILON)
124 return {0, 0, 0};
125
126 const RealType a = (_coords[right_idx].t - t) / h;
127 const RealType b = (t - _coords[left_idx].t) / h;
128
129 // Derivative coefficients
130 // da/dt = -1/h
131 // db/dt = 1/h
132 // dc/dt = -h/6 * (3a^2 - 1)
133 // dd/dt = h/6 * (3b^2 - 1)
134
135 const RealType da = -1.0 / h;
136 const RealType db = 1.0 / h;
137 const RealType dc = -h / 6.0 * (3.0 * a * a - 1.0);
138 const RealType dd_coeff = h / 6.0 * (3.0 * b * b - 1.0);
139
140 return _coords[left_idx].pos * da + _coords[right_idx].pos * db + _dd[left_idx].pos * dc +
141 _dd[right_idx].pos * dd_coeff;
142 }
143 }
144 return {0, 0, 0};
145 }
double RealType
Type for real numbers.
Definition config.h:27
constexpr RealType EPSILON
Machine epsilon for real numbers.
Definition config.h:51
RealType t
Time.
Definition coord.h:26

References EPSILON, INTERP_CUBIC, INTERP_LINEAR, INTERP_STATIC, LOG, and math::Coord::t.

Referenced by fers_get_interpolated_motion_path().

+ Here is the caller graph for this function:

◆ operator=() [1/2]

Path & math::Path::operator= ( const Path )
delete

◆ operator=() [2/2]

Path & math::Path::operator= ( Path &&  )
delete

◆ setInterp()

void math::Path::setInterp ( InterpType  settype)
noexcept

Changes the interpolation type.

Parameters
settypeThe new interpolation type to be used.

Definition at line 164 of file path.cpp.

165 {
166 _type = settype;
167 _final = false;
168 }

Referenced by fers_get_interpolated_motion_path(), math::from_json(), and serial::xml_parser_utils::parseMotionPath().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: