gwnavruntime/queries/utils/baseastarquery.h Source File

baseastarquery.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 #pragma once
8 
20 
21 namespace Kaim
22 {
23 
24 class Path;
25 
28 {
31 
43 
55 
58 };
59 
60 inline const char* ToString(AStarQueryResult e)
61 {
62  static const char* s_strs[] =
63  {
64  "ASTAR_NOT_INITIALIZED",
65  "ASTAR_NOT_PROCESSED",
66 
67  "ASTAR_PROCESSING_TRAVERSAL",
68  "ASTAR_PROCESSING_TRAVERSAL_DONE",
69  "ASTAR_PROCESSING_ABSTRACT_PATH",
70  "ASTAR_PROCESSING_REFINING_INIT",
71  "ASTAR_PROCESSING_REFINING_RESETCOST",
72  "ASTAR_PROCESSING_REFINING",
73  "ASTAR_PROCESSING_PATHCLAMPING_INIT",
74  "ASTAR_PROCESSING_PATHCLAMPING",
75  "ASTAR_PROCESSING_PATHBUILDING",
76  "ASTAR_PROCESSING_CHANNEL_INIT",
77  "ASTAR_PROCESSING_CHANNEL_COMPUTE",
78 
79  "ASTAR_DONE_START_OUTSIDE",
80  "ASTAR_DONE_START_NAVTAG_FORBIDDEN",
81  "ASTAR_DONE_END_OUTSIDE",
82  "ASTAR_DONE_END_NAVTAG_FORBIDDEN",
83  "ASTAR_DONE_PATH_NOT_FOUND",
84  "ASTAR_DONE_NAVDATA_CHANGED",
85  "ASTAR_DONE_ERROR_LACK_OF_WORKING_MEMORY",
86  "ASTAR_DONE_COMPUTATION_ERROR",
87  "ASTAR_DONE_CHANNELCONFIG_ERROR",
88  "ASTAR_DONE_CHANNELCOMPUTATION_ERROR",
89  "ASTAR_DONE_COMPUTATION_CANCELED",
90 
91  "ASTAR_DONE_DEST_IS_START_NO_PATH",
92  "ASTAR_DONE_PATH_FOUND"
93  };
94  const KyInt32 enumCount = ASTAR_DONE_PATH_FOUND + 1;
95  static_assert(enumCount == sizeof(s_strs) / sizeof(const char*), "AStarQueryResult and its string array have not the same size");
96  KyInt32 idx = (KyInt32)e;
97  return idx >= 0 && idx < enumCount ? s_strs[idx] : "AStarQueryResult_UNKNOWN";
98 }
99 
100 template <class OSTREAM>
101 inline OSTREAM& operator<<(OSTREAM& os, AStarQueryResult e) { os << ToString(e); return os; }
102 
103 
106 {
107 public:
108  static QueryType GetStaticType() { return TypeAStar; }
109  static Ptr<BaseBlobHandler> CreateStaticQueryBlobHandler();
110 
111  // ------------------------------ IQuery implementation ------------------------------
112 
113  virtual QueryType GetType() const { return TypeAStar; }
114  virtual void BuildQueryBlob(BaseBlobHandler* blobHandler);
115  virtual void InitFromQueryBlob(World* world, void* blob);
116  virtual Ptr<BaseBlobHandler> CreateQueryBlobHandler() { return CreateStaticQueryBlobHandler(); }
117 
118  // ------------------------------ IPathFinderQuery implementation ------------------------------
119 
120  virtual void GetPathFinderTextResult(String&) const;
121  virtual void DisplayPropagationBounds(DisplayList& displayList) const;
122  virtual PathFinderResult GetPathFinderResult() const;
123  virtual const Vec3f* GetDestination() const { return &m_destPos3f; }
124 
125  // ------------------------------ BindToDatabase ------------------------------
126 
128  void BindToDatabase(Database* database);
129 
130  // ------------------------------ inputs setters ------------------------------
131 
133  void Initialize(const Vec3f& startPos, const Vec3f& destPos);
134 
136  void SetStartTrianglePtr(const NavTrianglePtr& startTrianglePtr);
137 
139  void SetStartNavGraphEdgePtr(const NavGraphEdgePtr& startNavGraphEdgePtr, NavGraphEdgeDirection startNavGraphEdgeDirection);
140 
142  void SetStartNavGraphVertexPtr(const NavGraphVertexPtr& startNavGraphVertexPtr);
143 
145  void SetDestTrianglePtr(const NavTrianglePtr& destTrianglePtr);
146 
148  void SetDestNavGraphEdgePtr(const NavGraphEdgePtr& destNavGraphEdgePtr, NavGraphEdgeDirection destNavGraphEdgeDirection);
149 
151  void SetDestNavGraphVertexPtr(const NavGraphVertexPtr& destNavGraphVertexPtr);
152 
153  // ------------------------------ configuration setters ------------------------------
154 
155  void SetTryCanGoMode(PathFinderQueryTryCanGoMode tryCanGoMode) { m_tryCanGoMode = tryCanGoMode; }
156  void SetPropagationBoxExtent(KyFloat32 propagationBoxExtent) { m_propagationBoxExtent = propagationBoxExtent; }
157 
158  void SetFromOutsideNavMeshDistance(KyFloat32 fromOutsideNavMeshDistance) { m_traversalParams.m_fromOutsideNavMeshDistance = fromOutsideNavMeshDistance; }
159  void SetToOutsideNavMeshDistance(KyFloat32 toOutsideNavMeshDistance) { m_traversalParams.m_toOutsideNavMeshDistance = toOutsideNavMeshDistance; }
160 
161  void SetAbstractGraphTraversalMode(PathFinderAbstractGraphTraversalMode abstractGraphTraversalMode) { m_abstractGraphTraversalMode = abstractGraphTraversalMode; }
162 
163  void SetComputeChannelMode(PathFinderQueryComputeChannelMode computeChannelMode) { m_computeChannelMode = computeChannelMode; }
164  void SetChannelComputerConfig(const ChannelComputerConfig& channelComputerConfig) { m_channelComputerConfig = channelComputerConfig; }
165 
166  void SetPositionSpatializationRange(const PositionSpatializationRange& positionSpatializationRange) { m_traversalParams.m_positionSpatializationRange = positionSpatializationRange; }
167  void SetNumberOfProcessedNodePerFrame(KyUInt32 numberOfProcessedNodePerFrame) { m_traversalParams.m_numberOfVisitedNodePerAdvance = numberOfProcessedNodePerFrame; }
168  void SetPathClamperFlagMask(PathClamperFlagMask pathClamperFlagMask) { m_pathClamperFlagMask = pathClamperFlagMask; }
169 
170  // ------------------------------ results getter -----------------------------
171 
172  Path* GetPath() const { return m_path; }
173  Path* GetAbstractPath() const { return m_abstractPath; }
174  AStarQueryResult GetResult() const { return m_result; }
175  ChannelArrayComputerResult GetChannelResult() const { return m_channelResult; }
176 
177  // ------------------------------ inputs getters -----------------------------
178 
179  const Vec3f& GetStartPos() const { return IPathFinderQuery::GetStartPos(); }
180  const NavTrianglePtr& GetStartTrianglePtr() const { return m_startTrianglePtr; }
181  const NavGraphEdgePtr& GetStartNavGraphEdgePtr() const { return m_startNavGraphEdgePtr; }
182  const NavGraphVertexPtr& GetStartNavGraphVertexPtr() const { return m_startNavGraphVertexPtr; }
183 
184  const Vec3f& GetDestPos() const { return m_destPos3f; }
185  const NavTrianglePtr& GetDestTrianglePtr() const { return m_destTrianglePtr; }
186  const NavGraphEdgePtr& GetDestNavGraphEdgePtr() const { return m_destNavGraphEdgePtr; }
187  const NavGraphVertexPtr& GetDestNavGraphVertexPtr() const { return m_destNavGraphVertexPtr; }
188 
189  // ------------------------------ configuration getters ------------------------------
190 
191  PathFinderQueryTryCanGoMode GetTryCanGoMode() const { return m_tryCanGoMode; }
192  KyFloat32 GetPropagationBoxExtent() const { return m_propagationBoxExtent; }
193 
194  KyFloat32 GetFromOutsideNavMeshDistance() const { return m_traversalParams.m_fromOutsideNavMeshDistance; }
195  KyFloat32 GetToOutsideNavMeshDistance() const { return m_traversalParams.m_toOutsideNavMeshDistance; }
196 
197  PathClamperFlagMask GetPathClamperFlagMask() const { return m_pathClamperFlagMask; }
198 
199  PathFinderAbstractGraphTraversalMode GetAbstractGraphTraversalMode() const { return m_abstractGraphTraversalMode; }
200 
201  PathFinderQueryComputeChannelMode GetComputeChannelMode() const { return m_computeChannelMode; }
202  const ChannelComputerConfig& GetChannelComputerConfig() const { return m_channelComputerConfig; }
203 
204  const PositionSpatializationRange& GetPositionSpatializationRange() const { return m_traversalParams.m_positionSpatializationRange; }
205  KyUInt32 GetNumberOfProcessedNodePerFrame() const { return m_traversalParams.m_numberOfVisitedNodePerAdvance; }
206 
207 public: // internal
208  void ComputePathRefinerConfigInternals() { m_pathRefinerConfig.ComputeInternals(); }
209  const PathRefinerConfig& GetPathRefinerConfig() const { return m_pathRefinerConfig; }
210 
211 protected:
212  BaseAStarQuery();
213  virtual ~BaseAStarQuery() {}
214  void SetResult(AStarQueryResult result) { m_result = result; }
215  void InitTraversalParamsAndPropagationCellFilter();
216  void ReplaceNodesOfShortestPathOnMiddleOfNavHalfEdge(WorkingMemory* workingMemory);
217 
218 protected:
219  // ------------------------------ start -----------------------------
222  NavGraphEdgeDirection m_startNavGraphEdgeDirection;
224 
225  // ------------------------------ destination -----------------------------
229  NavGraphEdgeDirection m_destNavGraphEdgeDirection;
231 
232  // ------------------------------ configuration -----------------------------
234  PathRefinerConfig m_pathRefinerConfig;
236  PathFinderAbstractGraphTraversalMode m_abstractGraphTraversalMode;
238 
239  // ------------------------------ computed -----------------------------
242  bool m_isStartTriangleHooked;
243  TraversalParameters m_traversalParams; // contains a mix of configuration and computed
244  Ptr<CellFilter> m_propagationCellFilter;
245 
246  // ------------------------------ results -----------------------------
247  Ptr<Path> m_abstractPath;
249  ChannelArrayComputerResult m_channelResult;
250 };
251 
252 
253 KY_INLINE void BaseAStarQuery::SetStartTrianglePtr(const NavTrianglePtr& startTrianglePtr)
254 {
255  m_startTrianglePtr = startTrianglePtr;
258 }
259 
260 KY_INLINE void BaseAStarQuery::SetStartNavGraphEdgePtr(const NavGraphEdgePtr& startNavGraphEdgePtr, NavGraphEdgeDirection startNavGraphEdgeDirection)
261 {
262  m_startNavGraphEdgePtr = startNavGraphEdgePtr;
263  m_startNavGraphEdgeDirection = startNavGraphEdgeDirection;
266 }
267 
268 KY_INLINE void BaseAStarQuery::SetStartNavGraphVertexPtr(const NavGraphVertexPtr& startNavGraphVertexPtr)
269 {
270  m_startNavGraphVertexPtr = startNavGraphVertexPtr;
273 }
274 
275 KY_INLINE void BaseAStarQuery::SetDestTrianglePtr(const NavTrianglePtr& destTrianglePtr)
276 {
277  m_destTrianglePtr = destTrianglePtr;
280 }
281 
282 KY_INLINE void BaseAStarQuery::SetDestNavGraphEdgePtr(const NavGraphEdgePtr& destNavGraphEdgePtr, NavGraphEdgeDirection destNavGraphEdgeDirection)
283 {
284  m_destNavGraphEdgePtr = destNavGraphEdgePtr;
285  m_destNavGraphEdgeDirection = destNavGraphEdgeDirection;
288 }
289 
290 KY_INLINE void BaseAStarQuery::SetDestNavGraphVertexPtr(const NavGraphVertexPtr& destNavGraphVertexPtr)
291 {
292  m_destNavGraphVertexPtr = destNavGraphVertexPtr;
295 }
296 
297 
298 }
299 
300 
ChannelComputerConfig m_channelComputerConfig
The parameter set specific to Channels computation.
Definition: ipathfinderquery.h:86
NavTrianglePtr m_startTrianglePtr
If no m_startTrianglePtr is set, it will be automatically computed from m_startPos3f.
Definition: baseastarquery.h:220
void Invalidate()
Invalidates this object.
Definition: navtriangleptr.h:125
Indicates that a path could not be found between the start and destination points.
Definition: baseastarquery.h:48
Base class for all pathfinder queries.
Definition: ipathfinderquery.h:34
Base class for AstarQuery.
Definition: baseastarquery.h:105
NavGraphEdgeDirection m_startNavGraphEdgeDirection
if NAVGRAPHEDGE_BIDIRECTIONAL query starts also inside m_startNavGraphEdgePtr reverse edge if it exis...
Definition: baseastarquery.h:222
Vec3f m_destInsidePos3f
if m_destInsidePos3f is outside NavMesh it is the computed inside pos in the 2d range of m_toOutsideN...
Definition: baseastarquery.h:241
PathFinderQueryComputeChannelMode
This enum tells if the PathFinderQuery should compute Channels around path sections laying on the Nav...
Definition: ipathfinderquery.h:25
Vec3f m_startInsidePos3f
if m_startPos3f is outside NavMesh it is the computed inside pos in the 2d range of m_fromOutsideNavM...
Definition: baseastarquery.h:240
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Unused. Kept here for backward compatibility.
Definition: baseastarquery.h:41
virtual const Vec3f * GetDestination() const
This function is virtual because not all the PathFinders have a preset destination, it may return nullptr.
Definition: baseastarquery.h:123
KyFloat32 m_propagationBoxExtent
limits propagation to the (start-dest) segment inflated by m_propagationBoxExtent. default 200.0f
Definition: baseastarquery.h:237
Indicates that a computation error caused the query to stop.
Definition: baseastarquery.h:53
Indicates that insufficient working memory caused the query to stop.
Definition: baseastarquery.h:50
PathClamperFlag
These flags determine if some specific positions must have their altitude clamped on NavMesh...
Definition: pathclamperflag.h:15
void Invalidate()
Invalidates this object.
Definition: navgraphvertexptr.h:101
void SetDestNavGraphVertexPtr(const NavGraphVertexPtr &destNavGraphVertexPtr)
Sets destination to a NavGraphVertex.
Definition: baseastarquery.h:290
Indicates that a computation error caused the query to stop.
Definition: baseastarquery.h:51
void SetStartNavGraphEdgePtr(const NavGraphEdgePtr &startNavGraphEdgePtr, NavGraphEdgeDirection startNavGraphEdgeDirection)
Sets start inside a NavGraphEdge. if startNavGraphEdgeDirection specifies if query can start in rever...
Definition: baseastarquery.h:260
Indicates that the refined path is being clamped to navMesh according to the altitude tolerance...
Definition: baseastarquery.h:39
virtual void GetPathFinderTextResult(String &) const
Fills the String with an explanation of the result. Use this to debug your pathfinder query...
Definition: baseastarquery.cpp:259
virtual QueryType GetType() const
Get query type.
Definition: baseastarquery.h:113
Indicates that the NavTag at the starting point is forbidden.
Definition: baseastarquery.h:45
Indicates the query has not yet been launched.
Definition: baseastarquery.h:30
PathClamperFlagMask m_pathClamperFlagMask
default PathClamperFlag_ClampAll
Definition: baseastarquery.h:235
Indicates that the channel is initialized, the channel is being computed.
Definition: baseastarquery.h:42
NavGraphEdgeDirection m_destNavGraphEdgeDirection
if NAVGRAPHEDGE_BIDIRECTIONAL query ends also inside m_startNavGraphEdgePtr reverse edge if it exists...
Definition: baseastarquery.h:229
void Invalidate()
Invalidates this object.
Definition: navgraphedgeptr.h:116
AStarQueryResult m_result
Updated during processing to indicate the result of the PathFinderQueryResult query.
Definition: baseastarquery.h:248
Indicates that the NavTag at the destination point is forbidden.
Definition: baseastarquery.h:47
This class is a runtime container for Autodesk Navigation WorldElements such as NavData, Bots, BoxObstacles, TagVolumes...
Definition: world.h:52
Indicates that the input channelComputerConfig is invalid.
Definition: baseastarquery.h:52
Ptr< Path > m_path
The Path found by the query.
Definition: ipathfinderquery.h:94
PathFinderAbstractGraphTraversalMode m_abstractGraphTraversalMode
default PATHFINDER_TRAVERSE_ABSTRACT_GRAPHS
Definition: baseastarquery.h:236
KyFloat32 m_fromOutsideNavMeshDistance
The maximum distance from the start along the X axis and along the Y axis that will be searched for N...
Definition: traversalparams.h:54
PathFinderQueryTryCanGoMode
This enums tells if a RayCanGoQuery should be performed from start position to destination position b...
Definition: pathfinderquerytrycangomode.h:22
Indicates that the refining process is being initialized.
Definition: baseastarquery.h:35
An internal class that stores parameters used to control the propagation of traversals.
Definition: traversalparams.h:18
PathFinderQueryComputeChannelMode m_computeChannelMode
The mode toggling Channels computation.
Definition: ipathfinderquery.h:85
virtual void DisplayPropagationBounds(DisplayList &displayList) const
Fill the displayList with display info that may help to understand a PathFinderFailure (mainly propag...
Definition: baseastarquery.cpp:297
Indicates that a NavMesh triangle could not be found for the starting point.
Definition: baseastarquery.h:44
QueryType
Enumerates all the type of query.
Definition: iquery.h:25
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:57
Vec3f m_destPos3f
The destination position.
Definition: baseastarquery.h:226
Indicates that the Astar traversal algorithm has been launched, but has not yet completed.
Definition: baseastarquery.h:32
Indicates the query has not yet been initialized.
Definition: baseastarquery.h:29
Indicates that the refiner is done, but the path has not yet been clamped to the navMesh.
Definition: baseastarquery.h:38
Indicates that the computation has been canceled.
Definition: baseastarquery.h:54
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Ptr< Path > m_abstractPath
The Abstract Path found by the query.
Definition: baseastarquery.h:247
void SetDestTrianglePtr(const NavTrianglePtr &destTrianglePtr)
If no destTrianglePtr is set, it will be automatically computed during the query. Optional input...
Definition: baseastarquery.h:275
Each instance of this class uniquely identifies a single NavGraphVertex in a NavGraph.
Definition: navgraphvertexptr.h:17
NavGraphVertexPtr m_destNavGraphVertexPtr
if valid, query ends at m_startNavGraphVertexPtr
Definition: baseastarquery.h:230
Indicates that the query has not yet been initialized.
Definition: iquery.h:295
void SetStartTrianglePtr(const NavTrianglePtr &startTrianglePtr)
If no startTrianglePtr is set, it will be automatically computed during the query.
Definition: baseastarquery.h:253
PathFinderResult
Enumerates the possible status of a IPathFinderQuery.
Definition: ipathfinderquery.h:38
std::int32_t KyInt32
int32_t
Definition: types.h:24
Indicates that the cost from nodes that are on navMesh are beeing recomputed since they may have been...
Definition: baseastarquery.h:36
NavGraphEdgePtr m_destNavGraphEdgePtr
if valid, query ends inside a NavGraphEdge
Definition: baseastarquery.h:228
NavGraphEdgePtr m_startNavGraphEdgePtr
if valid, query starts inside a NavGraphEdge
Definition: baseastarquery.h:221
Indicates that query starting location and ending location are equals. computing a Path would have le...
Definition: baseastarquery.h:56
NavGraphVertexPtr m_startNavGraphVertexPtr
if valid, query starts at m_startNavGraphVertexPtr
Definition: baseastarquery.h:223
Indicates that the query has stopped and must be relaunched because of a change in the NavData...
Definition: baseastarquery.h:49
Indicates that the clamping algorithm has completed, but the path has not yet been built...
Definition: baseastarquery.h:40
Each instance of this class uniquely identifies a single NavTriangle in a NavFloor.
Definition: navtriangleptr.h:17
Indicates that the Astar traversal algorithm traversed AbstractGraph, and the Abstract path is being ...
Definition: baseastarquery.h:34
Indicates that the Astar traversal algorithm is finished, and that a path is found and is prepared to...
Definition: baseastarquery.h:33
Indicates that the query has not yet been launched.
Definition: iquery.h:296
PathFinderQueryTryCanGoMode m_tryCanGoMode
default PATHFINDER_TRY_RAYCANGO_IF_NO_COST
Definition: baseastarquery.h:233
void SetStartNavGraphVertexPtr(const NavGraphVertexPtr &startNavGraphVertexPtr)
Sets start to a NavGraphVertex. Optional input.
Definition: baseastarquery.h:268
Indicates that the destination point of the query is outside the NavMesh.
Definition: baseastarquery.h:46
ChannelArrayComputerResult
ChannelArrayComputerResult.
Definition: channelarraycomputerresult.h:13
PositionSpatializationRange m_positionSpatializationRange
The altitude range used to find NavMesh triangles that correspond to the start and destination points...
Definition: traversalparams.h:46
Each instance of this class uniquely identifies a single and mono-directionnal NavGraphEdge in a NavG...
Definition: navgraphedgeptr.h:20
Indicates that a path has been found between the start and destination.
Definition: baseastarquery.h:57
void BindToDatabase(Database *database)
Binds the query with database, clears inputs and results, sets the configuration to defaults...
Definition: baseastarquery.cpp:59
Indicates that the path found is being refined.
Definition: baseastarquery.h:37
void SetDestNavGraphEdgePtr(const NavGraphEdgePtr &destNavGraphEdgePtr, NavGraphEdgeDirection destNavGraphEdgeDirection)
Sets destination inside a NavGraphEdge. destNavGraphEdgeDirection specifies if query can start in rev...
Definition: baseastarquery.h:282
float KyFloat32
float
Definition: types.h:32
3d vector using 32bits floating points.
Definition: vec3f.h:16
NavTrianglePtr m_destTrianglePtr
If no m_destTrianglePtr is set, it will be automatically computed from m_destPos3f.
Definition: baseastarquery.h:227
KyFloat32 m_toOutsideNavMeshDistance
The maximum distance from the destination along the X axis and along the Y axis that will be searched...
Definition: traversalparams.h:62
AStarQueryResult
Enumerates the possible results of an AStarQuery.
Definition: baseastarquery.h:27