gwnavruntime/channel/diagonalstripcomputer.h Source File

diagonalstripcomputer.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 #ifndef Navigation_DiagonalStripComputer_H
8 #define Navigation_DiagonalStripComputer_H
9 
11 #include "gwnavruntime/path/path.h"
12 
14 
15 
21 
24 
25 
26 namespace Kaim
27 {
28 
29 class DiagonalStripComputerContext;
30 class Path;
31 
32 class DiagonalStripComputerConfig
33 {
34 public:
35  DiagonalStripComputerConfig() { SetDefaults(); }
36  void SetDefaults()
37  {
38  m_idealClearanceRadius = 2.5f;
39  m_idealPathDistFromCorners = 1.0f;
40  m_advancedVisualDebuggingEnabled = false;
41  }
42 
43  KyFloat32 m_idealClearanceRadius;
44  KyFloat32 m_idealPathDistFromCorners;
45  bool m_advancedVisualDebuggingEnabled;
46 };
47 
49 {
52 
53  DiagonalStripResult_BuildDiagonalForPathEdge,
54  DiagonalStripResult_ComputingMaxRadius_Init,
55  DiagonalStripResult_ComputingMaxRadius,
56  DiagonalStripResult_ComputingNeighborCompatibleRadius_Backward_Init,
57  DiagonalStripResult_ComputingNeighborCompatibleRadius_Backward,
58  DiagonalStripResult_ComputingNeighborCompatibleRadius_Forward_Init,
59  DiagonalStripResult_ComputingNeighborCompatibleRadius_Forward,
60 
61  DiagonalStripResult_Done_DiagonalStripComputerError,
62  DiagonalStripResult_Done_ComputeMaxRadiusError,
63  DiagonalStripResult_Done_ComputeNeighborCompatibleRadiusError,
64 
65  DiagonalStripResult_Done
66 };
67 
68 enum DiagonalStripJunctionType
69 {
70  JunctionType_Slanting,
71  JunctionType_AlmostOrtho
72 };
73 
74 class DiagonalStripComputer
75 {
76 public:
77  KY_DEFINE_NEW_DELETE_OPERATORS(MemStat_QueryWorkingMem)
78 public:
79  DiagonalStripComputer();
80  ~DiagonalStripComputer();
81 
82  void Clear();
83  void Init(Database* database, const Path* path, KyUInt32 firstEdgeIdxOfSection, KyUInt32 lastEdgeIdxOfSection, DiagonalStrip* diagonalStrip);
84 
85  bool IsFinished() const { return m_result >= DiagonalStripResult_Done_DiagonalStripComputerError; }
86 
87  void* GetTraverseLogicUserData() const { return m_traverseLogicUserData; }
88  void SetTraverseLogicUserData(void* traverseLogicUserData) { m_traverseLogicUserData = traverseLogicUserData; }
89 
90  DiagonalStripComputerResult GetResult() const { return m_result; }
91  DiagonalStripComputerConfig& GetComputerConfig() { return m_computerConfig; }
92  void SetComputerConfig(const DiagonalStripComputerConfig& computerConfig) { m_computerConfig = computerConfig; }
93 
94 protected:
95  KyResult ComputeCornerRadius(KyUInt32 cornerIdx);
96 
97  enum ComputeCompatibleRadiusResult { OutOfNeighborhood, Shrinked, Unchanged };
98 
99  KyResult ComputeForwardNeighborCompatibleCornerRadius(KyUInt32 cornerIdx);
100  KyResult ComputeBackwardNeighborCompatibleCornerRadius(KyUInt32 cornerIdx);
101  ComputeCompatibleRadiusResult ComputeCompatibleRadius(const Vec3f& cornerPos, CornerType cornerType, KyUInt32 otherIdx, KyFloat32& cornerRadius);
102 
103  void InitContext(DiagonalStripComputerContext& context, WorkingMemory* workingMemory);
104  void PostProcessPolylineCastResult(PolylineCastIntersector& clearancePolygonIntersector);
105  KyResult FillDiagonalStripFromPolylineCastResult(PolylineCastIntersector& clearancePolygonIntersector);
106  bool IsCCWQuadConvex(const Vec3f& A, const Vec3f& B, const Vec3f& C, const Vec3f& D);
107  void ComputeBissectriceEndPoints(DiagonalStripComputerContext& context, const Vec3f& nextPointOnPath, KyFloat32 nextEdgelength2D,
108  KyFloat32 dotProdWithNextEdge, KyFloat32 crossProdWithNextEdge);
109 
110  bool PushCorner(const Vec3f& pos, CornerType cornerType, bool force = false);
111  bool DiagonalStripComputerGetLastButOnCornerPos(CornerType cornerType, Vec3f& pos);
112  KyResult MakeJunctionWithCurrentDiagonalStrip(PolylineCastIntersector& clearancePolygonIntersector);
113  void PushEndPoint();
114 public :
115  template<class TraverseLogic>
116  void Advance(WorkingMemory* workingMemory, ChannelArrayComputerStats& channelStats);
117 
118  template<class TraverseLogic>
119  KyResult ComputeDiagonalsFromPath(WorkingMemory* workingMemory, ChannelArrayComputerStats& stats);
120 
121  template<class TraverseLogic>
122  KyResult BuildDiagonalsForPathEdge(WorkingMemory* workingMemory);
123 
124  template<class TraverseLogic>
125  KyResult ProcessTheOneTrapezeStartingThePolygon(WorkingMemory* workingMemory, DiagonalStripComputerContext& context, KyFloat32 maxDotProdStart);
126 
127  template<class TraverseLogic>
128  KyResult ProcessPolygonWithTriangles(WorkingMemory* workingMemory, DiagonalStripComputerContext& context,
129  Vec3f& bissectricIntersection, bool bissectriceIntersect, KyFloat32 maxDotProdStart, KyFloat32 minDotProdEnd);
130 
131  template<class TraverseLogic>
132  KyResult ProcessTwoOppositeTriangles(WorkingMemory* workingMemory, DiagonalStripComputerContext& context,
133  const Vec3f& endPointLeft, const Vec3f& endPointRight, const Vec3f& endPointOnPath);
134 
135  template<class TraverseLogic>
136  KyResult EndPolygonFromAlmostOrthoStart(WorkingMemory* workingMemory, DiagonalStripComputerContext& context, KyFloat32 minDotProdEnd);
137 
138  template<class TraverseLogic>
139  KyResult BuildDiagonalsInTrapeze(WorkingMemory* workingMemory, const Vec3f& pathEdgeStart, const Vec3f& pathEdgeEnd, NavTrianglePtr& inAndOutTrianglePtr,
140  const Vec3f& pointOnStartSideLeft, const Vec3f& pointOnEndSideLeft, const Vec3f& pointOnStartSideRight, const Vec3f& pointOnEndSideRight);
141 
142  template<class TraverseLogic>
143  KyResult BuildDiagonalsInTriangle(WorkingMemory* workingMemory, const Vec3f& pathEdgeStart, const Vec3f& pathEdgeEnd, NavTrianglePtr& inAndOutTrianglePtr,
144  const Vec3f& pointOnStartSideLeft, const Vec3f& pointOnStartSideRight, const Vec3f& pointOnEndSideLeft, const Vec3f& pointOnEndSideRight, bool forceTrapeze = false);
145 public: // internal
146  void ClearDisplayList();
147  void CreateDisplayList();
148  static VisualShapeColor GetVisualDebugQuadColor();
149  static VisualShapeColor GetVisualDebugTriangleColor();
150 protected:
151  Database* m_database;
152  DiagonalStripComputerConfig m_computerConfig;
153  void* m_traverseLogicUserData;
154  KyFloat32 m_cornerMaxRadius;
155 
157 
158  const Path* m_rawPath;
159 
160  DiagonalStrip* m_diagonalStrip;
161 
162  // diagonal strip temp
163  KyUInt32 m_currentPathEdgeIdx;
164  KyUInt32 m_firstEdgeIdxOfSection;
165  KyUInt32 m_lastEdgeIdxOfSection;
166  KyInt32 m_currentCornerIdx;
167 
168  Vec3f m_startPointOnLeft;
169  Vec3f m_startPointOnRight;
170  DiagonalStripJunctionType m_startJunctionType;
171  Vec3f m_lastStripCornerLeft;
172  Vec3f m_lastStripCornerRight;
173  ScopedDisplayList* m_displayList;
174 
175 };
176 
177 
178 } // namespace Kaim
179 
180 
181 
183 
184 
185 #endif // Navigation_DiagonalStripComputer_H
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
Indicates the query has not yet been launched.
Definition: diagonalstripcomputer.h:52
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
Definition: gamekitcrowddispersion.h:20
DiagonalStripComputerResult
Definition: diagonalstripcomputer.h:49
Indicates that the query has not yet been initialized.
Definition: iquery.h:346
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137
unsigned int KyUInt32
Type used internally to represent an unsigned 32-bit integer.
Definition: types.h:36
Indicates that the query has not yet been launched.
Definition: iquery.h:347
Indicates the query has not yet been initialized.
Definition: diagonalstripcomputer.h:51
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43