gwnavruntime/queries/utils/baseastarquery.h Source File

baseastarquery.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 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 
8 // Primary contact: JUBA - secondary contact: NOBODY
9 #ifndef Navigation_BaseAStarQuery_H
10 #define Navigation_BaseAStarQuery_H
11 
21 
22 
23 namespace Kaim
24 {
25 
26 class Path;
27 
30 {
33 
45 
57 
60 };
61 
69 {
70  ASTAR_DO_NOT_TRY_RAYCANGO = 0,
71  ASTAR_DO_TRY_RAYCANGO = 1
72 };
73 
75 class BaseAStarQuery : public IPathFinderQuery
76 {
77 public:
78  static QueryType GetStaticType() { return TypeAStar; }
79  virtual QueryType GetType() const { return TypeAStar; }
80  virtual void BuildQueryBlob(BaseBlobHandler* blobHandler);
81  virtual void InitFromQueryBlob(World* world, void* blob);
82  virtual Ptr<BaseBlobHandler> CreateQueryBlobHandler() { return CreateStaticQueryBlobHandler(); }
83  static Ptr<BaseBlobHandler> CreateStaticQueryBlobHandler();
84 
85  // ---------------------------------- Main API functions ----------------------------------
86 
87  virtual void GetPathFinderTextResult(String&) const;
88  virtual void DisplayPropagationBounds(ScopedDisplayList& displayList) const;
89  virtual PathFinderResult GetPathFinderResult() const;
90  virtual const Vec3f* GetDestination() const;
91 
92  AStarQueryResult GetResult() const;
93  KyFloat32 GetFromOutsideNavMeshDistance() const;
94  KyFloat32 GetToOutsideNavMeshDistance() const;
95  KyFloat32 GetPropagationBoxExtent() const;
96  const Vec3f& GetStartPos() const;
97  const Vec3f& GetDestPos() const;
98  const NavTrianglePtr& GetStartTrianglePtr() const;
99  const NavGraphEdgePtr& GetStartNavGraphEdgePtr() const;
100  const NavGraphVertexPtr& GetStartNavGraphVertexPtr() const;
101  const NavTrianglePtr& GetDestTrianglePtr() const;
102  const NavGraphEdgePtr& GetDestNavGraphEdgePtr() const;
103  const NavGraphVertexPtr& GetDestNavGraphVertexPtr() const;
104  AStarQueryTryCanGoMode GetTryCanGoMode() const;
105  PathFinderQueryComputeChannelMode GetComputeChannelMode() const;
106  const ChannelComputerConfig& GetChannelComputerConfig() const;
107  Path* GetPath() const;
108  KyUInt32 GetNumberOfProcessedNodePerFrame() const;
109  Path* GetAbstractPath() const;
110  PathFinderAbstractGraphTraversalMode GetAbstractGraphTraversalMode() const;
111 
112  const PositionSpatializationRange& GetPositionSpatializationRange() const;
113 
114  void ComputePathRefinerConfigInternals();
115  const PathRefinerConfig& GetPathRefinerConfig() const;
116 
117 
118 public: // Internal
119  void BindToDatabase(Database* database);
120  void Initialize(const Vec3f& startPos, const Vec3f& destPos);
121 
122  void SetStartTrianglePtr(const NavTrianglePtr& startTrianglePtr);
123  void SetStartNavGraphEdgePtr(const NavGraphEdgePtr& startNavGraphEdgePtr, NavGraphEdgeDirection navGraphEdgePathfindMode);
124  void SetStartNavGraphVertexPtr(const NavGraphVertexPtr& startNavGraphVertexPtr);
125 
126  void SetDestTrianglePtr(const NavTrianglePtr& destTrianglePtr);
127  void SetDestNavGraphEdgePtr(const NavGraphEdgePtr& startNavGraphEdgePtr, NavGraphEdgeDirection navGraphEdgePathfindMode);
128  void SetDestNavGraphVertexPtr(const NavGraphVertexPtr& startNavGraphVertexPtr);
129 
130  void SetTryCanGoMode(AStarQueryTryCanGoMode tryCanGoMode);
131  void SetComputeChannelMode(PathFinderQueryComputeChannelMode computeChannelMode);
132  void SetChannelComputerConfig(const ChannelComputerConfig& channelComputerConfig);
133  void SetPropagationBoxExtent(KyFloat32 propagationBoxExtent);
134  void SetPositionSpatializationRange(const PositionSpatializationRange& positionSpatializationRange);
135  void SetFromOutsideNavMeshDistance(KyFloat32 fromOutsideNavMeshDistance);
136  void SetToOutsideNavMeshDistance(KyFloat32 toOutsideNavMeshDistance);
137  void SetNumberOfProcessedNodePerFrame(KyUInt32 numberOfProcessedNodePerFrame);
138  void SetAbstractGraphTraversalMode(PathFinderAbstractGraphTraversalMode abstractGraphTraversalMode);
139  void SetPathClamperFlagMask(PathClamperFlagMask pathClamperFlagMask); // Call this method after BindToDatabase()
140 
141 protected :
142  BaseAStarQuery();
143  virtual ~BaseAStarQuery() {}
144  void SetResult(AStarQueryResult result);
145 
146  void InitCellFilterFromAbstractGraph();
147  void ReplaceNodesOfShortestPathOnMiddleOfNavHalfEdge(WorkingMemory* workingMemory);
148 protected :
152  // after the call to Initialize
153  NavTrianglePtr m_startTrianglePtr;
154 
158  // after the call to Initialize
159  NavTrianglePtr m_destTrianglePtr;
160 
162 
163  NavGraphEdgePtr m_startNavGraphEdgePtr;
164  NavGraphEdgePtr m_destNavGraphEdgePtr;
167  NavGraphEdgeDirection m_navGraphEdgePathfindMode;
168 
171  NavGraphVertexPtr m_destNavGraphVertexPtr;
172 
176 
177  AStarQueryTryCanGoMode m_tryCanGoMode;
178  TraversalParameters m_traversalParams;
179  PathRefinerConfig m_pathRefinerConfig;
180  PathClamperFlagMask m_pathClamperFlagMask; // Control PathClamper options
183  Ptr<CellFilter> m_propagationCellFilter;
185  Ptr<Path> m_abstractPath;
186 
188 };
190 
191 KY_INLINE void BaseAStarQuery::SetResult(AStarQueryResult result) { m_result = result; }
192 KY_INLINE void BaseAStarQuery::SetTryCanGoMode(AStarQueryTryCanGoMode tryCanGoMode) { m_tryCanGoMode = tryCanGoMode; }
193 KY_INLINE void BaseAStarQuery::SetComputeChannelMode(PathFinderQueryComputeChannelMode mode) { m_computeChannelMode = mode; }
194 KY_INLINE void BaseAStarQuery::SetChannelComputerConfig(const ChannelComputerConfig& config) { m_channelComputerConfig = config; }
195 KY_INLINE void BaseAStarQuery::SetPropagationBoxExtent(KyFloat32 propagationBoxExtent) { m_propagationBoxExtent = propagationBoxExtent; }
197 KY_INLINE void BaseAStarQuery::SetStartTrianglePtr(const NavTrianglePtr& startTrianglePtr)
198 {
199  m_startTrianglePtr = startTrianglePtr;
200  KY_LOG_WARNING_IF(m_startNavGraphEdgePtr.IsValid(), ("You are setting a start NavTrianglePtr whereas a start NavGraphEdgePtr was set too."));
201  KY_LOG_WARNING_IF(m_startNavGraphVertexPtr.IsValid(), ("You are setting a start NavTrianglePtr whereas a start NavGraphVertexPtr was set too."));
204 }
205 
206 KY_INLINE void BaseAStarQuery::SetStartNavGraphEdgePtr(const NavGraphEdgePtr& startNavGraphEdgePtr, NavGraphEdgeDirection navGraphEdgePathfindMode)
207 {
208  m_startNavGraphEdgePtr = startNavGraphEdgePtr;
209  m_navGraphEdgePathfindMode = navGraphEdgePathfindMode;
210  KY_LOG_WARNING_IF(m_startTrianglePtr.IsValid(), ("You are setting a start NavGraphEdgePtr whereas a start NavTrianglePtr was set too."));
211  KY_LOG_WARNING_IF(m_startNavGraphVertexPtr.IsValid(), ("You are setting a start NavGraphEdgePtr whereas a start NavGraphVertexPtr was set too."));
214 }
215 
216 KY_INLINE void BaseAStarQuery::SetStartNavGraphVertexPtr(const NavGraphVertexPtr& startNavGraphVertexPtr)
217 {
218  m_startNavGraphVertexPtr = startNavGraphVertexPtr;
219  KY_LOG_WARNING_IF(m_startTrianglePtr.IsValid(), ("You are setting a start NavGraphVertexPtr whereas a start NavTrianglePtr was set too."));
220  KY_LOG_WARNING_IF(m_startNavGraphEdgePtr.IsValid(), ("You are setting a start NavGraphVertexPtr whereas a start NavGraphEdgePtr was set too."));
223 }
224 
225 KY_INLINE void BaseAStarQuery::SetDestTrianglePtr(const NavTrianglePtr& destTrianglePtr)
226 {
227  m_destTrianglePtr = destTrianglePtr;
228  KY_LOG_WARNING_IF(m_destNavGraphEdgePtr.IsValid(), ("You are setting a dest NavTrianglePtr whereas a dest NavGraphEdgePtr was set too."));
229  KY_LOG_WARNING_IF(m_destNavGraphVertexPtr.IsValid(), ("You are setting a dest NavTrianglePtr whereas a dest NavGraphVertexPtr was set too."));
230  m_destNavGraphEdgePtr.Invalidate();
231  m_destNavGraphVertexPtr.Invalidate();
232 }
233 
234 KY_INLINE void BaseAStarQuery::SetDestNavGraphEdgePtr(const NavGraphEdgePtr& destNavGraphEdgePtr, NavGraphEdgeDirection navGraphEdgePathfindMode)
235 {
236  m_destNavGraphEdgePtr = destNavGraphEdgePtr;
237  m_navGraphEdgePathfindMode = navGraphEdgePathfindMode;
238  KY_LOG_WARNING_IF(m_destTrianglePtr.IsValid(), ("You are setting a dest NavGraphEdgePtr whereas a dest NavTrianglePtr was set too."));
239  KY_LOG_WARNING_IF(m_destNavGraphVertexPtr.IsValid(), ("You are setting a dest NavGraphEdgePtr whereas a dest NavGraphVertexPtr was set too."));
241  m_destNavGraphVertexPtr.Invalidate();
242 }
243 
244 KY_INLINE void BaseAStarQuery::SetDestNavGraphVertexPtr(const NavGraphVertexPtr& destNavGraphVertexPtr)
245 {
246  m_destNavGraphVertexPtr = destNavGraphVertexPtr;
247  KY_LOG_WARNING_IF(m_destTrianglePtr.IsValid(), ("You are setting a dest NavGraphVertexPtr whereas a dest NavTrianglePtr was set too."));
248  KY_LOG_WARNING_IF(m_destNavGraphEdgePtr.IsValid(), ("You are setting a dest NavGraphVertexPtr whereas a dest NavGraphEdgePtr was set too."));
250  m_destNavGraphEdgePtr.Invalidate();
251 }
252 
253 KY_INLINE AStarQueryResult BaseAStarQuery::GetResult() const { return m_result; }
254 KY_INLINE const Vec3f& BaseAStarQuery::GetDestPos() const { return m_destPos3f; }
255 KY_INLINE const NavTrianglePtr& BaseAStarQuery::GetStartTrianglePtr() const { return m_startTrianglePtr; }
256 KY_INLINE const NavGraphEdgePtr& BaseAStarQuery::GetStartNavGraphEdgePtr() const { return m_startNavGraphEdgePtr; }
257 KY_INLINE const NavGraphVertexPtr& BaseAStarQuery::GetStartNavGraphVertexPtr() const { return m_startNavGraphVertexPtr; }
258 KY_INLINE const NavTrianglePtr& BaseAStarQuery::GetDestTrianglePtr() const { return m_destTrianglePtr; }
259 KY_INLINE const NavGraphEdgePtr& BaseAStarQuery::GetDestNavGraphEdgePtr() const { return m_destNavGraphEdgePtr; }
260 KY_INLINE const NavGraphVertexPtr& BaseAStarQuery::GetDestNavGraphVertexPtr() const { return m_destNavGraphVertexPtr; }
261 KY_INLINE Path* BaseAStarQuery::GetPath() const { return m_path; }
262 KY_INLINE Path* BaseAStarQuery::GetAbstractPath() const { return m_abstractPath; }
263 KY_INLINE AStarQueryTryCanGoMode BaseAStarQuery::GetTryCanGoMode() const { return m_tryCanGoMode; }
264 KY_INLINE PathFinderQueryComputeChannelMode BaseAStarQuery::GetComputeChannelMode() const { return m_computeChannelMode; }
265 KY_INLINE const ChannelComputerConfig& BaseAStarQuery::GetChannelComputerConfig() const { return m_channelComputerConfig; }
266 KY_INLINE const Vec3f* BaseAStarQuery::GetDestination() const { return &GetDestPos(); }
267 KY_INLINE KyFloat32 BaseAStarQuery::GetPropagationBoxExtent() const { return m_propagationBoxExtent; }
268 
269 KY_INLINE KyFloat32 BaseAStarQuery::GetFromOutsideNavMeshDistance() const { return m_traversalParams.GetFromOutsideNavMeshDistance(); }
270 KY_INLINE KyFloat32 BaseAStarQuery::GetToOutsideNavMeshDistance() const { return m_traversalParams.GetToOutsideNavMeshDistance(); }
271 KY_INLINE KyUInt32 BaseAStarQuery::GetNumberOfProcessedNodePerFrame() const { return m_traversalParams.GetNumberOfProcessedNodePerFrame(); }
272 KY_INLINE const Vec3f& BaseAStarQuery::GetStartPos() const { return IPathFinderQuery::GetStartPos(); }
273 
274 KY_INLINE void BaseAStarQuery::SetFromOutsideNavMeshDistance(KyFloat32 fromOutsideNavMeshDistance)
275 {
276  m_traversalParams.SetFromOutsideNavMeshDistance(fromOutsideNavMeshDistance);
277 }
278 KY_INLINE void BaseAStarQuery::SetToOutsideNavMeshDistance(KyFloat32 toOutsideNavMeshDistance)
279 {
280  m_traversalParams.SetToOutsideNavMeshDistance(toOutsideNavMeshDistance);
281 }
282 KY_INLINE void BaseAStarQuery::SetNumberOfProcessedNodePerFrame(KyUInt32 numberOfProcessedNodePerFrame)
283 {
284  m_traversalParams.SetNumberOfProcessedNodePerFrame(numberOfProcessedNodePerFrame);
285 }
286 KY_INLINE void BaseAStarQuery::SetPositionSpatializationRange(const PositionSpatializationRange& positionSpatializationRange)
287 {
288  m_traversalParams.SetPositionSpatializationRange(positionSpatializationRange);
289 }
290 
291 KY_INLINE void BaseAStarQuery::SetAbstractGraphTraversalMode(PathFinderAbstractGraphTraversalMode abstractGraphTraversalMode)
292 {
293  m_traversalParams.SetAbstractGraphTraversalMode(abstractGraphTraversalMode);
294 }
295 
296 KY_INLINE PathFinderAbstractGraphTraversalMode BaseAStarQuery::GetAbstractGraphTraversalMode() const
297 {
298  return m_traversalParams.GetAbstractGraphTraversalMode();
299 }
300 
301 KY_INLINE const PositionSpatializationRange& BaseAStarQuery::GetPositionSpatializationRange() const { return m_traversalParams.GetPositionSpatializationRange(); }
302 
303 KY_INLINE void BaseAStarQuery::ComputePathRefinerConfigInternals() { m_pathRefinerConfig.ComputeInternals();}
304 KY_INLINE const PathRefinerConfig& BaseAStarQuery::GetPathRefinerConfig() const { return m_pathRefinerConfig;}
305 KY_INLINE void BaseAStarQuery::SetPathClamperFlagMask(PathClamperFlagMask pathClamperFlagMask) { m_pathClamperFlagMask = pathClamperFlagMask; }
306 }
307 
308 #endif //Navigation_BaseAstarQuery_H
309 
ChannelComputerConfig m_channelComputerConfig
The parameter set specific to Channels computation.
Definition: ipathfinderquery.h:103
bool IsValid() const
Returns true if this object refers to a valid triangle: i.e. a triangle in a validNavFloor. see NavFloorPtr::IsValid().
Definition: navtriangleptr.h:132
NavTrianglePtr m_startTrianglePtr
The NavMesh triangle that corresponds to m_startPos3f.
Definition: baseastarquery.h:165
void Invalidate()
Invalidates this object.
Definition: navtriangleptr.h:134
Indicates that a path could not be found between the start and destination points.
Definition: baseastarquery.h:50
bool IsValid() const
Returns true if this object refers to a valid NavGraphVertex: i.e. a NavGraphVertex in a validNavGrap...
Definition: navgraphvertexptr.h:113
Vec3f m_destInsidePos3f
if m_destPos3f is slightly outside and we hook on the NavMesh, it is the computed inside pos...
Definition: baseastarquery.h:189
PathFinderQueryComputeChannelMode
This enum tells if the PathFinderQuery should compute Channels around path sections laying on the Nav...
Definition: ipathfinderquery.h:28
Vec3f m_startInsidePos3f
if m_startPos3f is slightly outside and we hook on the NavMesh, it is the computed inside pos...
Definition: baseastarquery.h:188
Unused. Kept here for backward compatibility.
Definition: baseastarquery.h:43
KyFloat32 m_propagationBoxExtent
the propagation is limited to a 2d oriented bounding box computed by inflating the segment going from...
Definition: baseastarquery.h:196
Indicates that a computation error caused the query to stop.
Definition: baseastarquery.h:55
Indicates that insufficient working memory caused the query to stop.
Definition: baseastarquery.h:52
void Invalidate()
Invalidates this object.
Definition: navgraphvertexptr.h:114
Indicates that a computation error caused the query to stop.
Definition: baseastarquery.h:53
Indicates that the refined path is being clamped to navMesh according to the altitude tolerance...
Definition: baseastarquery.h:41
Indicates that the NavTag at the starting point is forbidden.
Definition: baseastarquery.h:47
Indicates the query has not yet been launched.
Definition: baseastarquery.h:32
Indicates that the channel is initialized, the channel is being computed.
Definition: baseastarquery.h:44
void Invalidate()
Invalidates this object.
Definition: navgraphedgeptr.h:130
AStarQueryResult m_result
Updated during processing to indicate the result of the PathFinderQueryResult query.
Definition: baseastarquery.h:201
virtual void DisplayPropagationBounds(ScopedDisplayList &displayList) const
Fill the displayList with display info that may help to understand a PathFinderFailure (mainly propag...
Indicates that the NavTag at the destination point is forbidden.
Definition: baseastarquery.h:49
Indicates that the input channelComputerConfig is invalid.
Definition: baseastarquery.h:54
Ptr< Path > m_path
The Path found by the query.
Definition: ipathfinderquery.h:98
NavGraphEdgeDirection m_navGraphEdgePathfindMode
Whether we should pathfind on that edge both ways or not.
Definition: baseastarquery.h:181
Indicates that the refining process is being initialized.
Definition: baseastarquery.h:37
An internal class that stores parameters used to control the propagation of traversals through the Na...
Definition: traversalparams.h:23
PathFinderQueryComputeChannelMode m_computeChannelMode
The mode toggling Channels computation.
Definition: ipathfinderquery.h:102
Indicates that a NavMesh triangle could not be found for the starting point.
Definition: baseastarquery.h:46
QueryType
Enumerates all the type of query.
Definition: iquery.h:29
Vec3f m_destPos3f
The destination point for the path request.
Definition: baseastarquery.h:187
Indicates that the Astar traversal algorithm has been launched, but has not yet completed.
Definition: baseastarquery.h:34
Indicates the query has not yet been initialized.
Definition: baseastarquery.h:31
Indicates that the refiner is done, but the path has not yet been clamped to the navMesh.
Definition: baseastarquery.h:40
PathFinderAbstractGraphTraversalMode
Enumerates the possible way of dealing with AbstractGraphs.
Definition: pathfinderabstractgraphtraversalmode.h:16
Indicates that the computation has been canceled.
Definition: baseastarquery.h:56
AStarQueryTryCanGoMode
This enums tells if the AstarQuery should try to perform a RayCanGoQuery from start position to desti...
Definition: baseastarquery.h:70
Definition: gamekitcrowddispersion.h:20
virtual void GetPathFinderTextResult(String &) const
Fills the String with an explanation of the result. Use this to debug your pathfinder query...
Ptr< Path > m_abstractPath
The Abstract Path found by the query.
Definition: baseastarquery.h:199
Each instance of this class uniquely identifies a single NavGraphVertex in a NavGraph.
Definition: navgraphvertexptr.h:22
Indicates that the query has not yet been initialized.
Definition: iquery.h:346
PathFinderResult
Enumerates the possible status of a IPathFinderQuery.
Definition: ipathfinderquery.h:43
Indicates that the cost from nodes that are on navMesh are beeing recomputed since they may have been...
Definition: baseastarquery.h:38
NavGraphEdgePtr m_startNavGraphEdgePtr
When this NavGraph edge is valid, that means that you want the path to start with that edge...
Definition: baseastarquery.h:177
Indicates that query starting location and ending location are equals. computing a Path would have le...
Definition: baseastarquery.h:58
NavGraphVertexPtr m_startNavGraphVertexPtr
When this NavGraph vertex is valid, that means that you want the path to start at that vertice...
Definition: baseastarquery.h:184
Indicates that the query has stopped and must be relaunched because of a change in the NavData...
Definition: baseastarquery.h:51
Indicates that the clamping algorithm has completed, but the path has not yet been built...
Definition: baseastarquery.h:42
Each instance of this class uniquely identifies a single NavTriangle in a NavFloor.
Definition: navtriangleptr.h:22
Indicates that the Astar traversal algorithm traversed AbstractGraph, and the Abstract path is being ...
Definition: baseastarquery.h:36
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
bool IsValid() const
Returns true if this object refers to a valid NavGraphEdge: i.e. a NavGraphEdge in a valid NavGraph...
Definition: navgraphedgeptr.h:129
Indicates that the Astar traversal algorithm is finished, and that a path is found and is prepared to...
Definition: baseastarquery.h:35
Indicates that the query has not yet been launched.
Definition: iquery.h:347
virtual const Vec3f * GetDestination() const
This function is virtual because not all the PathFinders have a preset destination, it may return KY_NULL.
Definition: baseastarquery.h:280
Indicates that the destination point of the query is outside the NavMesh.
Definition: baseastarquery.h:48
Each instance of this class uniquely identifies a single and mono-directionnal NavGraphEdge in a NavG...
Definition: navgraphedgeptr.h:25
void Initialize()
Should be called by the derived class before trying to perform the query or to push it in a QueryQueu...
Definition: iquery.h:404
Indicates that a path has been found between the start and destination.
Definition: baseastarquery.h:59
Indicates that the path found is being refined.
Definition: baseastarquery.h:39
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
This class defines a three-dimensional vector whose coordinates are stored using floating-point numbe...
Definition: vec3f.h:23
NavTrianglePtr m_destTrianglePtr
The NavMesh triangle that corresponds to m_destPos3f.
Definition: baseastarquery.h:173
AStarQueryResult
Enumerates the possible results of an AStarQuery.
Definition: baseastarquery.h:29