WSF
WsfRouteFinder.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 WSFROUTEFINDER_HPP
16#define WSFROUTEFINDER_HPP
17
18#include <limits>
19#include <map>
20#include <memory>
21#include <set>
22#include <string>
23
24#include "UtEntity.hpp"
25#include "UtScriptClassDefine.hpp"
26#include "UtVec2.hpp"
27#include "WsfDraw.hpp"
28#include "WsfGeoPoint.hpp"
29#include "WsfObject.hpp"
30class WsfPlatform;
31#include "WsfRoute.hpp"
32
34{
35public:
36 // defines behavior for when starting point or targeted point are contained inside an avoidance region
43
45 {
46 CLOCKWISE = 0x01,
48 NEITHER = 0x03
49 };
50
51 WsfRouteFinder(WsfSimulation* aSimulationPtr);
52 WsfRouteFinder(const WsfRouteFinder& aSrc);
54 ~WsfRouteFinder() override;
55
56 WsfRouteFinder* Clone() const override { return new WsfRouteFinder(*this); }
57
58 static std::unique_ptr<UtScriptClass> CreateScriptClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
59
60 void Avoid(WsfPlatform& aPlatform, double aRadius);
61 void Avoid(const WsfGeoPoint& aPoint, double aRadius);
62 void ClearAvoidances();
63
64 WsfRoute* Route(double aTime, const WsfGeoPoint& aFrom, const WsfGeoPoint& aTo, double speed, int branchIndex = 0);
65 // returns the avoidances relevant for the last computed route (1 avoidance per leg of 2 route points)
66 WsfRoute* RouteAvoidances();
67
68 void DrawRoute(double duration, const UtVec3d& color);
69 void DrawGraph(double duration, const UtVec3d& color);
70 void DrawAvoidances(double duration, const UtVec3d& color);
71
72 ImpossibleRouteResponse GetImpossibleRouteResponse(void) { return mImpossibleRouteResponse; }
73 void SetImpossibleRouteResponse(ImpossibleRouteResponse aResponse) { mImpossibleRouteResponse = aResponse; }
74 void SetMaxArcLength(double aArcLength) { mMaxArcLength = aArcLength; }
75 WsfSimulation* GetSimulation() const { return mSimulationPtr; }
76
77private:
78 class Line2d
79 {
80 public:
81 Line2d()
82 : mBeg()
83 , mEnd()
84 {
85 }
86 Line2d(const UtVec2d& a, const UtVec2d& b)
87 : mBeg(a)
88 , mEnd(b)
89 {
90 }
91
92 UtVec2d IntoVec() const { return (mEnd - mBeg); }
93
94 UtVec2d mBeg;
95 UtVec2d mEnd;
96 };
97
98 class Circle2d
99 {
100 public:
101 Circle2d()
102 : mLoc()
103 , mRadius(0.0)
104 {
105 }
106 Circle2d(const UtVec2d& aPoint, double aRadius)
107 : mLoc(aPoint)
108 , mRadius(aRadius)
109 {
110 }
111
112 UtVec2d mLoc;
113 double mRadius;
114 };
115
116 class Avoidance
117 {
118 public:
119 Avoidance(const UtVec2d& aLocation, double aRadius, double aDistance, const WsfGeoPoint& aOrigPt, unsigned short aID)
120 : mCircle(aLocation, aRadius)
121 , mDistance(aDistance)
122 , mID(aID)
123 , mOriginalPoint(aOrigPt)
124 {
125 mNear = mDistance - mCircle.mRadius;
126 mFar = mDistance + mCircle.mRadius;
127 }
128 Avoidance(const UtVec2d& aLocation, unsigned short aID = 65535)
129 : mCircle(aLocation, 0)
130 , mDistance(0)
131 , mNear(0)
132 , mFar(0)
133 , mID(aID)
134 , mOriginalPoint()
135 {
136 }
137
138 void SetRadius(double aRadius)
139 {
140 mCircle.mRadius = aRadius;
141 mNear = mDistance - mCircle.mRadius;
142 mFar = mDistance + mCircle.mRadius;
143 }
144
145 bool operator<(const Avoidance& aRhs) const { return (mNear < aRhs.mNear); }
146
147 bool operator==(const Avoidance& aRhs) const
148 {
149 return (mCircle.mLoc.Equals(aRhs.mCircle.mLoc) && (mCircle.mRadius == aRhs.mCircle.mRadius));
150 }
151
152 Circle2d mCircle;
153
154 double mDistance;
155 double mNear;
156 double mFar;
157
158 unsigned short mID;
159
160 WsfGeoPoint mOriginalPoint;
161
162 std::vector<Avoidance*> mOverlaps;
163 };
164
165 class GraphBranch;
166 class GraphNode
167 {
168 public:
169 GraphNode(Avoidance* aAvoidPtr)
170 : mAvoidPtr(aAvoidPtr)
171 , mBranches()
172 {
173 }
174 ~GraphNode()
175 {
176 for (std::vector<GraphBranch*>::iterator it = mBranches.begin(); it != mBranches.end(); ++it)
177 {
178 delete *it;
179 }
180 }
181
182 Avoidance* mAvoidPtr; // not responsible to clean this up, class owns the object
183 std::vector<GraphBranch*> mBranches;
184 };
185
186 class GraphBranch
187 {
188 public:
189 GraphBranch(const Line2d& aLine, GraphNode* aNodePtr)
190 : mFromPoint(aLine.mBeg)
191 , mToPoint(aLine.mEnd)
192 , mNodePtr(aNodePtr)
193 , mVisited(false)
194 {
195 }
196 GraphBranch(const UtVec2d& aFromPoint, const UtVec2d& aToPoint, GraphNode* aNodePtr)
197 : mFromPoint(aFromPoint)
198 , mToPoint(aToPoint)
199 , mNodePtr(aNodePtr)
200 , mVisited(false)
201 {
202 }
203
204 OrientationAround Orientation();
205 UtVec2d mFromPoint; // point of this node
206 UtVec2d mToPoint; // point of this node
207 GraphNode* mNodePtr; // adjacent avoidance to this node point
208 // do not delete this on deconstruction,
209 // branch instances are owned by nodes, so nodes clean up
210 bool mVisited;
211 };
212
213
215
216 GraphNode* GenerateGraph();
217 std::vector<GraphBranch*> FindBestGraphPath(); // searches mGraphNodes
218 std::vector<GraphBranch*> FindGraphPathUsingBranch(unsigned int index); // searches mGraphNodes down branch at index
219 // -> index 0 = best branch, index 1 = 2nd
220 // best branch, etc...
221 void FindBestGraphPathRecursive(GraphNode* next,
222 UtVec2d& prev,
223 double dist = 0,
224 OrientationAround enteringOrientation = NEITHER);
226
227
229
230
232 UtVec2d GetLocal(const double wcs[3]);
233 UtVec2d GetLocal(const WsfGeoPoint& pt);
234 void GetGlobal(const UtVec2d& pt, double wcs[3]);
235 WsfGeoPoint GetGlobal(const UtVec2d& pt);
237 void DrawCircle(const WsfGeoPoint& center, double radius);
239 bool Contains(const Circle2d& circle, const UtVec2d& point);
241 bool Contains(const Circle2d& a, const Circle2d& b);
243 bool Intersects(const Circle2d& a, const Circle2d& b);
245 bool Intersects(const Line2d& line, const Circle2d& circle);
247 bool Intersection(const Line2d& line1, const Line2d& line2, UtVec2d& point);
249 double ArcLength(const Circle2d& circle, const UtVec2d& fromPt, const UtVec2d& toPt);
251 double ArcLength(const Circle2d& circle, const UtVec2d& fromPt, const UtVec2d& toPt, OrientationAround orientation);
253 bool OuterTangents(const Circle2d& a, const Circle2d& b, Line2d& cw, Line2d& ccw, bool onEdge = false);
254 bool InnerTangents(const Circle2d& a, const Circle2d& b, Line2d& cw, Line2d& ccw, bool onEdge = false);
255 std::pair<UtVec2d, UtVec2d> TangentPoints(const UtVec2d& src, const Circle2d& circle, bool onEdge = false);
257 std::vector<Avoidance*> GetAvoidancesIntersectedBy(const Line2d& aLine);
258 std::vector<Avoidance*> GetAvoidancesContaining(const UtVec2d& aPoint);
259 bool IntersectsAnAvoidance(const Line2d& aLine);
260 bool LocalInsertAvoidance(const Avoidance& avoid);
262
264 double mMaxArcLength; // default: max double value
265
267 ImpossibleRouteResponse mImpossibleRouteResponse;
269 double mSmallFudge;
270 double mVerySmallFudge;
271 double mPercentAvoidancePad;
272
274 bool mAvoidancesChanged;
276 double mCurrentRouteTime;
278 int mLastRouteIndex;
280 WsfRoute mRoute;
281 WsfRoute mRouteAvoidances;
283 UtEntity mReferenceEntity;
285 WsfGeoPoint mGeoSource;
286 WsfGeoPoint mGeoTarget;
287 UtVec2d mSource; // actual starting point
288 UtVec2d mFirst; // first valid point outside of avoidances to start route finding from
289 UtVec2d mTarget;
290 Avoidance* mSourceAvoidancePtr;
291 Avoidance* mTargetAvoidancePtr;
293 WsfDraw mDraw;
295 std::map<size_t, double> mAvoidPlatformIdRadius;
297 std::vector<std::pair<WsfGeoPoint, double>> mAvoidLocationRadius;
299 std::vector<Avoidance> mAvoidances;
300 unsigned short mNextAvoidanceId;
302 double mBestPathDist;
303 std::vector<GraphNode*> mGraphNodes;
304 std::vector<GraphBranch*> mBestPath; // do not need to delete this on deconstruction, objects owned by mGraphNodes
305 std::vector<GraphBranch*> mGraphPathStack; // do not need to delete this on deconstruction, objects owned by mGraphNodes
306 WsfSimulation* mSimulationPtr;
307};
308
310class WSF_EXPORT WsfScriptRouteFinderClass : public UtScriptClass
311{
312public:
313 WsfScriptRouteFinderClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
314
316
317 void* Create(const UtScriptContext& aContext) override;
318 void* Clone(void* aObjectPtr) override;
319 void Destroy(void* aObjectPtr) override;
320
323 UT_DECLARE_SCRIPT_METHOD(ClearAvoidances);
326 UT_DECLARE_SCRIPT_METHOD(RouteAvoidances);
330 UT_DECLARE_SCRIPT_METHOD(ImpossibleRouteResponse);
331 UT_DECLARE_SCRIPT_METHOD(SetImpossibleRouteResponse);
332 UT_DECLARE_SCRIPT_METHOD(SetMaxArcLength);
333};
334
335#endif
bool operator==(int aId, const WsfStringInt &aRhs)
Equal relational operator for the case of an integer on the LHS and a StringId on the RHS.
Definition WsfStringId.hpp:69
bool Contains(std::vector< int > &aQueryTargetIds, const WsfTrack &aShooterTrack)
Definition WsfWeaponThreatProcessor.cpp:1462
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Definition WsfGeoPoint.hpp:29
WsfObject()
This is the constructor for the WsfObject class.
Definition WsfObject.cpp:88
virtual WsfObject * Clone() const =0
Platforms represent a entity within the simulation.
Definition WsfPlatform.hpp:115
Definition WsfRouteFinder.hpp:34
void SetImpossibleRouteResponse(ImpossibleRouteResponse aResponse)
Definition WsfRouteFinder.hpp:73
ImpossibleRouteResponse GetImpossibleRouteResponse(void)
Definition WsfRouteFinder.hpp:72
WsfRouteFinder & operator=(const WsfRouteFinder &)=delete
WsfSimulation * GetSimulation() const
Definition WsfRouteFinder.hpp:75
ImpossibleRouteResponse
Definition WsfRouteFinder.hpp:38
@ SHIFT_OUTSIDE_AVOIDANCES
Definition WsfRouteFinder.hpp:40
@ SHRINK_AVOIDANCES
Definition WsfRouteFinder.hpp:39
@ IGNORE_IMPOSSIBLE_AVOIDANCES
Definition WsfRouteFinder.hpp:41
WsfRouteFinder(WsfSimulation *aSimulationPtr)
Definition WsfRouteFinder.cpp:30
void SetMaxArcLength(double aArcLength)
Definition WsfRouteFinder.hpp:74
OrientationAround
Definition WsfRouteFinder.hpp:45
@ CLOCKWISE
Definition WsfRouteFinder.hpp:46
@ NEITHER
Definition WsfRouteFinder.hpp:48
@ COUNTERCLOCKWISE
Definition WsfRouteFinder.hpp:47
WsfRouteFinder * Clone() const override
Definition WsfRouteFinder.hpp:56
A collection of WsfWaypoint objects that represent a path to be followed.
Definition WsfRoute.hpp:40
UT_DECLARE_SCRIPT_METHOD(DrawAvoidances)
void Destroy(void *aObjectPtr) override
Definition WsfRouteFinder.cpp:1465
UT_DECLARE_SCRIPT_METHOD(DrawGraph)
UT_DECLARE_SCRIPT_METHOD(DrawRoute)
UT_DECLARE_SCRIPT_METHOD(SetMaxArcLength)
WsfScriptRouteFinderClass(const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)
Definition WsfRouteFinder.cpp:1426
UT_DECLARE_SCRIPT_METHOD(RouteAvoidances)
void * Create(const UtScriptContext &aContext) override
Definition WsfRouteFinder.cpp:1451
UT_DECLARE_SCRIPT_METHOD(ClearAvoidances)
UT_DECLARE_SCRIPT_METHOD(ImpossibleRouteResponse)
UT_DECLARE_SCRIPT_METHOD(SetImpossibleRouteResponse)
The main controller for a simulation.
Definition WsfSimulation.hpp:109
Copyrights Multiple, All Rights Reserved