WSF
WsfRoute.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright 2003-2015 The Boeing Company. All rights reserved.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11// ****************************************************************************
12// Updated by Infoscitex, a DCS Company.
13// ****************************************************************************
14
15#ifndef WSFROUTE_HPP
16#define WSFROUTE_HPP
17
18#include "wsf_export.h"
19
20#include <memory>
21#include <string>
22#include <vector>
23
24class UtInput;
25class UtInputBlock;
26#include "UtLLPos.hpp"
27#include "UtLog.hpp"
28class UtScriptClass;
29class UtScriptRef;
30class UtScriptTypes;
31
32#include "WsfAuxDataEnabled.hpp"
33#include "WsfObject.hpp"
34#include "WsfStringId.hpp"
35#include "WsfWaypoint.hpp"
36
38
40{
41public:
42 static constexpr const char* cTYPE_KIND = "route";
43
44 using WaypointVector = std::vector<WsfWaypoint>;
45 using WayptVecIter = std::vector<WsfWaypoint>::iterator;
46 using WaypointPtrVector = std::vector<WsfWaypoint*>;
47 using WaypointSegment = std::pair<WsfWaypoint, WsfWaypoint>;
48
55
56 WsfRoute() = default;
57 WsfRoute(const std::string& aName);
58 WsfRoute(const WsfRoute& aSrc);
59 ~WsfRoute() override;
60
61 WsfRoute& operator=(const WsfRoute& aRhs);
62 WsfWaypoint& operator[](size_t aIndex);
63 const WsfWaypoint& operator[](size_t aIndex) const;
64
65 WsfRoute* Clone() const override;
66 virtual bool Initialize(double aSimTime = 0.0);
67 bool ProcessInput(UtInput& aInput) override;
68
69 const char* GetScriptClassName() const override;
70
71 static std::unique_ptr<UtScriptClass> CreateScriptClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
72 static std::unique_ptr<UtScriptClass> CreateIteratorScriptClass(const std::string& aClassName,
73 UtScriptTypes* aScriptTypesPtr);
74
75 void Append(const WsfWaypoint& aWaypoint);
76 void Append(const WsfRoute& aRoute);
77
78 void Insert(WayptVecIter aIter, const WsfWaypoint& aWaypoint);
79 void Insert(int aIndex, const WsfWaypoint& aWaypoint);
80
81 void Remove(unsigned int aWaypointIndex);
82
83 void Transform(double aRefLat, double aRefLon, double aHeading);
84
85 void TransformNED(double aNorth, double aEast, double aDown);
86
87 void GetSubroute(const WsfWaypoint& aFromWaypoint, const WsfWaypoint& aToWaypoint, WsfRoute& aRoute) const;
88
89 void GetSubroute(int aStartIndex, int aEndIndex, WsfRoute& aRoute) const;
90
91 void AppendSubroute(int aStartIndex, int aEndIndex, WsfRoute& aRoute) const;
92
93 void GetAllNodes(WaypointPtrVector& aWaypointPtrVector);
94
95 int GetAdjacentNodeIndices(int aWaypointIndex, int* aAdjacentNodeIndices) const;
96
97 int FindWaypointIndex(double aLat, double aLon, double aAlt);
98 int FindWaypointIndex(const WsfWaypoint& aWpt);
99
100 bool IsBetweenWaypoints(const double aPointLL[2],
101 const unsigned int aFirstWaypointIndex,
102 const unsigned int aSecondWaypointIndex,
103 const double aTolerancePercentage = 0.01) const;
104
105 double GetDistance(int aFromWaypointIndex, int aToWaypointIndex) const;
106
107 double GetDistanceOffset(const double aFromLL[2], const double aToLL[2], const double aPointLL[2], double& aOffsetDist) const;
108
109 double GetDistanceAlongRoute(const double aFromLL[2], const double aToLL[2]) const;
110
111 double GetDistanceAlongRoute(const double aFromLL[2], const double aToLL[2], double& aOffsetDist) const;
112
113 bool GetEndPointsAtDistance(double aDistance, int& aWaypointIndex) const;
114
115 static bool ProjectOntoRoute(const double aPointLL[2],
116 const double aSegmentStartLL[2],
117 const double aSegmentEndLL[2],
118 double aWaypointLL[2]);
119
120 bool PointAlongRoute(double aDistanceFromStart, double aPointAlongRoute[2], int& aSegmentIndex);
121
122 bool ProjectOntoRoute(const double aPointLL[2], int& aSegmentIndex, double aProjectedLL[2], double& aDistance) const;
123
124 bool ProjectOntoRoute(const double aPointLL[2], double& aDistanceFromRoute, double& aDistanceAlongRoute) const;
125
126 int ProjectOntoRouteFast(const double aPointLL[2], double& aDistanceFromRoute, double& aDistanceAlongRoute) const;
127
129 double aLon,
130 int aClosestWaypointIndex,
131 int& aSegmentIndex,
132 double aProjectedLL[2]);
133
134 int Intersect(WsfRoute& aOtherRoute, std::vector<RouteIntersection>& aIntersections);
135
139 double GetTotalLength() const { return mTotalLength; }
140
141 double GetTravelTime() const;
142
143 double GetTravelTimeToPosition(const double aPosition[2]) const;
144
145 WsfWaypoint& GetWaypointAt(size_t aIndex);
146 const WsfWaypoint& GetWaypointAt(size_t aIndex) const;
147
148 unsigned int GetWaypointIndexAt(WsfStringId aLabelId) const;
149
150 bool IsGlobalRoute() const;
151
152 void SetNetworkRouteId(unsigned int aRouteId);
153
157 unsigned int GetNetworkRouteId() const { return mRouteId; }
158
159 void SetSpeed(double aSpeed);
160
163 double GetSpeed(unsigned int aIndex) const { return mWaypoints[aIndex].GetSpeed(); };
164
167 const WaypointVector& GetWaypoints() const { return mWaypoints; }
168
170 WayptVecIter Begin() { return mWaypoints.begin(); }
171
174 WayptVecIter End() { return mWaypoints.end(); }
175
177 void Clear();
178
181 bool Empty() const { return mWaypoints.empty(); }
182
185 unsigned int GetSize() const { return static_cast<unsigned int>(mWaypoints.size()); }
186
188 void Print(ut::log::MessageStream& aStream) const;
189
191 void Swap(WsfRoute& aRhs)
192 {
193 std::swap(mRouteId, aRhs.mRouteId);
194 std::swap(mRouteId, aRhs.mRouteId);
195 std::swap(mWaypoints, aRhs.mWaypoints);
196 std::swap(mTotalLength, aRhs.mTotalLength);
197 std::swap(mWaypointReferenceCountPtr, aRhs.mWaypointReferenceCountPtr);
198 std::swap(mTrackedReferencePtr, aRhs.mTrackedReferencePtr);
199 }
200
204 UtReferenceCount* GetWaypointReferenceCount()
205 {
206 if (mWaypointReferenceCountPtr == nullptr)
207 {
208 mWaypointReferenceCountPtr = new UtReferenceCount(1);
209 }
210 return mWaypointReferenceCountPtr;
211 }
212
214 template<typename T>
215 void Serialize(T& aBuff)
216 {
218 aBuff& mRouteId& mWaypoints& mLabelId& mTotalLength;
219 }
220
221 UtScriptRef* ScriptRef();
222 UtScriptRef* ConstScriptRef() const;
223 UtScriptRef* ScriptRefManage();
224
225 static void ProcessInputBlock(UtInputBlock& aInputBlock, WsfRoute* aRoutePtr, bool aAllowName);
226 bool ProcessNavigationInput(UtInput& aInput);
227 void ProcessWaypoint(UtInput& aInput, WsfWaypoint& aWaypoint);
228
229private:
231 class Segment
232 {
233 public:
234 Segment() = default;
235 Segment(double aLat1, double aLon1, double aLat2, double aLon2)
236 : mBegin(aLat1, aLon1)
237 , mEnd(aLat2, aLon2)
238 {
239 }
240
241 bool operator<(const Segment& aRhs) { return mBegin.GetLat() < aRhs.mBegin.GetLat(); }
242
243 UtLLPos mBegin;
244 UtLLPos mEnd;
245 };
246 using SegmentList = std::vector<Segment>;
247
249 struct Intersection
250 {
253 int mSegmentIndices[2];
254 Segment mSegments[2]; // The actual line segments as passed in.
255 UtLLPos mPoint;
256 };
257 using IntersectionList = std::vector<Intersection>;
258
259 double ComputeDistance(unsigned int& aFirstWptIndex, unsigned int& aSecondWptIndex);
260 void ClearWaypointReference()
261 {
262 if (mWaypointReferenceCountPtr != nullptr)
263 {
264 mWaypointReferenceCountPtr->RemoveStrongRef();
265 mWaypointReferenceCountPtr = nullptr;
266 }
267 }
268
269 double CalculateTurnWaypointDistance(const WsfWaypoint& aWaypoint) const;
270
271 double ProcessTurnWaypoint(const WsfWaypoint& aWaypoint, double aNewHeading, double aCurrentHeading);
272
273 // void UpdateRouteIdentifier();
274
275 static void IntersectSegments(const SegmentList& aSegmentList, IntersectionList& aIntersections);
276
277 static bool GreatCircleIntersect(const Segment& aSegment1, const Segment& aSegment2, UtLLPos& aInteceptPosition);
278
279 unsigned int mRouteId = 0; // Identifier in the context of a route network
280 WaypointVector mWaypoints{}; // The actual waypoints
281 bool mOffsetRouteValid = false; // Convert offset waypoints to be relative to a single origin
282 // rather than the last waypoint when a route is tranformed.
283
284 WsfStringId mLabelId{}; // Current label ID during reading.
285 double mTotalLength = 0.0;
286 UtReferenceCount* mWaypointReferenceCountPtr = nullptr;
287
288}; // class WsfRoute
289
290// Specialize std::swap() for WsfRoute
291namespace std
292{
293template<>
294inline void swap(WsfRoute& aLhs, WsfRoute& aRhs)
295{
296 aLhs.Swap(aRhs);
297}
298
299} // namespace std
300
301#endif
UtStringId WsfStringId
WsfStringId – the same thing as UtStringId.
Definition WsfStringId.hpp:23
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
WsfAuxDataEnabled()=default
void Serialize(T &aBuff)
For XIO (de)serialization.
Definition WsfObject.hpp:104
WsfObject()
This is the constructor for the WsfObject class.
Definition WsfObject.cpp:88
virtual WsfObject * Clone() const =0
WsfObject & operator=(const WsfObject &aRhs)
Assignment operator.
Definition WsfObject.cpp:258
virtual bool ProcessInput(UtInput &aInput)
Definition WsfObject.cpp:140
const char * GetScriptClassName() const override
Definition WsfObject.cpp:115
A collection of WsfWaypoint objects that represent a path to be followed.
Definition WsfRoute.hpp:40
void GetAllNodes(WaypointPtrVector &aWaypointPtrVector)
Definition WsfRoute.cpp:405
void Swap(WsfRoute &aRhs)
Swap two WsfRoute's efficiently.
Definition WsfRoute.hpp:191
double GetTotalLength() const
Get the total distance along all waypoints in the route.
Definition WsfRoute.hpp:139
std::vector< WsfWaypoint * > WaypointPtrVector
Definition WsfRoute.hpp:46
bool IsBetweenWaypoints(const double aPointLL[2], const unsigned int aFirstWaypointIndex, const unsigned int aSecondWaypointIndex, const double aTolerancePercentage=0.01) const
Definition WsfRoute.cpp:489
bool GetEndPointsAtDistance(double aDistance, int &aWaypointIndex) const
Definition WsfRoute.cpp:925
const WaypointVector & GetWaypoints() const
Definition WsfRoute.hpp:167
int ProjectOntoRouteFast(const double aPointLL[2], double &aDistanceFromRoute, double &aDistanceAlongRoute) const
Definition WsfRoute.cpp:1088
static std::unique_ptr< UtScriptClass > CreateScriptClass(const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)
Definition WsfScriptRouteClass.cpp:853
int GetAdjacentNodeIndices(int aWaypointIndex, int *aAdjacentNodeIndices) const
Definition WsfRoute.cpp:448
WayptVecIter End()
Definition WsfRoute.hpp:174
std::pair< WsfWaypoint, WsfWaypoint > WaypointSegment
Definition WsfRoute.hpp:47
static std::unique_ptr< UtScriptClass > CreateIteratorScriptClass(const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)
Definition WsfScriptRouteClass.cpp:858
int Intersect(WsfRoute &aOtherRoute, std::vector< RouteIntersection > &aIntersections)
Definition WsfRoute.cpp:1286
bool ProjectOntoRouteGivenClosestWaypoint(double aLat, double aLon, int aClosestWaypointIndex, int &aSegmentIndex, double aProjectedLL[2])
Definition WsfRoute.cpp:1250
std::vector< WsfWaypoint >::iterator WayptVecIter
Definition WsfRoute.hpp:45
static bool ProjectOntoRoute(const double aPointLL[2], const double aSegmentStartLL[2], const double aSegmentEndLL[2], double aWaypointLL[2])
Definition WsfRoute.cpp:967
double GetSpeed(unsigned int aIndex) const
Definition WsfRoute.hpp:163
void GetSubroute(const WsfWaypoint &aFromWaypoint, const WsfWaypoint &aToWaypoint, WsfRoute &aRoute) const
Definition WsfRoute.cpp:324
int FindWaypointIndex(double aLat, double aLon, double aAlt)
Definition WsfRoute.cpp:428
WsfRoute()=default
virtual bool Initialize(double aSimTime=0.0)
Definition WsfRoute.cpp:132
UtReferenceCount * GetWaypointReferenceCount()
Definition WsfRoute.hpp:204
void TransformNED(double aNorth, double aEast, double aDown)
Definition WsfRoute.cpp:1884
void AppendSubroute(int aStartIndex, int aEndIndex, WsfRoute &aRoute) const
Definition WsfRoute.cpp:375
void Serialize(T &aBuff)
For XIO (de)serialization.
Definition WsfRoute.hpp:215
void Transform(double aRefLat, double aRefLon, double aHeading)
Definition WsfRoute.cpp:1832
void Insert(WayptVecIter aIter, const WsfWaypoint &aWaypoint)
Definition WsfRoute.cpp:204
double GetDistanceAlongRoute(const double aFromLL[2], const double aToLL[2]) const
Definition WsfRoute.cpp:750
std::vector< WsfWaypoint > WaypointVector
Definition WsfRoute.hpp:44
double GetDistance(int aFromWaypointIndex, int aToWaypointIndex) const
Definition WsfRoute.cpp:660
WsfWaypoint & operator[](size_t aIndex)
Definition WsfRoute.cpp:108
bool PointAlongRoute(double aDistanceFromStart, double aPointAlongRoute[2], int &aSegmentIndex)
Definition WsfRoute.cpp:1215
bool Empty() const
Definition WsfRoute.hpp:181
WayptVecIter Begin()
Return an iterator to the first waypoint in the route.
Definition WsfRoute.hpp:170
void Remove(unsigned int aWaypointIndex)
Definition WsfRoute.cpp:275
unsigned int GetNetworkRouteId() const
Get the network route Id associated with this route.
Definition WsfRoute.hpp:157
static constexpr const char * cTYPE_KIND
Definition WsfRoute.hpp:42
void Append(const WsfWaypoint &aWaypoint)
Add the given point to the end of the waypoint vector.
Definition WsfRoute.cpp:141
double GetDistanceOffset(const double aFromLL[2], const double aToLL[2], const double aPointLL[2], double &aOffsetDist) const
Definition WsfRoute.cpp:678
unsigned int GetSize() const
Definition WsfRoute.hpp:185
Definition WsfWaypoint.hpp:57
WsfOpticalAttenuation::Segment Segment
Definition WsfOpticalAttenuationTables.hpp:31
Template specialization for wsf::comm::Address. Allows usage of Address in std::unordered_map/set.
Definition WsfCommAddress.hpp:185
void swap(WsfRoute &aLhs, WsfRoute &aRhs)
Definition WsfRoute.hpp:294
Definition WsfRoute.hpp:50
int mWaypointIndex2
Definition WsfRoute.hpp:52
int mWaypointIndex1
Definition WsfRoute.hpp:51
UtLLPos mPoint
Definition WsfRoute.hpp:53
Copyrights Multiple, All Rights Reserved