gwnavruntime/queries/astarquery.h Source File

astarquery.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_AstarQuery_H
10 #define Navigation_AstarQuery_H
11 
17 #include "gwnavruntime/path/path.h"
19 
20 
21 namespace Kaim
22 {
23 
60 
61 
62 template<class TraverseLogic>
63 class AStarQuery : public BaseAStarQuery
64 {
65 public:
66 
67  // ---------------------------------- Public Member Functions ----------------------------------
68 
69  AStarQuery();
70  virtual ~AStarQuery();
71 
72  // ---------------------------------- Functions to set up the query ----------------------------------
73 
77  void BindToDatabase(Database* database);
78 
84  void Initialize(const Vec3f& startPos, const Vec3f& destPos);
85 
86  // ---------------------------------- write accessors for query inputs ----------------------------------
87 
91  void SetStartTrianglePtr(const NavTrianglePtr& startTrianglePtr);
92 
96  void SetStartNavGraphEdgePtr(const NavGraphEdgePtr& startNavGraphEdgePtr, NavGraphEdgeDirection navGraphEdgePathfindMode);
97 
101  void SetStartNavGraphVertexPtr(const NavGraphVertexPtr& startNavGraphVertexPtr);
102 
106  void SetDestTrianglePtr(const NavTrianglePtr& destTrianglePtr);
107 
111  void SetDestNavGraphEdgePtr(const NavGraphEdgePtr& startNavGraphEdgePtr, NavGraphEdgeDirection navGraphEdgePathfindMode);
112 
117  void SetDestNavGraphVertexPtr(const NavGraphVertexPtr& startNavGraphVertexPtr);
118 
119  // ---------------------------------- write accessors for query parameters ----------------------------------
120 
123  void SetPropagationBoxExtent(KyFloat32 propagationBoxExtent);
124 
127  void SetTryCanGoMode(AStarQueryTryCanGoMode tryCanGoMode);
128 
131  void SetFromOutsideNavMeshDistance(KyFloat32 fromOutsideNavMeshDistance);
132 
135  void SetToOutsideNavMeshDistance(KyFloat32 toOutsideNavMeshDistance);
136 
139  void SetPositionSpatializationRange(const PositionSpatializationRange& positionSpatializationRange);
140 
144 
147  void SetChannelComputerConfig(const ChannelComputerConfig& channelComputerConfig);
148 
152 
155  void SetNumberOfProcessedNodePerFrame(KyUInt32 numberOfProcessedNodePerFrame);
156 
157  // ---------------------------------- Query framework functions ----------------------------------
158 
161  virtual void Advance(WorkingMemory* workingMemory);
162 
163  virtual void ReleaseWorkingMemoryOnCancelDuringProcess(WorkingMemory* workingMemory = KY_NULL);
164 
165  // ---------------------------------- Accessors ----------------------------------
166  AStarQueryResult GetResult() const;
167  AStarQueryTryCanGoMode GetTryCanGoMode() const;
168  KyFloat32 GetFromOutsideNavMeshDistance() const;
169  KyFloat32 GetToOutsideNavMeshDistance() const;
170  KyFloat32 GetPropagationBoxExtent() const;
171  const Vec3f& GetStartPos() const;
172  const Vec3f& GetDestPos() const;
173  const NavTrianglePtr& GetStartTrianglePtr() const;
174  const NavGraphEdgePtr& GetStartNavGraphEdgePtr() const;
175  const NavGraphVertexPtr& GetStartNavGraphVertexPtr() const;
176  const NavTrianglePtr& GetDestTrianglePtr() const;
177  const NavGraphEdgePtr& GetDestNavGraphEdgePtr() const;
178  const NavGraphVertexPtr& GetDestNavGraphVertexPtr() const;
179  Path* GetPath() const;
180  KyUInt32 GetNumberOfProcessedNodePerFrame() const;
181 
182  const PositionSpatializationRange& GetPositionSpatializationRange() const;
183 
184  void ComputePathRefinerConfigInternals();
185  const PathRefinerConfig& GetPathRefinerConfig() const;
186 
187 public: //Internal
188  bool HasNavDataChanged();
189 
190 protected:
191  void SetFinish(WorkingMemory* workingMemory);
192  KyResult ComputeStartGraphEdgeOrGraphVertexOrTriangle(PathFinderQueryUtils& queryUtils);
193  KyResult ComputeStartTriangle(PathFinderQueryUtils& queryUtils);
194  KyResult ComputeDestTriangleIfNeeded(PathFinderQueryUtils& queryUtils);
195  KyResult InitializeContextAndStartNode(PathFinderQueryUtils& queryUtils);
196  KyResult InitDestinationNode();
197  KyResult InitDestinationNodeFromDestNavGraphEdge();
198  KyResult InitDestinationNodeFromDestNavGraphVertex();
199  KyResult InitDestinationNodeFromDestNavTriangle();
200  KyResult InitTraversalFromStartNode(PathFinderQueryUtils& queryUtils);
201  void InitPropagationBounds();
202 
203  KyResult CheckNavDataChangeFromAstarContext(WorkingMemory* workingMemory);
204  KyResult CheckNavDataChange(WorkingMemory* workingMemory);
205  bool HasExplorationReachedDestNode();
206 
207  bool ShouldReturnAfterTryingCanGo(WorkingMemory* workingMemory);
208 
209  KyUInt32 CountAbstractGraphNodes(WorkingMemory* workingMemory, AStarNodeIndex& concreteDestinationNodeIdx);
210  void BuildAbstractPath(WorkingMemory* workingMemory, AStarNodeIndex& concreteDestAStarNodeIndex);
211 
212 protected:
213  class TraversalCustomizer
214  {
215  public:
216  typedef TraverseLogic TLogic;
217 
218  TraversalCustomizer();
219 
220 
221  bool CanTraverse(const NavTriangleRawPtr& triangleRawPtr, KyFloat32* costMultiplier);
222  bool CanTraverse(const NavGraphEdgeRawPtr& edgeRawPtr, KyFloat32* costMultiplier);
223  bool CanEnterNavTag(const NavTag& exitNavTag, const NavTag& enterNavTag, const Vec3f& pos);
224  KyFloat32 GetHeuristicFromNodePosition(const Vec3f& nodePosition);
225 
226  void* GetTraverseLogicUserData() const { return m_traverseLogicUserData; }
227  bool ShouldVisitNode(AStarTraversalContext* aStarTraversalContext, AStarNodeIndex nodeIndex);
228  bool IsNodeOutsidePropagationBounds(AStarTraversalContext* aStarTraversalContext, AStarNodeIndex nodeIndex);
229  bool ShouldOpenHalfEdgeNode(const NavHalfEdgeRawPtr& halfEdge, NavHalfEdgeRawPtr& pairHalfEdgeOfNewNode);
230  bool ShouldOpenGraphVertexNode(const NavGraphVertexRawPtr& navGraphVertexRawPtr);
231  bool ShouldOpenAbstractGraphNode(const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr);
232  bool ShouldOpenNavTriangleUnderAbstractGraphNode(const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr);
233  Vec3f ComputeNodePositionOnHalfEdge(AStarTraversalContext* aStarTraversalContext, const Vec3f& startPosOfEdge, const Vec3f& endPosOfEdge, AStarNodeIndex predecessorNodeIndex);
234  KyResult OnNavTriangleExplored(AStarTraversalContext* aStarTraversalContext, const NavTriangleRawPtr& navTriangleRawPtr, AStarNodeIndex currentNodeIndex);
235  KyResult OnNavGraphEdgeExplored(AStarTraversalContext* aStarTraversalContext, const NavGraphEdgeRawPtr& navGraphEdgeRawPtr, AStarNodeIndex currentNodeIndex);
236 
237  OrientedBox2d m_propagationBox;
238  AStarQuery<TraverseLogic>* m_astarQuery;
239  NavTriangleRawPtr m_destTriangleRawPtr;
240  NavGraphEdgeRawPtr m_destNavGraphEdgeRawPtr[2];
242  };
243 
244  AStarTraversal<TraversalCustomizer> m_traversal;
245 };
246 
247 }
248 
250 
251 #endif //Navigation_AstarQuery_H
252 
PathFinderQueryComputeChannelMode
This enum tells if the PathFinderQuery should compute Channels around path sections laying on the Nav...
Definition: ipathfinderquery.h:28
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
This class represents a three-dimensional bounding box with a free orientation on the (X...
Definition: orientedbox2d.h:53
void SetDestNavGraphEdgePtr(const NavGraphEdgePtr &startNavGraphEdgePtr, NavGraphEdgeDirection navGraphEdgePathfindMode)
Optional NavGraph edge you want the dest position must be considered to lie on.
Definition: astarquery.inl:63
void SetChannelComputerConfig(const ChannelComputerConfig &channelComputerConfig)
Write accessor for m_channelComputerConfig.
Definition: astarquery.inl:117
void SetAbstractGraphTraversalMode(PathFinderAbstractGraphTraversalMode abstractGraphTraversalMode)
Write accessor for TraversalParams::m_abstractGraphTraversalMode.
Definition: astarquery.inl:105
Class that aggregates parameters that allow to configure the channel computation of a Bot...
Definition: channelcomputerconfig.h:76
This class is an helper used internaly by the PathFinder Queries to factorize Code.
Definition: pathfinderqueryutils.h:37
virtual void ReleaseWorkingMemoryOnCancelDuringProcess(WorkingMemory *workingMemory=0)
Called when a query is canceled in FlushCommands while its status is QueryInProcess to make sure that...
Definition: astarquery.inl:163
#define KY_NULL
Null value.
Definition: types.h:247
void SetPositionSpatializationRange(const PositionSpatializationRange &positionSpatializationRange)
Write accessor for TraversalParams::m_positionSpatializationRange.
Definition: astarquery.inl:79
void BindToDatabase(Database *database)
Binds the query with the specified Database, clears all the inputs and outputs and sets all other par...
Definition: astarquery.inl:30
Each instance of this class uniquely identifies a single NavGraphEdge in a NavGraph.
Definition: navgraphedgerawptr.h:33
void SetToOutsideNavMeshDistance(KyFloat32 toOutsideNavMeshDistance)
Write accessor for TraversalParams::m_toOutsideNavMeshDistance.
Definition: astarquery.inl:89
void SetNumberOfProcessedNodePerFrame(KyUInt32 numberOfProcessedNodePerFrame)
Write accessor for TraversalParams::m_numberOfVisitedNodePerFrame.
Definition: astarquery.inl:99
void SetStartNavGraphVertexPtr(const NavGraphVertexPtr &startNavGraphVertexPtr)
Optional NavGraph Vertex you want the start position must be considered to be on. ...
Definition: astarquery.inl:57
void SetDestNavGraphVertexPtr(const NavGraphVertexPtr &startNavGraphVertexPtr)
Optional NavGraph Vertex you want the dest position must be considered to be on.
Definition: astarquery.inl:68
void SetPropagationBoxExtent(KyFloat32 propagationBoxExtent)
Write accessor for m_propagationBoxExtent.
Definition: astarquery.inl:94
virtual void Advance(WorkingMemory *workingMemory)
Performs a single iteration of the PathFinder.
Definition: astarquery.inl:227
This class is a runtime container for all NavData that represents the world from the point of view of...
Definition: database.h:64
void SetStartNavGraphEdgePtr(const NavGraphEdgePtr &startNavGraphEdgePtr, NavGraphEdgeDirection navGraphEdgePathfindMode)
Optional NavGraph edge you want the start position must be considered to lie on.
Definition: astarquery.inl:52
PathFinderAbstractGraphTraversalMode
Enumerates the possible way of dealing with AbstractGraphs.
Definition: pathfinderabstractgraphtraversalmode.h:16
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
Runs an A-star algorithm to find a Path through the navigation data (NavMesh & NavGraph) from a start...
Definition: astarquery.h:64
Each instance of this class uniquely identifies a single NavGraphVertex in a NavGraph.
Definition: navgraphvertexptr.h:22
Each instance of this class uniquely identifies a single NavTriangle in a NavFloor.
Definition: navtrianglerawptr.h:30
void SetDestTrianglePtr(const NavTrianglePtr &destTrianglePtr)
The NavMesh triangle that corresponds to m_destPos3f.
Definition: astarquery.inl:47
Each instance of this class uniquely identifies a single NavTriangle in a NavFloor.
Definition: navtriangleptr.h:22
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
void SetTryCanGoMode(AStarQueryTryCanGoMode tryCanGoMode)
Write accessor for m_tryCanGoMode.
Definition: astarquery.inl:74
void SetStartTrianglePtr(const NavTrianglePtr &startTrianglePtr)
The NavMesh triangle that corresponds to m_startPos3f.
Definition: astarquery.inl:42
void * m_traverseLogicUserData
This userData is typically passed by the Bot.
Definition: iquery.h:278
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
void SetComputeChannelMode(PathFinderQueryComputeChannelMode computeChannelMode)
Write accessor for m_computeChannelMode.
Definition: astarquery.inl:111
Each instance of this class uniquely identifies a singleNavHalfEdge in a NavFloor.
Definition: navhalfedgerawptr.h:34
Each instance of this class uniquely identifies a single NavGraphVertex in a NavGraph.
Definition: navgraphvertexrawptr.h:36
The class representing a path.
Definition: path.h:42
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
void SetFromOutsideNavMeshDistance(KyFloat32 fromOutsideNavMeshDistance)
Write accessor for TraversalParams::m_fromOutsideNavMeshDistance.
Definition: astarquery.inl:84
AStarQueryResult
Enumerates the possible results of an AStarQuery.
Definition: baseastarquery.h:29