WSF
WsfNavigationMesh.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 WSFNAVIGATIONMESH_HPP
16#define WSFNAVIGATIONMESH_HPP
17
18#include "wsf_export.h"
19
20#include <limits>
21#include <map>
22
23#include "UtVec3.hpp"
24#include "WsfDraw.hpp"
25#include "WsfGeoPoint.hpp"
26#include "WsfMover.hpp"
27#include "WsfNavigationCell.hpp"
28#include "WsfPathFinder.hpp"
29#include "WsfZone.hpp"
30#include "WsfZoneDefinition.hpp"
32
33#define FLOAT_EPSILON 1.0E-6F
34
36{
37public:
38 WsfNavigationMesh(WsfScenario* aScenarioPtr);
39 ~WsfNavigationMesh() override;
40 bool ProcessInput(UtInput& aInput) override;
41 const char* GetScriptClassName() const override;
50
51 void CreateNavigationMesh();
52 // void CreateGridOfCentroids();
53 void GetCellNeighbors(WsfNavigationCell* aNavCellPtr);
54 int GetXSize() { return mXSize; }
55 int GetYSize() { return mYSize; }
56 int GetNumCells() { return static_cast<int>(mMeshCells.size()); }
57 void DebugDrawMesh();
58 void DebugDrawZones() override;
59 WsfPathFinder::node_iterator GetGrid(long aX, long aY);
60 bool Initialize(WsfSimulation* aSimulationPtr) override;
61
62 bool shortest_path(const_node_iterator aSrcNodeIter,
63 const_node_iterator aDstNodeIter,
64 NodeList& aPath,
65 double& aCost,
66 const cost_func* aCostFuncPtr = nullptr) const override;
67
68 bool FindPath(const WsfGeoPoint& aStartPtr, WsfGeoPoint& aEndPtr, WsfRoute& aRoute, double& aCost) override;
69
70 const WsfPFNode* GetClosestNode(const WsfGeoPoint& aPointPtr) override;
71 void RefineFromCurrentIndex(int aIndex);
72 bool RefineFromCurrentPosition(int aIndex, double aLat, double aLon, double aAlt, WsfRoute& aRoute, const WsfRoute* aOriginalRoute);
73 WsfNavigationCell* GetCellForPoint(const WsfGeoPoint& aPoint);
74 std::vector<WsfNavigationCell*> GetCellsForPoint(const WsfGeoPoint& aPoint);
75
76 void TessellateCell(WsfNavigationCell* aCellPtr, WsfZoneDefinition* aZonePtr, int aCurrentTessLevel);
77
78 ZONE_INTERACTION GetCellZoneInteraction(WsfNavigationCell* aCellPtr, WsfZoneDefinition* aZonePtr);
79 void ReNumberMeshCells();
80 void SetMeshBoundries(double aLLA[3]);
81 void SetMeshCenter();
82 void InsertCellIntoGrid(WsfNavigationCell* aNavCellPtr);
83 void LinkGridNeighbors(WsfNavigationCell* aNavCellPtr);
84 int GetFurthestVisiblePoint(int aIndex, WsfRoute& aRoute);
85 bool LineOfSightTest(WsfNavigationCell* aFromCellPtr, int aIndexFrom, int aIndexTo, WsfRoute& aRoute);
86
87 void MovePointAlongPath(WsfGeoPoint& aPoint, int aIndexFrom, int aIndexTo);
88 void MovePointTowardsCentroid(WsfGeoPoint& aPoint, int aIndexFrom, WsfNavigationCell* aCellPtr);
89 bool ComputeSetRoute(WsfMover& aMover, WsfRoute& aRoute, int& aInitialPointIndex) override;
90 bool ComputeFindPath(WsfMover& aMover, WsfRoute& aRoute) override;
91 void GetRouteIntersectionPoints();
92 void CleanUpDuplicatePoints();
93 WsfGeoPoint* FindClosestValidPoint(double aSimTime, const WsfGeoPoint& aGeoPoint) override;
94
96 bool IsNavMesh() override { return true; }
97
98 void SetRefineUpdateTime(double aTime) { mRefineUpdateTime = aTime; }
99 double GetRefineUpdateTime() { return mRefineUpdateTime; }
100
101 void SetNavMeshThinkTime(double aTime) { mNavMeshThinkTime = aTime; }
102 double GetNavMeshThinkTime() { return mNavMeshThinkTime; }
103
104private:
105 void GenerateExportedNavMesh();
106 void ImportNavMesh();
107
108 class pf_cost_func : public PFGraph::cost_func
109 {
110 public:
111 double operator()(const WsfPFEdge& aEdge, const WsfPFNode& aNode1, const WsfPFNode& aNode2) const override
112 {
113 double cost = (aEdge.mLength * 2); // scale the distance to make it more influential
114 return cost;
115 }
116
117 double operator()(const WsfPFNode& aNode1, const WsfPFNode& aNode2) const override
118 {
119 double estimate = aNode2.mLoc.GetDistanceFrom(aNode1.mLoc);
120 return estimate;
121 }
122
123 // adding consider_node function to the cost_func. This will flag a node to be ignored during pathfinding.
124 bool consider_node(const WsfPFNode& aNode1) const override
125 {
126 if (aNode1.mWeight ==
127 std::numeric_limits<double>::max()) // NO_FLY_ZONES are marked as std::numeric_limits<double>::max()
128 // and won't be considered in pathfinding
129 {
130 return false;
131 }
132 else
133 {
134 return true;
135 }
136 }
137 };
138
139protected:
140 std::vector<WsfNavigationCell*> mMeshCells;
141 std::vector<WsfNavigationCell*>::iterator mMeshCellsIterator;
144 std::vector<WsfPFNode*> mMeshNodes;
145 std::vector<WsfGeoPoint> mAdjustedPath;
146 std::vector<WsfNavigationCell*> mGetCellForPointCache; // GetCellForPoint is an expensive function, keep a cache of
147 // recently accessed cells.
148
149private:
150 double mMaxLat;
151 double mMinLat;
152 double mMaxLon;
153 double mMinLon;
154 double mCenterLLA[3];
155 double mRefineUpdateTime;
156 double mNavMeshThinkTime;
157 std::string mInputFile;
158 std::string mOutputFile;
159 bool mLoadBinaryFile;
160 std::map<unsigned int, WsfNavigationCell*> mCellMap;
161};
162
165{
166public:
167 WsfScriptNavigationMeshClass(const std::string& aClassName, UtScriptTypes* aScriptTypesPtr);
168
169 UT_DECLARE_SCRIPT_METHOD(DebugDrawMesh); // NO_DOC | FOR_TEST_ONLY
170};
171
172#endif
#define WSF_EXPORT
Definition WsfXIO_Export.hpp:35
Provides the capability to draw shapes into the WSF replay file.
Definition WsfDraw.hpp:35
Definition WsfGeoPoint.hpp:29
double GetDistanceFrom(double aLocationWCS[3]) const
Definition WsfGeoPoint.cpp:151
Definition WsfMover.hpp:37
Definition WsfNavigationCell.hpp:29
void SetRefineUpdateTime(double aTime)
Definition WsfNavigationMesh.hpp:98
int GetXSize()
Definition WsfNavigationMesh.hpp:54
ZONE_INTERACTION
Definition WsfNavigationMesh.hpp:43
@ THREE_VERTS_INSIDE
Definition WsfNavigationMesh.hpp:47
@ ZONE_VERT_INSIDE
Definition WsfNavigationMesh.hpp:48
@ TWO_VERTS_INSIDE
Definition WsfNavigationMesh.hpp:46
@ NO_INTERACTION
Definition WsfNavigationMesh.hpp:44
@ ONE_VERT_INSIDE
Definition WsfNavigationMesh.hpp:45
WsfDraw * mDebugRouteDrawPtr
Definition WsfNavigationMesh.hpp:143
std::vector< WsfGeoPoint > mAdjustedPath
Definition WsfNavigationMesh.hpp:145
WsfNavigationMesh(WsfScenario *aScenarioPtr)
Definition WsfNavigationMesh.cpp:36
bool IsNavMesh() override
Definition WsfNavigationMesh.hpp:96
double GetRefineUpdateTime()
Definition WsfNavigationMesh.hpp:99
double GetNavMeshThinkTime()
Definition WsfNavigationMesh.hpp:102
std::vector< WsfNavigationCell * > mGetCellForPointCache
Definition WsfNavigationMesh.hpp:146
std::vector< WsfPFNode * > mMeshNodes
Definition WsfNavigationMesh.hpp:144
WsfDraw * mDebugMeshDrawPtr
Definition WsfNavigationMesh.hpp:142
int GetYSize()
Definition WsfNavigationMesh.hpp:55
int GetNumCells()
Definition WsfNavigationMesh.hpp:56
void SetNavMeshThinkTime(double aTime)
Definition WsfNavigationMesh.hpp:101
std::vector< WsfNavigationCell * > mMeshCells
Definition WsfNavigationMesh.hpp:140
std::vector< WsfNavigationCell * >::iterator mMeshCellsIterator
Definition WsfNavigationMesh.hpp:141
Definition WsfPathFinder.hpp:58
WsfGeoPoint mLoc
Definition WsfPathFinder.hpp:79
double mWeight
Definition WsfPathFinder.hpp:77
long mXSize
Definition WsfPathFinder.hpp:196
virtual void DebugDrawZones()
Definition WsfPathFinder.cpp:1052
WsfPathFinder(WsfScenario *aScenarioPtr, WsfGeoPoint &aUpperLeftPtr, WsfGeoPoint &aLowerRightPtr, double aGridSizeDegrees)
Definition WsfPathFinder.cpp:64
virtual WsfGeoPoint * FindClosestValidPoint(double aSimTime, const WsfGeoPoint &aGeoPoint)
Definition WsfPathFinder.cpp:909
const char * GetScriptClassName() const override
Definition WsfPathFinder.cpp:1295
bool ProcessInput(UtInput &aInput) override
Definition WsfPathFinder.cpp:465
bool ComputeFindPath(WsfMover &aMover, WsfRoute &aRoute) override
Definition WsfPathFinder.cpp:1185
virtual bool FindPath(const WsfGeoPoint &aStartPtr, WsfGeoPoint &aEndPtr, WsfRoute &aRoute, double &aCost)
Definition WsfPathFinder.cpp:314
bool shortest_path(const_node_iterator aSrcNodeIter, const_node_iterator aDstNodeIter, NodeList &aPath, double &aCost, const cost_func *aCostFuncPtr=nullptr) const override
Definition WsfPathFinder.cpp:395
virtual bool Initialize(WsfSimulation *aSimulationPtr)
Definition WsfPathFinder.cpp:102
node_iterator GetGrid(long aX, long aY)
Definition WsfPathFinder.cpp:418
bool ComputeSetRoute(WsfMover &aMover, WsfRoute &aRoute, int &aInitialPointIndex) override
Definition WsfPathFinder.cpp:1192
virtual WsfGeoPoint GetRandomLocation()
Definition WsfPathFinder.cpp:1021
long mYSize
Definition WsfPathFinder.hpp:197
virtual const WsfPFNode * GetClosestNode(const WsfGeoPoint &aPointPtr)
Definition WsfPathFinder.cpp:292
A collection of WsfWaypoint objects that represent a path to be followed.
Definition WsfRoute.hpp:40
Contains the data required to create a simulation, and acts as the entry point for input file process...
Definition WsfScenario.hpp:111
UT_DECLARE_SCRIPT_METHOD(DebugDrawMesh)
WsfScriptNavigationMeshClass(const std::string &aClassName, UtScriptTypes *aScriptTypesPtr)
Definition WsfNavigationMesh.cpp:1875
WsfScriptObjectClass(const std::string &aClassName, UtScriptTypes *aTypesPtr)
Definition WsfScriptObjectClass.cpp:24
The main controller for a simulation.
Definition WsfSimulation.hpp:109
A class for defining a zone.
Definition WsfZoneDefinition.hpp:32
Definition WsfPathFinder.hpp:87
double mLength
Definition WsfPathFinder.hpp:102
Copyrights Multiple, All Rights Reserved