WSF
WsfZoneRouteFinder.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#ifndef WSFZONEROUTEFINDER_HPP
13#define WSFZONEROUTEFINDER_HPP
14
15#include <memory>
16
17#include "UtScriptClassDefine.hpp"
18#include "UtVec2.hpp"
19#include "UtVec3.hpp" //included in WsfDraw.hpp, but also here for completeness
20#include "WsfDraw.hpp"
21#include "WsfGeoPoint.hpp"
22#include "WsfObject.hpp"
23class WsfRoute;
24class WsfZone;
26
27
29{
30public:
31 WsfZoneRouteFinder(WsfSimulation* aSimulationPtr);
33 ~WsfZoneRouteFinder() override;
35
36 WsfZoneRouteFinder* Clone() const override { return new WsfZoneRouteFinder(*this); }
37
38 static std::unique_ptr<UtScriptClass> CreateScriptClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
39
40 void ClearAvoidanceZones();
41
42 void DrawGraph(double aDuration, const UtVec3d& aColor);
43 void DrawAvoidances(double aDuration, const UtVec3d& aColor);
44
45 WsfSimulation* GetSimulation() const { return mSimulationPtr; }
46
47 void AvoidZone(WsfZone* aZonePtr);
51 const WsfZone* GetAvoidanceZone(size_t aIndex) const noexcept;
54 size_t NumberOfAvoidanceZones() const noexcept { return mAvoidZones.size(); }
55 WsfRoute* RouteAroundZones(const WsfGeoPoint& aFrom, const WsfGeoPoint& aTo, double aSpeed);
56
57private:
58 class Line2d
59 {
60 public:
61 Line2d()
62 : mBeg()
63 , mEnd()
64 {
65 }
66 Line2d(const UtVec2d& a, const UtVec2d& b)
67 : mBeg(a)
68 , mEnd(b)
69 {
70 }
71
72 UtVec2d IntoVec() const { return (mEnd - mBeg); }
73
74 UtVec2d mBeg;
75 UtVec2d mEnd;
76 };
77
78 class ZoneGraphNode
79 {
80 public:
81 ZoneGraphNode() = delete;
82 ZoneGraphNode(const UtVec2d& aLocation)
83 : mVisited(false)
84 , mLoc(aLocation)
85 , mEdges()
86 {
87 }
88
89 bool mVisited;
90 UtVec2d mLoc;
91 std::vector<ZoneGraphNode*> mEdges;
92 };
93
95
96
98 UtVec2d GetLocal(const WsfGeoPoint& pt);
99 void GetGlobal(const UtVec2d& pt, double wcs[3]);
100 WsfGeoPoint GetGlobal(const UtVec2d& pt);
101
103 bool Intersection(const Line2d& line1, const Line2d& line2, UtVec2d& point);
104
105 // returns distance to closest point
106 double ClosestPointOnLineSegment(const UtVec2d& aPoint, const UtVec2d& aLine1, const UtVec2d& aLine2, UtVec2d& aClosest);
108
109
110 bool Intersects(const Line2d& aLine, std::vector<UtVec2d> aPolygon);
111 bool Intersects(const Line2d& aLine, std::vector<std::vector<UtVec2d>> aPolygons);
112
113 UtVec2d NearestSafePoint(const UtVec2d& aPt);
114
115 void DrawPolygon(double aDuration, const UtVec3d& aColor, std::vector<UtVec2d>& aPolygon);
116
117 void ShortestZoneGraphPathRecursive(ZoneGraphNode* aNodePtr, UtVec2d& aTarget, double aDist = 0);
118
120 WsfGeoPoint mGeoStart;
121 WsfGeoPoint mGeoEnd;
122 UtVec2d mStart;
123 UtVec2d mEnd;
124
125 UtVec2d mSafeStart; // first valid point outside of avoidances to start route finding from
126 UtVec2d mSafeEnd; // first valid point outside of avoidances to end route finding to
127
129 WsfDraw mDraw;
130 WsfSimulation* mSimulationPtr;
131
133
134 std::vector<ZoneGraphNode*> mZoneGraph;
135 std::vector<WsfZoneDefinition*> mAvoidZones;
136 std::vector<std::vector<UtVec2d>> mLocalZones; // vector<UtVec2d> representation of mAvoidZones
137 double mBestZonePathDist;
138 std::vector<ZoneGraphNode*> mBestZonePath; // do not need to delete this on deconstruction, objects owned elsewhere
139 std::vector<ZoneGraphNode*> mZonePathStack; // do not need to delete this on deconstruction, objects owned elsewhere
140};
141
143class WSF_EXPORT WsfScriptZoneRouteFinderClass : public UtScriptClass
144{
145public:
146 WsfScriptZoneRouteFinderClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
147
149
150 void* Create(const UtScriptContext& aContext) override;
151 void* Clone(void* aObjectPtr) override;
152 void Destroy(void* aObjectPtr) override;
153
156 UT_DECLARE_SCRIPT_METHOD(NumberOfAvoidanceZones);
157 UT_DECLARE_SCRIPT_METHOD(GetAvoidanceZone);
158 UT_DECLARE_SCRIPT_METHOD(RouteAroundZones);
159 UT_DECLARE_SCRIPT_METHOD(ClearAvoidanceZones);
162};
163
164#endif
#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
A collection of WsfWaypoint objects that represent a path to be followed.
Definition WsfRoute.hpp:40
UT_DECLARE_SCRIPT_METHOD(NumberOfAvoidanceZones)
void Destroy(void *aObjectPtr) override
Definition WsfZoneRouteFinder.cpp:567
UT_DECLARE_SCRIPT_METHOD(RouteAroundZones)
WsfScriptZoneRouteFinderClass(const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)
Definition WsfZoneRouteFinder.cpp:532
UT_DECLARE_SCRIPT_METHOD(DrawAvoidances)
UT_DECLARE_SCRIPT_METHOD(ClearAvoidanceZones)
void * Create(const UtScriptContext &aContext) override
Definition WsfZoneRouteFinder.cpp:553
UT_DECLARE_SCRIPT_METHOD(AvoidZone_1)
UT_DECLARE_SCRIPT_METHOD(AvoidZone_2)
UT_DECLARE_SCRIPT_METHOD(GetAvoidanceZone)
The main controller for a simulation.
Definition WsfSimulation.hpp:109
A class for defining a zone.
Definition WsfZoneDefinition.hpp:32
size_t NumberOfAvoidanceZones() const noexcept
Definition WsfZoneRouteFinder.hpp:54
WsfZoneRouteFinder & operator=(const WsfZoneRouteFinder &)=delete
WsfZoneRouteFinder * Clone() const override
Definition WsfZoneRouteFinder.hpp:36
WsfSimulation * GetSimulation() const
Definition WsfZoneRouteFinder.hpp:45
WsfZoneRouteFinder(WsfSimulation *aSimulationPtr)
Definition WsfZoneRouteFinder.cpp:28
Definition WsfZone.hpp:63
Copyrights Multiple, All Rights Reserved