gwnavruntime/channel/channelsectionwidener.h Source File

channelsectionwidener.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_ChannelSectionWidener_H
8 #define Navigation_ChannelSectionWidener_H
9 
15 
16 
17 
18 namespace Kaim
19 {
20 
21 class Database;
22 class Channel;
23 class Gate;
24 class ScopedDisplayList;
25 class ChannelComputerConfig;
26 
27 class ChannelSectionWidener
28 {
29 public:
30  ChannelSectionWidener();
31 
32  void Clear();
33 
34  void SetConfig(const ChannelComputerConfig& config);
35  void SetStartGatePosTrianglePtr(const NavTrianglePtr& sectionStartNavTrianglePtr);
36 
37  void InitializeWidener(Database* database, Channel* channel, const Vec2f& pathEdgeDir2d, KyFloat32 pathEdgeLength,
38  const Vec3f& edgeStartPos, const Vec3f& edgeEndPos, const Vec2f& startGateDirOnLeft,
39  const Vec2f& endGateDirOnLeft, GateType endGateType, const Vec3f& endGateFixedPos);
40 
41  enum WideningSide
42  {
43  WideningSide_LeftAndRight,
44  WideningSide_LeftOnly,
45  WideningSide_RightOnly
46  };
47 
48  template<class TLogic>
49  KyResult WidenChannel(WorkingMemory* workingMem, void* traverseLogicUserData, QueryDynamicOutput* queryDynamicOutput, WideningSide wideningSide);
50 
51 public: //Internal
52  void ConfigureIntersector(PolylineCastIntersector &intersector);
53  KyResult ProcessPolylineCastResult(WorkingMemory* workingMem, PolylineCastIntersector &intersector, WideningSide wideningSide);
54 
55  KyResult AdaptExtremityGatesToPolyline(WideningSide wideningSide);
56  KyResult AddIntermediaryGatesFromPolylines();
57 
58 
59  void MoveIteratorsBeyondX(SharedPoolList<Vec2f>::Iterator& currentLeftIt, SharedPoolList<Vec2f>::Iterator& currentRightIt, KyFloat32 xValue);
60 
61  KyResult FillChannelWithIntermediarygates(WorkingMemory* workingMemory, WideningSide wideningSide);
62 
63  KyResult FixStartGateWidth(WideningSide wideningSide);
64  KyResult AddLastGate(WideningSide wideningSide);
65 
66  void ComputeTrapezoid();
67  void FillExtremityContext(PolylineExtremityContext& context, bool isOnLeft);
68 
69  class GateCandidate
70  {
71  public :
72  GateCandidate() : m_x(KyFloat32MAXVAL), m_yOnLeft(KyFloat32MAXVAL), m_yOnRight(KyFloat32MAXVAL) {}
73 
74  public :
75  KyFloat32 m_x;
76  KyFloat32 m_yOnLeft;
77  KyFloat32 m_yOnRight;
78  };
79 
80  void ComputeGateYValuesNoConstraint(const SharedPoolList<Vec2f>::Iterator& currentLeftIt,
81  const SharedPoolList<Vec2f>::Iterator& currentRightIt, GateCandidate& newGate);
82 
83  KyResult ComputeGateYValuesWithXandYDiffConstraint(const SharedPoolList<Vec2f>::Iterator& currentLeftIt,
84  const SharedPoolList<Vec2f>::Iterator& currentRightIt, GateCandidate& currentGate, GateCandidate& newGate);
85 
86  KyResult ComputeGateYValuesWithXConstraintFromCurrentGate(const SharedPoolList<Vec2f>::Iterator& currentLeftIt,
87  const SharedPoolList<Vec2f>::Iterator& currentRightIt, GateCandidate& currentGate, GateCandidate& newGate,
88  KyFloat32* differenceFromBorder = KY_NULL, KyFloat32* moreConstraintXForMaxDist = KY_NULL);
89  KyResult ComputeGateYValuesWithXConstraintFromCurrentGateOnLeft(const SharedPoolList<Vec2f>::Iterator& currentLeftIt,
90  GateCandidate &currentGate, GateCandidate &newGate, KyFloat32& differenceFromBorder, KyFloat32& moreConstraintX);
91  KyResult ComputeGateYValuesWithXConstraintFromCurrentGateOnRight(const SharedPoolList<Vec2f>::Iterator& currentRightIt,
92  GateCandidate &currentGate, GateCandidate &newGate, KyFloat32& differenceFromBorder, KyFloat32& moreConstraintX);
93 
94  KyResult ComputeYValuesOfCurrentGateAndEndGate(const SharedPoolList<Vec2f>::Iterator& currentLeftIt, const SharedPoolList<Vec2f>::Iterator& currentRightIt,
95  GateCandidate& currentGate, KyFloat32* differenceFromBorder = KY_NULL, KyFloat32* moreConstraintXForMaxDist = KY_NULL);
96  KyResult ComputeYValuesOfCurrentGateAndEndGateOnLeft(const SharedPoolList<Vec2f>::Iterator& currentRightIt, GateCandidate& currentGate,
97  KyFloat32& differenceFromBorder, KyFloat32& moreConstraintX);
98  KyResult ComputeYValuesOfCurrentGateAndEndGateOnRight(const SharedPoolList<Vec2f>::Iterator& currentRightIt, GateCandidate& currentGate,
99  KyFloat32& differenceFromBorder, KyFloat32& moreConstraintX);
100 
101  KyResult ComputelastIntermediaryGateAndEndGate(SharedPoolList<Vec2f>::Iterator &currentLeftIt, SharedPoolList<Vec2f>::Iterator &currentRightIt, GateCandidate& currentGate);
102  KyResult AddIntermediaryGateAtX(SharedPoolList<Vec2f>::Iterator& currentLeftIt, SharedPoolList<Vec2f>::Iterator& currentRightIt, GateCandidate& currentGate, KyFloat32 xValue);
103 
104  void AddGatesToRespectMaxDistanceBetweenGates(const SharedPoolList<Vec2f>::Iterator& currentLeftIt,
105  const SharedPoolList<Vec2f>::Iterator& currentRightIt, GateCandidate& currentGate, GateCandidate& newGate);
106 
107  SharedPoolList<Vec2f>::Iterator GetMoreConstraintSlopeForward(const Vec2f& point, SharedPoolList<Vec2f>& polyline,
108  const SharedPoolList<Vec2f>::Iterator& currentIt, const SharedPoolList<Vec2f>::Iterator& firstIteratorNotToTest);
109  SharedPoolList<Vec2f>::Iterator GetMoreConstraintSlopeBackward(const Vec2f& point, SharedPoolList<Vec2f>& polyline,
110  const SharedPoolList<Vec2f>::Iterator& currentIt, const SharedPoolList<Vec2f>::Iterator& firstIteratorNotToTest);
111 
112  KY_INLINE bool CanMoveLeftStartPos() const { return m_startType != LeftTurnEnd; }
113  KY_INLINE bool CanMoveRightStartPos() const { return m_startType != RightTurnEnd; }
114  KY_INLINE bool CanMoveLeftEndPos() const { return m_endType != LeftTurnStart; }
115  KY_INLINE bool CanMoveRightEndPos() const { return m_endType != RightTurnStart; }
116 public:
117  ChannelBorderSimplifier m_simplifier;
118  Database* m_database;
119  Channel* m_channel;
120 
121  // input
122  Vec3f m_edgeStartPos;
123  Vec3f m_edgeEndPos;
124  Vec2f m_startGateDirOnLeft;
125  Vec2f m_endGateDirOnLeft;
126  Vec3f m_endGateFixedPos; // not relevant for endGate
127  GateType m_startType;
128  GateType m_endType;
129 
130  NavTrianglePtr m_sectionStartNavTriangle;
131  WorldIntegerPos m_edgeStartIntegerPos;
132 
133  // input & output
134  Vec2f m_startGateLeftPos;
135  Vec2f m_startGateRightPos;
136 
137  // working members
138  KyFloat32 m_margin;
139  Vec3f m_trapezoidStartLeftPos;
140  Vec3f m_trapezoidEndLeftPos;
141  Vec3f m_trapezoidStartRightPos;
142  Vec3f m_trapezoidEndRightPos;
143  KyArray<GateCandidate> m_gates;
144 
145  SharedPoolList<GateCandidate>::NodePool m_gatePool;
146  SharedPoolList<GateCandidate> m_gateCandidates;
147 
148  Vec2f m_startLeftLocal;
149  Vec2f m_startRightLocal;
150  Vec2f m_endLeftLocal;
151  Vec2f m_endRightLocal;
152  KyFloat32 m_startGateMaxX;
153  KyFloat32 m_endGateMinX;
154 
155  KyFloat32 m_tooFarFromBorderThreshold;
156  KyFloat32 m_internalMinDistFromBorder;
157  ScopedDisplayList* m_displayList;
158 };
159 
160 // Class for scoped object defined in ChannelSectionWidener::WidenChannel
161 // do not use KY_EXIT_SCOPE_BEGIN inside function to avoid link error on vc8 with scoped object declared in template function
162 KY_EXIT_CLASS_SCOPE_BEGIN(ChannelSectionWidener, WidenChannel)
163 KY_DELETE_AND_SET_NULL(self->m_displayList);
164 KY_EXIT_CLASS_SCOPE_END
165 
166 template<class TLogic>
167 inline KyResult ChannelSectionWidener::WidenChannel(WorkingMemory* workingMem, void* traverseLogicUserData, QueryDynamicOutput* queryDynamicOutput, WideningSide wideningSide)
168 {
169  KY_EXIT_SCOPE_INSTANCE(ChannelSectionWidener, WidenChannel);
170 
171  if (m_simplifier.m_advancedVisualDebuggingEnabled)
172  {
173  m_displayList = KY_NEW ScopedDisplayList(m_simplifier.m_database->GetWorld());
174  m_displayList->InitSingleFrameLifespan("temp Gates", "ChannelSectionWidener");
175  }
176 
177  // collect borders
178  PolylineCastIntersector intersector;
179  ConfigureIntersector(intersector);
180 
181  if (PolylineCastHelper::RunPolylineCast<TLogic>(workingMem, m_database, traverseLogicUserData, queryDynamicOutput, intersector) == KY_ERROR)
182  return KY_ERROR;
183 
184  return ProcessPolylineCastResult(workingMem, intersector, wideningSide);
185 }
186 
187 } // namespace Kaim
188 
189 #endif // Navigation_ChannelSectionWidener_H
Indicates the Gate is the start of a sampled turn to the left (CCW). The next Gate must have either L...
Definition: channel.h:31
Indicates the Gate is a right turn end.
Definition: channel.h:38
#define KyFloat32MAXVAL
The maximum value that can be stored in the KyFloat32 variable type.
Definition: types.h:227
KyInt32 KyResult
Defines a type that can be returned by methods or functions in the Gameware Navigation SDK to indicat...
Definition: types.h:254
GateType
Enumerates the different kind of Gates.
Definition: channel.h:23
Indicates the Gate is a left turn end.
Definition: channel.h:33
Indicates the Gate is the start of a sampled turn to the right (CW). The next Gate must have either R...
Definition: channel.h:36
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
#define KY_ERROR
Shorthand for Kaim::Result::Failure.
Definition: types.h:272
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43