gwnavruntime/queries/utils/astartraversal.h Source File

astartraversal.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_AStarTraversal_H
10 #define Navigation_AStarTraversal_H
11 
14 
18 
20 
22 
24 
25 namespace Kaim
26 {
27 
28 class TraversalVisitNodeContext
29 {
30 public:
31  TraversalVisitNodeContext() {}
32  void Clear();
33 
34 public:
35  NavGraphVertexRawPtr m_visitedGraphVertexRawPtr;
36  AStarNodeIndex m_visitedNodeIndex;
37 };
38 
39 template<class TraversalCustomzier>
40 class AStarTraversal
41 {
42  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_Query)
43 public:
44  typedef typename TraversalCustomzier::TLogic TraverseLogic;
45 
46  // Constructs a new instance of this class.
47  AStarTraversal() : m_traversalCustomizer(), m_astarContext(KY_NULL), m_traversalParams(KY_NULL) {}
48  AStarTraversal(const TraversalCustomzier& customizer) : m_traversalCustomizer(customizer), m_astarContext(KY_NULL), m_traversalParams(KY_NULL) {}
49 
50  KyResult InitializeContextAndStartNode(QueryUtils& queryUtils, const Vec3f& startPos3f, const NavTrianglePtr& startTrianglePtr);
51  KyResult InitializeContextAndStartNode(QueryUtils& queryUtils, const Vec3f& startPos3f, const NavGraphEdgePtr& startNavGraphEdgePtr);
52  KyResult InitializeContextAndStartNode(QueryUtils& queryUtils, const Vec3f& startPos3f, const NavGraphVertexPtr& startNavGraphVertexPtr);
53 
54  // must be called after the StartNode initialisation
55  KyResult InitializeDestNode(const Vec3f& destPos, const NavTrianglePtr& destTrianglePtr);
56  KyResult InitializeDestNode(const Vec3f& destPos, const NavGraphEdgePtr& destNavGraphEdgePtr);
57  KyResult InitializeDestNode(const NavGraphVertexPtr& destNavGraphVertexPtr);
58 
59  KyResult ExploreAllNodesInTriangle(ActiveData* activeData, const NavTriangleRawPtr& triangleRawPtr, AStarNodeIndex currentNodeIndex);
60  // used only when we start the traversal from a NavGraphEdge
61  KyResult ExploreAllNodesInNavGraphEdge(ActiveData* activeData, const Vec3f& posOnEdge, const NavGraphEdgeRawPtr& navGraphEdgeRawPtr, AStarNodeIndex currentNodeIndex, NavGraphEdgeDirection m_navGraphEdgePathfindMode);
62 
63  KY_INLINE bool IsThereNodeToVisit() { return m_astarContext->m_traversalBinHeap.IsEmpty() == false; }
64 
65  // Performs a single iteration of the AStar Algorithm.
66  KyResult VisitNode(QueryUtils& queryUtils, TraversalVisitNodeContext& visitNodeContext);
67  KyResult UpdateOpenedOrClosedNode(AStarNodeIndex neighborNodeIndex, AStarNodeIndex currentNodeIndex,
68  KyFloat32 costFromCurrentNode, KyFloat32 costMultiplierFromCurrent);
69 
70 private:
71  KyResult ExploreNeighborsOfHalfEdgeNode(ActiveData* activeData, AStarNodeIndex indexOfOpenWithLowerCost, const NavHalfEdgeRawPtr& currentEdgeRawPtr,
72  const NavHalfEdgeRawPtr& pairHalfEdgeRawPtr, const Vec3f& nodePosition, const LogicDoNotUseCanEnterNavTag&);
73  KyResult ExploreNeighborsOfHalfEdgeNode(ActiveData* activeData, AStarNodeIndex indexOfOpenWithLowerCost, const NavHalfEdgeRawPtr& currentEdgeRawPtr,
74  const NavHalfEdgeRawPtr& pairHalfEdgeRawPtr, const Vec3f& nodePosition, const LogicDoUseCanEnterNavTag&);
75 
76  KyResult ExploreNeighborsOfHalfEdgeNode(ActiveData* activeData, AStarNodeIndex indexOfOpenWithLowerCost, const NavHalfEdgeRawPtr& halfEdgeRawPtr);
77  KyResult ExploreNeighborsOfGraphVertexNode(ActiveData* activeData, AStarNodeIndex indexOfOpenWithLowerCost, NavGraphVertexRawPtr& visitedGraphVertexRawPtr);
78  KyResult ExploreNeighborsOfAbstractGraphNode(AStarNodeIndex currentCostNodeIndex, const AbstractGraphNodeRawPtr& currentAbstractNodeRawPtr);
79 
80  KyResult ExploreHalfEdgesOfTriangle(ActiveData* activeData, const NavTriangleRawPtr& triangleRawPtr, AStarNodeIndex currentNodeIndex);
81  KyResult ExploreGraphVerticesInTriangle(const NavTriangleRawPtr& triangleRawPtr, AStarNodeIndex currentNodeIndex);
82 
83  KyResult ExploreAbstractGraphNodesOnNavHalEdgeRawPtr(const NavHalfEdgeRawPtr& navHalfEdgeRawPtr, AStarNodeIndex currentNodeIndex);
84 
85  KyResult CreateNewHalfEdgeNode(ActiveData* activeData, const NavHalfEdgeRawPtr& HalfEdge, const NavHalfEdgeRawPtr& pairHalfEdge,
86  const Vec3f& startPosOfEdge, const Vec3f& endPosOfEdge, AStarNodeIndex predecessorIndex);
87 
88  KyResult CreateNewGraphVertexNode(const NavGraphVertexRawPtr& navGraphVertexRawPtr, AStarNodeIndex predecessorIndex,
89  KyFloat32 costFromCurrentNode, KyFloat32 costMultiplier);
90  KyResult CreateNewAbstractGraphNode(const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr, const AbstractGraphNodeRawPtr& pairedAbstractGraphNodeRawPtr,
91  AStarNodeIndex predecessorNodeIndex, KyFloat32 costFromCurrentNode);
92 
93  KyResult OpenOrUpdateGraphVertex(const NavGraphVertexRawPtr& navGraphVertexRawPtr, AStarNodeIndex vertexNodeIndex, AStarNodeIndex currentNodeIndex,
94  KyFloat32 costFromCurrentNode, KyFloat32 costMultiplier);
95 
96  KyResult OpenOrUpdateHalfEdge(ActiveData* activeData, const NavHalfEdgeRawPtr& halfEdge, AStarNodeIndex halfEdgeNodeIndex,
97  const Vec3f& startPosOfEdge, const Vec3f& endPosOfEdge, AStarNodeIndex currentNodeIndex);
98 
99  KyResult OpenOrUpdateAbstractGraphNode(const AbstractGraphNodeRawPtr& neighborAbstractNodeRawPtr,
100  AStarNodeIndex neighborAstarNodeIndex, AStarNodeIndex currentNodeIndex, KyFloat32 costFromCurrentNode);
101 
102  bool ShouldOpenHalfEdgeNode(const NavHalfEdgeRawPtr& halfEdge, NavHalfEdgeRawPtr& pairHalfEdgeOfNewNode);
103  bool ShouldOpenGraphVertexNode(const NavGraphVertexRawPtr& navGraphVertexRawPtr);
104  bool ShouldOpenAbstractGraphNode(const AbstractGraphNodeRawPtr& abstractGraphNodeRawPtr, AbstractGraphNodeRawPtr& pairedAbstractGraphNodeRawPtr);
105 
106  bool CanTraverseNavTriangle(const NavTriangleRawPtr& triangle);
107  bool CanTraverseNavTriangleAndGetCost(const NavTriangleRawPtr& triangle, const Vec3f& A, const Vec3f& B, KyFloat32& cost, KyFloat32& costMultiplier);
108  bool CanTraverseGraphEdgeAndGetCost(const NavGraphEdgeRawPtr& edge, const Vec3f& A, const Vec3f& B, KyFloat32& cost, KyFloat32& costMultiplier);
109 
110  KyFloat32 EvaluateCostToDest(const Vec3f& nodePosition);
111 
112 public: // internal
113  KyResult InitializeInvalidDestNode();
114 
115 public:
116  TraversalCustomzier m_traversalCustomizer;
117 public:
118  AStarTraversalContext* m_astarContext;
119  TraversalParameters* m_traversalParams;
120 };
121 
122 }
123 
125 
126 #endif //Navigation_AStarTraversal_H
127 
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43